TestHelpers.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. using CsvHelper.Configuration.Attributes;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Globalization;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Text;
  10. using System.Text.RegularExpressions;
  11. using Xunit;
  12. using Xunit.Abstractions;
  13. using Xunit.Sdk;
  14. namespace Terminal.Gui;
  15. // This class enables test functions annotated with the [AutoInitShutdown] attribute to
  16. // automatically call Application.Init at start of the test and Application.Shutdown after the
  17. // test exits.
  18. //
  19. // This is necessary because a) Application is a singleton and Init/Shutdown must be called
  20. // as a pair, and b) all unit test functions should be atomic..
  21. [AttributeUsage (AttributeTargets.Class | AttributeTargets.Method)]
  22. public class AutoInitShutdownAttribute : BeforeAfterTestAttribute {
  23. readonly Type _driverType;
  24. /// <summary>
  25. /// Initializes a [AutoInitShutdown] attribute, which determines if/how Application.Init and
  26. /// Application.Shutdown are automatically called Before/After a test runs.
  27. /// </summary>
  28. /// <param name="autoInit">If true, Application.Init will be called Before the test runs.</param>
  29. /// <param name="autoShutdown">If true, Application.Shutdown will be called After the test runs.</param>
  30. /// <param name="consoleDriverType">
  31. /// Determines which ConsoleDriver (FakeDriver, WindowsDriver,
  32. /// CursesDriver, NetDriver) will be used when Application.Init is called. If null FakeDriver will be used.
  33. /// Only valid if <paramref name="autoInit"/> is true.
  34. /// </param>
  35. /// <param name="useFakeClipboard">
  36. /// If true, will force the use of <see cref="FakeDriver.FakeClipboard"/>.
  37. /// Only valid if <see cref="ConsoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.
  38. /// </param>
  39. /// <param name="fakeClipboardAlwaysThrowsNotSupportedException">
  40. /// Only valid if <paramref name="autoInit"/> is true.
  41. /// Only valid if <see cref="ConsoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.
  42. /// </param>
  43. /// <param name="fakeClipboardIsSupportedAlwaysTrue">
  44. /// Only valid if <paramref name="autoInit"/> is true.
  45. /// Only valid if <see cref="ConsoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.
  46. /// </param>
  47. /// <param name="configLocation">
  48. /// Determines what config file locations <see cref="ConfigurationManager"/> will
  49. /// load from.
  50. /// </param>
  51. public AutoInitShutdownAttribute (bool autoInit = true,
  52. Type consoleDriverType = null,
  53. bool useFakeClipboard = true,
  54. bool fakeClipboardAlwaysThrowsNotSupportedException = false,
  55. bool fakeClipboardIsSupportedAlwaysTrue = false,
  56. ConfigurationManager.ConfigLocations configLocation = ConfigurationManager.ConfigLocations.DefaultOnly)
  57. {
  58. AutoInit = autoInit;
  59. CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo ("en-US");
  60. _driverType = consoleDriverType ?? typeof (FakeDriver);
  61. FakeDriver.FakeBehaviors.UseFakeClipboard = useFakeClipboard;
  62. FakeDriver.FakeBehaviors.FakeClipboardAlwaysThrowsNotSupportedException = fakeClipboardAlwaysThrowsNotSupportedException;
  63. FakeDriver.FakeBehaviors.FakeClipboardIsSupportedAlwaysFalse = fakeClipboardIsSupportedAlwaysTrue;
  64. ConfigurationManager.Locations = configLocation;
  65. }
  66. bool AutoInit { get; }
  67. public override void Before (MethodInfo methodUnderTest)
  68. {
  69. Debug.WriteLine ($"Before: {methodUnderTest.Name}");
  70. if (AutoInit) {
  71. #if DEBUG_IDISPOSABLE
  72. // Clear out any lingering Responder instances from previous tests
  73. if (Responder.Instances.Count == 0) {
  74. Assert.Empty (Responder.Instances);
  75. } else {
  76. Responder.Instances.Clear ();
  77. }
  78. #endif
  79. Application.Init ((ConsoleDriver)Activator.CreateInstance (_driverType));
  80. }
  81. }
  82. public override void After (MethodInfo methodUnderTest)
  83. {
  84. Debug.WriteLine ($"After: {methodUnderTest.Name}");
  85. if (AutoInit) {
  86. Application.Shutdown ();
  87. #if DEBUG_IDISPOSABLE
  88. if (Responder.Instances.Count == 0) {
  89. Assert.Empty (Responder.Instances);
  90. } else {
  91. Responder.Instances.Clear ();
  92. }
  93. #endif
  94. }
  95. }
  96. }
  97. [AttributeUsage (AttributeTargets.Class | AttributeTargets.Method)]
  98. public class TestRespondersDisposed : BeforeAfterTestAttribute {
  99. public TestRespondersDisposed () => CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo ("en-US");
  100. public override void Before (MethodInfo methodUnderTest)
  101. {
  102. Debug.WriteLine ($"Before: {methodUnderTest.Name}");
  103. #if DEBUG_IDISPOSABLE
  104. // Clear out any lingering Responder instances from previous tests
  105. Responder.Instances.Clear ();
  106. Assert.Empty (Responder.Instances);
  107. #endif
  108. }
  109. public override void After (MethodInfo methodUnderTest)
  110. {
  111. Debug.WriteLine ($"After: {methodUnderTest.Name}");
  112. #if DEBUG_IDISPOSABLE
  113. Assert.Empty (Responder.Instances);
  114. #endif
  115. }
  116. }
  117. [AttributeUsage (AttributeTargets.Class | AttributeTargets.Method)]
  118. public class SetupFakeDriverAttribute : BeforeAfterTestAttribute {
  119. /// <summary>
  120. /// Enables test functions annotated with the [SetupFakeDriver] attribute to
  121. /// set Application.Driver to new FakeDriver(). The driver is setup with
  122. /// 10 rows and columns.
  123. /// </summary>
  124. public SetupFakeDriverAttribute () { }
  125. public override void Before (MethodInfo methodUnderTest)
  126. {
  127. Debug.WriteLine ($"Before: {methodUnderTest.Name}");
  128. Assert.Null (Application.Driver);
  129. Application.Driver = new FakeDriver () { Rows = 10, Cols = 10 };
  130. }
  131. public override void After (MethodInfo methodUnderTest)
  132. {
  133. Debug.WriteLine ($"After: {methodUnderTest.Name}");
  134. Application.Driver = null;
  135. }
  136. }
  137. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
  138. public class TestDateAttribute : Xunit.Sdk.BeforeAfterTestAttribute
  139. {
  140. CultureInfo _currentCulture = CultureInfo.CurrentCulture;
  141. public TestDateAttribute()
  142. {
  143. CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
  144. }
  145. public override void Before(MethodInfo methodUnderTest)
  146. {
  147. Assert.Equal(CultureInfo.CurrentCulture, CultureInfo.InvariantCulture);
  148. }
  149. public override void After(MethodInfo methodUnderTest)
  150. {
  151. CultureInfo.CurrentCulture = _currentCulture;
  152. Assert.Equal(CultureInfo.CurrentCulture, _currentCulture);
  153. }
  154. }
  155. partial class TestHelpers {
  156. [GeneratedRegex ("\\s+$", RegexOptions.Multiline)]
  157. private static partial Regex TrailingWhiteSpaceRegEx ();
  158. [GeneratedRegex ("^\\s+", RegexOptions.Multiline)]
  159. private static partial Regex LeadingWhitespaceRegEx ();
  160. public static string DriverContentsToString (ConsoleDriver driver = null)
  161. {
  162. var sb = new StringBuilder ();
  163. driver ??= Application.Driver;
  164. var contents = driver.Contents;
  165. for (var r = 0; r < driver.Rows; r++) {
  166. for (var c = 0; c < driver.Cols; c++) {
  167. var rune = contents [r, c].Rune;
  168. if (rune.DecodeSurrogatePair (out var sp)) {
  169. sb.Append (sp);
  170. } else {
  171. sb.Append ((char)rune.Value);
  172. }
  173. if (rune.GetColumns () > 1) {
  174. c++;
  175. }
  176. // See Issue #2616
  177. //foreach (var combMark in contents [r, c].CombiningMarks) {
  178. // sb.Append ((char)combMark.Value);
  179. //}
  180. }
  181. sb.AppendLine ();
  182. }
  183. return sb.ToString ();
  184. }
  185. #pragma warning disable xUnit1013 // Public method should be marked as test
  186. /// <summary>
  187. /// Asserts that the driver contents match the expected contents, optionally ignoring any trailing whitespace.
  188. /// </summary>
  189. /// <param name="expectedLook"></param>
  190. /// <param name="output"></param>
  191. /// <param name="driver">The ConsoleDriver to use. If null <see cref="Application.Driver"/> will be used.</param>
  192. /// <param name="ignoreLeadingWhitespace"></param>
  193. public static void AssertDriverContentsAre (string expectedLook, ITestOutputHelper output, ConsoleDriver driver = null, bool ignoreLeadingWhitespace = false)
  194. {
  195. #pragma warning restore xUnit1013 // Public method should be marked as test
  196. var actualLook = DriverContentsToString (driver);
  197. if (string.Equals (expectedLook, actualLook)) {
  198. return;
  199. }
  200. // get rid of trailing whitespace on each line (and leading/trailing whitespace of start/end of full string)
  201. expectedLook = TrailingWhiteSpaceRegEx ().Replace (expectedLook, "").Trim ();
  202. actualLook = TrailingWhiteSpaceRegEx ().Replace (actualLook, "").Trim ();
  203. if (ignoreLeadingWhitespace) {
  204. expectedLook = LeadingWhitespaceRegEx ().Replace (expectedLook, "").Trim ();
  205. actualLook = LeadingWhitespaceRegEx ().Replace (actualLook, "").Trim ();
  206. }
  207. // standardize line endings for the comparison
  208. expectedLook = expectedLook.Replace ("\r\n", "\n");
  209. actualLook = actualLook.Replace ("\r\n", "\n");
  210. // If test is about to fail show user what things looked like
  211. if (!string.Equals (expectedLook, actualLook)) {
  212. output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
  213. output?.WriteLine (" But Was:" + Environment.NewLine + actualLook);
  214. }
  215. Assert.Equal (expectedLook, actualLook);
  216. }
  217. /// <summary>
  218. /// Asserts that the driver contents are equal to the expected look, and that the cursor is at the expected position.
  219. /// </summary>
  220. /// <param name="expectedLook"></param>
  221. /// <param name="output"></param>
  222. /// <param name="driver">The ConsoleDriver to use. If null <see cref="Application.Driver"/> will be used.</param>
  223. /// <returns></returns>
  224. public static Rect AssertDriverContentsWithFrameAre (string expectedLook, ITestOutputHelper output, ConsoleDriver driver = null)
  225. {
  226. var lines = new List<List<Rune>> ();
  227. var sb = new StringBuilder ();
  228. driver ??= Application.Driver;
  229. var x = -1;
  230. var y = -1;
  231. var w = -1;
  232. var h = -1;
  233. var contents = driver.Contents;
  234. for (var r = 0; r < driver.Rows; r++) {
  235. var runes = new List<Rune> ();
  236. for (var c = 0; c < driver.Cols; c++) {
  237. var rune = contents [r, c].Rune;
  238. if (rune != (Rune)' ') {
  239. if (x == -1) {
  240. x = c;
  241. y = r;
  242. for (var i = 0; i < c; i++) {
  243. runes.InsertRange (i, new List<Rune> { (Rune)' ' });
  244. }
  245. }
  246. if (rune.GetColumns () > 1) {
  247. c++;
  248. }
  249. if (c + 1 > w) {
  250. w = c + 1;
  251. }
  252. h = r - y + 1;
  253. }
  254. if (x > -1) {
  255. runes.Add (rune);
  256. }
  257. // See Issue #2616
  258. //foreach (var combMark in contents [r, c].CombiningMarks) {
  259. // runes.Add (combMark);
  260. //}
  261. }
  262. if (runes.Count > 0) {
  263. lines.Add (runes);
  264. }
  265. }
  266. // Remove unnecessary empty lines
  267. if (lines.Count > 0) {
  268. for (var r = lines.Count - 1; r > h - 1; r--) {
  269. lines.RemoveAt (r);
  270. }
  271. }
  272. // Remove trailing whitespace on each line
  273. foreach (var row in lines) {
  274. for (var c = row.Count - 1; c >= 0; c--) {
  275. var rune = row [c];
  276. if (rune != (Rune)' ' || row.Sum (x => x.GetColumns ()) == w) {
  277. break;
  278. }
  279. row.RemoveAt (c);
  280. }
  281. }
  282. // Convert Rune list to string
  283. for (var r = 0; r < lines.Count; r++) {
  284. var line = StringExtensions.ToString (lines [r]);
  285. if (r == lines.Count - 1) {
  286. sb.Append (line);
  287. } else {
  288. sb.AppendLine (line);
  289. }
  290. }
  291. var actualLook = sb.ToString ();
  292. if (string.Equals (expectedLook, actualLook)) {
  293. return new Rect (x > -1 ? x : 0, y > -1 ? y : 0, w > -1 ? w : 0, h > -1 ? h : 0);
  294. }
  295. // standardize line endings for the comparison
  296. expectedLook = expectedLook.Replace ("\r\n", "\n");
  297. actualLook = actualLook.Replace ("\r\n", "\n");
  298. // Remove the first and the last line ending from the expectedLook
  299. if (expectedLook.StartsWith ("\n")) {
  300. expectedLook = expectedLook [1..];
  301. }
  302. if (expectedLook.EndsWith ("\n")) {
  303. expectedLook = expectedLook [..^1];
  304. }
  305. output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
  306. output?.WriteLine (" But Was:" + Environment.NewLine + actualLook);
  307. Assert.Equal (expectedLook, actualLook);
  308. return new Rect (x > -1 ? x : 0, y > -1 ? y : 0, w > -1 ? w : 0, h > -1 ? h : 0);
  309. }
  310. #pragma warning disable xUnit1013 // Public method should be marked as test
  311. /// <summary>
  312. /// Verifies <paramref name="expectedAttributes"/> are found at the locations specified by <paramref name="expectedLook"/>.
  313. /// <paramref name="expectedLook"/> is a bitmap of indexes into <paramref name="expectedAttributes"/> (e.g. "00110"
  314. /// means the attribute at <c>expectedAttributes[1]</c> is expected at the 3rd and 4th columns of the 1st row of driver.Contents).
  315. /// </summary>
  316. /// <param name="expectedLook">
  317. /// Numbers between 0 and 9 for each row/col of the console. Must be valid indexes into <paramref name="expectedAttributes"/>.
  318. /// </param>
  319. /// <param name="driver">The ConsoleDriver to use. If null <see cref="Application.Driver"/> will be used.</param>
  320. /// <param name="expectedAttributes"></param>
  321. public static void AssertDriverAttributesAre (string expectedLook, ConsoleDriver driver = null, params Attribute [] expectedAttributes)
  322. {
  323. #pragma warning restore xUnit1013 // Public method should be marked as test
  324. if (expectedAttributes.Length > 10) {
  325. throw new ArgumentException ("This method only works for UIs that use at most 10 colors");
  326. }
  327. expectedLook = expectedLook.Trim ();
  328. driver ??= Application.Driver;
  329. var contents = driver.Contents;
  330. var line = 0;
  331. foreach (var lineString in expectedLook.Split ('\n').Select (l => l.Trim ())) {
  332. for (var c = 0; c < lineString.Length; c++) {
  333. var val = contents [line, c].Attribute;
  334. var match = expectedAttributes.Where (e => e == val).ToList ();
  335. switch (match.Count) {
  336. case 0:
  337. throw new Exception ($"{DriverContentsToString (driver)}\n" +
  338. $"Expected Attribute {val} (PlatformColor = {val.Value.PlatformColor}) at Contents[{line},{c}] {contents [line, c]} ((PlatformColor = {contents [line, c].Attribute.Value.PlatformColor}) was not found.\n" +
  339. $" Expected: {string.Join (",", expectedAttributes.Select (c => c))}\n" +
  340. $" But Was: <not found>");
  341. case > 1:
  342. throw new ArgumentException ($"Bad value for expectedColors, {match.Count} Attributes had the same Value");
  343. }
  344. var colorUsed = Array.IndexOf (expectedAttributes, match [0]).ToString () [0];
  345. var userExpected = lineString [c];
  346. if (colorUsed != userExpected) {
  347. throw new Exception ($"{DriverContentsToString (driver)}\n" +
  348. $"Unexpected Attribute at Contents[{line},{c}] {contents [line, c]}.\n" +
  349. $" Expected: {userExpected} ({expectedAttributes [int.Parse (userExpected.ToString ())]})\n" +
  350. $" But Was: {colorUsed} ({val})\n");
  351. }
  352. }
  353. line++;
  354. }
  355. }
  356. /// <summary>
  357. /// Verifies the console used all the <paramref name="expectedColors"/> when rendering.
  358. /// If one or more of the expected colors are not used then the failure will output both
  359. /// the colors that were found to be used and which of your expectations was not met.
  360. /// </summary>
  361. /// <param name="driver">if null uses <see cref="Application.Driver"/></param>
  362. /// <param name="expectedColors"></param>
  363. internal static void AssertDriverUsedColors (ConsoleDriver driver = null, params Attribute [] expectedColors)
  364. {
  365. driver ??= Application.Driver;
  366. var contents = driver.Contents;
  367. var toFind = expectedColors.ToList ();
  368. // Contents 3rd column is an Attribute
  369. var colorsUsed = new HashSet<Attribute> ();
  370. for (var r = 0; r < driver.Rows; r++) {
  371. for (var c = 0; c < driver.Cols; c++) {
  372. var val = contents [r, c].Attribute;
  373. if (val.HasValue) {
  374. colorsUsed.Add (val.Value);
  375. var match = toFind.FirstOrDefault (e => e == val);
  376. // need to check twice because Attribute is a struct and therefore cannot be null
  377. if (toFind.Any (e => e == val)) {
  378. toFind.Remove (match);
  379. }
  380. }
  381. }
  382. }
  383. if (!toFind.Any ()) {
  384. return;
  385. }
  386. var sb = new StringBuilder ();
  387. sb.AppendLine ("The following colors were not used:" + string.Join ("; ", toFind.Select (a => a.ToString ())));
  388. sb.AppendLine ("Colors used were:" + string.Join ("; ", colorsUsed.Select (a => a.ToString ())));
  389. throw new Exception (sb.ToString ());
  390. }
  391. #pragma warning disable xUnit1013 // Public method should be marked as test
  392. /// <summary>
  393. /// Verifies two strings are equivalent. If the assert fails, output will be generated to standard
  394. /// output showing the expected and actual look.
  395. /// </summary>
  396. /// <param name="output"></param>
  397. /// <param name="expectedLook">
  398. /// A string containing the expected look. Newlines should be specified as "\r\n" as
  399. /// they will be converted to <see cref="Environment.NewLine"/> to make tests platform independent.
  400. /// </param>
  401. /// <param name="actualLook"></param>
  402. public static void AssertEqual (ITestOutputHelper output, string expectedLook, string actualLook)
  403. {
  404. // Convert newlines to platform-specific newlines
  405. expectedLook = ReplaceNewLinesToPlatformSpecific (expectedLook);
  406. // If test is about to fail show user what things looked like
  407. if (!string.Equals (expectedLook, actualLook)) {
  408. output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
  409. output?.WriteLine (" But Was:" + Environment.NewLine + actualLook);
  410. }
  411. Assert.Equal (expectedLook, actualLook);
  412. }
  413. #pragma warning restore xUnit1013 // Public method should be marked as test
  414. static string ReplaceNewLinesToPlatformSpecific (string toReplace)
  415. {
  416. var replaced = toReplace;
  417. replaced = Environment.NewLine.Length switch {
  418. 2 when !replaced.Contains ("\r\n") => replaced.Replace ("\n", Environment.NewLine),
  419. 1 => replaced.Replace ("\r\n", Environment.NewLine),
  420. var _ => replaced
  421. };
  422. return replaced;
  423. }
  424. /// <summary>
  425. /// Gets a list of instances of all classes derived from View.
  426. /// </summary>
  427. /// <returns>List of View objects</returns>
  428. public static List<View> GetAllViews () => typeof (View).Assembly.GetTypes ()
  429. .Where (type => type.IsClass && !type.IsAbstract && type.IsPublic && type.IsSubclassOf (typeof (View)))
  430. .Select (type => GetTypeInitializer (type, type.GetConstructor (Array.Empty<Type> ()))).ToList ();
  431. static View GetTypeInitializer (Type type, ConstructorInfo ctor)
  432. {
  433. View viewType = null;
  434. if (type.IsGenericType && type.IsTypeDefinition) {
  435. var gTypes = new List<Type> ();
  436. foreach (var args in type.GetGenericArguments ()) {
  437. gTypes.Add (typeof (object));
  438. }
  439. type = type.MakeGenericType (gTypes.ToArray ());
  440. Assert.IsType (type, (View)Activator.CreateInstance (type));
  441. } else {
  442. var paramsInfo = ctor.GetParameters ();
  443. Type paramType;
  444. var pTypes = new List<object> ();
  445. if (type.IsGenericType) {
  446. foreach (var args in type.GetGenericArguments ()) {
  447. paramType = args.GetType ();
  448. if (args.Name == "T") {
  449. pTypes.Add (typeof (object));
  450. } else {
  451. AddArguments (paramType, pTypes);
  452. }
  453. }
  454. }
  455. foreach (var p in paramsInfo) {
  456. paramType = p.ParameterType;
  457. if (p.HasDefaultValue) {
  458. pTypes.Add (p.DefaultValue);
  459. } else {
  460. AddArguments (paramType, pTypes);
  461. }
  462. }
  463. if (type.IsGenericType && !type.IsTypeDefinition) {
  464. viewType = (View)Activator.CreateInstance (type);
  465. Assert.IsType (type, viewType);
  466. } else {
  467. viewType = (View)ctor.Invoke (pTypes.ToArray ());
  468. Assert.IsType (type, viewType);
  469. }
  470. }
  471. return viewType;
  472. }
  473. static void AddArguments (Type paramType, List<object> pTypes)
  474. {
  475. if (paramType == typeof (Rect)) {
  476. pTypes.Add (Rect.Empty);
  477. } else if (paramType == typeof (string)) {
  478. pTypes.Add (string.Empty);
  479. } else if (paramType == typeof (int)) {
  480. pTypes.Add (0);
  481. } else if (paramType == typeof (bool)) {
  482. pTypes.Add (true);
  483. } else if (paramType.Name == "IList") {
  484. pTypes.Add (new List<object> ());
  485. } else if (paramType.Name == "View") {
  486. var top = new Toplevel ();
  487. var view = new View ();
  488. top.Add (view);
  489. pTypes.Add (view);
  490. } else if (paramType.Name == "View[]") {
  491. pTypes.Add (new View [] { });
  492. } else if (paramType.Name == "Stream") {
  493. pTypes.Add (new MemoryStream ());
  494. } else if (paramType.Name == "String") {
  495. pTypes.Add (string.Empty);
  496. } else if (paramType.Name == "TreeView`1[T]") {
  497. pTypes.Add (string.Empty);
  498. } else {
  499. pTypes.Add (null);
  500. }
  501. }
  502. }