/Src/Compilers/CSharp/Test/Emit/CodeGen/WinRTCollectionTests.cs
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
- // 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.
- using System.Collections.Generic;
- using Microsoft.CodeAnalysis.CSharp;
- using Microsoft.CodeAnalysis.CSharp.Symbols;
- using Microsoft.CodeAnalysis.CSharp.Syntax;
- using ProprietaryTestResources = Microsoft.CodeAnalysis.Test.Resources.Proprietary;
- using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
- using Microsoft.CodeAnalysis.Test.Utilities;
- using Roslyn.Test.Utilities;
- using Xunit;
- namespace Microsoft.CodeAnalysis.CSharp.UnitTests.CodeGen
- {
- public class WinRTCollectionTests : CSharpTestBase
- {
- private MetadataReference[] _legacyRefs = null;
- public MetadataReference[] LegacyRefs
- {
- get
- {
- if (_legacyRefs == null)
- {
- var list = new List<MetadataReference>(WinRtRefs.Length + 2);
- list.AddRange(WinRtRefs);
- list.Add(
- new MetadataImageReference(
- TestResources.WinRt.Windows_Languages_WinRTTest.AsImmutableOrNull(),
- display: "WinRTTest"));
- list.Add(
- new MetadataImageReference(
- ProprietaryTestResources.NetFX.v4_0_30319_17929.System_Core.AsImmutableOrNull(),
- display: "SystemCore"));
- _legacyRefs = list.ToArray();
- }
- return _legacyRefs;
- }
- }
- [Fact, WorkItem(762316, "DevDiv")]
- public void InheritFromTypeWithProjections()
- {
- var source = @"
- using Windows.UI.Xaml;
-
- public sealed class BehaviorCollection : DependencyObjectCollection
- {
- private int count;
-
- public BehaviorCollection()
- {
- count = this.Count;
- }
-
- public object GetItem(int i)
- {
- return this[i];
- }
- }";
- var comp = CreateCompilationWithMscorlib45(source, references: WinRtRefs);
- comp.VerifyDiagnostics();
- }
- [Fact]
- public void IVectorProjectionTests()
- {
- var source =
- @"using System;
- using Windows.Data.Json;
- public class Class1
- {
- public static void Main(string[] args)
- {
- var jsonArray = new JsonArray();
- var a = JsonValue.CreateStringValue(""a"");
- jsonArray.Add(a);
- var b = JsonValue.CreateStringValue(""b"");
- jsonArray.Insert(0, b);
- jsonArray.Remove(b);
- Console.WriteLine(jsonArray.Contains(b));
- Console.WriteLine(jsonArray.IndexOf(a));
- jsonArray.RemoveAt(0);
- Console.WriteLine(jsonArray.Count);
- jsonArray.Add(b);
- foreach (var json in jsonArray)
- {
- Console.WriteLine(json.GetString());
- }
- Console.WriteLine(jsonArray.Count);
- jsonArray.Clear();
- Console.WriteLine(jsonArray.Count);
- }
- }";
- string expectedOutput =
- @"False
- 0
- 0
- b
- 1
- 0";
- var verifier = CompileAndVerifyOnWin8Only(source,
- expectedOutput: expectedOutput,
- additionalRefs: WinRtRefs,
- emitOptions: EmitOptions.RefEmitBug);
- verifier.VerifyIL("Class1.Main",
- @"{
- // Code size 174 (0xae)
- .maxstack 3
- .locals init (Windows.Data.Json.JsonArray V_0, //jsonArray
- Windows.Data.Json.JsonValue V_1, //a
- Windows.Data.Json.JsonValue V_2, //b
- System.Collections.Generic.IEnumerator<Windows.Data.Json.IJsonValue> V_3)
- IL_0000: newobj ""Windows.Data.Json.JsonArray..ctor()""
- IL_0005: stloc.0
- IL_0006: ldstr ""a""
- IL_000b: call ""Windows.Data.Json.JsonValue Windows.Data.Json.JsonValue.CreateStringValue(string)""
- IL_0010: stloc.1
- IL_0011: ldloc.0
- IL_0012: ldloc.1
- IL_0013: callvirt ""void System.Collections.Generic.ICollection<Windows.Data.Json.IJsonValue>.Add(Windows.Data.Json.IJsonValue)""
- IL_0018: ldstr ""b""
- IL_001d: call ""Windows.Data.Json.JsonValue Windows.Data.Json.JsonValue.CreateStringValue(string)""
- IL_0022: stloc.2
- IL_0023: ldloc.0
- IL_0024: ldc.i4.0
- IL_0025: ldloc.2
- IL_0026: callvirt ""void System.Collections.Generic.IList<Windows.Data.Json.IJsonValue>.Insert(int, Windows.Data.Json.IJsonValue)""
- IL_002b: ldloc.0
- IL_002c: ldloc.2
- IL_002d: callvirt ""bool System.Collections.Generic.ICollection<Windows.Data.Json.IJsonValue>.Remove(Windows.Data.Json.IJsonValue)""
- IL_0032: pop
- IL_0033: ldloc.0
- IL_0034: ldloc.2
- IL_0035: callvirt ""bool System.Collections.Generic.ICollection<Windows.Data.Json.IJsonValue>.Contains(Windows.Data.Json.IJsonValue)""
- IL_003a: call ""void System.Console.WriteLine(bool)""
- IL_003f: ldloc.0
- IL_0040: ldloc.1
- IL_0041: callvirt ""int System.Collections.Generic.IList<Windows.Data.Json.IJsonValue>.IndexOf(Windows.Data.Json.IJsonValue)""
- IL_0046: call ""void System.Console.WriteLine(int)""
- IL_004b: ldloc.0
- IL_004c: ldc.i4.0
- IL_004d: callvirt ""void System.Collections.Generic.IList<Windows.Data.Json.IJsonValue>.RemoveAt(int)""
- IL_0052: ldloc.0
- IL_0053: callvirt ""int System.Collections.Generic.ICollection<Windows.Data.Json.IJsonValue>.Count.get""
- IL_0058: call ""void System.Console.WriteLine(int)""
- IL_005d: ldloc.0
- IL_005e: ldloc.2
- IL_005f: callvirt ""void System.Collections.Generic.ICollection<Windows.Data.Json.IJsonValue>.Add(Windows.Data.Json.IJsonValue)""
- IL_0064: ldloc.0
- IL_0065: callvirt ""System.Collections.Generic.IEnumerator<Windows.Data.Json.IJsonValue> System.Collections.Generic.IEnumerable<Windows.Data.Json.IJsonValue>.GetEnumerator()""
- IL_006a: stloc.3
- .try
- {
- IL_006b: br.s IL_007d
- IL_006d: ldloc.3
- IL_006e: callvirt ""Windows.Data.Json.IJsonValue System.Collections.Generic.IEnumerator<Windows.Data.Json.IJsonValue>.Current.get""
- IL_0073: callvirt ""string Windows.Data.Json.IJsonValue.GetString()""
- IL_0078: call ""void System.Console.WriteLine(string)""
- IL_007d: ldloc.3
- IL_007e: callvirt ""bool System.Collections.IEnumerator.MoveNext()""
- IL_0083: brtrue.s IL_006d
- IL_0085: leave.s IL_0091
- }
- finally
- {
- IL_0087: ldloc.3
- IL_0088: brfalse.s IL_0090
- IL_008a: ldloc.3
- IL_008b: callvirt ""void System.IDisposable.Dispose()""
- IL_0090: endfinally
- }
- IL_0091: ldloc.0
- IL_0092: callvirt ""int System.Collections.Generic.ICollection<Windows.Data.Json.IJsonValue>.Count.get""
- IL_0097: call ""void System.Console.WriteLine(int)""
- IL_009c: ldloc.0
- IL_009d: callvirt ""void System.Collections.Generic.ICollection<Windows.Data.Json.IJsonValue>.Clear()""
- IL_00a2: ldloc.0
- IL_00a3: callvirt ""int System.Collections.Generic.ICollection<Windows.Data.Json.IJsonValue>.Count.get""
- IL_00a8: call ""void System.Console.WriteLine(int)""
- IL_00ad: ret
- }
- ");
- }
- [Fact]
- public void IVectorViewProjectionTests()
- {
- var source =
- @"using System;
- using Windows.Foundation;
- public class Class1
- {
- public static void Main(string[] args)
- {
- var results = new WwwFormUrlDecoder(""?param1=test"");
- Console.Out.WriteLine(results[0].Name + results[0].Value);
- }
- }";
- var expectedOut = "param1test";
- var verifier = CompileAndVerifyOnWin8Only(
- source,
- expectedOutput: expectedOut,
- additionalRefs: WinRtRefs,
- emitOptions: EmitOptions.RefEmitBug);
- verifier.VerifyIL("Class1.Main",
- @"{
- // Code size 51 (0x33)
- .maxstack 4
- .locals init (Windows.Foundation.WwwFormUrlDecoder V_0) //results
- IL_0000: ldstr ""?param1=test""
- IL_0005: newobj ""Windows.Foundation.WwwFormUrlDecoder..ctor(string)""
- IL_000a: stloc.0
- IL_000b: call ""System.IO.TextWriter System.Console.Out.get""
- IL_0010: ldloc.0
- IL_0011: ldc.i4.0
- IL_0012: callvirt ""Windows.Foundation.IWwwFormUrlDecoderEntry System.Collections.Generic.IReadOnlyList<Windows.Foundation.IWwwFormUrlDecoderEntry>.this[int].get""
- IL_0017: callvirt ""string Windows.Foundation.IWwwFormUrlDecoderEntry.Name.get""
- IL_001c: ldloc.0
- IL_001d: ldc.i4.0
- IL_001e: callvirt ""Windows.Foundation.IWwwFormUrlDecoderEntry System.Collections.Generic.IReadOnlyList<Windows.Foundation.IWwwFormUrlDecoderEntry>.this[int].get""
- IL_0023: callvirt ""string Windows.Foundation.IWwwFormUrlDecoderEntry.Value.get""
- IL_0028: call ""string string.Concat(string, string)""
- IL_002d: callvirt ""void System.IO.TextWriter.WriteLine(string)""
- IL_0032: ret
- }");
- }
- [Fact]
- public void IMapProjectionTests()
- {
- var source =
- @"using System;
- using System.Collections.Generic;
- using Windows.ApplicationModel.DataTransfer;
- public class Class1
- {
- public static void Main(string[] args)
- {
- var dataPackage = new DataPackage();
- var dpps = dataPackage.Properties;
- dpps.Add(new KeyValuePair<string, object>(""testKey1"", ""testValue1""));
- Console.Out.WriteLine(dpps.ContainsKey(""testKey1""));
- Console.Out.WriteLine(dpps[""testKey1""]);
- dpps.Add(""testKey2"", ""testValue2"");
- object tv2;
- dpps.TryGetValue(""testKey2"", out tv2);
- Console.Out.WriteLine(tv2);
- dpps[""testKey2""] = ""testValue3"";
- dpps.Remove(""testKey1"");
- var valsEnumerator = dpps.Values.GetEnumerator();
- var keysEnumerator = dpps.Keys.GetEnumerator();
- while (keysEnumerator.MoveNext() && valsEnumerator.MoveNext())
- {
- Console.Out.WriteLine(keysEnumerator.Current + valsEnumerator.Current);
- }
- }
- }";
- var expectedOut =
- @"True
- testValue1
- testValue2
- testKey2testValue3
- ";
- var verifier = CompileAndVerifyOnWin8Only(
- source,
- expectedOutput: expectedOut,
- additionalRefs: WinRtRefs,
- emitOptions: EmitOptions.RefEmitBug);
- verifier.VerifyIL("Class1.Main",
- @"{
- // Code size 213 (0xd5)
- .maxstack 3
- .locals init (Windows.ApplicationModel.DataTransfer.DataPackagePropertySet V_0, //dpps
- object V_1, //tv2
- System.Collections.Generic.IEnumerator<object> V_2, //valsEnumerator
- System.Collections.Generic.IEnumerator<string> V_3) //keysEnumerator
- IL_0000: newobj ""Windows.ApplicationModel.DataTransfer.DataPackage..ctor()""
- IL_0005: callvirt ""Windows.ApplicationModel.DataTransfer.DataPackagePropertySet Windows.ApplicationModel.DataTransfer.DataPackage.Properties.get""
- IL_000a: stloc.0
- IL_000b: ldloc.0
- IL_000c: ldstr ""testKey1""
- IL_0011: ldstr ""testValue1""
- IL_0016: newobj ""System.Collections.Generic.KeyValuePair<string, object>..ctor(string, object)""
- IL_001b: callvirt ""void System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string, object>>.Add(System.Collections.Generic.KeyValuePair<string, object>)""
- IL_0020: call ""System.IO.TextWriter System.Console.Out.get""
- IL_0025: ldloc.0
- IL_0026: ldstr ""testKey1""
- IL_002b: callvirt ""bool System.Collections.Generic.IDictionary<string, object>.ContainsKey(string)""
- IL_0030: callvirt ""void System.IO.TextWriter.WriteLine(bool)""
- IL_0035: call ""System.IO.TextWriter System.Console.Out.get""
- IL_003a: ldloc.0
- IL_003b: ldstr ""testKey1""
- IL_0040: callvirt ""object System.Collections.Generic.IDictionary<string, object>.this[string].get""
- IL_0045: callvirt ""void System.IO.TextWriter.WriteLine(object)""
- IL_004a: ldloc.0
- IL_004b: ldstr ""testKey2""
- IL_0050: ldstr ""testValue2""
- IL_0055: callvirt ""void System.Collections.Generic.IDictionary<string, object>.Add(string, object)""
- IL_005a: ldloc.0
- IL_005b: ldstr ""testKey2""
- IL_0060: ldloca.s V_1
- IL_0062: callvirt ""bool System.Collections.Generic.IDictionary<string, object>.TryGetValue(string, out object)""
- IL_0067: pop
- IL_0068: call ""System.IO.TextWriter System.Console.Out.get""
- IL_006d: ldloc.1
- IL_006e: callvirt ""void System.IO.TextWriter.WriteLine(object)""
- IL_0073: ldloc.0
- IL_0074: ldstr ""testKey2""
- IL_0079: ldstr ""testValue3""
- IL_007e: callvirt ""void System.Collections.Generic.IDictionary<string, object>.this[string].set""
- IL_0083: ldloc.0
- IL_0084: ldstr ""testKey1""
- IL_0089: callvirt ""bool System.Collections.Generic.IDictionary<string, object>.Remove(string)""
- IL_008e: pop
- IL_008f: ldloc.0
- IL_0090: callvirt ""System.Collections.Generic.ICollection<object> System.Collections.Generic.IDictionary<string, object>.Values.get""
- IL_0095: callvirt ""System.Collections.Generic.IEnumerator<object> System.Collections.Generic.IEnumerable<object>.GetEnumerator()""
- IL_009a: stloc.2
- IL_009b: ldloc.0
- IL_009c: callvirt ""System.Collections.Generic.ICollection<string> System.Collections.Generic.IDictionary<string, object>.Keys.get""
- IL_00a1: callvirt ""System.Collections.Generic.IEnumerator<string> System.Collections.Generic.IEnumerable<string>.GetEnumerator()""
- IL_00a6: stloc.3
- IL_00a7: br.s IL_00c4
- IL_00a9: call ""System.IO.TextWriter System.Console.Out.get""
- IL_00ae: ldloc.3
- IL_00af: callvirt ""string System.Collections.Generic.IEnumerator<string>.Current.get""
- IL_00b4: ldloc.2
- IL_00b5: callvirt ""object System.Collections.Generic.IEnumerator<object>.Current.get""
- IL_00ba: call ""string string.Concat(object, object)""
- IL_00bf: callvirt ""void System.IO.TextWriter.WriteLine(string)""
- IL_00c4: ldloc.3
- IL_00c5: callvirt ""bool System.Collections.IEnumerator.MoveNext()""
- IL_00ca: brfalse.s IL_00d4
- IL_00cc: ldloc.2
- IL_00cd: callvirt ""bool System.Collections.IEnumerator.MoveNext()""
- IL_00d2: brtrue.s IL_00a9
- IL_00d4: ret
- }");
- }
- // TODO: There are no suitable winmd members to test the IMapView projections,
- // a custom winmd will have to be used after winmd references are implemented
- [Fact]
- public void MultipleInterfaceMethodConflictTests()
- {
- var source =
- @"using Windows.Data.Json;
- using Windows.Foundation;
- public class Class1
- {
- public static void Main(string[] args)
- {
- var en = new JsonArray().GetEnumerator();
- en = new WwwFormUrlDecoder(""?param1=test"").GetEnumerator();
- }
- }";
- var comp = CreateCompilation(source, references: WinRtRefs);
- // JsonArray implements both IEnumerable and IList, which both have a GetEnumerator
- // method. We can't know which interface method to call, so we shouldn't emit a
- // GetEnumerator method at all.
- comp.VerifyDiagnostics(
- Diagnostic(ErrorCode.ERR_NoSuchMemberOrExtension, "GetEnumerator")
- .WithArguments("Windows.Data.Json.JsonArray", "GetEnumerator"),
- Diagnostic(ErrorCode.ERR_NoSuchMemberOrExtension, "GetEnumerator")
- .WithArguments("Windows.Foundation.WwwFormUrlDecoder", "GetEnumerator"));
- }
- [Fact]
- public void LegacyCollectionTest01()
- {
- var source =
- @"using Windows.Languages.WinRTTest;
- using System.Collections.Generic;
- using System.Reflection;
- using System.Linq.Expressions;
- using System;
- using System.Linq;
- class AllMembers
- {
- private static int FailedCount = 0;
- private static bool ValidateMethod(TestMethodCalled actual, TestMethodCalled expected)
- {
- var temp = Console.ForegroundColor;
- if (actual != expected)
- {
- FailedCount++;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write(""FAIL: "");
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write(""PASS: "");
- }
- Console.ForegroundColor = temp;
- Console.WriteLine(""Expected: {0}, Actual: {1}"", expected, actual);
- return actual == expected;
- }
- private static bool ValidateValue(object actual, object expected)
- {
- var temp = Console.ForegroundColor;
- if (actual.ToString() != expected.ToString())
- {
- FailedCount++;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write(""FAIL: "");
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write(""PASS: "");
- }
- Console.ForegroundColor = temp;
- Console.WriteLine(""Expected: {0}, Actual: {1}"", expected, actual);
- return actual.ToString() == expected.ToString();
- }
- static void TestIIterableMembers()
- {
- Console.WriteLine(""=== IIterableFloat ==="");
- var i = new IIterableFloat();
- i.ClearFlag();
- IEnumerator<float> enumerator = ((IEnumerable<float>)i).GetEnumerator();
- ValidateMethod(i.GetFlagState(), TestMethodCalled.IIterable_First);
- }
- static int Main()
- {
- TestIIterableMembers();
-
- Console.WriteLine(FailedCount);
- return FailedCount;
- }
- }";
- var verifier = CompileAndVerify(source,
- additionalRefs: LegacyRefs,
- emitOptions: EmitOptions.RefEmitBug,
- verify: false);
- verifier.VerifyDiagnostics(
- // (3,1): info CS8019: Unnecessary using directive.
- // using System.Reflection;
- Diagnostic(ErrorCode.INF_UnusedUsingDirective, "using System.Reflection;"),
- // (4,1): info CS8019: Unnecessary using directive.
- // using System.Linq.Expressions;
- Diagnostic(ErrorCode.INF_UnusedUsingDirective, "using System.Linq.Expressions;"),
- // (6,1): info CS8019: Unnecessary using directive.
- // using System.Linq;
- Diagnostic(ErrorCode.INF_UnusedUsingDirective, "using System.Linq;"));
- verifier.VerifyIL("AllMembers.TestIIterableMembers",
- @"{
- // Code size 41 (0x29)
- .maxstack 2
- IL_0000: ldstr ""=== IIterableFloat ===""
- IL_0005: call ""void System.Console.WriteLine(string)""
- IL_000a: newobj ""Windows.Languages.WinRTTest.IIterableFloat..ctor()""
- IL_000f: dup
- IL_0010: callvirt ""void Windows.Languages.WinRTTest.IIterableFloat.ClearFlag()""
- IL_0015: dup
- IL_0016: callvirt ""System.Collections.Generic.IEnumerator<float> System.Collections.Generic.IEnumerable<float>.GetEnumerator()""
- IL_001b: pop
- IL_001c: callvirt ""Windows.Languages.WinRTTest.TestMethodCalled Windows.Languages.WinRTTest.IIterableFloat.GetFlagState()""
- IL_0021: ldc.i4.1
- IL_0022: call ""bool AllMembers.ValidateMethod(Windows.Languages.WinRTTest.TestMethodCalled, Windows.Languages.WinRTTest.TestMethodCalled)""
- IL_0027: pop
- IL_0028: ret
- }");
- }
- [Fact]
- public void LegacyCollectionTest02()
- {
- var source =
- @"using Windows.Languages.WinRTTest;
- using System.Collections.Generic;
- using System.Reflection;
- using System.Linq.Expressions;
- using System;
- using System.Linq;
- class AllMembers
- {
- private static int FailedCount = 0;
- private static bool ValidateMethod(TestMethodCalled actual, TestMethodCalled expected)
- {
- var temp = Console.ForegroundColor;
- if (actual != expected)
- {
- FailedCount++;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write(""FAIL: "");
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write(""PASS: "");
- }
- Console.ForegroundColor = temp;
- Console.WriteLine(""Expected: {0}, Actual: {1}"", expected, actual);
- return actual == expected;
- }
- private static bool ValidateValue(object actual, object expected)
- {
- var temp = Console.ForegroundColor;
- if (actual.ToString() != expected.ToString())
- {
- FailedCount++;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write(""FAIL: "");
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write(""PASS: "");
- }
- Console.ForegroundColor = temp;
- Console.WriteLine(""Expected: {0}, Actual: {1}"", expected, actual);
- return actual.ToString() == expected.ToString();
- }
- static void TestIVectorIntMembers()
- {
- Console.WriteLine(""=== IVectorInt ==="");
- var v = new IVectorInt();
- //Add
- v.ClearFlag();
- v.Add(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
- ValidateValue(v[0], 1);
- //Contains
- v.ClearFlag();
- bool b = v.Contains(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(b, true);
- //CopyTo
- v.ClearFlag();
- int[] arr = new int[10];
- v.CopyTo(arr, 0);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(arr[0], 1);
- ValidateValue(arr[1], 0); //there should be nothing there! :)
- //GetEnumerator
- v.ClearFlag();
- int count = v.Count;
- IEnumerator<int> enumerator = ((IEnumerable<int>)v).GetEnumerator();
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IIterable_First);
- int index = 0;
- foreach (var e in v)
- {
- index = index + 1;
- ValidateValue(e, index);
- }
- ValidateValue(index, 1); //there should only be 1 element there
- //IndexOf
- v.ClearFlag();
- var rez = v.IndexOf(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(rez, 0); // 1 is on the first line :)
- //Insert
- v.ClearFlag();
- v.Insert(1, 2);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
- ValidateValue(v[1], 2);
- //IsReadOnly
- v.ClearFlag();
- bool isReadOnly = v.IsReadOnly;
- ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
- ValidateValue(isReadOnly, false);
- //Indexing
- v.ClearFlag();
- int val = v[0];
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(val, 1);
- v.ClearFlag();
- val = v[1];
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(val, 2);
- //Remove
- v.ClearFlag();
- v.Remove(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue(v.Count, 1);
- //RemoveAt
- v.ClearFlag();
- v.RemoveAt(0);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue(v.Count, 0);
- //Clear
- v.Add(1);
- v.Add(2);
- v.ClearFlag();
- v.Clear();
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
- ValidateValue(v.Count, 0);
- }
- static void TestIVectorStructMembers()
- {
- Console.WriteLine(""=== IVectorStruct ==="");
- var v = new IVectorStruct();
- var ud = new UserDefinedStruct()
- {
- Id = 1
- }
- ;
- //Add
- v.ClearFlag();
- v.Add(ud);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
- ValidateValue(v[0].Id, 1);
- //Contains
- v.ClearFlag();
- bool b = v.Contains(ud);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(b, true);
- //CopyTo
- v.ClearFlag();
- UserDefinedStruct[] arr = new UserDefinedStruct[10];
- v.CopyTo(arr, 0);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(arr[0].Id, ud.Id);
- //GetEnumerator
- v.ClearFlag();
- int count = v.Count;
- IEnumerator<UserDefinedStruct> enumerator = ((IEnumerable<UserDefinedStruct>)v).GetEnumerator();
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_get_Size);
- enumerator.MoveNext();
- ValidateValue((enumerator.Current).Id, 1);
- int index = 0;
- foreach (var e in v)
- {
- index = index + 1;
- ValidateValue(e.Id, index);
- }
- ValidateValue(index, 1); //there should only be 1 element there
- //IndexOf
- v.ClearFlag();
- var rez = v.IndexOf(ud);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(rez, 0); // 1 is on the first line :)
- //Insert
- v.ClearFlag();
- v.Insert(1, new UserDefinedStruct()
- {
- Id = 4
- }
- );
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
- ValidateValue(v[1].Id, 4);
- //IsReadOnly
- v.ClearFlag();
- bool isReadOnly = v.IsReadOnly;
- ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
- ValidateValue(isReadOnly, false);
- //Indexing
- v.ClearFlag();
- var val = v[0];
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(val.Id, ud.Id);
- v.ClearFlag();
- val = v[1];
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(val.Id, 4);
- //Remove
- v.ClearFlag();
- v.Remove(ud);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue(v.Count, 1);
- //RemoveAt
- v.ClearFlag();
- v.RemoveAt(0);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue(v.Count, 0);
- //Clear
- v.Add(ud);
- v.Add(new UserDefinedStruct()
- {
- Id = 4
- }
- );
- v.ClearFlag();
- v.Clear();
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
- ValidateValue(v.Count, 0);
- }
- static void TestIVectorUintStructMembers()
- {
- Console.WriteLine(""=== IVectorUintStruct ==="");
- var v = new IVectorUintStruct();
- //Add
- v.ClearFlag();
- v.Add(7);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
- ValidateValue((v as IList<uint>)[0], 7);
- //Contains
- v.ClearFlag();
- bool b = v.Contains(7);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(b, true);
- //IndexOf
- v.ClearFlag();
- var rez = ((IList<uint>)v).IndexOf(7);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(rez, 0);
- //Insert
- v.ClearFlag();
- v.Insert(1, 5);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
- ValidateValue((v as IList<uint>)[1], 5);
- //IsReadOnly
- v.ClearFlag();
- bool isReadOnly = ((IList<uint>)v).IsReadOnly;
- ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
- ValidateValue(isReadOnly, false);
- //Indexing
- v.ClearFlag();
- uint val = ((uint)(v as IList<uint>)[0]);
- ValidateValue(val, 7);
- v.ClearFlag();
- val = ((IList<uint>)v)[1];
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(val, 5);
- //Remove
- v.ClearFlag();
- v.Remove(5);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue(((IList<uint>)v).Count, 1);
- //RemoveAt
- try
- {
- v.ClearFlag();
- ((IList<uint>)v).RemoveAt(0);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue(((IList<uint>)v).Count, 0);
- }
- catch (Exception exce)
- {
- Console.WriteLine(""RemoveAt"");
- Console.WriteLine(exce.Message);
- }
- //Clear
- v.Add(1);
- v.Add(2);
- v.ClearFlag();
- ((IList<uint>)v).Clear();
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
- ValidateValue(((IList<uint>)v).Count, 0);
- var ud = new UserDefinedStruct()
- {
- Id = 1
- }
- ;
- //Add
- v.ClearFlag();
- v.Add(ud);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
- ValidateValue(((IList<UserDefinedStruct>)v)[0].Id, 1);
- //Contains
- v.ClearFlag();
- b = v.Contains(ud);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(b, true);
- //'CopyTo
- //v.ClearFlag()
- //Dim arr As UserDefinedStruct()
- //ReDim arr(10)
- //v.CopyTo(arr, 0)
- //ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt)
- //ValidateValue(arr[0].Id, ud.Id)
- //GetEnumerator
- v.ClearFlag();
- int count = ((IList<UserDefinedStruct>)v).Count;
- IEnumerator<UserDefinedStruct> enumerator = ((IList<UserDefinedStruct>)v).GetEnumerator();
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetMany);
- enumerator.MoveNext();
- ValidateValue((enumerator.Current).Id, 1);
- //IndexOf
- v.ClearFlag();
- rez = v.IndexOf(ud);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(rez, 0); // 1 is on the first line :)
- //Insert
- v.ClearFlag();
- v.Insert(1, new UserDefinedStruct()
- {
- Id = 4
- }
- );
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
- ValidateValue(((IList<UserDefinedStruct>)v)[1].Id, 4);
- //IsReadOnly
- v.ClearFlag();
- isReadOnly = ((IList<UserDefinedStruct>)v).IsReadOnly;
- ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
- ValidateValue(isReadOnly, false);
- //Indexing
- v.ClearFlag();
- var val2 = ((IList<UserDefinedStruct>)v)[0];
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(val2.Id, ud.Id);
- v.ClearFlag();
- val2 = ((IList<UserDefinedStruct>)v)[1];
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(val2.Id, 4);
- //Remove
- v.ClearFlag();
- v.Remove(ud);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue(((IList<UserDefinedStruct>)v).Count, 1);
- //RemoveAt
- v.ClearFlag();
- ((IList<UserDefinedStruct>)v).RemoveAt(0);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue(((IList<UserDefinedStruct>)v).Count, 0);
- //Clear
- v.Add(ud);
- v.Add(new UserDefinedStruct()
- {
- Id = 4
- }
- );
- v.ClearFlag();
- ((IList<UserDefinedStruct>)v).Clear();
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
- ValidateValue(((IList<UserDefinedStruct>)v).Count, 0);
- }
- static void TestIVectorUintFloatMembers()
- {
- Console.WriteLine(""=== IVectorUintIVectorFloat ==="");
- var v = new IVectorUintIVectorFloat();
- //Add
- v.ClearFlag();
- v.Add(7);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
- ValidateValue(((IList<uint>)v).Count, 1);
- try
- {
- ValidateValue(((IList<uint>)v)[0], 7);
- }
- catch (ArgumentException exc)
- {
- Console.WriteLine(exc.Message);
- }
- //Contains
- v.ClearFlag();
- bool b = v.Contains(7);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(b, true);
- //IndexOf
- v.ClearFlag();
- var rez = ((IList<uint>)v).IndexOf(7);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(rez, 0);
- //Insertv.ClearFlag()
- v.Insert(1, 5);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
- try
- {
- ValidateValue(((IList<uint>)v)[1], 5);
- }
- catch (ArgumentException exc)
- {
- Console.WriteLine(exc.Message);
- }
- //IsReadOnly
- v.ClearFlag();
- bool isReadOnly = ((IList<uint>)v).IsReadOnly;
- ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
- ValidateValue(isReadOnly, false);
- //Indexing
- try
- {
- v.ClearFlag();
- var val = (v as IList<uint>)[0];
- ValidateValue(val, 7);
- v.ClearFlag();
- val = ((IList<uint>)v)[1];
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(val, 5);
- }
- catch (Exception exce)
- {
- Console.WriteLine(""Indexing"");
- Console.WriteLine(exce.Message);
- }
- //Remove
- v.ClearFlag();
- v.Remove(5);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue(((IList<uint>)v).Count, 1);
- //RemoveAt
- try
- {
- v.ClearFlag();
- ((IList<uint>)v).RemoveAt(0);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue(((IList<uint>)v).Count, 0);
- }
- catch (Exception exce)
- {
- Console.WriteLine(""RemoveAt"");
- Console.WriteLine(exce.Message);
- }
- //Clear
- v.Add(1);
- v.Add(2);
- v.ClearFlag();
- ((IList<uint>)v).Clear();
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
- ValidateValue(((IList<uint>)v).Count, 0);
- //single
- //Add
- v.ClearFlag();
- float one = 1;
- v.Add(one);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
- ValidateValue(((IList<float>)v)[0], one);
- //Contains
- v.ClearFlag();
- b = v.Contains(one);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(b, true);
- //'CopyTo
- //v.ClearFlag()
- //Dim arr As single()
- //ReDim arr(10)
- //v.CopyTo(arr, 0)
- //ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt)
- //ValidateValue(arr[0].Id, ud.Id)
- //IndexOf
- v.ClearFlag();
- rez = v.IndexOf(one);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(rez, 0); // 1 is on the first line :)
- //Insert
- v.ClearFlag();
- v.Insert(1, (float)4);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
- ValidateValue(((IList<float>)v)[1], 4);
- //IsReadOnly
- v.ClearFlag();
- isReadOnly = ((IList<float>)v).IsReadOnly;
- ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
- ValidateValue(isReadOnly, false);
- //Indexing
- v.ClearFlag();
- var val2 = ((IList<float>)v)[0];
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(val2, one);
- v.ClearFlag();
- val2 = ((IList<float>)v)[1];
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(val2, 4);
- //Remove
- v.ClearFlag();
- v.Remove(one);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue(((IList<float>)v).Count, 1);
- //RemoveAt
- v.ClearFlag();
- ((IList<float>)v).RemoveAt(0);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue(((IList<float>)v).Count, 0);
- //Clear
- v.Add(one);
- v.ClearFlag();
- ((IList<float>)v).Clear();
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
- ValidateValue(((IList<float>)v).Count, 0);
- }
- static void TestIVectorIntIMapIntIntMembers()
- {
- Console.WriteLine(""=== IVectorIntIMapIntInt ==="");
- var v = new IVectorIntIMapIntInt();
- //Add
- v.ClearFlag();
- v.Add(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
- ValidateValue((v as IList<int>)[0], 1);
- //Contains
- v.ClearFlag();
- bool b = v.Contains(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(b, true);
- //CopyTo
- v.ClearFlag();
- int[] arr = new int[10];
- v.CopyTo(arr, 0);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(arr[0], 1);
- ValidateValue(arr[1], 0); //there should be nothing there! :)
- //'GetEnumerator
- //v.ClearFlag()
- //Dim count As Integer = v.Count
- //Dim enumerator As IEnumerator(Of Integer) = v.GetEnumerator()
- //ValidateMethod(v.GetFlagState(), TestMethodCalled.IIterable_First)
- //Dim index As Integer = 0
- //For Each e In v
- // index = index + 1
- // ValidateValue(e, index)
- //Next
- //ValidateValue(index, 1) 'there should only be 1 element there
- //IndexOf
- v.ClearFlag();
- var rez = v.IndexOf(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(rez, 0); // 1 is on the first line :)
- //Insert
- v.ClearFlag();
- v.Insert(1, 2);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
- ValidateValue((v as IList<int>)[1], 2);
- //IsReadOnly
- v.ClearFlag();
- bool isReadOnly = ((IList<int>)v).IsReadOnly;
- ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
- ValidateValue(isReadOnly, false);
- //Indexing
- v.ClearFlag();
- int val = ((int)(v as IList<int>)[0]);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(val, 1);
- v.ClearFlag();
- val = ((IList<int>)v)[1];
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(val, 2);
- //Remove
- v.ClearFlag();
- ((IList<int>)v).Remove(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue(((IList<int>)v).Count, 1);
- //RemoveAt
- v.ClearFlag();
- v.RemoveAt(0);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue(((IList<int>)v).Count, 0);
- //Clear
- v.Add(1);
- v.Add(2);
- v.ClearFlag();
- ((IList<int>)v).Clear();
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
- ValidateValue(((IList<int>)v).Count, 0);
- var m = v;
- //Add
- m.ClearFlag();
- m.Add(1, 2);
- ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_Insert);
- ValidateValue(((IDictionary<int, int>)m).Count, 1);
- //ContainsKey
- m.ClearFlag();
- bool key = m.ContainsKey(1);
- ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_HasKey);
- //Lookup
- m.ClearFlag();
- int val2 = ((int)(v as IDictionary<int, int>)[1]);
- ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_Lookup);
- ValidateValue(val2, 2);
- //Keys
- m.ClearFlag();
- var keys = m.Keys;
- ValidateMethod(m.GetFlagState(), TestMethodCalled.NotSet);
- //Values
- m.ClearFlag();
- var values = m.Values;
- ValidateMethod(m.GetFlagState(), TestMethodCalled.NotSet);
- //Lookup
- m.ClearFlag();
- int outVal;
- bool success = ((IDictionary<int, int>)m).TryGetValue(1, out outVal);
- ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_Lookup);
- ValidateValue(success, true);
- ValidateValue(outVal, 2);
- //Add
- m.ClearFlag();
- m.Add(new KeyValuePair<int, int>(3, 4));
- ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_Insert);
- ValidateValue(((IDictionary<int, int>)m).Count, 2);
- //Contains
- m.ClearFlag();
- bool contains = m.Contains(new KeyValuePair<int, int>(3, 4));
- ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_Lookup);
- ValidateValue(contains, true);
- //non-existant pair
- m.ClearFlag();
- contains = m.Contains(new KeyValuePair<int, int>(8, 9));
- ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_HasKey);
- ValidateValue(contains, false);
- //Remove
- m.ClearFlag();
- bool remove = ((IDictionary<int, int>)m).Remove(1);
- ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_Remove);
- ValidateValue(((IDictionary<int, int>)m).Count, 1);
- ValidateValue(remove, true);
- //CopyTo
- //m.ClearFlag()
- //Dim arr As KeyValuePair(Of Integer, Integer)()
- //ReDim arr(10)
- //m.CopyTo(arr, 1)
- //ValidateMethod(m.GetFlagState(), TestMethodCalled.IVector_GetAt)
- //ValidateValue(arr[0].Value, 2)
- //Count
- m.ClearFlag();
- int count = ((IDictionary<int, int>)m).Count;
- ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_get_Size);
- ValidateValue(count, 1);
- //isReadOnly
- m.ClearFlag();
- isReadOnly = ((IDictionary<int, int>)m).IsReadOnly;
- ValidateMethod(m.GetFlagState(), TestMethodCalled.NotSet);
- ValidateValue(isReadOnly, false);
- //Remove
- m.ClearFlag();
- var rez2 = m.Remove(new KeyValuePair<int, int>(3, 4));
- ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_Remove);
- ValidateValue(rez2, true);
- m.ClearFlag();
- rez2 = m.Remove(new KeyValuePair<int, int>(2, 3));
- ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_HasKey);
- ValidateValue(rez2, false);
- m.Add(1, 2);
- m.Add(2, 3);
- m.ClearFlag();
- ((IDictionary<int, int>)m).Clear();
- ValidateMethod(m.GetFlagState(), TestMethodCalled.IMap_Clear);
- ValidateValue(((IDictionary<int, int>)m).Count, 0);
- }
- static void TestIVectorExplicitAddMembers()
- {
- IVectorExplicitAdd v = new IVectorExplicitAdd();
- //Calling the user defined Add method
- v.ClearFlag();
- ((IMemberAdd)v).Add(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.UserDef_Add);
- v.ClearFlag();
- ((IMemberAdd)v).Add(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.UserDef_Add);
- //Calling the Interface Add's method
- v.ClearFlag();
- ((IList<int>)v).Add(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
- ValidateValue(v[0], 1);
- }
- static void TestIVectorViewMembers()
- {
- var v = new IVectorViewInt();
- v.ClearFlag();
- int count = v.Count;
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVectorView_get_Size);
- }
- static void TestIVectorUIntIVectorViewIntMembers()
- {
- Console.WriteLine(""=== IVectorUintIVectorViewInt ==="");
- var v = new IVectorUintIVectorViewInt();
- //Add
- v.ClearFlag();
- v.Add(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
- ValidateValue((v as IList<uint>)[0], 1);
- //Contains
- v.ClearFlag();
- bool b = v.Contains(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(b, true);
- //CopyTo
- v.ClearFlag();
- uint[] arr = new uint[10];
- v.CopyTo(arr, 0);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(arr[0], 1);
- ValidateValue(arr[1], 0); //there should be nothing there! :)
- //GetEnumerator
- v.ClearFlag();
- uint count = ((uint)(v as IList<uint>).Count);
- IEnumerator<uint> enumerator = ((IEnumerable<uint>)v).GetEnumerator();
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IIterable_First);
- uint index = 0;
- foreach (var e in v)
- {
- index = ((uint)index + 1);
- ValidateValue(e, index);
- }
- ValidateValue(index, 1); //there should only be 1 element there
- //IndexOf
- v.ClearFlag();
- var rez = v.IndexOf(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(rez, 0); // 1 is on the first line :)
- //Insert
- v.ClearFlag();
- v.Insert(1, 2);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
- ValidateValue((v as IList<uint>)[1], 2);
- //IsReadOnly
- v.ClearFlag();
- bool isReadOnly = v.IsReadOnly;
- ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
- ValidateValue(isReadOnly, false);
- //Indexing
- v.ClearFlag();
- uint val = (v as IList<uint>)[0];
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(val, 1);
- v.ClearFlag();
- val = (((IList<uint>)v))[1];
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(val, 2);
- //Remove
- v.ClearFlag();
- v.Remove(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue((v as IList<uint>).Count, 1);
- //RemoveAt
- v.ClearFlag();
- v.RemoveAt(0);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue((v as IList<uint>).Count, 0);
- //Clear
- v.Add(1);
- v.Add(2);
- v.ClearFlag();
- v.Clear();
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
- ValidateValue((v as IList<uint>).Count, 0);
- // IVectorView members
- v.Add(1);
- v.Add(2);
- v.ClearFlag();
- ValidateValue(((IReadOnlyList<uint>)v).Count, 2);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_get_Size);
- v.ClearFlag();
- ValidateValue(((IReadOnlyList<uint>)v)[0], 1);
- ValidateValue(((IReadOnlyList<uint>)v)[1], 2);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVectorView_GetAt);
- }
- static void TestIVectorIntIVectorViewUintMembers()
- {
- Console.WriteLine(""=== IVectorIntIVectorViewUint ==="");
- var v = new IVectorIntIVectorViewUint();
- //Add
- v.ClearFlag();
- v.Add(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Append);
- ValidateValue((v as IList<int>)[0], 1);
- //Contains
- v.ClearFlag();
- bool b = v.Contains(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(b, true);
- //CopyTo
- v.ClearFlag();
- int[] arr = new int[10];
- v.CopyTo(arr, 0);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(arr[0], 1);
- ValidateValue(arr[1], 0); //there should be nothing there! :)
- //GetEnumerator
- v.ClearFlag();
- uint count = ((uint)(((IList<int>)v)).Count);
- IEnumerator<int> enumerator = (((IList<int>)v)).GetEnumerator();
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IIterable_First);
- uint index = 0;
- foreach (var e in (((IList<int>)v)))
- {
- index = ((uint)index + 1);
- ValidateValue(e, index);
- }
- ValidateValue(index, 1); //there should only be 1 element there
- //IndexOf
- v.ClearFlag();
- var rez = v.IndexOf(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_IndexOf);
- ValidateValue(rez, 0); // 1 is on the first line :)
- //Insert
- v.ClearFlag();
- v.Insert(1, 2);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_InsertAt);
- ValidateValue((v as IList<int>)[1], 2);
- //IsReadOnly
- v.ClearFlag();
- bool isReadOnly = v.IsReadOnly;
- ValidateMethod(v.GetFlagState(), TestMethodCalled.NotSet);
- ValidateValue(isReadOnly, false);
- //Indexing
- v.ClearFlag();
- uint val = ((uint)(v as IList<int>)[0]);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(val, 1);
- v.ClearFlag();
- val = ((uint)(((IList<int>)v))[1]);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- ValidateValue(val, 2);
- //Remove
- v.ClearFlag();
- v.Remove(1);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue((((IList<int>)v)).Count, 1);
- //RemoveAt
- v.ClearFlag();
- v.RemoveAt(0);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_RemoveAt);
- ValidateValue((((IList<int>)v)).Count, 0);
- //Clear
- v.Add(1);
- v.Add(2);
- v.ClearFlag();
- v.Clear();
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_Clear);
- ValidateValue((((IList<int>)v)).Count, 0);
- // IVectorView members
- v.Add(1);
- v.Add(2);
- v.ClearFlag();
- ValidateValue(((IReadOnlyList<uint>)v)[0], 0);
- ValidateValue(((IReadOnlyList<uint>)v)[1], 0);
- ValidateMethod(v.GetFlagState(), TestMethodCalled.IVector_GetAt);
- }
- static void TestIVectorStructIVectorViewStructMembers()
- {
- Console.WriteLine(""=== IVectorStructIVectorView…
Large files files are truncated, but you can click here to view the full file