PageRenderTime 61ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/Src/Compilers/CSharp/Test/Emit/CodeGen/WinRTCollectionTests.cs

https://github.com/EkardNT/Roslyn
C# | 7443 lines | 7248 code | 42 blank | 153 comment | 2 complexity | 6c30fac654fbeaf461328d7ac2aac221 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. // Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  2. using System.Collections.Generic;
  3. using Microsoft.CodeAnalysis.CSharp;
  4. using Microsoft.CodeAnalysis.CSharp.Symbols;
  5. using Microsoft.CodeAnalysis.CSharp.Syntax;
  6. using ProprietaryTestResources = Microsoft.CodeAnalysis.Test.Resources.Proprietary;
  7. using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
  8. using Microsoft.CodeAnalysis.Test.Utilities;
  9. using Roslyn.Test.Utilities;
  10. using Xunit;
  11. namespace Microsoft.CodeAnalysis.CSharp.UnitTests.CodeGen
  12. {
  13. public class WinRTCollectionTests : CSharpTestBase
  14. {
  15. private MetadataReference[] _legacyRefs = null;
  16. public MetadataReference[] LegacyRefs
  17. {
  18. get
  19. {
  20. if (_legacyRefs == null)
  21. {
  22. var list = new List<MetadataReference>(WinRtRefs.Length + 2);
  23. list.AddRange(WinRtRefs);
  24. list.Add(
  25. new MetadataImageReference(
  26. TestResources.WinRt.Windows_Languages_WinRTTest.AsImmutableOrNull(),
  27. display: "WinRTTest"));
  28. list.Add(
  29. new MetadataImageReference(
  30. ProprietaryTestResources.NetFX.v4_0_30319_17929.System_Core.AsImmutableOrNull(),
  31. display: "SystemCore"));
  32. _legacyRefs = list.ToArray();
  33. }
  34. return _legacyRefs;
  35. }
  36. }
  37. [Fact, WorkItem(762316, "DevDiv")]
  38. public void InheritFromTypeWithProjections()
  39. {
  40. var source = @"
  41. using Windows.UI.Xaml;
  42. public sealed class BehaviorCollection : DependencyObjectCollection
  43. {
  44. private int count;
  45. public BehaviorCollection()
  46. {
  47. count = this.Count;
  48. }
  49. public object GetItem(int i)
  50. {
  51. return this[i];
  52. }
  53. }";
  54. var comp = CreateCompilationWithMscorlib45(source, references: WinRtRefs);
  55. comp.VerifyDiagnostics();
  56. }
  57. [Fact]
  58. public void IVectorProjectionTests()
  59. {
  60. var source =
  61. @"using System;
  62. using Windows.Data.Json;
  63. public class Class1
  64. {
  65. public static void Main(string[] args)
  66. {
  67. var jsonArray = new JsonArray();
  68. var a = JsonValue.CreateStringValue(""a"");
  69. jsonArray.Add(a);
  70. var b = JsonValue.CreateStringValue(""b"");
  71. jsonArray.Insert(0, b);
  72. jsonArray.Remove(b);
  73. Console.WriteLine(jsonArray.Contains(b));
  74. Console.WriteLine(jsonArray.IndexOf(a));
  75. jsonArray.RemoveAt(0);
  76. Console.WriteLine(jsonArray.Count);
  77. jsonArray.Add(b);
  78. foreach (var json in jsonArray)
  79. {
  80. Console.WriteLine(json.GetString());
  81. }
  82. Console.WriteLine(jsonArray.Count);
  83. jsonArray.Clear();
  84. Console.WriteLine(jsonArray.Count);
  85. }
  86. }";
  87. string expectedOutput =
  88. @"False
  89. 0
  90. 0
  91. b
  92. 1
  93. 0";
  94. var verifier = CompileAndVerifyOnWin8Only(source,
  95. expectedOutput: expectedOutput,
  96. additionalRefs: WinRtRefs,
  97. emitOptions: EmitOptions.RefEmitBug);
  98. verifier.VerifyIL("Class1.Main",
  99. @"{
  100. // Code size 174 (0xae)
  101. .maxstack 3
  102. .locals init (Windows.Data.Json.JsonArray V_0, //jsonArray
  103. Windows.Data.Json.JsonValue V_1, //a
  104. Windows.Data.Json.JsonValue V_2, //b
  105. System.Collections.Generic.IEnumerator<Windows.Data.Json.IJsonValue> V_3)
  106. IL_0000: newobj ""Windows.Data.Json.JsonArray..ctor()""
  107. IL_0005: stloc.0
  108. IL_0006: ldstr ""a""
  109. IL_000b: call ""Windows.Data.Json.JsonValue Windows.Data.Json.JsonValue.CreateStringValue(string)""
  110. IL_0010: stloc.1
  111. IL_0011: ldloc.0
  112. IL_0012: ldloc.1
  113. IL_0013: callvirt ""void System.Collections.Generic.ICollection<Windows.Data.Json.IJsonValue>.Add(Windows.Data.Json.IJsonValue)""
  114. IL_0018: ldstr ""b""
  115. IL_001d: call ""Windows.Data.Json.JsonValue Windows.Data.Json.JsonValue.CreateStringValue(string)""
  116. IL_0022: stloc.2
  117. IL_0023: ldloc.0
  118. IL_0024: ldc.i4.0
  119. IL_0025: ldloc.2
  120. IL_0026: callvirt ""void System.Collections.Generic.IList<Windows.Data.Json.IJsonValue>.Insert(int, Windows.Data.Json.IJsonValue)""
  121. IL_002b: ldloc.0
  122. IL_002c: ldloc.2
  123. IL_002d: callvirt ""bool System.Collections.Generic.ICollection<Windows.Data.Json.IJsonValue>.Remove(Windows.Data.Json.IJsonValue)""
  124. IL_0032: pop
  125. IL_0033: ldloc.0
  126. IL_0034: ldloc.2
  127. IL_0035: callvirt ""bool System.Collections.Generic.ICollection<Windows.Data.Json.IJsonValue>.Contains(Windows.Data.Json.IJsonValue)""
  128. IL_003a: call ""void System.Console.WriteLine(bool)""
  129. IL_003f: ldloc.0
  130. IL_0040: ldloc.1
  131. IL_0041: callvirt ""int System.Collections.Generic.IList<Windows.Data.Json.IJsonValue>.IndexOf(Windows.Data.Json.IJsonValue)""
  132. IL_0046: call ""void System.Console.WriteLine(int)""
  133. IL_004b: ldloc.0
  134. IL_004c: ldc.i4.0
  135. IL_004d: callvirt ""void System.Collections.Generic.IList<Windows.Data.Json.IJsonValue>.RemoveAt(int)""
  136. IL_0052: ldloc.0
  137. IL_0053: callvirt ""int System.Collections.Generic.ICollection<Windows.Data.Json.IJsonValue>.Count.get""
  138. IL_0058: call ""void System.Console.WriteLine(int)""
  139. IL_005d: ldloc.0
  140. IL_005e: ldloc.2
  141. IL_005f: callvirt ""void System.Collections.Generic.ICollection<Windows.Data.Json.IJsonValue>.Add(Windows.Data.Json.IJsonValue)""
  142. IL_0064: ldloc.0
  143. IL_0065: callvirt ""System.Collections.Generic.IEnumerator<Windows.Data.Json.IJsonValue> System.Collections.Generic.IEnumerable<Windows.Data.Json.IJsonValue>.GetEnumerator()""
  144. IL_006a: stloc.3
  145. .try
  146. {
  147. IL_006b: br.s IL_007d
  148. IL_006d: ldloc.3
  149. IL_006e: callvirt ""Windows.Data.Json.IJsonValue System.Collections.Generic.IEnumerator<Windows.Data.Json.IJsonValue>.Current.get""
  150. IL_0073: callvirt ""string Windows.Data.Json.IJsonValue.GetString()""
  151. IL_0078: call ""void System.Console.WriteLine(string)""
  152. IL_007d: ldloc.3
  153. IL_007e: callvirt ""bool System.Collections.IEnumerator.MoveNext()""
  154. IL_0083: brtrue.s IL_006d
  155. IL_0085: leave.s IL_0091
  156. }
  157. finally
  158. {
  159. IL_0087: ldloc.3
  160. IL_0088: brfalse.s IL_0090
  161. IL_008a: ldloc.3
  162. IL_008b: callvirt ""void System.IDisposable.Dispose()""
  163. IL_0090: endfinally
  164. }
  165. IL_0091: ldloc.0
  166. IL_0092: callvirt ""int System.Collections.Generic.ICollection<Windows.Data.Json.IJsonValue>.Count.get""
  167. IL_0097: call ""void System.Console.WriteLine(int)""
  168. IL_009c: ldloc.0
  169. IL_009d: callvirt ""void System.Collections.Generic.ICollection<Windows.Data.Json.IJsonValue>.Clear()""
  170. IL_00a2: ldloc.0
  171. IL_00a3: callvirt ""int System.Collections.Generic.ICollection<Windows.Data.Json.IJsonValue>.Count.get""
  172. IL_00a8: call ""void System.Console.WriteLine(int)""
  173. IL_00ad: ret
  174. }
  175. ");
  176. }
  177. [Fact]
  178. public void IVectorViewProjectionTests()
  179. {
  180. var source =
  181. @"using System;
  182. using Windows.Foundation;
  183. public class Class1
  184. {
  185. public static void Main(string[] args)
  186. {
  187. var results = new WwwFormUrlDecoder(""?param1=test"");
  188. Console.Out.WriteLine(results[0].Name + results[0].Value);
  189. }
  190. }";
  191. var expectedOut = "param1test";
  192. var verifier = CompileAndVerifyOnWin8Only(
  193. source,
  194. expectedOutput: expectedOut,
  195. additionalRefs: WinRtRefs,
  196. emitOptions: EmitOptions.RefEmitBug);
  197. verifier.VerifyIL("Class1.Main",
  198. @"{
  199. // Code size 51 (0x33)
  200. .maxstack 4
  201. .locals init (Windows.Foundation.WwwFormUrlDecoder V_0) //results
  202. IL_0000: ldstr ""?param1=test""
  203. IL_0005: newobj ""Windows.Foundation.WwwFormUrlDecoder..ctor(string)""
  204. IL_000a: stloc.0
  205. IL_000b: call ""System.IO.TextWriter System.Console.Out.get""
  206. IL_0010: ldloc.0
  207. IL_0011: ldc.i4.0
  208. IL_0012: callvirt ""Windows.Foundation.IWwwFormUrlDecoderEntry System.Collections.Generic.IReadOnlyList<Windows.Foundation.IWwwFormUrlDecoderEntry>.this[int].get""
  209. IL_0017: callvirt ""string Windows.Foundation.IWwwFormUrlDecoderEntry.Name.get""
  210. IL_001c: ldloc.0
  211. IL_001d: ldc.i4.0
  212. IL_001e: callvirt ""Windows.Foundation.IWwwFormUrlDecoderEntry System.Collections.Generic.IReadOnlyList<Windows.Foundation.IWwwFormUrlDecoderEntry>.this[int].get""
  213. IL_0023: callvirt ""string Windows.Foundation.IWwwFormUrlDecoderEntry.Value.get""
  214. IL_0028: call ""string string.Concat(string, string)""
  215. IL_002d: callvirt ""void System.IO.TextWriter.WriteLine(string)""
  216. IL_0032: ret
  217. }");
  218. }
  219. [Fact]
  220. public void IMapProjectionTests()
  221. {
  222. var source =
  223. @"using System;
  224. using System.Collections.Generic;
  225. using Windows.ApplicationModel.DataTransfer;
  226. public class Class1
  227. {
  228. public static void Main(string[] args)
  229. {
  230. var dataPackage = new DataPackage();
  231. var dpps = dataPackage.Properties;
  232. dpps.Add(new KeyValuePair<string, object>(""testKey1"", ""testValue1""));
  233. Console.Out.WriteLine(dpps.ContainsKey(""testKey1""));
  234. Console.Out.WriteLine(dpps[""testKey1""]);
  235. dpps.Add(""testKey2"", ""testValue2"");
  236. object tv2;
  237. dpps.TryGetValue(""testKey2"", out tv2);
  238. Console.Out.WriteLine(tv2);
  239. dpps[""testKey2""] = ""testValue3"";
  240. dpps.Remove(""testKey1"");
  241. var valsEnumerator = dpps.Values.GetEnumerator();
  242. var keysEnumerator = dpps.Keys.GetEnumerator();
  243. while (keysEnumerator.MoveNext() && valsEnumerator.MoveNext())
  244. {
  245. Console.Out.WriteLine(keysEnumerator.Current + valsEnumerator.Current);
  246. }
  247. }
  248. }";
  249. var expectedOut =
  250. @"True
  251. testValue1
  252. testValue2
  253. testKey2testValue3
  254. ";
  255. var verifier = CompileAndVerifyOnWin8Only(
  256. source,
  257. expectedOutput: expectedOut,
  258. additionalRefs: WinRtRefs,
  259. emitOptions: EmitOptions.RefEmitBug);
  260. verifier.VerifyIL("Class1.Main",
  261. @"{
  262. // Code size 213 (0xd5)
  263. .maxstack 3
  264. .locals init (Windows.ApplicationModel.DataTransfer.DataPackagePropertySet V_0, //dpps
  265. object V_1, //tv2
  266. System.Collections.Generic.IEnumerator<object> V_2, //valsEnumerator
  267. System.Collections.Generic.IEnumerator<string> V_3) //keysEnumerator
  268. IL_0000: newobj ""Windows.ApplicationModel.DataTransfer.DataPackage..ctor()""
  269. IL_0005: callvirt ""Windows.ApplicationModel.DataTransfer.DataPackagePropertySet Windows.ApplicationModel.DataTransfer.DataPackage.Properties.get""
  270. IL_000a: stloc.0
  271. IL_000b: ldloc.0
  272. IL_000c: ldstr ""testKey1""
  273. IL_0011: ldstr ""testValue1""
  274. IL_0016: newobj ""System.Collections.Generic.KeyValuePair<string, object>..ctor(string, object)""
  275. IL_001b: callvirt ""void System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string, object>>.Add(System.Collections.Generic.KeyValuePair<string, object>)""
  276. IL_0020: call ""System.IO.TextWriter System.Console.Out.get""
  277. IL_0025: ldloc.0
  278. IL_0026: ldstr ""testKey1""
  279. IL_002b: callvirt ""bool System.Collections.Generic.IDictionary<string, object>.ContainsKey(string)""
  280. IL_0030: callvirt ""void System.IO.TextWriter.WriteLine(bool)""
  281. IL_0035: call ""System.IO.TextWriter System.Console.Out.get""
  282. IL_003a: ldloc.0
  283. IL_003b: ldstr ""testKey1""
  284. IL_0040: callvirt ""object System.Collections.Generic.IDictionary<string, object>.this[string].get""
  285. IL_0045: callvirt ""void System.IO.TextWriter.WriteLine(object)""
  286. IL_004a: ldloc.0
  287. IL_004b: ldstr ""testKey2""
  288. IL_0050: ldstr ""testValue2""
  289. IL_0055: callvirt ""void System.Collections.Generic.IDictionary<string, object>.Add(string, object)""
  290. IL_005a: ldloc.0
  291. IL_005b: ldstr ""testKey2""
  292. IL_0060: ldloca.s V_1
  293. IL_0062: callvirt ""bool System.Collections.Generic.IDictionary<string, object>.TryGetValue(string, out object)""
  294. IL_0067: pop
  295. IL_0068: call ""System.IO.TextWriter System.Console.Out.get""
  296. IL_006d: ldloc.1
  297. IL_006e: callvirt ""void System.IO.TextWriter.WriteLine(object)""
  298. IL_0073: ldloc.0
  299. IL_0074: ldstr ""testKey2""
  300. IL_0079: ldstr ""testValue3""
  301. IL_007e: callvirt ""void System.Collections.Generic.IDictionary<string, object>.this[string].set""
  302. IL_0083: ldloc.0
  303. IL_0084: ldstr ""testKey1""
  304. IL_0089: callvirt ""bool System.Collections.Generic.IDictionary<string, object>.Remove(string)""
  305. IL_008e: pop
  306. IL_008f: ldloc.0
  307. IL_0090: callvirt ""System.Collections.Generic.ICollection<object> System.Collections.Generic.IDictionary<string, object>.Values.get""
  308. IL_0095: callvirt ""System.Collections.Generic.IEnumerator<object> System.Collections.Generic.IEnumerable<object>.GetEnumerator()""
  309. IL_009a: stloc.2
  310. IL_009b: ldloc.0
  311. IL_009c: callvirt ""System.Collections.Generic.ICollection<string> System.Collections.Generic.IDictionary<string, object>.Keys.get""
  312. IL_00a1: callvirt ""System.Collections.Generic.IEnumerator<string> System.Collections.Generic.IEnumerable<string>.GetEnumerator()""
  313. IL_00a6: stloc.3
  314. IL_00a7: br.s IL_00c4
  315. IL_00a9: call ""System.IO.TextWriter System.Console.Out.get""
  316. IL_00ae: ldloc.3
  317. IL_00af: callvirt ""string System.Collections.Generic.IEnumerator<string>.Current.get""
  318. IL_00b4: ldloc.2
  319. IL_00b5: callvirt ""object System.Collections.Generic.IEnumerator<object>.Current.get""
  320. IL_00ba: call ""string string.Concat(object, object)""
  321. IL_00bf: callvirt ""void System.IO.TextWriter.WriteLine(string)""
  322. IL_00c4: ldloc.3
  323. IL_00c5: callvirt ""bool System.Collections.IEnumerator.MoveNext()""
  324. IL_00ca: brfalse.s IL_00d4
  325. IL_00cc: ldloc.2
  326. IL_00cd: callvirt ""bool System.Collections.IEnumerator.MoveNext()""
  327. IL_00d2: brtrue.s IL_00a9
  328. IL_00d4: ret
  329. }");
  330. }
  331. // TODO: There are no suitable winmd members to test the IMapView projections,
  332. // a custom winmd will have to be used after winmd references are implemented
  333. [Fact]
  334. public void MultipleInterfaceMethodConflictTests()
  335. {
  336. var source =
  337. @"using Windows.Data.Json;
  338. using Windows.Foundation;
  339. public class Class1
  340. {
  341. public static void Main(string[] args)
  342. {
  343. var en = new JsonArray().GetEnumerator();
  344. en = new WwwFormUrlDecoder(""?param1=test"").GetEnumerator();
  345. }
  346. }";
  347. var comp = CreateCompilation(source, references: WinRtRefs);
  348. // JsonArray implements both IEnumerable and IList, which both have a GetEnumerator
  349. // method. We can't know which interface method to call, so we shouldn't emit a
  350. // GetEnumerator method at all.
  351. comp.VerifyDiagnostics(
  352. Diagnostic(ErrorCode.ERR_NoSuchMemberOrExtension, "GetEnumerator")
  353. .WithArguments("Windows.Data.Json.JsonArray", "GetEnumerator"),
  354. Diagnostic(ErrorCode.ERR_NoSuchMemberOrExtension, "GetEnumerator")
  355. .WithArguments("Windows.Foundation.WwwFormUrlDecoder", "GetEnumerator"));
  356. }
  357. [Fact]
  358. public void LegacyCollectionTest01()
  359. {
  360. var source =
  361. @"using Windows.Languages.WinRTTest;
  362. using System.Collections.Generic;
  363. using System.Reflection;
  364. using System.Linq.Expressions;
  365. using System;
  366. using System.Linq;
  367. class AllMembers
  368. {
  369. private static int FailedCount = 0;
  370. private static bool ValidateMethod(TestMethodCalled actual, TestMethodCalled expected)
  371. {
  372. var temp = Console.ForegroundColor;
  373. if (actual != expected)
  374. {
  375. FailedCount++;
  376. Console.ForegroundColor = ConsoleColor.Red;
  377. Console.Write(""FAIL: "");
  378. }
  379. else
  380. {
  381. Console.ForegroundColor = ConsoleColor.Green;
  382. Console.Write(""PASS: "");
  383. }
  384. Console.ForegroundColor = temp;
  385. Console.WriteLine(""Expected: {0}, Actual: {1}"", expected, actual);
  386. return actual == expected;
  387. }
  388. private static bool ValidateValue(object actual, object expected)
  389. {
  390. var temp = Console.ForegroundColor;
  391. if (actual.ToString() != expected.ToString())
  392. {
  393. FailedCount++;
  394. Console.ForegroundColor = ConsoleColor.Red;
  395. Console.Write(""FAIL: "");
  396. }
  397. else
  398. {
  399. Console.ForegroundColor = ConsoleColor.Green;
  400. Console.Write(""PASS: "");
  401. }
  402. Console.ForegroundColor = temp;
  403. Console.WriteLine(""Expected: {0}, Actual: {1}"", expected, actual);
  404. return actual.ToString() == expected.ToString();
  405. }
  406. static void TestIIterableMembers()
  407. {
  408. Console.WriteLine(""=== IIterableFloat ==="");
  409. var i = new IIterableFloat();
  410. i.ClearFlag();
  411. IEnumerator<float> enumerator = ((IEnumerable<float>)i).GetEnumerator();
  412. ValidateMethod(i.GetFlagState(), TestMethodCalled.IIterable_First);
  413. }
  414. static int Main()
  415. {
  416. TestIIterableMembers();
  417. Console.WriteLine(FailedCount);
  418. return FailedCount;
  419. }
  420. }";
  421. var verifier = CompileAndVerify(source,
  422. additionalRefs: LegacyRefs,
  423. emitOptions: EmitOptions.RefEmitBug,
  424. verify: false);
  425. verifier.VerifyDiagnostics(
  426. // (3,1): info CS8019: Unnecessary using directive.
  427. // using System.Reflection;
  428. Diagnostic(ErrorCode.INF_UnusedUsingDirective, "using System.Reflection;"),
  429. // (4,1): info CS8019: Unnecessary using directive.
  430. // using System.Linq.Expressions;
  431. Diagnostic(ErrorCode.INF_UnusedUsingDirective, "using System.Linq.Expressions;"),
  432. // (6,1): info CS8019: Unnecessary using directive.
  433. // using System.Linq;
  434. Diagnostic(ErrorCode.INF_UnusedUsingDirective, "using System.Linq;"));
  435. verifier.VerifyIL("AllMembers.TestIIterableMembers",
  436. @"{
  437. // Code size 41 (0x29)
  438. .maxstack 2
  439. IL_0000: ldstr ""=== IIterableFloat ===""
  440. IL_0005: call ""void System.Console.WriteLine(string)""
  441. IL_000a: newobj ""Windows.Languages.WinRTTest.IIterableFloat..ctor()""
  442. IL_000f: dup
  443. IL_0010: callvirt ""void Windows.Languages.WinRTTest.IIterableFloat.ClearFlag()""
  444. IL_0015: dup
  445. IL_0016: callvirt ""System.Collections.Generic.IEnumerator<float> System.Collections.Generic.IEnumerable<float>.GetEnumerator()""
  446. IL_001b: pop
  447. IL_001c: callvirt ""Windows.Languages.WinRTTest.TestMethodCalled Windows.Languages.WinRTTest.IIterableFloat.GetFlagState()""
  448. IL_0021: ldc.i4.1
  449. IL_0022: call ""bool AllMembers.ValidateMethod(Windows.Languages.WinRTTest.TestMethodCalled, Windows.Languages.WinRTTest.TestMethodCalled)""
  450. IL_0027: pop
  451. IL_0028: ret
  452. }");
  453. }
  454. [Fact]
  455. public void LegacyCollectionTest02()
  456. {
  457. var source =
  458. @"using Windows.Languages.WinRTTest;
  459. using System.Collections.Generic;
  460. using System.Reflection;
  461. using System.Linq.Expressions;
  462. using System;
  463. using System.Linq;
  464. class AllMembers
  465. {
  466. private static int FailedCount = 0;
  467. private static bool ValidateMethod(TestMethodCalled actual, TestMethodCalled expected)
  468. {
  469. var temp = Console.ForegroundColor;
  470. if (actual != expected)
  471. {
  472. FailedCount++;
  473. Console.ForegroundColor = ConsoleColor.Red;
  474. Console.Write(""FAIL: "");
  475. }
  476. else
  477. {
  478. Console.ForegroundColor = ConsoleColor.Green;
  479. Console.Write(""PASS: "");
  480. }
  481. Console.ForegroundColor = temp;
  482. Console.WriteLine(""Expected: {0}, Actual: {1}"", expected, actual);
  483. return actual == expected;
  484. }
  485. private static bool ValidateValue(object actual, object expected)
  486. {
  487. var temp = Console.ForegroundColor;
  488. if (actual.ToString() != expected.ToString())
  489. {
  490. FailedCount++;
  491. Console.ForegroundColor = ConsoleColor.Red;
  492. Console.Write(""FAIL: "");
  493. }
  494. else
  495. {
  496. Console.ForegroundColor = ConsoleColor.Green;
  497. Console.Write(""PASS: "");
  498. }
  499. Console.ForegroundColor = temp;
  500. Console.WriteLine(""Expected: {0}, Actual: {1}"", expected, actual);
  501. return actual.ToString() == expected.ToString();
  502. }
  503. static void TestIVectorIntMembers()
  504. {
  505. Console.WriteLine(""=== IVectorInt ==="");
  506. var v = new IVectorInt();
  507. //Add
  508. v.ClearFlag();
  509. v.Add(1);
  510. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
  511. ValidateValue(v[0], 1);
  512. //Contains
  513. v.ClearFlag();
  514. bool b = v.Contains(1);
  515. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  516. ValidateValue(b, true);
  517. //CopyTo
  518. v.ClearFlag();
  519. int[] arr = new int[10];
  520. v.CopyTo(arr, 0);
  521. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  522. ValidateValue(arr[0], 1);
  523. ValidateValue(arr[1], 0); //there should be nothing there! :)
  524. //GetEnumerator
  525. v.ClearFlag();
  526. int count = v.Count;
  527. IEnumerator<int> enumerator = ((IEnumerable<int>)v).GetEnumerator();
  528. ValidateMethod(v.GetFlagState(), TestMethodCalled.IIterable_First);
  529. int index = 0;
  530. foreach (var e in v)
  531. {
  532. index = index + 1;
  533. ValidateValue(e, index);
  534. }
  535. ValidateValue(index, 1); //there should only be 1 element there
  536. //IndexOf
  537. v.ClearFlag();
  538. var rez = v.IndexOf(1);
  539. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  540. ValidateValue(rez, 0); // 1 is on the first line :)
  541. //Insert
  542. v.ClearFlag();
  543. v.Insert(1, 2);
  544. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
  545. ValidateValue(v[1], 2);
  546. //IsReadOnly
  547. v.ClearFlag();
  548. bool isReadOnly = v.IsReadOnly;
  549. ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
  550. ValidateValue(isReadOnly, false);
  551. //Indexing
  552. v.ClearFlag();
  553. int val = v[0];
  554. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  555. ValidateValue(val, 1);
  556. v.ClearFlag();
  557. val = v[1];
  558. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  559. ValidateValue(val, 2);
  560. //Remove
  561. v.ClearFlag();
  562. v.Remove(1);
  563. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  564. ValidateValue(v.Count, 1);
  565. //RemoveAt
  566. v.ClearFlag();
  567. v.RemoveAt(0);
  568. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  569. ValidateValue(v.Count, 0);
  570. //Clear
  571. v.Add(1);
  572. v.Add(2);
  573. v.ClearFlag();
  574. v.Clear();
  575. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
  576. ValidateValue(v.Count, 0);
  577. }
  578. static void TestIVectorStructMembers()
  579. {
  580. Console.WriteLine(""=== IVectorStruct ==="");
  581. var v = new IVectorStruct();
  582. var ud = new UserDefinedStruct()
  583. {
  584. Id = 1
  585. }
  586. ;
  587. //Add
  588. v.ClearFlag();
  589. v.Add(ud);
  590. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
  591. ValidateValue(v[0].Id, 1);
  592. //Contains
  593. v.ClearFlag();
  594. bool b = v.Contains(ud);
  595. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  596. ValidateValue(b, true);
  597. //CopyTo
  598. v.ClearFlag();
  599. UserDefinedStruct[] arr = new UserDefinedStruct[10];
  600. v.CopyTo(arr, 0);
  601. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  602. ValidateValue(arr[0].Id, ud.Id);
  603. //GetEnumerator
  604. v.ClearFlag();
  605. int count = v.Count;
  606. IEnumerator<UserDefinedStruct> enumerator = ((IEnumerable<UserDefinedStruct>)v).GetEnumerator();
  607. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_get_Size);
  608. enumerator.MoveNext();
  609. ValidateValue((enumerator.Current).Id, 1);
  610. int index = 0;
  611. foreach (var e in v)
  612. {
  613. index = index + 1;
  614. ValidateValue(e.Id, index);
  615. }
  616. ValidateValue(index, 1); //there should only be 1 element there
  617. //IndexOf
  618. v.ClearFlag();
  619. var rez = v.IndexOf(ud);
  620. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  621. ValidateValue(rez, 0); // 1 is on the first line :)
  622. //Insert
  623. v.ClearFlag();
  624. v.Insert(1, new UserDefinedStruct()
  625. {
  626. Id = 4
  627. }
  628. );
  629. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
  630. ValidateValue(v[1].Id, 4);
  631. //IsReadOnly
  632. v.ClearFlag();
  633. bool isReadOnly = v.IsReadOnly;
  634. ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
  635. ValidateValue(isReadOnly, false);
  636. //Indexing
  637. v.ClearFlag();
  638. var val = v[0];
  639. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  640. ValidateValue(val.Id, ud.Id);
  641. v.ClearFlag();
  642. val = v[1];
  643. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  644. ValidateValue(val.Id, 4);
  645. //Remove
  646. v.ClearFlag();
  647. v.Remove(ud);
  648. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  649. ValidateValue(v.Count, 1);
  650. //RemoveAt
  651. v.ClearFlag();
  652. v.RemoveAt(0);
  653. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  654. ValidateValue(v.Count, 0);
  655. //Clear
  656. v.Add(ud);
  657. v.Add(new UserDefinedStruct()
  658. {
  659. Id = 4
  660. }
  661. );
  662. v.ClearFlag();
  663. v.Clear();
  664. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
  665. ValidateValue(v.Count, 0);
  666. }
  667. static void TestIVectorUintStructMembers()
  668. {
  669. Console.WriteLine(""=== IVectorUintStruct ==="");
  670. var v = new IVectorUintStruct();
  671. //Add
  672. v.ClearFlag();
  673. v.Add(7);
  674. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
  675. ValidateValue((v as IList<uint>)[0], 7);
  676. //Contains
  677. v.ClearFlag();
  678. bool b = v.Contains(7);
  679. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  680. ValidateValue(b, true);
  681. //IndexOf
  682. v.ClearFlag();
  683. var rez = ((IList<uint>)v).IndexOf(7);
  684. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  685. ValidateValue(rez, 0);
  686. //Insert
  687. v.ClearFlag();
  688. v.Insert(1, 5);
  689. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
  690. ValidateValue((v as IList<uint>)[1], 5);
  691. //IsReadOnly
  692. v.ClearFlag();
  693. bool isReadOnly = ((IList<uint>)v).IsReadOnly;
  694. ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
  695. ValidateValue(isReadOnly, false);
  696. //Indexing
  697. v.ClearFlag();
  698. uint val = ((uint)(v as IList<uint>)[0]);
  699. ValidateValue(val, 7);
  700. v.ClearFlag();
  701. val = ((IList<uint>)v)[1];
  702. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  703. ValidateValue(val, 5);
  704. //Remove
  705. v.ClearFlag();
  706. v.Remove(5);
  707. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  708. ValidateValue(((IList<uint>)v).Count, 1);
  709. //RemoveAt
  710. try
  711. {
  712. v.ClearFlag();
  713. ((IList<uint>)v).RemoveAt(0);
  714. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  715. ValidateValue(((IList<uint>)v).Count, 0);
  716. }
  717. catch (Exception exce)
  718. {
  719. Console.WriteLine(""RemoveAt"");
  720. Console.WriteLine(exce.Message);
  721. }
  722. //Clear
  723. v.Add(1);
  724. v.Add(2);
  725. v.ClearFlag();
  726. ((IList<uint>)v).Clear();
  727. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
  728. ValidateValue(((IList<uint>)v).Count, 0);
  729. var ud = new UserDefinedStruct()
  730. {
  731. Id = 1
  732. }
  733. ;
  734. //Add
  735. v.ClearFlag();
  736. v.Add(ud);
  737. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
  738. ValidateValue(((IList<UserDefinedStruct>)v)[0].Id, 1);
  739. //Contains
  740. v.ClearFlag();
  741. b = v.Contains(ud);
  742. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  743. ValidateValue(b, true);
  744. //'CopyTo
  745. //v.ClearFlag()
  746. //Dim arr As UserDefinedStruct()
  747. //ReDim arr(10)
  748. //v.CopyTo(arr, 0)
  749. //ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt)
  750. //ValidateValue(arr[0].Id, ud.Id)
  751. //GetEnumerator
  752. v.ClearFlag();
  753. int count = ((IList<UserDefinedStruct>)v).Count;
  754. IEnumerator<UserDefinedStruct> enumerator = ((IList<UserDefinedStruct>)v).GetEnumerator();
  755. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetMany);
  756. enumerator.MoveNext();
  757. ValidateValue((enumerator.Current).Id, 1);
  758. //IndexOf
  759. v.ClearFlag();
  760. rez = v.IndexOf(ud);
  761. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  762. ValidateValue(rez, 0); // 1 is on the first line :)
  763. //Insert
  764. v.ClearFlag();
  765. v.Insert(1, new UserDefinedStruct()
  766. {
  767. Id = 4
  768. }
  769. );
  770. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
  771. ValidateValue(((IList<UserDefinedStruct>)v)[1].Id, 4);
  772. //IsReadOnly
  773. v.ClearFlag();
  774. isReadOnly = ((IList<UserDefinedStruct>)v).IsReadOnly;
  775. ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
  776. ValidateValue(isReadOnly, false);
  777. //Indexing
  778. v.ClearFlag();
  779. var val2 = ((IList<UserDefinedStruct>)v)[0];
  780. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  781. ValidateValue(val2.Id, ud.Id);
  782. v.ClearFlag();
  783. val2 = ((IList<UserDefinedStruct>)v)[1];
  784. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  785. ValidateValue(val2.Id, 4);
  786. //Remove
  787. v.ClearFlag();
  788. v.Remove(ud);
  789. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  790. ValidateValue(((IList<UserDefinedStruct>)v).Count, 1);
  791. //RemoveAt
  792. v.ClearFlag();
  793. ((IList<UserDefinedStruct>)v).RemoveAt(0);
  794. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  795. ValidateValue(((IList<UserDefinedStruct>)v).Count, 0);
  796. //Clear
  797. v.Add(ud);
  798. v.Add(new UserDefinedStruct()
  799. {
  800. Id = 4
  801. }
  802. );
  803. v.ClearFlag();
  804. ((IList<UserDefinedStruct>)v).Clear();
  805. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
  806. ValidateValue(((IList<UserDefinedStruct>)v).Count, 0);
  807. }
  808. static void TestIVectorUintFloatMembers()
  809. {
  810. Console.WriteLine(""=== IVectorUintIVectorFloat ==="");
  811. var v = new IVectorUintIVectorFloat();
  812. //Add
  813. v.ClearFlag();
  814. v.Add(7);
  815. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
  816. ValidateValue(((IList<uint>)v).Count, 1);
  817. try
  818. {
  819. ValidateValue(((IList<uint>)v)[0], 7);
  820. }
  821. catch (ArgumentException exc)
  822. {
  823. Console.WriteLine(exc.Message);
  824. }
  825. //Contains
  826. v.ClearFlag();
  827. bool b = v.Contains(7);
  828. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  829. ValidateValue(b, true);
  830. //IndexOf
  831. v.ClearFlag();
  832. var rez = ((IList<uint>)v).IndexOf(7);
  833. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  834. ValidateValue(rez, 0);
  835. //Insertv.ClearFlag()
  836. v.Insert(1, 5);
  837. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
  838. try
  839. {
  840. ValidateValue(((IList<uint>)v)[1], 5);
  841. }
  842. catch (ArgumentException exc)
  843. {
  844. Console.WriteLine(exc.Message);
  845. }
  846. //IsReadOnly
  847. v.ClearFlag();
  848. bool isReadOnly = ((IList<uint>)v).IsReadOnly;
  849. ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
  850. ValidateValue(isReadOnly, false);
  851. //Indexing
  852. try
  853. {
  854. v.ClearFlag();
  855. var val = (v as IList<uint>)[0];
  856. ValidateValue(val, 7);
  857. v.ClearFlag();
  858. val = ((IList<uint>)v)[1];
  859. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  860. ValidateValue(val, 5);
  861. }
  862. catch (Exception exce)
  863. {
  864. Console.WriteLine(""Indexing"");
  865. Console.WriteLine(exce.Message);
  866. }
  867. //Remove
  868. v.ClearFlag();
  869. v.Remove(5);
  870. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  871. ValidateValue(((IList<uint>)v).Count, 1);
  872. //RemoveAt
  873. try
  874. {
  875. v.ClearFlag();
  876. ((IList<uint>)v).RemoveAt(0);
  877. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  878. ValidateValue(((IList<uint>)v).Count, 0);
  879. }
  880. catch (Exception exce)
  881. {
  882. Console.WriteLine(""RemoveAt"");
  883. Console.WriteLine(exce.Message);
  884. }
  885. //Clear
  886. v.Add(1);
  887. v.Add(2);
  888. v.ClearFlag();
  889. ((IList<uint>)v).Clear();
  890. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
  891. ValidateValue(((IList<uint>)v).Count, 0);
  892. //single
  893. //Add
  894. v.ClearFlag();
  895. float one = 1;
  896. v.Add(one);
  897. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
  898. ValidateValue(((IList<float>)v)[0], one);
  899. //Contains
  900. v.ClearFlag();
  901. b = v.Contains(one);
  902. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  903. ValidateValue(b, true);
  904. //'CopyTo
  905. //v.ClearFlag()
  906. //Dim arr As single()
  907. //ReDim arr(10)
  908. //v.CopyTo(arr, 0)
  909. //ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt)
  910. //ValidateValue(arr[0].Id, ud.Id)
  911. //IndexOf
  912. v.ClearFlag();
  913. rez = v.IndexOf(one);
  914. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  915. ValidateValue(rez, 0); // 1 is on the first line :)
  916. //Insert
  917. v.ClearFlag();
  918. v.Insert(1, (float)4);
  919. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
  920. ValidateValue(((IList<float>)v)[1], 4);
  921. //IsReadOnly
  922. v.ClearFlag();
  923. isReadOnly = ((IList<float>)v).IsReadOnly;
  924. ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
  925. ValidateValue(isReadOnly, false);
  926. //Indexing
  927. v.ClearFlag();
  928. var val2 = ((IList<float>)v)[0];
  929. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  930. ValidateValue(val2, one);
  931. v.ClearFlag();
  932. val2 = ((IList<float>)v)[1];
  933. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  934. ValidateValue(val2, 4);
  935. //Remove
  936. v.ClearFlag();
  937. v.Remove(one);
  938. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  939. ValidateValue(((IList<float>)v).Count, 1);
  940. //RemoveAt
  941. v.ClearFlag();
  942. ((IList<float>)v).RemoveAt(0);
  943. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  944. ValidateValue(((IList<float>)v).Count, 0);
  945. //Clear
  946. v.Add(one);
  947. v.ClearFlag();
  948. ((IList<float>)v).Clear();
  949. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
  950. ValidateValue(((IList<float>)v).Count, 0);
  951. }
  952. static void TestIVectorIntIMapIntIntMembers()
  953. {
  954. Console.WriteLine(""=== IVectorIntIMapIntInt ==="");
  955. var v = new IVectorIntIMapIntInt();
  956. //Add
  957. v.ClearFlag();
  958. v.Add(1);
  959. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
  960. ValidateValue((v as IList<int>)[0], 1);
  961. //Contains
  962. v.ClearFlag();
  963. bool b = v.Contains(1);
  964. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  965. ValidateValue(b, true);
  966. //CopyTo
  967. v.ClearFlag();
  968. int[] arr = new int[10];
  969. v.CopyTo(arr, 0);
  970. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  971. ValidateValue(arr[0], 1);
  972. ValidateValue(arr[1], 0); //there should be nothing there! :)
  973. //'GetEnumerator
  974. //v.ClearFlag()
  975. //Dim count As Integer = v.Count
  976. //Dim enumerator As IEnumerator(Of Integer) = v.GetEnumerator()
  977. //ValidateMethod(v.GetFlagState(), TestMethodCalled.IIterable_First)
  978. //Dim index As Integer = 0
  979. //For Each e In v
  980. // index = index + 1
  981. // ValidateValue(e, index)
  982. //Next
  983. //ValidateValue(index, 1) 'there should only be 1 element there
  984. //IndexOf
  985. v.ClearFlag();
  986. var rez = v.IndexOf(1);
  987. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  988. ValidateValue(rez, 0); // 1 is on the first line :)
  989. //Insert
  990. v.ClearFlag();
  991. v.Insert(1, 2);
  992. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
  993. ValidateValue((v as IList<int>)[1], 2);
  994. //IsReadOnly
  995. v.ClearFlag();
  996. bool isReadOnly = ((IList<int>)v).IsReadOnly;
  997. ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
  998. ValidateValue(isReadOnly, false);
  999. //Indexing
  1000. v.ClearFlag();
  1001. int val = ((int)(v as IList<int>)[0]);
  1002. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  1003. ValidateValue(val, 1);
  1004. v.ClearFlag();
  1005. val = ((IList<int>)v)[1];
  1006. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  1007. ValidateValue(val, 2);
  1008. //Remove
  1009. v.ClearFlag();
  1010. ((IList<int>)v).Remove(1);
  1011. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  1012. ValidateValue(((IList<int>)v).Count, 1);
  1013. //RemoveAt
  1014. v.ClearFlag();
  1015. v.RemoveAt(0);
  1016. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  1017. ValidateValue(((IList<int>)v).Count, 0);
  1018. //Clear
  1019. v.Add(1);
  1020. v.Add(2);
  1021. v.ClearFlag();
  1022. ((IList<int>)v).Clear();
  1023. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
  1024. ValidateValue(((IList<int>)v).Count, 0);
  1025. var m = v;
  1026. //Add
  1027. m.ClearFlag();
  1028. m.Add(1, 2);
  1029. ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_Insert);
  1030. ValidateValue(((IDictionary<int, int>)m).Count, 1);
  1031. //ContainsKey
  1032. m.ClearFlag();
  1033. bool key = m.ContainsKey(1);
  1034. ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_HasKey);
  1035. //Lookup
  1036. m.ClearFlag();
  1037. int val2 = ((int)(v as IDictionary<int, int>)[1]);
  1038. ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_Lookup);
  1039. ValidateValue(val2, 2);
  1040. //Keys
  1041. m.ClearFlag();
  1042. var keys = m.Keys;
  1043. ValidateMethod(m.GetFlagState(), TestMethodCalled.NotSet);
  1044. //Values
  1045. m.ClearFlag();
  1046. var values = m.Values;
  1047. ValidateMethod(m.GetFlagState(), TestMethodCalled.NotSet);
  1048. //Lookup
  1049. m.ClearFlag();
  1050. int outVal;
  1051. bool success = ((IDictionary<int, int>)m).TryGetValue(1, out outVal);
  1052. ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_Lookup);
  1053. ValidateValue(success, true);
  1054. ValidateValue(outVal, 2);
  1055. //Add
  1056. m.ClearFlag();
  1057. m.Add(new KeyValuePair<int, int>(3, 4));
  1058. ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_Insert);
  1059. ValidateValue(((IDictionary<int, int>)m).Count, 2);
  1060. //Contains
  1061. m.ClearFlag();
  1062. bool contains = m.Contains(new KeyValuePair<int, int>(3, 4));
  1063. ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_Lookup);
  1064. ValidateValue(contains, true);
  1065. //non-existant pair
  1066. m.ClearFlag();
  1067. contains = m.Contains(new KeyValuePair<int, int>(8, 9));
  1068. ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_HasKey);
  1069. ValidateValue(contains, false);
  1070. //Remove
  1071. m.ClearFlag();
  1072. bool remove = ((IDictionary<int, int>)m).Remove(1);
  1073. ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_Remove);
  1074. ValidateValue(((IDictionary<int, int>)m).Count, 1);
  1075. ValidateValue(remove, true);
  1076. //CopyTo
  1077. //m.ClearFlag()
  1078. //Dim arr As KeyValuePair(Of Integer, Integer)()
  1079. //ReDim arr(10)
  1080. //m.CopyTo(arr, 1)
  1081. //ValidateMethod(m.GetFlagState(), TestMethodCalled.IVector_GetAt)
  1082. //ValidateValue(arr[0].Value, 2)
  1083. //Count
  1084. m.ClearFlag();
  1085. int count = ((IDictionary<int, int>)m).Count;
  1086. ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_get_Size);
  1087. ValidateValue(count, 1);
  1088. //isReadOnly
  1089. m.ClearFlag();
  1090. isReadOnly = ((IDictionary<int, int>)m).IsReadOnly;
  1091. ValidateMethod(m.GetFlagState(), TestMethodCalled.NotSet);
  1092. ValidateValue(isReadOnly, false);
  1093. //Remove
  1094. m.ClearFlag();
  1095. var rez2 = m.Remove(new KeyValuePair<int, int>(3, 4));
  1096. ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_Remove);
  1097. ValidateValue(rez2, true);
  1098. m.ClearFlag();
  1099. rez2 = m.Remove(new KeyValuePair<int, int>(2, 3));
  1100. ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_HasKey);
  1101. ValidateValue(rez2, false);
  1102. m.Add(1, 2);
  1103. m.Add(2, 3);
  1104. m.ClearFlag();
  1105. ((IDictionary<int, int>)m).Clear();
  1106. ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_Clear);
  1107. ValidateValue(((IDictionary<int, int>)m).Count, 0);
  1108. }
  1109. static void TestIVectorExplicitAddMembers()
  1110. {
  1111. IVectorExplicitAdd v = new IVectorExplicitAdd();
  1112. //Calling the user defined Add method
  1113. v.ClearFlag();
  1114. ((IMemberAdd)v).Add(1);
  1115. ValidateMethod(v.GetFlagState(), TestMethodCalled.UserDef_Add);
  1116. v.ClearFlag();
  1117. ((IMemberAdd)v).Add(1);
  1118. ValidateMethod(v.GetFlagState(), TestMethodCalled.UserDef_Add);
  1119. //Calling the Interface Add's method
  1120. v.ClearFlag();
  1121. ((IList<int>)v).Add(1);
  1122. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
  1123. ValidateValue(v[0], 1);
  1124. }
  1125. static void TestIVectorViewMembers()
  1126. {
  1127. var v = new IVectorViewInt();
  1128. v.ClearFlag();
  1129. int count = v.Count;
  1130. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVectorView_get_Size);
  1131. }
  1132. static void TestIVectorUIntIVectorViewIntMembers()
  1133. {
  1134. Console.WriteLine(""=== IVectorUintIVectorViewInt ==="");
  1135. var v = new IVectorUintIVectorViewInt();
  1136. //Add
  1137. v.ClearFlag();
  1138. v.Add(1);
  1139. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
  1140. ValidateValue((v as IList<uint>)[0], 1);
  1141. //Contains
  1142. v.ClearFlag();
  1143. bool b = v.Contains(1);
  1144. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  1145. ValidateValue(b, true);
  1146. //CopyTo
  1147. v.ClearFlag();
  1148. uint[] arr = new uint[10];
  1149. v.CopyTo(arr, 0);
  1150. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  1151. ValidateValue(arr[0], 1);
  1152. ValidateValue(arr[1], 0); //there should be nothing there! :)
  1153. //GetEnumerator
  1154. v.ClearFlag();
  1155. uint count = ((uint)(v as IList<uint>).Count);
  1156. IEnumerator<uint> enumerator = ((IEnumerable<uint>)v).GetEnumerator();
  1157. ValidateMethod(v.GetFlagState(), TestMethodCalled.IIterable_First);
  1158. uint index = 0;
  1159. foreach (var e in v)
  1160. {
  1161. index = ((uint)index + 1);
  1162. ValidateValue(e, index);
  1163. }
  1164. ValidateValue(index, 1); //there should only be 1 element there
  1165. //IndexOf
  1166. v.ClearFlag();
  1167. var rez = v.IndexOf(1);
  1168. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  1169. ValidateValue(rez, 0); // 1 is on the first line :)
  1170. //Insert
  1171. v.ClearFlag();
  1172. v.Insert(1, 2);
  1173. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
  1174. ValidateValue((v as IList<uint>)[1], 2);
  1175. //IsReadOnly
  1176. v.ClearFlag();
  1177. bool isReadOnly = v.IsReadOnly;
  1178. ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
  1179. ValidateValue(isReadOnly, false);
  1180. //Indexing
  1181. v.ClearFlag();
  1182. uint val = (v as IList<uint>)[0];
  1183. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  1184. ValidateValue(val, 1);
  1185. v.ClearFlag();
  1186. val = (((IList<uint>)v))[1];
  1187. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  1188. ValidateValue(val, 2);
  1189. //Remove
  1190. v.ClearFlag();
  1191. v.Remove(1);
  1192. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  1193. ValidateValue((v as IList<uint>).Count, 1);
  1194. //RemoveAt
  1195. v.ClearFlag();
  1196. v.RemoveAt(0);
  1197. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  1198. ValidateValue((v as IList<uint>).Count, 0);
  1199. //Clear
  1200. v.Add(1);
  1201. v.Add(2);
  1202. v.ClearFlag();
  1203. v.Clear();
  1204. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
  1205. ValidateValue((v as IList<uint>).Count, 0);
  1206. // IVectorView members
  1207. v.Add(1);
  1208. v.Add(2);
  1209. v.ClearFlag();
  1210. ValidateValue(((IReadOnlyList<uint>)v).Count, 2);
  1211. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_get_Size);
  1212. v.ClearFlag();
  1213. ValidateValue(((IReadOnlyList<uint>)v)[0], 1);
  1214. ValidateValue(((IReadOnlyList<uint>)v)[1], 2);
  1215. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVectorView_GetAt);
  1216. }
  1217. static void TestIVectorIntIVectorViewUintMembers()
  1218. {
  1219. Console.WriteLine(""=== IVectorIntIVectorViewUint ==="");
  1220. var v = new IVectorIntIVectorViewUint();
  1221. //Add
  1222. v.ClearFlag();
  1223. v.Add(1);
  1224. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
  1225. ValidateValue((v as IList<int>)[0], 1);
  1226. //Contains
  1227. v.ClearFlag();
  1228. bool b = v.Contains(1);
  1229. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  1230. ValidateValue(b, true);
  1231. //CopyTo
  1232. v.ClearFlag();
  1233. int[] arr = new int[10];
  1234. v.CopyTo(arr, 0);
  1235. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  1236. ValidateValue(arr[0], 1);
  1237. ValidateValue(arr[1], 0); //there should be nothing there! :)
  1238. //GetEnumerator
  1239. v.ClearFlag();
  1240. uint count = ((uint)(((IList<int>)v)).Count);
  1241. IEnumerator<int> enumerator = (((IList<int>)v)).GetEnumerator();
  1242. ValidateMethod(v.GetFlagState(), TestMethodCalled.IIterable_First);
  1243. uint index = 0;
  1244. foreach (var e in (((IList<int>)v)))
  1245. {
  1246. index = ((uint)index + 1);
  1247. ValidateValue(e, index);
  1248. }
  1249. ValidateValue(index, 1); //there should only be 1 element there
  1250. //IndexOf
  1251. v.ClearFlag();
  1252. var rez = v.IndexOf(1);
  1253. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
  1254. ValidateValue(rez, 0); // 1 is on the first line :)
  1255. //Insert
  1256. v.ClearFlag();
  1257. v.Insert(1, 2);
  1258. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
  1259. ValidateValue((v as IList<int>)[1], 2);
  1260. //IsReadOnly
  1261. v.ClearFlag();
  1262. bool isReadOnly = v.IsReadOnly;
  1263. ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
  1264. ValidateValue(isReadOnly, false);
  1265. //Indexing
  1266. v.ClearFlag();
  1267. uint val = ((uint)(v as IList<int>)[0]);
  1268. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  1269. ValidateValue(val, 1);
  1270. v.ClearFlag();
  1271. val = ((uint)(((IList<int>)v))[1]);
  1272. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  1273. ValidateValue(val, 2);
  1274. //Remove
  1275. v.ClearFlag();
  1276. v.Remove(1);
  1277. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  1278. ValidateValue((((IList<int>)v)).Count, 1);
  1279. //RemoveAt
  1280. v.ClearFlag();
  1281. v.RemoveAt(0);
  1282. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
  1283. ValidateValue((((IList<int>)v)).Count, 0);
  1284. //Clear
  1285. v.Add(1);
  1286. v.Add(2);
  1287. v.ClearFlag();
  1288. v.Clear();
  1289. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
  1290. ValidateValue((((IList<int>)v)).Count, 0);
  1291. // IVectorView members
  1292. v.Add(1);
  1293. v.Add(2);
  1294. v.ClearFlag();
  1295. ValidateValue(((IReadOnlyList<uint>)v)[0], 0);
  1296. ValidateValue(((IReadOnlyList<uint>)v)[1], 0);
  1297. ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
  1298. }
  1299. static void TestIVectorStructIVectorViewStructMembers()
  1300. {
  1301. Console.WriteLine(""=== IVectorStructIVectorView

Large files files are truncated, but you can click here to view the full file