diff --git a/src/System.Collections.NonGeneric.sln b/src/System.Collections.NonGeneric.sln index caf4dbe974ca..8f8af47c6b60 100644 --- a/src/System.Collections.NonGeneric.sln +++ b/src/System.Collections.NonGeneric.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Collections.NonGeneric", "System.Collections.NonGeneric\src\System.Collections.NonGeneric.csproj", "{585E3764-534B-4A12-8BD5-8578CB826A45}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Collections.NonGeneric.Tests", "System.Collections.NonGeneric\tests\System.Collections.NonGeneric.Tests.csproj", "{D857AA4D-7D23-4EAF-8367-C548604F587F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {585E3764-534B-4A12-8BD5-8578CB826A45}.Debug|Any CPU.Build.0 = Debug|Any CPU {585E3764-534B-4A12-8BD5-8578CB826A45}.Release|Any CPU.ActiveCfg = Release|Any CPU {585E3764-534B-4A12-8BD5-8578CB826A45}.Release|Any CPU.Build.0 = Release|Any CPU + {D857AA4D-7D23-4EAF-8367-C548604F587F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D857AA4D-7D23-4EAF-8367-C548604F587F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D857AA4D-7D23-4EAF-8367-C548604F587F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D857AA4D-7D23-4EAF-8367-C548604F587F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/System.Collections.NonGeneric/tests/CaseInsensitiveComparer/CaseInsensitiveComparer_CultureInfo.cs b/src/System.Collections.NonGeneric/tests/CaseInsensitiveComparer/CaseInsensitiveComparer_CultureInfo.cs new file mode 100644 index 000000000000..dd98874c71d4 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/CaseInsensitiveComparer/CaseInsensitiveComparer_CultureInfo.cs @@ -0,0 +1,161 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using System.Globalization; +using Xunit; + +public class CaseInsensitiveComparer_CultureInfo +{ + + public bool runTest() + { + //////////// Global Variables used for all tests + int iCountErrors = 0; + int iCountTestcases = 0; + + CaseInsensitiveComparer comparer; + + try + { + ///////////////////////// START TESTS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + //[]vanila - the ctor simply sets the ComapreInfo to the current culture - CultureInfo.CurrentCulture.CompareInfo + //There is no easy way to test this other than make sure that string comparison is case insenstive + + iCountTestcases++; + iCountTestcases++; + iCountTestcases++; + + var somePopularCultureNames = new string[] { + "cs-CZ","da-DK","de-DE","el-GR","en-US", + "es-ES","fi-FI","fr-FR","hu-HU","it-IT", + "ja-JP","ko-KR","nb-NO","nl-NL","pl-PL", + "pt-BR","pt-PT","ru-RU","sv-SE","tr-TR", + "zh-CN","zh-HK","zh-TW" }; + foreach (string cultureName in somePopularCultureNames) + { + CultureInfo culture = new CultureInfo(cultureName); + if (culture == null) + { + continue; + } + comparer = new CaseInsensitiveComparer(culture); + + if (comparer.Compare("hello", "HELLO") != 0) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>, Culture: {2}", 0, comparer.Compare("hello", "HELLO"), culture.Name); + } + + //same strings should work ok + if (comparer.Compare("hello", "hello") != 0) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>, Culture: {2}", 0, comparer.Compare("hello", "hello"), culture.Name); + } + + //different strings should return false + if (comparer.Compare("hello", "mello") == 0) + { + iCountErrors++; + Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>, Culture: {2}", "non-zero", comparer.Compare("hello", "mello"), culture.Name); + } + + // "tr-TR" = "Turkish (Turkey)" + // Turkish has lower-case and upper-case version of the dotted "i", so the upper case of "i" (U+0069) isn't "I" (U+0049), but rather "İ" (U+0130). + if (culture.Name != "tr-TR") + { + if (comparer.Compare("file", "FILE") != 0) + { + iCountErrors++; + Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>, Culture: {2}", 0, comparer.Compare("file", "FILE"), culture.Name); + } + } + else + { + if (comparer.Compare("file", "FILE") == 0) + { + iCountErrors++; + Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>, Culture: {2}", "non-zero", comparer.Compare("file", "FILE"), culture.Name); + } + } + + //[]Other data types should work as is + iCountTestcases++; + if (comparer.Compare(5, 5) != 0) + { + iCountErrors++; + Console.WriteLine("Err_347tsfg! wrong value returned"); + } + + if (comparer.Compare(5, 10) == 0) + { + iCountErrors++; + Console.WriteLine("Err_973425sdg! wrong value returned"); + } + } + + //[]parm test + iCountTestcases++; + try + { + + + comparer = new CaseInsensitiveComparer(null); + + iCountErrors++; + Console.WriteLine("Err_9745sdg! Exception not thrown"); + } + catch (ArgumentNullException) + { + } + catch (Exception ex) + { + iCountErrors++; + Console.WriteLine("Err_9745sdg! Unexpected exception thrown, " + ex.GetType().Name); + } + /////////////////////////////////////////////////////////////////// + /////////////////////////// END TESTS ///////////////////////////// + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==" + exc_general.ToString()); + } + //// Finish Diagnostics + + if (iCountErrors == 0) + { + return true; + } + else + { + return false; + } + } + + + + [Fact] + public static void ExecuteCaseInsensitiveComparer_CultureInfo() + { + bool bResult = false; + var test = new CaseInsensitiveComparer_CultureInfo(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + }} + + diff --git a/src/System.Collections.NonGeneric/tests/CaseInsensitiveComparer/CaseInsensitiveComparer_Default.cs b/src/System.Collections.NonGeneric/tests/CaseInsensitiveComparer/CaseInsensitiveComparer_Default.cs new file mode 100644 index 000000000000..fad39efc4836 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/CaseInsensitiveComparer/CaseInsensitiveComparer_Default.cs @@ -0,0 +1,141 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Threading; +using System.Collections; +using System.Globalization; +using Xunit; + +public class CaseInsensitiveComparer_Default +{ + public bool runTest() + { + //////////// Global Variables used for all tests + int iCountErrors = 0; + int iCountTestcases = 0; + + CaseInsensitiveComparer comparer; + CaseInsensitiveComparer defaultComparer; + + try + { + ///////////////////////// START TESTS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + //[]vanila - Default sets the ComapreInfo to the current culture - CultureInfo.CurrentCulture.CompareInfo + //There is no easy way to test this other than make sure that string comparison is case insenstive + + iCountTestcases++; + iCountTestcases++; + + var somePopularCultureNames = new string[] { + "cs-CZ","da-DK","de-DE","el-GR","en-US", + "es-ES","fi-FI","fr-FR","hu-HU","it-IT", + "ja-JP","ko-KR","nb-NO","nl-NL","pl-PL", + "pt-BR","pt-PT","ru-RU","sv-SE","tr-TR", + "zh-CN","zh-HK","zh-TW" }; + foreach (string cultureName in somePopularCultureNames) + { + CultureInfo culture = new CultureInfo(cultureName); + if (culture == null) + { + continue; + } + comparer = new CaseInsensitiveComparer(culture); + defaultComparer = CaseInsensitiveComparer.Default; + + if (defaultComparer.Compare("hello", "HELLO") != 0) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultComparer.Compare("hello", "HELLO")); + } + + //same strings should work ok + if (defaultComparer.Compare("hello", "hello") != 0) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultComparer.Compare("hello", "hello")); + } + + //different strings should return false + if (defaultComparer.Compare("hello", "mello") == 0) + { + iCountErrors++; + Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultComparer.Compare("hello", "mello")); + } + + //What would turkey do? - Since we are comparing with the default culture, unless this is run on a turkish machine, this will pass + if (CultureInfo.CurrentCulture.Name != "tr-TR") + { + if (defaultComparer.Compare("file", "FILE") != 0) + { + iCountErrors++; + Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultComparer.Compare("file", "FILE")); + } + } + else + { + if (defaultComparer.Compare("file", "FILE") == 0) + { + iCountErrors++; + Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultComparer.Compare("file", "FILE")); + } + } + + //[]Other data types should work as is + iCountTestcases++; + if (defaultComparer.Compare(5, 5) != 0) + { + iCountErrors++; + Console.WriteLine("Err_347tsfg! wrong value returned"); + } + + if (defaultComparer.Compare(5, 10) == 0) + { + iCountErrors++; + Console.WriteLine("Err_973425sdg! wrong value returned"); + } + } + + /////////////////////////////////////////////////////////////////// + /////////////////////////// END TESTS ///////////////////////////// + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==" + exc_general.ToString()); + } + //// Finish Diagnostics + + if (iCountErrors == 0) + { + return true; + } + else + { + return false; + } + } + + + + [Fact] + public static void ExecuteCaseInsensitiveComparer_Default() + { + bool bResult = false; + var test = new CaseInsensitiveComparer_Default(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } +} diff --git a/src/System.Collections.NonGeneric/tests/CaseInsensitiveComparer/CaseInsensitiveComparer_DefaultInvariant.cs b/src/System.Collections.NonGeneric/tests/CaseInsensitiveComparer/CaseInsensitiveComparer_DefaultInvariant.cs new file mode 100644 index 000000000000..dca1893eac8f --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/CaseInsensitiveComparer/CaseInsensitiveComparer_DefaultInvariant.cs @@ -0,0 +1,133 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Threading; +using System.Collections; +using System.Globalization; +using Xunit; + +public class CaseInsensitiveComparer_DefaultInvariant +{ + + public bool runTest() + { + //////////// Global Variables used for all tests + int iCountErrors = 0; + int iCountTestcases = 0; + + CaseInsensitiveComparer comparer; + CaseInsensitiveComparer defaultInvComparer; + + try + { + ///////////////////////// START TESTS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + //[]vanila - Default sets the ComapreInfo to the current culture - CultureInfo.CurrentCulture.CompareInfo + //There is no easy way to test this other than make sure that string comparison is case insenstive + + iCountTestcases++; + iCountTestcases++; + + var somePopularCultureNames = new string[] { + "cs-CZ","da-DK","de-DE","el-GR","en-US", + "es-ES","fi-FI","fr-FR","hu-HU","it-IT", + "ja-JP","ko-KR","nb-NO","nl-NL","pl-PL", + "pt-BR","pt-PT","ru-RU","sv-SE","tr-TR", + "zh-CN","zh-HK","zh-TW" }; + foreach (string cultureName in somePopularCultureNames) + { + CultureInfo culture = new CultureInfo(cultureName); + if (culture == null) + { + continue; + } + comparer = new CaseInsensitiveComparer(culture); + defaultInvComparer = CaseInsensitiveComparer.DefaultInvariant; + + if (defaultInvComparer.Compare("hello", "HELLO") != 0) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultInvComparer.Compare("hello", "HELLO")); + } + + //same strings should work ok + if (defaultInvComparer.Compare("hello", "hello") != 0) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultInvComparer.Compare("hello", "hello")); + } + + //different strings should return false + if (defaultInvComparer.Compare("hello", "mello") == 0) + { + iCountErrors++; + Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultInvComparer.Compare("hello", "mello")); + } + + //What would turkey do? - Since we are comparing with the invariant culture, this will pass + if (defaultInvComparer.Compare("file", "FILE") != 0) + { + iCountErrors++; + Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultInvComparer.Compare("file", "FILE")); + } + + //[]Other data types should work as is + iCountTestcases++; + if (defaultInvComparer.Compare(5, 5) != 0) + { + iCountErrors++; + Console.WriteLine("Err_347tsfg! wrong value returned"); + } + + if (defaultInvComparer.Compare(5, 10) == 0) + { + iCountErrors++; + Console.WriteLine("Err_973425sdg! wrong value returned"); + } + } + + /////////////////////////////////////////////////////////////////// + /////////////////////////// END TESTS ///////////////////////////// + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==" + exc_general.ToString()); + } + //// Finish Diagnostics + + if (iCountErrors == 0) + { + return true; + } + else + { + return false; + } + } + + + + [Fact] + public static void ExecuteCaseInsensitiveComparer_DefaultInvariant() + { + bool bResult = false; + var test = new CaseInsensitiveComparer_DefaultInvariant(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } +} + + diff --git a/src/System.Collections.NonGeneric/tests/CaseInsensitiveComparer/CaseInsensitiveComparer_Object.cs b/src/System.Collections.NonGeneric/tests/CaseInsensitiveComparer/CaseInsensitiveComparer_Object.cs new file mode 100644 index 000000000000..60edaf371cd6 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/CaseInsensitiveComparer/CaseInsensitiveComparer_Object.cs @@ -0,0 +1,156 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using System.Globalization; +using Xunit; + +public class CaseInsensitiveComparer_Object +{ + public bool runTest() + { + //////////// Global Variables used for all tests + int iCountErrors = 0; + int iCountTestcases = 0; + + CaseInsensitiveComparer comparer; + String str1; + String str2; + + try + { + ///////////////////////// START TESTS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + //[]vanila - the ctor simply sets the ComapreInfo to the current culture - CultureInfo.CurrentCulture.CompareInfo + //There is no easy way to test this other than make sure that string comparison is case insenstive + + iCountTestcases++; + + comparer = new CaseInsensitiveComparer(); + + if (comparer.Compare("hello", "HELLO") != 0) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, comparer.Compare("hello", "HELLO")); + } + + //same strings should work ok + if (comparer.Compare("hello", "hello") != 0) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, comparer.Compare("hello", "hello")); + } + + //different strings should return false + if (comparer.Compare("hello", "mello") == 0) + { + iCountErrors++; + Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, comparer.Compare("hello", "mello")); + } + + + //[]Other data types should work as is + iCountTestcases++; + if (comparer.Compare(5, 5) != 0) + { + iCountErrors++; + Console.WriteLine("Err_347tsfg! wrong value returned"); + } + + if (comparer.Compare(5, 10) == 0) + { + iCountErrors++; + Console.WriteLine("Err_973425sdg! wrong value returned"); + } + + //[]we will consider nulls + iCountTestcases++; + if (comparer.Compare(5, null) <= 0) + { + iCountErrors++; + Console.WriteLine("Err_83sdg! wrong value returned, " + comparer.Compare(5, null)); + } + + if (comparer.Compare(null, 5) >= 0) + { + iCountErrors++; + Console.WriteLine("Err_94375sdg! wrong value returned, " + comparer.Compare(null, 5)); + } + + if (comparer.Compare(null, null) != 0) + { + iCountErrors++; + Console.WriteLine("Err_94375sdg! wrong value returned, " + comparer.Compare(null, null)); + } + + //[]we will consider nulls with Strings + iCountTestcases++; + str1 = "Hello"; + str2 = null; + if (comparer.Compare(str1, str2) <= 0) + { + iCountErrors++; + Console.WriteLine("Err_948732dsg! wrong value returned, " + comparer.Compare(str1, str2)); + } + + str1 = null; + str2 = "Hello"; + if (comparer.Compare(str1, str2) >= 0) + { + iCountErrors++; + Console.WriteLine("Err_948732dsg! wrong value returned, " + comparer.Compare(str1, str2)); + } + + str1 = null; + str2 = null; + if (comparer.Compare(str1, str2) != 0) + { + iCountErrors++; + Console.WriteLine("Err_948732dsg! wrong value returned, " + comparer.Compare(str1, str2)); + } + + + /////////////////////////////////////////////////////////////////// + /////////////////////////// END TESTS ///////////////////////////// + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==" + exc_general.ToString()); + } + //// Finish Diagnostics + + if (iCountErrors == 0) + { + return true; + } + else + { + return false; + } + } + + + + [Fact] + public static void ExecuteCaseInsensitiveComparer_Object() + { + bool bResult = false; + var test = new CaseInsensitiveComparer_ctor(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + }} + + diff --git a/src/System.Collections.NonGeneric/tests/CaseInsensitiveComparer/CaseInsensitiveComparer_ctor.cs b/src/System.Collections.NonGeneric/tests/CaseInsensitiveComparer/CaseInsensitiveComparer_ctor.cs new file mode 100644 index 000000000000..33496187ed12 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/CaseInsensitiveComparer/CaseInsensitiveComparer_ctor.cs @@ -0,0 +1,107 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using System.Globalization; +using Xunit; + +public class CaseInsensitiveComparer_ctor +{ + + public bool runTest() + { + //////////// Global Variables used for all tests + int iCountErrors = 0; + int iCountTestcases = 0; + + CaseInsensitiveComparer comparer; + + try + { + ///////////////////////// START TESTS //////////////////////////// + + //[]vanila - the ctor simply sets the ComapreInfo to the current culture - CultureInfo.CurrentCulture.CompareInfo + //There is no easy way to test this other than make sure that string comparison is case insenstive + + iCountTestcases++; + + comparer = new CaseInsensitiveComparer(); + + if (comparer.Compare("hello", "HELLO") != 0) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, comparer.Compare("hello", "HELLO")); + } + + //same strings should work ok + if (comparer.Compare("hello", "hello") != 0) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, comparer.Compare("hello", "hello")); + } + + //different strings should return false + if (comparer.Compare("hello", "mello") == 0) + { + iCountErrors++; + Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, comparer.Compare("hello", "mello")); + } + + + //[]Other data types should work as is + iCountTestcases++; + if (comparer.Compare(5, 5) != 0) + { + iCountErrors++; + Console.WriteLine("Err_347tsfg! wrong value returned"); + } + + if (comparer.Compare(5, 10) == 0) + { + iCountErrors++; + Console.WriteLine("Err_973425sdg! wrong value returned"); + } + + /////////////////////////////////////////////////////////////////// + /////////////////////////// END TESTS ///////////////////////////// + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==" + exc_general.ToString()); + } + //// Finish Diagnostics + + if (iCountErrors == 0) + { + return true; + } + else + { + return false; + } + } + + + [Fact] + public static void ExecuteCaseInsensitiveComparer_ctor() + { + bool bResult = false; + var test = new CaseInsensitiveComparer_ctor(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } +} + + diff --git a/src/System.Collections.NonGeneric/tests/CollectionBase/CollectionBase_AllMethods.cs b/src/System.Collections.NonGeneric/tests/CollectionBase/CollectionBase_AllMethods.cs new file mode 100644 index 000000000000..6cc7dc961aba --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/CollectionBase/CollectionBase_AllMethods.cs @@ -0,0 +1,506 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Threading; +using System.Collections; +using Xunit; + +public class CollectionBase_AllMethods +{ + public bool runTest() + { + //////////// Global Variables used for all tests + int iCountErrors = 0; + int iCountTestcases = 0; + + MyCollectionBase mycol1; + MyCollectionBase mycol2; + Foo f1; + Foo[] arrF1; + IEnumerator enu1; + Int32 iCount; + Object obj1; + + try + { + do + { + ///////////////////////// START TESTS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + //[]CollectionBase implements IList (which means both ICollection and IEnumerator as well :-() + //To test this class, we will implement our own strongly typed CollectionBase and call its methods + iCountTestcases++; + + //[] Count property + iCountTestcases++; + mycol1 = new MyCollectionBase(); + if (mycol1.Count != 0) + { + iCountErrors++; + Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count); + } + for (int i = 0; i < 100; i++) + mycol1.Add(new Foo()); + if (mycol1.Count != 100) + { + iCountErrors++; + Console.WriteLine("Err_2075sg! Expected value not returned, " + mycol1.Count); + } + + //[]this[int index] argument checking + iCountTestcases++; + mycol1 = new MyCollectionBase(); + for (int i = 0; i < 100; i++) + mycol1.Add(new Foo()); + + try + { + Object o = mycol1[-1]; + iCountErrors++; + Console.WriteLine("Err_0823afds Expected CollectionBase[-1] to throw ArgumentOutOfRangeException"); + } + catch (ArgumentOutOfRangeException) { } + + try + { + Object o = mycol1[100]; + iCountErrors++; + Console.WriteLine("Err_8094sadd Expected CollectionBase[100] with only 100 elements to throw ArgumentOutOfRangeException"); + } + catch (ArgumentOutOfRangeException) { } + + try + { + mycol1[-1] = new Foo(); + iCountErrors++; + Console.WriteLine("Err_2773apnn Expected CollectionBase[-1] to throw ArgumentOutOfRangeException"); + } + catch (ArgumentOutOfRangeException) { } + + try + { + mycol1[100] = new Foo(); + iCountErrors++; + Console.WriteLine("Err_3402hnxz Expected CollectionBase[100] with only 100 elements to throw ArgumentOutOfRangeException"); + } + catch (ArgumentOutOfRangeException) { } + + //[]CopyTo + iCountTestcases++; + mycol1 = new MyCollectionBase(); + for (int i = 0; i < 100; i++) + mycol1.Add(new Foo(i, i.ToString())); + arrF1 = new Foo[100]; + mycol1.CopyTo(arrF1, 0); + for (int i = 0; i < 100; i++) + { + if ((arrF1[i].IValue != i) || (arrF1[i].SValue != i.ToString())) + { + iCountErrors++; + Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned"); + } + } + + //Argument checking + mycol1 = new MyCollectionBase(); + for (int i = 0; i < 100; i++) + mycol1.Add(new Foo(i, i.ToString())); + arrF1 = new Foo[100]; + try + { + mycol1.CopyTo(arrF1, 50); + + iCountErrors++; + Console.WriteLine("Err_2075dfgv! Exception not thrown"); + } + catch (ArgumentException) + { + } + catch (Exception ex) + { + iCountErrors++; + Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); + } + + try + { + mycol1.CopyTo(arrF1, -1); + + iCountErrors++; + Console.WriteLine("Err_2075dfgv! Exception not thrown"); + } + catch (ArgumentException) + { + } + catch (Exception ex) + { + iCountErrors++; + Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); + } + + iCountTestcases++; + arrF1 = new Foo[200]; + mycol1.CopyTo(arrF1, 100); + for (int i = 0; i < 100; i++) + { + if ((arrF1[100 + i].IValue != i) || (arrF1[100 + i].SValue != i.ToString())) + { + iCountErrors++; + Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned"); + } + } + + //[]GetEnumerator + iCountTestcases++; + mycol1 = new MyCollectionBase(); + for (int i = 0; i < 100; i++) + mycol1.Add(new Foo(i, i.ToString())); + + enu1 = mycol1.GetEnumerator(); + //Calling current should throw here + try + { + //Calling current should throw here + f1 = (Foo)enu1.Current; + + iCountErrors++; + Console.WriteLine("Err_87543! Exception not thrown"); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); + } + + iCount = 0; + while (enu1.MoveNext()) + { + f1 = (Foo)enu1.Current; + if ((f1.IValue != iCount) || (f1.SValue != iCount.ToString())) + { + iCountErrors++; + Console.WriteLine("Err_87543! does not match, " + f1.IValue); + } + iCount++; + } + if (iCount != 100) + { + iCountErrors++; + Console.WriteLine("Err_87543! doesnot match"); + } + + //Calling current should throw here + try + { + //Calling current should throw here + f1 = (Foo)enu1.Current; + + iCountErrors++; + Console.WriteLine("Err_438fsfd! Exception not thrown"); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); + } + + //[]IsSynchronized + iCountTestcases++; + mycol1 = new MyCollectionBase(); + if (mycol1.IsSynchronized) + { + iCountErrors++; + Console.WriteLine("Err_275eg! Expected value not returned, " + ((ICollection)mycol1).IsSynchronized); + } + + //[]IsReadOnly + iCountTestcases++; + mycol1 = new MyCollectionBase(); + if (mycol1.IsReadOnly) + { + iCountErrors++; + Console.WriteLine("Err_2508aszp! Expected value not returned, " + mycol1.IsReadOnly); + } + + //[]IsFixedSize + iCountTestcases++; + mycol1 = new MyCollectionBase(); + if (mycol1.IsFixedSize) + { + iCountErrors++; + Console.WriteLine("Err_0803puj! Expected value not returned, " + mycol1.IsFixedSize); + } + + //[]SyncRoot - SyncRoot should be the reference to the underlying collection, not to MyCollectionBase + iCountTestcases++; + mycol1 = new MyCollectionBase(); + obj1 = mycol1.SyncRoot; + mycol2 = mycol1; + if (obj1 != mycol2.SyncRoot) + { + iCountErrors++; + Console.WriteLine("Err_9745sg! Expected value not returned"); + } + + //End of ICollection and IEnumerator methods + //Now to IList methods + //[]Add, this, Contains, RemoveAt, IndexOf + iCountTestcases++; + mycol1 = new MyCollectionBase(); + for (int i = 0; i < 100; i++) + mycol1.Add(new Foo(i, i.ToString())); + for (int i = 0; i < 100; i++) + { + if ((mycol1[i].IValue != i) || (mycol1[i].SValue != i.ToString())) + { + iCountErrors++; + Console.WriteLine("Err_2974swsg_" + i + "! Expected value not returned"); + } + if ((mycol1.IndexOf(new Foo(i, i.ToString())) != i)) + { + iCountErrors++; + Console.WriteLine("Err_205sg_" + i + "! Expected value not returned"); + } + } + for (int i = 99; i >= 0; i--) + { + mycol1.RemoveAt(0); + if ((mycol1.Count != (i))) + { + iCountErrors++; + Console.WriteLine("Err_2975sg_" + i + "! Expected value not returned"); + } + //WE have removed the first half by the time the counter comes there + if (i >= 50) + { + if ((!mycol1.Contains(new Foo(i, i.ToString())))) + { + iCountErrors++; + Console.WriteLine("Err_975wg_" + i + "! Expected value not returned"); + } + } + else + { + if ((mycol1.Contains(new Foo(i, i.ToString())))) + { + iCountErrors++; + Console.WriteLine("Err_975wg_" + i + "! Expected value not returned"); + } + } + } + + //[]Rest of the IList methods: this-set, Remove, Insert, Clear, IsFixedSize, IsReadOnly + iCountTestcases++; + mycol1 = new MyCollectionBase(); + if (((IList)mycol1).IsFixedSize) + { + iCountErrors++; + Console.WriteLine("Err_9753sfg! Expected value not returned, " + ((IList)mycol1).IsFixedSize); + } + if (((IList)mycol1).IsReadOnly) + { + iCountErrors++; + Console.WriteLine("Err_834sg! Expected value not returned, " + ((IList)mycol1).IsReadOnly); + } + for (int i = 0; i < 100; i++) + { + mycol1.Insert(i, new Foo(i, i.ToString())); + if (!(mycol1.Contains(new Foo(i, i.ToString())))) + { + iCountErrors++; + Console.WriteLine("Err_753sg_" + i + "! Expected value not returned"); + } + } + for (int i = 0; i < 100; i++) + { + mycol1.Remove(new Foo(i, i.ToString())); + if ((mycol1.Contains(new Foo(i, i.ToString())))) + { + iCountErrors++; + Console.WriteLine("Err_2085sg_" + i + "! Expected value not returned"); + } + } + mycol1 = new MyCollectionBase(); + for (int i = 0; i < 100; i++) + mycol1.Add(new Foo(i, i.ToString())); + mycol1.Clear(); + if (mycol1.Count != 0) + { + iCountErrors++; + Console.WriteLine("Err_847tfgdg! Expected value not returned, " + mycol1.Count); + } + mycol1 = new MyCollectionBase(); + for (int i = 0; i < 100; i++) + mycol1.Add(new Foo(i, i.ToString())); + for (int i = 0, j = 100; i < 100; i++, j--) + mycol1[i] = new Foo(j, j.ToString()); + for (int i = 0, j = 100; i < 100; i++, j--) + { + if ((mycol1.IndexOf(new Foo(j, j.ToString())) != i)) + { + iCountErrors++; + Console.WriteLine("Err_7342rfg_" + i + "! Expected value not returned"); + } + } + + mycol1 = new MyCollectionBase(); + mycol1.Add(new Foo()); + + /////////////////////////////////////////////////////////////////// + /////////////////////////// END TESTS ///////////////////////////// + + + } while (false); + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString()); + } + + //// Finish Diagnostics + if (iCountErrors == 0) + { + return true; + } + else + { + return false; + } + } + + + [Fact] + public static void ExecuteCollectionBase_AllMethods() + { + bool bResult = false; + var test = new CollectionBase_AllMethods(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } + + //CollectionBase is provided to be used as the base class for strongly typed collections. Lets use one of our own here + public class MyCollectionBase : CollectionBase + { + public MyCollectionBase() + { + } + + public int Add(Foo f1) + { + return List.Add(f1); + } + + public Foo this[int indx] + { + get { return (Foo)List[indx]; } + set { List[indx] = value; } + } + + public void CopyTo(Array array, Int32 index) + { + ((ICollection)List).CopyTo(array, index); + } + + public Int32 IndexOf(Foo f) + { + return ((IList)List).IndexOf(f); + } + + public Boolean Contains(Foo f) + { + return ((IList)List).Contains(f); + } + + public void Insert(Int32 index, Foo f) + { + ((IList)List).Insert(index, f); + } + + public void Remove(Foo f) + { + ((IList)List).Remove(f); + } + + public bool IsSynchronized + { + get { return ((ICollection)this).IsSynchronized; } + } + + public Object SyncRoot + { + get { return ((ICollection)this).SyncRoot; } + } + + public bool IsReadOnly + { + get { return List.IsReadOnly; } + } + + public bool IsFixedSize + { + get { return List.IsFixedSize; } + } + + } + + public class Foo + { + private Int32 _iValue; + private String _strValue; + + public Foo() + { + } + + public Foo(Int32 i, String str) + { + _iValue = i; + _strValue = str; + } + + public Int32 IValue + { + get { return _iValue; } + set { _iValue = value; } + } + + public String SValue + { + get { return _strValue; } + set { _strValue = value; } + } + + public override Boolean Equals(Object obj) + { + if (obj == null) + return false; + if (!(obj is Foo)) + return false; + if ((((Foo)obj).IValue == _iValue) && (((Foo)obj).SValue == _strValue)) + return true; + return false; + } + + public override Int32 GetHashCode() + { + return _iValue; + } + } +} \ No newline at end of file diff --git a/src/System.Collections.NonGeneric/tests/CollectionBase/CollectionBase_Capacity.cs b/src/System.Collections.NonGeneric/tests/CollectionBase/CollectionBase_Capacity.cs new file mode 100644 index 000000000000..9a04622e446e --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/CollectionBase/CollectionBase_Capacity.cs @@ -0,0 +1,496 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using Xunit; + +public class Capacity +{ + public const int MAX_RND_CAPACITY = 512; + public const int LARGE_CAPACITY = 1024; + public static readonly int DEFAULT_CAPACITY = new ArrayList().Capacity; + + private int _numErrors = 0; + private int _numTestcases = 0; + private int _retValue = 100; + + public delegate bool TestDelegate(); + + [Fact] + public static void CapacityTests() + { + Capacity objTest = new Capacity(); + + try + { + objTest.RunTest(); + } + catch (Exception e) + { + Console.WriteLine(" : FAIL The following exception was thorwn in RunTest(): \n" + e.ToString()); + objTest._numErrors++; + objTest._retValue = 1; + } + + Assert.Equal(objTest._retValue, 100); + } + + public bool RunTest() + { + bool retValue = true; + + retValue &= BeginTestcase(new TestDelegate(Capacity_Int32MinValue)); + retValue &= BeginTestcase(new TestDelegate(Capacity_NegRnd)); + retValue &= BeginTestcase(new TestDelegate(Capacity_Neg1)); + retValue &= BeginTestcase(new TestDelegate(Capacity_0)); + retValue &= BeginTestcase(new TestDelegate(Capacity_1)); + retValue &= BeginTestcase(new TestDelegate(Capacity_PosRnd)); + retValue &= BeginTestcase(new TestDelegate(Capacity_Large)); + retValue &= BeginTestcase(new TestDelegate(Capacity_Int32MaxValue)); + + retValue &= BeginTestcase(new TestDelegate(Capacity_2_With2Elements)); + retValue &= BeginTestcase(new TestDelegate(Capacity_Neg1_With2Elements)); + retValue &= BeginTestcase(new TestDelegate(Capacity_0_With2Elements)); + retValue &= BeginTestcase(new TestDelegate(Capacity_1_With2Elements)); + retValue &= BeginTestcase(new TestDelegate(Capacity_3_With2Elements)); + retValue &= BeginTestcase(new TestDelegate(Capacity_64_With2Elements)); + + retValue &= BeginTestcase(new TestDelegate(Capacity_Grow)); + retValue &= BeginTestcase(new TestDelegate(Capacity_Remove)); + retValue &= BeginTestcase(new TestDelegate(Capacity_GrowRemove)); + retValue &= BeginTestcase(new TestDelegate(Capacity_EqualNumElements)); + + return retValue; + } + + public bool Capacity_Int32MinValue() + { + bool retValue = true; + + retValue &= SetCapacityAndVerify(Int32.MinValue, typeof(ArgumentOutOfRangeException)); + + if (!retValue) + { + Console.WriteLine("Err_001!!! Verifying Int32.MinValue Capacity FAILED"); + } + + return retValue; + } + + public bool Capacity_NegRnd() + { + bool retValue = true; + Random rndGen = new Random(-55); + + retValue &= SetCapacityAndVerify(rndGen.Next(Int32.MinValue, 0), typeof(ArgumentOutOfRangeException)); + + if (!retValue) + { + Console.WriteLine("Err_002!!! Verifying negative random Capacity FAILED"); + } + + return retValue; + } + + public bool Capacity_Neg1() + { + bool retValue = true; + + retValue &= SetCapacityAndVerify(-1, typeof(ArgumentOutOfRangeException)); + + if (!retValue) + { + Console.WriteLine("Err_003!!! Verifying -1 Capacity FAILED"); + } + + return retValue; + } + + public bool Capacity_0() + { + bool retValue = true; + + retValue &= SetCapacityAndVerify(0, 0, null); + + if (!retValue) + { + Console.WriteLine("Err_004!!! Verifying 0 Capacity FAILED"); + } + + return retValue; + } + + public bool Capacity_1() + { + bool retValue = true; + + retValue &= SetCapacityAndVerify(1, 1, null); + + if (!retValue) + { + Console.WriteLine("Err_005!!! Verifying 1 Capacity FAILED"); + } + + return retValue; + } + + public bool Capacity_PosRnd() + { + bool retValue = true; + Random rndGen = new Random(-55); + int rndCapacity = rndGen.Next(2, MAX_RND_CAPACITY); + + retValue &= SetCapacityAndVerify(rndCapacity, rndCapacity, null); + + if (!retValue) + { + Console.WriteLine("Err_006!!! Verifying positive random Capacity FAILED"); + } + + return retValue; + } + + public bool Capacity_Large() + { + bool retValue = true; + + retValue &= SetCapacityAndVerify(LARGE_CAPACITY, LARGE_CAPACITY, null); + + if (!retValue) + { + Console.WriteLine("Err_007!!! Verifying1 Capacity FAILED"); + } + + return retValue; + } + + public bool Capacity_Int32MaxValue() + { + bool retValue = true; + + retValue &= SetCapacityAndVerify(Int32.MaxValue, typeof(OutOfMemoryException)); + + if (!retValue) + { + Console.WriteLine("Err_008!!! Verifying Int32.MaxValue Capacity FAILED"); + } + + return retValue; + } + + public bool Capacity_2_With2Elements() + { + bool retValue = true; + MyCollection mc = new MyCollection(); + Random rndGen = new Random(-55); + + mc.Add(rndGen.Next()); + mc.Add(rndGen.Next()); + + retValue &= SetCapacityAndVerify(mc, 2, 2, null); + + if (!retValue) + { + Console.WriteLine("Err_009!!! Verifying setting capacity to 2 with 2 elements in the collection FAILED"); + } + + return retValue; + } + + public bool Capacity_Neg1_With2Elements() + { + bool retValue = true; + MyCollection mc = new MyCollection(); + Random rndGen = new Random(-55); + + mc.Add(rndGen.Next()); + mc.Add(rndGen.Next()); + + retValue &= SetCapacityAndVerify(mc, -1, mc.Capacity, typeof(ArgumentOutOfRangeException)); + + if (!retValue) + { + Console.WriteLine("Err_010!!! Verifying setting capacity to -1 with 2 elements in the collection FAILED"); + } + + return retValue; + } + + public bool Capacity_0_With2Elements() + { + bool retValue = true; + MyCollection mc = new MyCollection(); + Random rndGen = new Random(-55); + + mc.Add(rndGen.Next()); + mc.Add(rndGen.Next()); + + retValue &= SetCapacityAndVerify(mc, 0, mc.Capacity, typeof(ArgumentOutOfRangeException)); + + if (!retValue) + { + Console.WriteLine("Err_011!!! Verifying setting capacity to 0 with 2 elements in the collection FAILED"); + } + + return retValue; + } + + public bool Capacity_1_With2Elements() + { + bool retValue = true; + MyCollection mc = new MyCollection(); + Random rndGen = new Random(-55); + + mc.Add(rndGen.Next()); + mc.Add(rndGen.Next()); + + retValue &= SetCapacityAndVerify(mc, 1, mc.Capacity, typeof(ArgumentOutOfRangeException)); + + if (!retValue) + { + Console.WriteLine("Err_012!!! Verifying setting capacity to 1 with 2 elements in the collection FAILED"); + } + + return retValue; + } + + public bool Capacity_3_With2Elements() + { + bool retValue = true; + MyCollection mc = new MyCollection(); + Random rndGen = new Random(-55); + + mc.Add(rndGen.Next()); + mc.Add(rndGen.Next()); + + retValue &= SetCapacityAndVerify(mc, 3, 3, null); + + if (!retValue) + { + Console.WriteLine("Err_012!!! Verifying setting capacity to 3 with 2 elements in the collection FAILED"); + } + + return retValue; + } + + public bool Capacity_64_With2Elements() + { + bool retValue = true; + MyCollection mc = new MyCollection(); + Random rndGen = new Random(-55); + + mc.Add(rndGen.Next()); + mc.Add(rndGen.Next()); + + retValue &= SetCapacityAndVerify(mc, 64, 64, null); + + if (!retValue) + { + Console.WriteLine("Err_013!!! Verifying setting capacity to 64 with 2 elements in the collection FAILED"); + } + + return retValue; + } + + public bool Capacity_Grow() + { + bool retValue = true; + MyCollection mc = new MyCollection(4); + int initialCapacity = mc.Capacity; + Random rndGen = new Random(-55); + + for (int i = 0; i < initialCapacity + 1; i++) + { + mc.Add(rndGen.Next()); + } + + retValue &= VerifyCapacity(mc, initialCapacity * 2); + + if (!retValue) + { + Console.WriteLine("Err_014!!! Verifying growing the capacity by adding elements tot he collection FAILED"); + } + + return retValue; + } + + public bool Capacity_Remove() + { + bool retValue = true; + MyCollection mc = new MyCollection(4); + int initialCapacity = mc.Capacity; + Random rndGen = new Random(-55); + + for (int i = 0; i < initialCapacity; i++) + { + mc.Add(rndGen.Next()); + } + + mc.RemoveAt(initialCapacity - 1); + + retValue &= SetCapacityAndVerify(mc, initialCapacity - 1, initialCapacity - 1, null); + + if (!retValue) + { + Console.WriteLine("Err_015!!! Verifying adding the same number of elements to the collection as the Capacity then remoiving one FAILED"); + } + + return retValue; + } + + public bool Capacity_GrowRemove() + { + bool retValue = true; + MyCollection mc = new MyCollection(4); + int initialCapacity = mc.Capacity; + Random rndGen = new Random(-55); + + for (int i = 0; i < initialCapacity + 1; i++) + { + mc.Add(rndGen.Next()); + } + mc.RemoveAt(initialCapacity); + + retValue &= SetCapacityAndVerify(mc, initialCapacity, initialCapacity, null); + + if (!retValue) + { + Console.WriteLine("Err_016!!! Verifying growing the capacity by adding elements tot he collection then removing one FAILED"); + } + + return retValue; + } + + public bool Capacity_EqualNumElements() + { + bool retValue = true; + MyCollection mc = new MyCollection(4); + int initialCapacity = mc.Capacity; + Random rndGen = new Random(-55); + + for (int i = 0; i < initialCapacity; i++) + { + mc.Add(rndGen.Next()); + } + + retValue &= VerifyCapacity(mc, 4); + + if (!retValue) + { + Console.WriteLine("Err_017!!! Verifying adding the same number of elements to the collection as the Capacity then remoiving one FAILED"); + } + + return retValue; + } + + public bool SetCapacityAndVerify(int capacity, Type expectedException) + { + return SetCapacityAndVerify(capacity, DEFAULT_CAPACITY, expectedException); + } + + public bool SetCapacityAndVerify(int capacity, int expectedCapacity, Type expectedException) + { + MyCollection mc = new MyCollection(); + return SetCapacityAndVerify(mc, capacity, expectedCapacity, expectedException); + } + + public bool SetCapacityAndVerify(MyCollection mc, int capacity, int expectedCapacity, Type expectedException) + { + bool retValue = true; + + try + { + mc.Capacity = capacity; + + if (null != expectedException) + { + Console.WriteLine("ERROR!!! Expected exception {0} and NOTHING was thrown", expectedException); + retValue = false; + } + } + catch (System.Exception e) + { + if (null == expectedException) + { + Console.WriteLine("ERROR!!! Expected NO exception to be thrown and {0} was thrown", e.GetType()); + retValue = false; + } + else if (e.GetType() != expectedException) + { + Console.WriteLine("ERROR!!! Expected exception {0} and {1} was thrown", expectedException, e.GetType()); + retValue = false; + } + } + + retValue &= VerifyCapacity(mc, expectedCapacity); + + return retValue; + } + + public bool VerifyCapacity(MyCollection mc, int expectedCapacity) + { + bool retValue = true; + + if (mc.Capacity != expectedCapacity) + { + Console.WriteLine("ERROR!!! MyCollection.Capacity={0} expected={1}", mc.Capacity, expectedCapacity); + retValue = false; + } + + if (mc.InnerListCapacity != expectedCapacity) + { + Console.WriteLine("ERROR!!! MyCollection.InnerList.Capacity={0} expected={1}", mc.InnerListCapacity, expectedCapacity); + retValue = false; + } + + return retValue; + } + + + + private bool BeginTestcase(TestDelegate test) + { + bool retValue = true; + + if (test()) + { + _numTestcases++; + retValue = true; + } + else + { + _numErrors++; + retValue = false; + } + + return retValue; + } + + public class MyCollection : CollectionBase + { + public MyCollection() : base() + { + + } + + public MyCollection(int capacity) : base(capacity) + { + + } + + public void Add(int value) + { + InnerList.Add(value); + } + + public int InnerListCapacity + { + get + { + return InnerList.Capacity; + } + } + + } +} \ No newline at end of file diff --git a/src/System.Collections.NonGeneric/tests/CollectionBase/CollectionBase_OnMethods.cs b/src/System.Collections.NonGeneric/tests/CollectionBase/CollectionBase_OnMethods.cs new file mode 100644 index 000000000000..89ba8e0550a8 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/CollectionBase/CollectionBase_OnMethods.cs @@ -0,0 +1,1037 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Threading; +using System.Collections; +using Xunit; + +public class CollectionBase_OnMethods +{ + + public bool runTest() + { + + //////////// Global Variables used for all tests + int iCountErrors = 0; + int iCountTestcases = 0; + + MyCollectionBase mycol; + Foo f, newF; + string expectedExceptionMessage; + + try + { + do + { + ///////////////////////// START TESTS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + //[] Vanilla Add + iCountTestcases++; + + mycol = new MyCollectionBase(); + f = new Foo(); + mycol.Add(f); + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (!mycol.OnInsertCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_4072ayps OnInsertComplete was never called"); + } + else if (0 != mycol.IndexOf(f)) + { + iCountErrors++; + Console.WriteLine("Err_0181salh Item was added"); + } + + //[] Add where Validate throws + iCountTestcases++; + mycol = new MyCollectionBase(); + mycol.OnValidateThrow = true; + expectedExceptionMessage = "OnValidate"; + f = new Foo(); + try + { + mycol.Add(f); + iCountErrors++; + Console.WriteLine("Err_1570pyqa Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_2708apsa Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (mycol.OnInsertCalled) + { + iCountErrors++; + Console.WriteLine("Err_56707awwaps OnInsert was called"); + } + else if (0 != mycol.Count) + { + iCountErrors++; + Console.WriteLine("Err_2708apsa Expected Empty Collection actual {0} elements", mycol.Count); + } + + //[] Add where OnInsert throws + iCountTestcases++; + mycol = new MyCollectionBase(); + mycol.OnInsertThrow = true; + expectedExceptionMessage = "OnInsert"; + f = new Foo(); + try + { + mycol.Add(f); + iCountErrors++; + Console.WriteLine("Err_35208asdo Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_30437sfdah Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (mycol.OnInsertCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_370asjhs OnInsertComplete was called"); + } + else if (0 != mycol.Count) + { + iCountErrors++; + Console.WriteLine("Err_3y07aza Expected Empty Collection actual {0} elements", mycol.Count); + } + + //[] Add where OnInsertComplete throws + iCountTestcases++; + mycol = new MyCollectionBase(); + mycol.OnInsertCompleteThrow = true; + expectedExceptionMessage = "OnInsertComplete"; + f = new Foo(); + try + { + mycol.Add(f); + iCountErrors++; + Console.WriteLine("Err_2548ashz Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_2708alkw Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (0 != mycol.Count) + { + iCountErrors++; + Console.WriteLine("Err_3680ahksd Expected Empty Collection actual {0} elements", mycol.Count); + } + + /******* Insert ******************************************************************************************/ + + //[] Vanilla Insert + iCountTestcases++; + mycol = new MyCollectionBase(); + + f = new Foo(); + mycol.Insert(0, f); + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (!mycol.OnInsertCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_270ash OnInsertComplete was never called"); + } + else if (0 != mycol.IndexOf(f)) + { + iCountErrors++; + Console.WriteLine("Err_208anla Item was added"); + } + + //[] Insert where Validate throws + iCountTestcases++; + mycol = new MyCollectionBase(); + mycol.OnValidateThrow = true; + expectedExceptionMessage = "OnValidate"; + f = new Foo(); + try + { + mycol.Insert(0, f); + iCountErrors++; + Console.WriteLine("Err_270ahsw Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_48708awhoh Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (mycol.OnInsertCalled) + { + iCountErrors++; + Console.WriteLine("Err_3708anw OnInsert was called"); + } + else if (0 != mycol.Count) + { + iCountErrors++; + Console.WriteLine("Err_707j2awn Expected Empty Collection actual {0} elements", mycol.Count); + } + + //[] Insert where OnInsert throws + iCountTestcases++; + mycol = new MyCollectionBase(); + mycol.OnInsertThrow = true; + expectedExceptionMessage = "OnInsert"; + f = new Foo(); + try + { + mycol.Insert(0, f); + iCountErrors++; + Console.WriteLine("Err_70378sanw Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_7302nna Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (mycol.OnInsertCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_1270jqna OnInsertComplete was called"); + } + else if (0 != mycol.Count) + { + iCountErrors++; + Console.WriteLine("Err_2707nqnq Expected Empty Collection actual {0} elements", mycol.Count); + } + + //[] Insert where OnInsertComplete throws + iCountTestcases++; + mycol = new MyCollectionBase(); + mycol.OnInsertCompleteThrow = true; + expectedExceptionMessage = "OnInsertComplete"; + f = new Foo(); + try + { + mycol.Insert(0, f); + iCountErrors++; + Console.WriteLine("Err_27087nqlkha Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_270hy1na Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (0 != mycol.Count) + { + iCountErrors++; + Console.WriteLine("Err_270978aw Expected Empty Collection actual {0} elements", mycol.Count); + } + + + /************** Remove ***************************************************************************************************************/ + + //[] Vanilla Remove + iCountTestcases++; + mycol = new MyCollectionBase(); + f = new Foo(); + + mycol.Add(f); + mycol.Remove(f); + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (!mycol.OnRemoveCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_348awq OnRemoveComplete was never called"); + } + else if (-1 != mycol.IndexOf(f)) + { + iCountErrors++; + Console.WriteLine("Err_0824answ Item was not removed"); + } + + //[] Remove where Validate throws + iCountTestcases++; + mycol = new MyCollectionBase(); + expectedExceptionMessage = "OnValidate"; + f = new Foo(); + try + { + mycol.Add(f); + mycol.OnValidateThrow = true; + mycol.Remove(f); + iCountErrors++; + Console.WriteLine("Err_08207hnas Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_87082aspz Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (mycol.OnRemoveCalled) + { + iCountErrors++; + Console.WriteLine("Err_7207snmqla OnRemove was called"); + } + else if (0 != mycol.IndexOf(f)) + { + iCountErrors++; + Console.WriteLine("Err_7270pahnz Element was actually removed {0}", mycol.IndexOf(f)); + } + + //[] Remove where OnRemove throws + iCountTestcases++; + mycol = new MyCollectionBase(); + mycol.OnRemoveThrow = true; + expectedExceptionMessage = "OnRemove"; + f = new Foo(); + try + { + mycol.Add(f); + mycol.Remove(f); + iCountErrors++; + Console.WriteLine("Err_7708aqyy Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_08281naws Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (mycol.OnRemoveCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_10871aklsj OnRemoveComplete was called"); + } + else if (0 != mycol.IndexOf(f)) + { + iCountErrors++; + Console.WriteLine("Err_2081aslkjs Element was actually removed {0}", mycol.IndexOf(f)); + } + + //[] Remove where OnRemoveComplete throws + iCountTestcases++; + mycol = new MyCollectionBase(); + mycol.OnRemoveCompleteThrow = true; + expectedExceptionMessage = "OnRemoveComplete"; + f = new Foo(); + try + { + mycol.Add(f); + mycol.Remove(f); + iCountErrors++; + Console.WriteLine("Err_10981nlskj Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_20981askjs Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (0 != mycol.IndexOf(f)) + { + iCountErrors++; + Console.WriteLine("Err_20909assfd Element was actually removed {0}", mycol.IndexOf(f)); + } + + + /******************* Clear ************************************************************************************************/ + + //[] Vanilla Clear + iCountTestcases++; + mycol = new MyCollectionBase(); + f = new Foo(); + + mycol.Add(f); + mycol.Clear(); + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (!mycol.OnClearCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_2136sdf OnClearComplete was never called"); + } + else if (0 != mycol.Count) + { + iCountErrors++; + Console.WriteLine("Err_9494aswa Items were not Cleared"); + } + + //[] Clear where Validate throws + iCountTestcases++; + mycol = new MyCollectionBase(); + expectedExceptionMessage = "OnValidate"; + f = new Foo(); + + mycol.Add(f); + mycol.OnValidateThrow = true; + mycol.Clear(); + + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (!mycol.OnClearCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_6549asff OnClearComplete was not called"); + } + else if (0 != mycol.Count) + { + iCountErrors++; + Console.WriteLine("Err_4649awajm Items were Cleared"); + } + + //[] Clear where OnClear throws + iCountTestcases++; + mycol = new MyCollectionBase(); + mycol.OnClearThrow = true; + expectedExceptionMessage = "OnClear"; + f = new Foo(); + try + { + mycol.Add(f); + mycol.Clear(); + iCountErrors++; + Console.WriteLine("Err_9444sjpjnException was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_78941joaException message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (mycol.OnClearCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_94944awfuu OnClearComplete was called"); + } + else if (1 != mycol.Count) + { + iCountErrors++; + Console.WriteLine("Err_6498 Items were not Cleared"); + } + + //[] Clear where OnClearComplete throws + iCountTestcases++; + mycol = new MyCollectionBase(); + mycol.OnClearCompleteThrow = true; + expectedExceptionMessage = "OnClearComplete"; + f = new Foo(); + try + { + mycol.Add(f); + mycol.Clear(); + iCountErrors++; + Console.WriteLine("Err_64977awad Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_0877asaw Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (0 != mycol.Count) + { + iCountErrors++; + Console.WriteLine("Err_1081lkajs Items were not Cleared"); + } + + + /**************************** Set ***********************************************************************************************************************/ + + //[] Vanilla Set + iCountTestcases++; + mycol = new MyCollectionBase(); + f = new Foo(1, "1"); + newF = new Foo(2, "2"); + + mycol.Add(f); + mycol[0] = newF; + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (!mycol.OnSetCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_1698asdf OnSetComplete was never called"); + } + else if (-1 != mycol.IndexOf(f) || 0 != mycol.IndexOf(newF)) + { + iCountErrors++; + Console.WriteLine("Err_9494safs Item was not Set"); + } + + //[] Set where Validate throws + iCountTestcases++; + mycol = new MyCollectionBase(); + expectedExceptionMessage = "OnValidate"; + f = new Foo(1, "1"); + newF = new Foo(2, "2"); + try + { + mycol.Add(f); + mycol.OnValidateThrow = true; + mycol[0] = newF; + iCountErrors++; + Console.WriteLine("Err_611awwa Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_69498hph Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (mycol.OnSetCalled) + { + iCountErrors++; + Console.WriteLine("Err_94887jio OnSet was called"); + } + else if (0 != mycol.IndexOf(f) || -1 != mycol.IndexOf(newF)) + { + iCountErrors++; + Console.WriteLine("Err_6549ihyopiu Element was actually Set {0}", mycol.IndexOf(f)); + } + + //[] Set where OnSet throws + iCountTestcases++; + mycol = new MyCollectionBase(); + mycol.OnSetThrow = true; + expectedExceptionMessage = "OnSet"; + f = new Foo(1, "1"); + newF = new Foo(2, "2"); + try + { + mycol.Add(f); + mycol[0] = newF; + iCountErrors++; + Console.WriteLine("Err_61518haiosd Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_196198sdklhsException message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (mycol.OnSetCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_6548dasfs OnSetComplete was called"); + } + else if (0 != mycol.IndexOf(f) || -1 != mycol.IndexOf(newF)) + { + iCountErrors++; + Console.WriteLine("Err_2797sah Element was actually Set {0}", mycol.IndexOf(f)); + } + + //[] Set where OnSetComplete throws + iCountTestcases++; + mycol = new MyCollectionBase(); + mycol.OnSetCompleteThrow = true; + expectedExceptionMessage = "OnSetComplete"; + f = new Foo(1, "1"); + newF = new Foo(2, "2"); + try + { + mycol.Add(f); + mycol[0] = newF; + iCountErrors++; + Console.WriteLine("Err_56498hkashException was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_13168hsaiuh Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (mycol.IsError) + { + iCountErrors++; + Console.WriteLine(mycol.ErrorMsg); + } + else if (0 != mycol.IndexOf(f) || -1 != mycol.IndexOf(newF)) + { + iCountErrors++; + Console.WriteLine("Err_64198ahihos Element was actually Set {0}", mycol.IndexOf(f)); + } + + /////////////////////////////////////////////////////////////////// + /////////////////////////// END TESTS ///////////////////////////// + } while (false); + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString()); + } + + + //// Finish Diagnostics + if (iCountErrors == 0) + { + return true; + } + else + { + return false; + } + } + + + + [Fact] + public static void ExecuteCollectionBase_OnMethods() + { + bool bResult = false; + var test = new CollectionBase_OnMethods(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + Assert.Equal(true, bResult); + } + + + //CollectionBase is provided to be used as the base class for strongly typed collections. Lets use one of our own here + public class MyCollectionBase : CollectionBase + { + public bool IsError = false; + public string ErrorMsg = String.Empty; + public bool OnValidateCalled, OnSetCalled, OnSetCompleteCalled, OnInsertCalled, OnInsertCompleteCalled, + OnClearCalled, OnClearCompleteCalled, OnRemoveCalled, OnRemoveCompleteCalled; + public bool OnValidateThrow, OnSetThrow, OnSetCompleteThrow, OnInsertThrow, OnInsertCompleteThrow, + OnClearThrow, OnClearCompleteThrow, OnRemoveThrow, OnRemoveCompleteThrow; + + + public MyCollectionBase() + { + OnValidateCalled = false; + OnSetCalled = false; + OnSetCompleteCalled = false; + OnInsertCalled = false; + OnInsertCompleteCalled = false; + OnClearCalled = false; + OnClearCompleteCalled = false; + OnRemoveCalled = false; + OnRemoveCompleteCalled = false; + + OnValidateThrow = false; + OnSetThrow = false; + OnSetCompleteThrow = false; + OnInsertThrow = false; + OnInsertCompleteThrow = false; + OnClearThrow = false; + OnClearCompleteThrow = false; + OnRemoveThrow = false; + OnRemoveCompleteThrow = false; + } + + public int Add(Foo f1) + { + return List.Add(f1); + } + + public Foo this[int indx] + { + get { return (Foo)List[indx]; } + set { List[indx] = value; } + } + + public void CopyTo(Array array, Int32 index) + { + ((ICollection)List).CopyTo(array, index); + } + + public Int32 IndexOf(Foo f) + { + return ((IList)List).IndexOf(f); + } + + public Boolean Contains(Foo f) + { + return ((IList)List).Contains(f); + } + + public void Insert(Int32 index, Foo f) + { + List.Insert(index, f); + } + + public void Remove(Foo f) + { + List.Remove(f); + } + + protected override void OnSet(int index, Object oldValue, Object newValue) + { + if (!OnValidateCalled) + { + IsError = true; + ErrorMsg += "Err_0882pxnk OnValidate has not been called\n"; + } + + if (this[index] != oldValue) + { + IsError = true; + ErrorMsg += "Err_1204phzn Value was already set\n"; + } + + OnSetCalled = true; + + if (OnSetThrow) + throw new Exception("OnSet"); + } + + protected override void OnInsert(int index, Object value) + { + if (!OnValidateCalled) + { + IsError = true; + ErrorMsg += "Err_0834halkh OnValidate has not been called\n"; + } + + if (index > Count) + { + IsError = true; + ErrorMsg += "Err_7332pghh Value was already set\n"; + } + + if (index != Count && this[index] == value) + { + IsError = true; + ErrorMsg += "Err_2702apqh OnInsert called with a bad index\n"; + } + + OnInsertCalled = true; + + if (OnInsertThrow) + throw new Exception("OnInsert"); + } + + protected override void OnClear() + { + if (Count == 0 || InnerList.Count == 0) + { + //Assumes Clear not called on an empty list + IsError = true; + ErrorMsg += "Err_2247alkhz List already empty\n"; + } + + OnClearCalled = true; + + if (OnClearThrow) + throw new Exception("OnClear"); + } + + protected override void OnRemove(int index, Object value) + { + if (!OnValidateCalled) + { + IsError = true; + ErrorMsg += "Err_3703pyaa OnValidate has not been called\n"; + } + + if (this[index] != value) + { + IsError = true; + ErrorMsg += "Err_1708afsw Value was already set\n"; + } + + OnRemoveCalled = true; + + if (OnRemoveThrow) + throw new Exception("OnRemove"); + } + + protected override void OnValidate(Object value) + { + OnValidateCalled = true; + + if (OnValidateThrow) + throw new Exception("OnValidate"); + } + + protected override void OnSetComplete(int index, Object oldValue, Object newValue) + { + if (!OnSetCalled) + { + IsError = true; + ErrorMsg += "Err_0282pyahn OnSet has not been called\n"; + } + + if (this[index] != newValue) + { + IsError = true; + ErrorMsg += "Err_2134pyqt Value has not been set\n"; + } + + OnSetCompleteCalled = true; + + if (OnSetCompleteThrow) + throw new Exception("OnSetComplete"); + } + + protected override void OnInsertComplete(int index, Object value) + { + if (!OnInsertCalled) + { + IsError = true; + ErrorMsg += "Err_5607aspyu OnInsert has not been called\n"; + } + + if (this[index] != value) + { + IsError = true; + ErrorMsg += "Err_3407ahpqValue has not been set\n"; + } + + OnInsertCompleteCalled = true; + + if (OnInsertCompleteThrow) + throw new Exception("OnInsertComplete"); + } + + protected override void OnClearComplete() + { + if (!OnClearCalled) + { + IsError = true; + ErrorMsg += "Err_3470sfas OnClear has not been called\n"; + } + + if (Count != 0 || InnerList.Count != 0) + { + IsError = true; + ErrorMsg += "Err_2507yuznb Value has not been set\n"; + } + + OnClearCompleteCalled = true; + + if (OnClearCompleteThrow) + throw new Exception("OnClearComplete"); + } + + protected override void OnRemoveComplete(int index, Object value) + { + if (!OnRemoveCalled) + { + IsError = true; + ErrorMsg += "Err_70782sypz OnRemve has not been called\n"; + } + + if (IndexOf((Foo)value) == index) + { + IsError = true; + ErrorMsg += "Err_3097saq Value still exists\n"; + } + + OnRemoveCompleteCalled = true; + + if (OnRemoveCompleteThrow) + throw new Exception("OnRemoveComplete"); + } + + public void ClearTest() + { + IsError = false; + ErrorMsg = String.Empty; + + OnValidateCalled = false; + OnSetCalled = false; + OnSetCompleteCalled = false; + OnInsertCalled = false; + OnInsertCompleteCalled = false; + OnClearCalled = false; + OnClearCompleteCalled = false; + OnRemoveCalled = false; + OnRemoveCompleteCalled = false; + + OnValidateThrow = false; + OnSetThrow = false; + OnSetCompleteThrow = false; + OnInsertThrow = false; + OnInsertCompleteThrow = false; + OnClearThrow = false; + OnClearCompleteThrow = false; + OnRemoveThrow = false; + OnRemoveCompleteThrow = false; + } + } + + public class Foo + { + private Int32 _iValue; + private String _strValue; + + public Foo() + { + } + + public Foo(Int32 i, String str) + { + _iValue = i; + _strValue = str; + } + + public Int32 IValue + { + get { return _iValue; } + set { _iValue = value; } + } + + public String SValue + { + get { return _strValue; } + set { _strValue = value; } + } + + public override Boolean Equals(Object obj) + { + if (obj == null) + return false; + if (!(obj is Foo)) + return false; + if ((((Foo)obj).IValue == _iValue) && (((Foo)obj).SValue == _strValue)) + return true; + return false; + } + + public override Int32 GetHashCode() + { + return _iValue; + } + } +} diff --git a/src/System.Collections.NonGeneric/tests/CollectionBase/CollectionBase_ctor.cs b/src/System.Collections.NonGeneric/tests/CollectionBase/CollectionBase_ctor.cs new file mode 100644 index 000000000000..1f31035b1292 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/CollectionBase/CollectionBase_ctor.cs @@ -0,0 +1,95 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using Xunit; + +public class CollectionBase_ctor +{ + private int _numErrors = 0; + private int _numTestcases = 0; + private int _retValue = 100; + + public delegate bool TestDelegate(); + + [Fact] + public static void ctorTests() + { + var objTest = new CollectionBase_ctor(); + + try + { + objTest.RunTest(); + } + catch (Exception e) + { + Console.WriteLine(" : FAIL The following exception was thorwn in RunTest(): \n" + e.ToString()); + objTest._numErrors++; + objTest._retValue = 1; + } + + Assert.Equal(objTest._retValue, 100); + } + + public bool RunTest() + { + bool retValue = true; + + retValue &= BeginTestcase(new TestDelegate(DefaultCapacity)); + + return retValue; + } + + public bool DefaultCapacity() + { + bool retValue = true; + MyCollection cb = new MyCollection(); + ArrayList al = new ArrayList(); + + if (cb.Capacity != al.Capacity) + { + Console.WriteLine("ERROR!!! CollectionBase.Capacity={0} expected={1}", cb.Capacity, al.Capacity); + retValue = false; + } + + if (cb.InnerListCapacity != al.Capacity) + { + Console.WriteLine("ERROR!!! CollectionBase.InnerList.Capacity={0} expected={1}", cb.InnerListCapacity, al.Capacity); + retValue = false; + } + + if (!retValue) + { + Console.WriteLine("Err_001!!! Verifying Capacity with default constructor FAILED"); + } + return retValue; + } + + private bool BeginTestcase(TestDelegate test) + { + if (test()) + { + _numTestcases++; + return true; + } + else + { + _numErrors++; + return false; + } + } + + public class MyCollection : CollectionBase + { + public int InnerListCapacity + { + get + { + return InnerList.Capacity; + } + } + + + } +} diff --git a/src/System.Collections.NonGeneric/tests/CollectionBase/CollectionBase_ctor_int.cs b/src/System.Collections.NonGeneric/tests/CollectionBase/CollectionBase_ctor_int.cs new file mode 100644 index 000000000000..58496f7e2f9f --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/CollectionBase/CollectionBase_ctor_int.cs @@ -0,0 +1,269 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using Xunit; + +public class CollectionBase_ctor_int +{ + public const int MAX_RND_CAPACITY = 512; + public const int LARGE_CAPACITY = 1024; + + private int _numErrors = 0; + private int _numTestcases = 0; + private int _retValue = 100; + + public delegate bool TestDelegate(); + + [Fact] + public static void ctor_intTests() + { + var objTest = new CollectionBase_ctor_int(); + + try + { + objTest.RunTest(); + } + catch (Exception e) + { + Console.WriteLine(" : FAIL The following exception was thorwn in RunTest(): \n" + e.ToString()); + objTest._numErrors++; + objTest._retValue = 1; + } + + Assert.Equal(objTest._retValue, 100); + } + + public bool RunTest() + { + bool retValue = true; + + retValue &= BeginTestcase(new TestDelegate(Capacity_Int32MinValue)); + retValue &= BeginTestcase(new TestDelegate(Capacity_NegRnd)); + retValue &= BeginTestcase(new TestDelegate(Capacity_Neg1)); + retValue &= BeginTestcase(new TestDelegate(Capacity_0)); + retValue &= BeginTestcase(new TestDelegate(Capacity_1)); + retValue &= BeginTestcase(new TestDelegate(Capacity_PosRnd)); + retValue &= BeginTestcase(new TestDelegate(Capacity_Large)); + retValue &= BeginTestcase(new TestDelegate(Capacity_Int32MaxValue)); + + + return retValue; + } + + public bool Capacity_Int32MinValue() + { + bool retValue = true; + + retValue &= VerifyCapacity(Int32.MinValue, typeof(ArgumentOutOfRangeException)); + + if (!retValue) + { + Console.WriteLine("Err_001!!! Verifying Int32.MinValue Capacity FAILED"); + } + + return retValue; + } + + public bool Capacity_NegRnd() + { + bool retValue = true; + Random rndGen = new Random(-55); + + retValue &= VerifyCapacity(rndGen.Next(Int32.MinValue, 0), typeof(ArgumentOutOfRangeException)); + + if (!retValue) + { + Console.WriteLine("Err_002!!! Verifying negative random Capacity FAILED"); + } + + return retValue; + } + + public bool Capacity_Neg1() + { + bool retValue = true; + + retValue &= VerifyCapacity(-1, typeof(ArgumentOutOfRangeException)); + + if (!retValue) + { + Console.WriteLine("Err_003!!! Verifying -1 Capacity FAILED"); + } + + return retValue; + } + + public bool Capacity_0() + { + bool retValue = true; + + retValue &= VerifyCapacity(0, 0, null); + + if (!retValue) + { + Console.WriteLine("Err_004!!! Verifying 0 Capacity FAILED"); + } + + return retValue; + } + + public bool Capacity_1() + { + bool retValue = true; + + retValue &= VerifyCapacity(1, 1, null); + + if (!retValue) + { + Console.WriteLine("Err_005!!! Verifying 1 Capacity FAILED"); + } + + return retValue; + } + + public bool Capacity_PosRnd() + { + bool retValue = true; + Random rndGen = new Random(-55); + int rndCapacity = rndGen.Next(2, MAX_RND_CAPACITY); + + retValue &= VerifyCapacity(rndCapacity, rndCapacity, null); + + if (!retValue) + { + Console.WriteLine("Err_006!!! Verifying positive random Capacity FAILED"); + } + + return retValue; + } + + public bool Capacity_Large() + { + bool retValue = true; + + retValue &= VerifyCapacity(LARGE_CAPACITY, LARGE_CAPACITY, null); + + if (!retValue) + { + Console.WriteLine("Err_007!!! Verifying1 Capacity FAILED"); + } + + return retValue; + } + + public bool Capacity_Int32MaxValue() + { + bool retValue = true; + + retValue &= VerifyCapacity(Int32.MaxValue, Int32.MaxValue, typeof(OutOfMemoryException)); + + if (!retValue) + { + Console.WriteLine("Err_008!!! Verifying Int32.MaxValue Capacity FAILED"); + } + + return retValue; + } + + public bool VerifyCapacity(int capacity, Type expectedException) + { + return VerifyCapacity(capacity, 0, expectedException); + } + + public bool VerifyCapacity(int capacity, int expectedCapacity, Type expectedException) + { + bool retValue = true; + MyCollection mc = null; + + try + { + mc = new MyCollection(capacity); + + if (null != expectedException) + { + Console.WriteLine("ERROR!!! Expected exception {0} and NOTHING was thrown", expectedException); + retValue = false; + } + } + catch (System.Exception e) + { + if (null == expectedException) + { + Console.WriteLine("ERROR!!! Expected NO exception to be thrown and {0} was thrown", e.GetType()); + retValue = false; + } + else if (e.GetType() != expectedException) + { + Console.WriteLine("ERROR!!! Expected exception {0} and {1} was thrown", expectedException, e.GetType()); + retValue = false; + } + } + + if (mc == null && expectedException == null) + { + Console.WriteLine("ERROR!!! Expected MyCollection NOT to be null"); + retValue = false; + } + + if (mc != null && expectedException != null) + { + Console.WriteLine("ERROR!!! Expected MyCollection to be null"); + retValue = false; + } + + if (mc != null) + { + if (mc.Capacity != expectedCapacity) + { + Console.WriteLine("ERROR!!! MyCollection.Capacity={0} expected={1}", mc.Capacity, expectedCapacity); + retValue = false; + } + + if (mc.InnerListCapacity != expectedCapacity) + { + Console.WriteLine("ERROR!!! MyCollection.InnerList.Capacity={0} expected={1}", mc.InnerListCapacity, expectedCapacity); + retValue = false; + } + } + + return retValue; + } + + + private bool BeginTestcase(TestDelegate test) + { + bool retValue = true; + + if (test()) + { + _numTestcases++; + retValue = true; + } + else + { + _numErrors++; + retValue = false; + } + + return retValue; + } + + public class MyCollection : CollectionBase + { + public MyCollection(int capacity) : base(capacity) + { + + } + + public int InnerListCapacity + { + get + { + return InnerList.Capacity; + } + } + } +} + diff --git a/src/System.Collections.NonGeneric/tests/CollectionsUtil/CollectionsUtilTests.cs b/src/System.Collections.NonGeneric/tests/CollectionsUtil/CollectionsUtilTests.cs new file mode 100644 index 000000000000..e5cda0754ff5 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/CollectionsUtil/CollectionsUtilTests.cs @@ -0,0 +1,137 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using System.Collections.Specialized; +using Xunit; + +public class CollectionsUtilTests +{ + private int _iCountErrors = 0; + private int _iCountTestcases = 0; + + public virtual bool runTest() + { + try + { + ///////////////////////// START TESTS //////////////////////////// + + // [] CollectionsUtil.CreateCaseInsensitiveHashtable() + _iCountTestcases++; + Hashtable hashtable = CollectionsUtil.CreateCaseInsensitiveHashtable(); + Eval(hashtable.Count, 0, "Err_001a! Hashtable Count was wrong."); + TryAdd(hashtable, "key1", "value1", true); + TryAdd(hashtable, "Key1", "value2", false); + Eval(hashtable.Count, 1, "Err_001b! Hashtable Count was wrong."); + + // [] CollectionsUtil.CreateCaseInsensitiveHashtable(int) + _iCountTestcases++; + hashtable = CollectionsUtil.CreateCaseInsensitiveHashtable(15); + Eval(hashtable.Count, 0, "Err_002a! Hashtable Count was wrong."); + TryAdd(hashtable, "key1", "value1", true); + TryAdd(hashtable, "Key1", "value2", false); + Eval(hashtable.Count, 1, "Err_002b! Hashtable Count was wrong."); + + // [] CollectionsUtil.CreateCaseInsensitiveHashtable(IDictionary) + _iCountTestcases++; + hashtable = CollectionsUtil.CreateCaseInsensitiveHashtable(hashtable); + Eval(hashtable.Count, 1, "Err_003a! Hashtable Count was wrong."); + TryAdd(hashtable, "key1", "value1", false); + TryAdd(hashtable, "Key2", "value2", true); + Eval(hashtable.Count, 2, "Err_003b! Hashtable Count was wrong."); + + // [] CollectionsUtil.CreateCaseInsensitiveSortedList() + _iCountTestcases++; + SortedList sortedList = CollectionsUtil.CreateCaseInsensitiveSortedList(); + Eval(sortedList.Count, 0, "Err_004a! SortedList Count was wrong."); + TryAdd(sortedList, "key1", "value1", true); + TryAdd(sortedList, "Key1", "value2", false); + Eval(sortedList.Count, 1, "Err_004b! SortedList Count was wrong."); + /////////////////////////// END TESTS ///////////////////////////// + } + catch (Exception exc_general) + { + _iCountErrors++; + Console.WriteLine(": Error Err_general! exc_general==\n" + exc_general.ToString()); + } + + //// Finish Diagnostics + if (_iCountErrors == 0) + { + return true; + } + else + { + Console.WriteLine("Fail! iCountErrors==" + _iCountErrors); + return false; + } + } + + bool Eval(T actual, T expected, String errorMsg) + { + bool retValue = expected == null ? actual == null : expected.Equals(actual); + if (!retValue) + { + Eval(retValue, errorMsg + + " Expected:" + (null == expected ? "" : expected.ToString()) + + " Actual:" + (null == actual ? "" : actual.ToString())); + } + return retValue; + } + + bool Eval(bool expression, String msg) + { + if (!expression) + { + _iCountErrors++; + Console.WriteLine(msg); + } + return expression; + } + + void TryAdd(IDictionary dict, Object key, Object value, Boolean shouldSucceed) + { + try + { + dict.Add(key, value); + if (!shouldSucceed) + { + _iCountErrors++; + Console.WriteLine("Err_101! Add succeeded when it should have failed!"); + } + } + catch (ArgumentException ex) + { + if (shouldSucceed) + { + _iCountErrors++; + Console.WriteLine("Err_102! Add failed when it should have succeeded! ex={0}", ex); + } + } + catch (Exception ex) + { + _iCountErrors++; + Console.WriteLine("Err_103! Add failed with unexpected exception! ex={0}", ex); + } + } + + [Fact] + public static void ExecuteCollectionsUtilTests() + { + bool bResult = false; + var test = new CollectionsUtilTests(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } +} diff --git a/src/System.Collections.NonGeneric/tests/Comparer/Comparer_CaseInsensitive.cs b/src/System.Collections.NonGeneric/tests/Comparer/Comparer_CaseInsensitive.cs new file mode 100644 index 000000000000..68fff34f66aa --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Comparer/Comparer_CaseInsensitive.cs @@ -0,0 +1,133 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Threading; +using System.Collections; +using System.Globalization; +using Xunit; + +public class Comparer_CaseInsensitive +{ + public bool runTest() + { + //////////// Global Variables used for all tests + int iCountErrors = 0; + int iCountTestcases = 0; + + Comparer comp; + + string[] str1 = { "Apple", "abc", }; + string[] str2 = { "Æble", "ABC" }; + + try + { + do + { + ///////////////////////// START TESTS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + //[] Vanila test case - The TextInfo property of the CultureInfo is used in the CaseInsensitiveHashCodeProvider + //TextInfo has GetCaseInsensitiveHashCode() methods + + iCountTestcases++; + var somePopularCultureNames = new string[] { + "cs-CZ","da-DK","de-DE","el-GR","en-US", + "es-ES","fi-FI","fr-FR","hu-HU","it-IT", + "ja-JP","ko-KR","nb-NO","nl-NL","pl-PL", + "pt-BR","pt-PT","ru-RU","sv-SE","tr-TR", + "zh-CN","zh-HK","zh-TW" }; + foreach (string cultureName in somePopularCultureNames) + { + CultureInfo culture = new CultureInfo(cultureName); + if (culture == null) + { + continue; + } + + iCountTestcases++; + + comp = new Comparer(culture); + + //The following cultures do this the other way round + //da-DK, is-IS, nb-NO, nn-NO + if (culture.Name != "da-DK" && culture.Name != "is-IS" && culture.Name != "nb-NO" && culture.Name != "nn-NO") + { + if (comp.Compare(str1[0], str2[0]) != 1) + { + iCountErrors++; + Console.WriteLine("Err_3245sdg, Wrong value returned, {0}, culture: {1}", comp.Compare(str1[0], str2[0]), culture); + } + } + else + { + if (comp.Compare(str1[0], str2[0]) != -1) + { + iCountErrors++; + Console.WriteLine("Err_297dg, Wrong value returned, {0}, culture: {1}", comp.Compare(str1[0], str2[0]), culture.Name); + } + } + + if (comp.Compare(str1[1], str2[1]) != -1) + { + iCountErrors++; + Console.WriteLine("Err_3467tsg, Wrong value returned, {0}, culture: {1}", comp.Compare(str1[1], str2[1]), culture.Name); + } + } + + //[] Call ctor with null CultureInfo + try + { + comp = new Comparer((CultureInfo)null); + iCountErrors++; + Console.WriteLine("Err_89743asjppn Expected ctor to throw ArgumentNullException"); + } + catch (ArgumentNullException) { } + catch (Exception e) + { + iCountErrors++; + Console.WriteLine("Err_4447abcn Unexpected exceptin thrown: {0}", e); + } + /////////////////////////// END TESTS ///////////////////////////// + } while (false); + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString()); + } + + //// Finish Diagnostics + if (iCountErrors == 0) + { + return true; + } + else + { + Console.WriteLine("Fail! iCountErrors==" + iCountErrors); + return false; + } + } + + + + [Fact] + public static void ExecuteComparer_CaseInsensitive() + { + bool bResult = false; + var cbA = new Comparer_CaseInsensitive(); + + try + { + bResult = cbA.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine(" : FAiL! Error Err_9999zzz! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } +} + diff --git a/src/System.Collections.NonGeneric/tests/Comparer/Comparer_DefaultInvariant.cs b/src/System.Collections.NonGeneric/tests/Comparer/Comparer_DefaultInvariant.cs new file mode 100644 index 000000000000..758d0299fde6 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Comparer/Comparer_DefaultInvariant.cs @@ -0,0 +1,117 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Threading; +using System.Collections; +using System.Globalization; +using Xunit; + +public class Comparer_DefaultInvariant +{ + public bool runTest() + { + //////////// Global Variables used for all tests + int iCountErrors = 0; + int iCountTestcases = 0; + + Comparer comp; + + string[] str1 = { "Apple", "abc", }; + string[] str2 = { "Æble", "ABC" }; + + try + { + do + { + ///////////////////////// START TESTS //////////////////////////// + + //[] Vanila test case - The TextInfo property of the CultureInfo is used in the CaseInsensitiveHashCodeProvider + //TextInfo has GetCaseInsensitiveHashCode() methods + + iCountTestcases++; + + var somePopularCultureNames = new string[] { + "cs-CZ","da-DK","de-DE","el-GR","en-US", + "es-ES","fi-FI","fr-FR","hu-HU","it-IT", + "ja-JP","ko-KR","nb-NO","nl-NL","pl-PL", + "pt-BR","pt-PT","ru-RU","sv-SE","tr-TR", + "zh-CN","zh-HK","zh-TW" }; + foreach (string cultureName in somePopularCultureNames) + { + CultureInfo culture = new CultureInfo(cultureName); + if (culture == null) + { + continue; + } + + iCountTestcases++; + + CultureInfo.DefaultThreadCurrentCulture = culture; + CultureInfo.DefaultThreadCurrentUICulture = culture; + Assert.Equal(CultureInfo.CurrentCulture.Name, culture.Name); + Assert.Equal(CultureInfo.CurrentUICulture.Name, culture.Name); + + comp = Comparer.DefaultInvariant; + + + //all cultures should sort the same way, irrespective of the thread's culture + if (comp.Compare(str1[0], str2[0]) != 1) + { + iCountErrors++; + Console.WriteLine("Err_39tsfg, Wrong value returned, {0}, culture: {1}", comp.Compare(str1[0], str2[0]), culture.Name); + } + + if (comp.Compare(str1[1], str2[1]) != -1) + { + iCountErrors++; + Console.WriteLine("Err_39tsfg, Wrong value returned, {0}, culture: {1}", comp.Compare(str1[1], str2[1]), culture.Name); + } + + } + /////////////////////////// END TESTS ///////////////////////////// + } while (false); + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString()); + } + + + + //// Finish Diagnostics + + if (iCountErrors == 0) + { + return true; + } + else + { + Console.WriteLine("Fail! iCountErrors==" + iCountErrors); + return false; + } + } + + + + [Fact] + public static void ExecuteComparer_DefaultInvariant() + { + bool bResult = false; + var cbA = new Comparer_DefaultInvariant(); + + try + { + bResult = cbA.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine(" : FAiL! Error Err_9999zzz! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } +} + diff --git a/src/System.Collections.NonGeneric/tests/Comparer/Comparer_Objects.cs b/src/System.Collections.NonGeneric/tests/Comparer/Comparer_Objects.cs new file mode 100644 index 000000000000..79ce7f26b08d --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Comparer/Comparer_Objects.cs @@ -0,0 +1,339 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using System.Globalization; +using Xunit; + +public class Comparer_Objects +{ + ///////////////////////////////////////////////////////////////////// + // Begin Testing run + ///////////////////////////////////////////////////////////////////// + public Boolean runTest() + { + int iCountTestcases = 0; + int iCountErrors = 0; + Object obj1, obj2; + int compRet; + Comparer comp; + + //------------------- TEST 1 + + //[]use Comparer to compare two different objects + try + { + ++iCountTestcases; + if (Comparer.Default.Compare(2, 1) <= 0) + { + ++iCountErrors; + Console.WriteLine("Err_001a, compare should have returned positive integer"); + } + } + catch (Exception ex) + { + ++iCountErrors; + Console.WriteLine("Err_001b, Unexpected exception was thrown ex: " + ex.ToString()); + } + + //------------------- TEST 2 + + //[]use Comparer to compare two different objects + try + { + ++iCountTestcases; + if (Comparer.Default.Compare(1, 2) >= 0) + { + ++iCountErrors; + Console.WriteLine("Err_002a, compare should have returned negative integer"); + } + } + catch (Exception ex) + { + ++iCountErrors; + Console.WriteLine("Err_002b, Unexpected exception was thrown ex: " + ex.ToString()); + } + + + //------------------- TEST 3 + + //[]use Comparer to compare two equal objects + try + { + ++iCountTestcases; + if (Comparer.Default.Compare(1, 1) != 0) + { + ++iCountErrors; + Console.WriteLine("Err_003a, compare should have returned 0 for equal objects"); + } + } + catch (Exception ex) + { + ++iCountErrors; + Console.WriteLine("Err_003b, Unexpected exception was thrown ex: " + ex.ToString()); + } + + //------------------- TEST 4 + + //[]use Comparer to compare a null object to a non null object + try + { + ++iCountTestcases; + if (Comparer.Default.Compare(null, 1) >= 0) + { + ++iCountErrors; + Console.WriteLine("Err_004a, a null object should be always less than something else"); + } + } + catch (Exception ex) + { + ++iCountErrors; + Console.WriteLine("Err_004b, Unexpected exception was thrown ex: " + ex.ToString()); + } + + //------------------- TEST 5 + + //[]use Comparer to compare an object to a null object + try + { + ++iCountTestcases; + if (Comparer.Default.Compare(0, null) <= 0) + { + ++iCountErrors; + Console.WriteLine("Err_005a, a null object should be always less than something else"); + } + } + catch (Exception ex) + { + ++iCountErrors; + Console.WriteLine("Err_005b, Unexpected exception was thrown ex: " + ex.ToString()); + } + + //------------------- TEST 6 + + //[]for two null objects comparer returns equal + try + { + ++iCountTestcases; + if (Comparer.Default.Compare(null, null) != 0) + { + ++iCountErrors; + Console.WriteLine("Err_006a, two nulls should be equal"); + } + } + catch (Exception ex) + { + ++iCountErrors; + Console.WriteLine("Err_006b, Unexpected exception was thrown ex: " + ex.ToString()); + } + + ///////////////////////////////////// NOW PASS IN THINGS THAT CANNOT BE COMPARED ///////////////// + + //------------------- TEST 7 + + //[]compare two objects that do not implement IComparable + try + { + ++iCountTestcases; + Comparer.Default.Compare(new Object(), new Object()); + + ++iCountErrors; + Console.WriteLine("Err_007a, Expected exception ArgumentException was not thrown."); + } + catch (ArgumentException) + { } + catch (Exception ex) + { + ++iCountErrors; + Console.WriteLine("Err_007b, Unexpected exception was thrown ex: " + ex.ToString()); + } + + + //------------------- TEST 8 + + //[]compare two objects that are not of the same type + try + { + ++iCountTestcases; + Comparer.Default.Compare(1L, 1); + + ++iCountErrors; + Console.WriteLine("Err_008a, Expected exception ArgumentException was not thrown."); + } + catch (ArgumentException) + { } + catch (Exception ex) + { + ++iCountErrors; + Console.WriteLine("Err_008b, Unexpected exception was thrown ex: " + ex.ToString()); + } + + //------------------- TEST 9 + + //[]compare two objects that are not of the same type + try + { + ++iCountTestcases; + Comparer.Default.Compare(1, 1L); + + ++iCountErrors; + Console.WriteLine("Err_009a, Expected exception ArgumentException was not thrown."); + } + catch (ArgumentException) + { } + catch (Exception ex) + { + ++iCountErrors; + Console.WriteLine("Err_009b, Unexpected exception was thrown ex: " + ex.ToString()); + } + + + //[]Verify Compare where only one object implements IComparable + //and exception is expected from incompatible types + comp = Comparer.Default; + + obj1 = "Aa"; + obj2 = new Object(); + + try + { + compRet = comp.Compare(obj1, obj2); + iCountErrors++; + Console.WriteLine("Err_37035ashz! Expected exception to be thrown"); + } + catch (ArgumentException) { } + catch (Exception e) + { + iCountErrors++; + Console.WriteLine("Err_3407pahs! Unexpected exception thrown {0}", e); + } + + try + { + compRet = comp.Compare(obj2, obj1); + iCountErrors++; + Console.WriteLine("Err_0777paya! Expected exception to be thrown"); + } + catch (ArgumentException) { } + catch (Exception e) + { + iCountErrors++; + Console.WriteLine("Err_73543aha! Unexpected exception thrown {0}", e); + } + + //[]Verify Compare where neither object implements IComparable + comp = Comparer.Default; + + obj1 = new Object(); + obj2 = new Object(); + + try + { + compRet = comp.Compare(obj1, obj2); + iCountErrors++; + Console.WriteLine("Err_22435asps! Expected exception to be thrown"); + } + catch (ArgumentException) { } + catch (Exception e) + { + iCountErrors++; + Console.WriteLine("Err_5649asdh! Unexpected exception thrown {0}", e); + } + + try + { + compRet = comp.Compare(obj2, obj1); + iCountErrors++; + Console.WriteLine("Err_9879nmmj! Expected exception to be thrown"); + } + catch (ArgumentException) { } + catch (Exception e) + { + iCountErrors++; + Console.WriteLine("Err_9881qa! Unexpected exception thrown {0}", e); + } + + //[]Verify Compare where only one object implements IComparable + //and it will handle the conversion + comp = Comparer.Default; + + obj1 = new Foo(5); + obj2 = new Bar(5); + + if (0 != comp.Compare(obj1, obj2)) + { + iCountErrors++; + Console.WriteLine("Err_3073ahsk! Expected Compare to return 0 Compare(obj1, obj2)={0}, Compare(obj2, obj1)={1}", + comp.Compare(obj1, obj2), comp.Compare(obj2, obj1)); + } + + obj1 = new Foo(1); + obj2 = new Bar(2); + + if (0 <= comp.Compare(obj1, obj2)) + { + iCountErrors++; + Console.WriteLine("Err_8922ayps! Expected Compare to return -1 Compare(obj1, obj2)={0}, Compare(obj2, obj1)={1}", + comp.Compare(obj1, obj2), comp.Compare(obj2, obj1)); + } + + + if (iCountErrors == 0) + { + return true; + } + else + { + Console.WriteLine("Fail! iCountErrors=" + iCountErrors.ToString()); + return false; + } + } + + + + [Fact] + public static void ExecuteComparer_Objects() + { + var runClass = new Comparer_Objects(); + Boolean bResult = runClass.runTest(); + + Assert.Equal(true, bResult); + } +} + + +public class Foo : IComparable +{ + public int Data; + + public Foo(int i) + { + Data = i; + } + + + public int CompareTo(Object o) + { + if (o is Foo) + { + return Data.CompareTo(((Foo)o).Data); + } + else if (o is Bar) + { + return Data.CompareTo(((Bar)o).Data); + } + + throw new ArgumentException("Object is not a Foo or a Bar"); + } +} + +public class Bar +{ + public int Data; + + public Bar(int i) + { + Data = i; + } +} diff --git a/src/System.Collections.NonGeneric/tests/DictionaryBase/DictionaryBase_OnMethods.cs b/src/System.Collections.NonGeneric/tests/DictionaryBase/DictionaryBase_OnMethods.cs new file mode 100644 index 000000000000..90ea41c0d1f6 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/DictionaryBase/DictionaryBase_OnMethods.cs @@ -0,0 +1,1035 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Threading; +using System.Collections; +using Xunit; + +public class DictionaryBase_OnMethods +{ + public bool runTest() + { + //////////// Global Variables used for all tests + int iCountErrors = 0; + int iCountTestcases = 0; + + MyDictionaryBase myDict; + Foo f, newF; + string expectedExceptionMessage; + + try + { + do + { + ///////////////////////// START TESTS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + /*********************************************************************************************************************** + Add + ***********************************************************************************************************************/ + + //[] Vanilla Add + iCountTestcases++; + myDict = new MyDictionaryBase(); + f = new Foo(); + myDict.Add(f, 0.ToString()); + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (!myDict.OnInsertCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_4072ayps OnInsertComplete was never called"); + } + else if (!myDict.Contains(f)) + { + iCountErrors++; + Console.WriteLine("Err_0181salh Item was added"); + } + + //[] Add where Validate throws + iCountTestcases++; + myDict = new MyDictionaryBase(); + myDict.OnValidateThrow = true; + expectedExceptionMessage = "OnValidate"; + f = new Foo(); + try + { + myDict.Add(f, 0.ToString()); + iCountErrors++; + Console.WriteLine("Err_1570pyqa Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_2708apsa Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (myDict.OnInsertCalled) + { + iCountErrors++; + Console.WriteLine("Err_56707awwaps OnInsert was called"); + } + else if (0 != myDict.Count) + { + iCountErrors++; + Console.WriteLine("Err_2708apsa Expected Empty Collection actual {0} elements", myDict.Count); + } + + //[] Add where OnInsert throws + iCountTestcases++; + myDict = new MyDictionaryBase(); + myDict.OnInsertThrow = true; + expectedExceptionMessage = "OnInsert"; + f = new Foo(); + try + { + myDict.Add(f, 0.ToString()); + iCountErrors++; + Console.WriteLine("Err_35208asdo Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_30437sfdah Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (myDict.OnInsertCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_370asjhs OnInsertComplete was called"); + } + else if (0 != myDict.Count) + { + iCountErrors++; + Console.WriteLine("Err_3y07aza Expected Empty Collection actual {0} elements", myDict.Count); + } + + //[] Add where OnInsertComplete throws + iCountTestcases++; + myDict = new MyDictionaryBase(); + myDict.OnInsertCompleteThrow = true; + expectedExceptionMessage = "OnInsertComplete"; + f = new Foo(); + try + { + myDict.Add(f, 0.ToString()); + iCountErrors++; + Console.WriteLine("Err_2548ashz Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_2708alkw Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (0 != myDict.Count) + { + iCountErrors++; + Console.WriteLine("Err_3680ahksd Expected Empty Collection actual {0} elements", myDict.Count); + } + + /*********************************************************************************************************************** + Remove + ***********************************************************************************************************************/ + + //[] Vanilla Remove + iCountTestcases++; + myDict = new MyDictionaryBase(); + f = new Foo(); + + myDict.Add(f, 0.ToString()); + myDict.Remove(f); + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (!myDict.OnRemoveCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_348awq OnRemoveComplete was never called"); + } + else if (myDict.Contains(f)) + { + iCountErrors++; + Console.WriteLine("Err_0824answ Item was not removed"); + } + + //[] Remove where Validate throws + iCountTestcases++; + myDict = new MyDictionaryBase(); + expectedExceptionMessage = "OnValidate"; + f = new Foo(); + try + { + myDict.Add(f, 0.ToString()); + myDict.OnValidateThrow = true; + myDict.Remove(f); + iCountErrors++; + Console.WriteLine("Err_08207hnas Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_87082aspz Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (myDict.OnRemoveCalled) + { + iCountErrors++; + Console.WriteLine("Err_7207snmqla OnRemove was called"); + } + else if (!myDict.Contains(f)) + { + iCountErrors++; + Console.WriteLine("Err_7270pahnz Element was actually removed {0}", myDict.Contains(f)); + } + + //[] Remove where OnRemove throws + iCountTestcases++; + myDict = new MyDictionaryBase(); + myDict.OnRemoveThrow = true; + expectedExceptionMessage = "OnRemove"; + f = new Foo(); + try + { + myDict.Add(f, 0.ToString()); + myDict.Remove(f); + iCountErrors++; + Console.WriteLine("Err_7708aqyy Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_08281naws Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (myDict.OnRemoveCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_10871aklsj OnRemoveComplete was called"); + } + else if (!myDict.Contains(f)) + { + iCountErrors++; + Console.WriteLine("Err_2081aslkjs Element was actually removed {0}", myDict.Contains(f)); + } + + //[] Remove where OnRemoveComplete throws + iCountTestcases++; + myDict = new MyDictionaryBase(); + myDict.OnRemoveCompleteThrow = true; + expectedExceptionMessage = "OnRemoveComplete"; + f = new Foo(); + try + { + myDict.Add(f, 0.ToString()); + myDict.Remove(f); + iCountErrors++; + Console.WriteLine("Err_10981nlskj Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_20981askjs Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (!myDict.Contains(f)) + { + iCountErrors++; + Console.WriteLine("Err_20909assfd Element was actually removed {0}", myDict.Contains(f)); + } + + /*********************************************************************************************************************** + Clear + ***********************************************************************************************************************/ + + //[] Vanilla Clear + iCountTestcases++; + myDict = new MyDictionaryBase(); + f = new Foo(); + + myDict.Add(f, 0.ToString()); + myDict.Clear(); + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (!myDict.OnClearCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_2136sdf OnClearComplete was never called"); + } + else if (0 != myDict.Count) + { + iCountErrors++; + Console.WriteLine("Err_9494aswa Items were not Cleared"); + } + + //[] Clear where Validate throws + iCountTestcases++; + myDict = new MyDictionaryBase(); + expectedExceptionMessage = "OnValidate"; + f = new Foo(); + + myDict.Add(f, 0.ToString()); + myDict.OnValidateThrow = true; + myDict.Clear(); + + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (!myDict.OnClearCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_6549asff OnClearComplete was not called"); + } + else if (0 != myDict.Count) + { + iCountErrors++; + Console.WriteLine("Err_4649awajm Items were Cleared"); + } + + //[] Clear where OnClear throws + iCountTestcases++; + myDict = new MyDictionaryBase(); + myDict.OnClearThrow = true; + expectedExceptionMessage = "OnClear"; + f = new Foo(); + try + { + myDict.Add(f, 0.ToString()); + myDict.Clear(); + iCountErrors++; + Console.WriteLine("Err_9444sjpjnException was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_78941joaException message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (myDict.OnClearCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_94944awfuu OnClearComplete was called"); + } + else if (1 != myDict.Count) + { + iCountErrors++; + Console.WriteLine("Err_6498 Items were not Cleared"); + } + + //[] Clear where OnClearComplete throws + iCountTestcases++; + myDict = new MyDictionaryBase(); + myDict.OnClearCompleteThrow = true; + expectedExceptionMessage = "OnClearComplete"; + f = new Foo(); + try + { + myDict.Add(f, 0.ToString()); + myDict.Clear(); + iCountErrors++; + Console.WriteLine("Err_64977awad Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_0877asaw Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (0 != myDict.Count) + { + iCountErrors++; + Console.WriteLine("Err_1081lkajs Items were not Cleared"); + } + + + /*********************************************************************************************************************** + Set that adds an item + ***********************************************************************************************************************/ + + //[] Vanilla Set + iCountTestcases++; + myDict = new MyDictionaryBase(); + f = new Foo(1, "1"); + newF = new Foo(2, "2"); + + myDict.Add(f, 1.ToString()); + myDict[newF] = 2.ToString(); + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (!myDict.OnSetCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_1698asdf OnSetComplete was never called"); + } + else if (!myDict.Contains(f) || !myDict.Contains(newF)) + { + iCountErrors++; + Console.WriteLine("Err_9494safs Item was not Set"); + } + + //[] Set where Validate throws + iCountTestcases++; + myDict = new MyDictionaryBase(); + expectedExceptionMessage = "OnValidate"; + f = new Foo(1, "1"); + newF = new Foo(2, "2"); + try + { + myDict.Add(f, 1.ToString()); + myDict.OnValidateThrow = true; + myDict[newF] = 2.ToString(); + iCountErrors++; + Console.WriteLine("Err_611awwa Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_69498hph Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (myDict.OnSetCalled) + { + iCountErrors++; + Console.WriteLine("Err_94887jio OnSet was called"); + } + else if (!myDict.Contains(f) || myDict.Contains(newF)) + { + iCountErrors++; + Console.WriteLine("Err_6549ihyopiu Element was actually Set {0}", myDict.Contains(f)); + } + + //[] Set where OnSet throws + iCountTestcases++; + myDict = new MyDictionaryBase(); + myDict.OnSetThrow = true; + expectedExceptionMessage = "OnSet"; + f = new Foo(1, "1"); + newF = new Foo(2, "2"); + try + { + myDict.Add(f, 1.ToString()); + myDict[newF] = 2.ToString(); + iCountErrors++; + Console.WriteLine("Err_61518haiosd Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_196198sdklhsException message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (myDict.OnSetCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_6548dasfs OnSetComplete was called"); + } + else if (!myDict.Contains(f) || myDict.Contains(newF)) + { + iCountErrors++; + Console.WriteLine("Err_2797sah Element was actually Set {0}", myDict.Contains(f)); + } + + //[] Set where OnSetComplete throws + iCountTestcases++; + myDict = new MyDictionaryBase(); + myDict.OnSetCompleteThrow = true; + expectedExceptionMessage = "OnSetComplete"; + f = new Foo(1, "1"); + newF = new Foo(2, "2"); + try + { + myDict.Add(f, 1.ToString()); + myDict[newF] = 2.ToString(); + iCountErrors++; + Console.WriteLine("Err_56498hkashException was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_13168hsaiuh Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (!myDict.Contains(f) || myDict.Contains(newF)) + { + iCountErrors++; + Console.WriteLine("Err_64198ahihos Element was actually Set {0}", myDict.Contains(f)); + } + + /*********************************************************************************************************************** + Set that sets an existing item + ***********************************************************************************************************************/ + + //[] Vanilla Set + iCountTestcases++; + myDict = new MyDictionaryBase(); + f = new Foo(1, "1"); + + myDict.Add(f, 1.ToString()); + myDict[f] = 2.ToString(); + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (!myDict.OnSetCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_1698asdf OnSetComplete was never called"); + } + else if (!myDict.Contains(f) || myDict[f] != "2") + { + iCountErrors++; + Console.WriteLine("Err_9494safs Item was not Set"); + } + + //[] Set where Validate throws + iCountTestcases++; + myDict = new MyDictionaryBase(); + expectedExceptionMessage = "OnValidate"; + f = new Foo(1, "1"); + try + { + myDict.Add(f, 1.ToString()); + myDict.OnValidateThrow = true; + myDict[f] = 2.ToString(); + iCountErrors++; + Console.WriteLine("Err_611awwa Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_69498hph Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (myDict.OnSetCalled) + { + iCountErrors++; + Console.WriteLine("Err_94887jio OnSet was called"); + } + else if (!myDict.Contains(f) || myDict[f] != "1") + { + iCountErrors++; + Console.WriteLine("Err_6549ihyopiu Element was actually Set {0}", myDict.Contains(f)); + } + + //[] Set where OnSet throws + iCountTestcases++; + myDict = new MyDictionaryBase(); + myDict.OnSetThrow = true; + expectedExceptionMessage = "OnSet"; + f = new Foo(1, "1"); + + try + { + myDict.Add(f, 1.ToString()); + myDict[f] = 2.ToString(); + iCountErrors++; + Console.WriteLine("Err_61518haiosd Exception was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_196198sdklhsException message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (myDict.OnSetCompleteCalled) + { + iCountErrors++; + Console.WriteLine("Err_6548dasfs OnSetComplete was called"); + } + else if (!myDict.Contains(f) || myDict[f] != "1") + { + iCountErrors++; + Console.WriteLine("Err_2797sah Element was actually Set {0}", myDict.Contains(f)); + } + + //[] Set where OnSetComplete throws + iCountTestcases++; + myDict = new MyDictionaryBase(); + myDict.OnSetCompleteThrow = true; + expectedExceptionMessage = "OnSetComplete"; + f = new Foo(1, "1"); + + try + { + myDict.Add(f, 1.ToString()); + myDict[f] = 2.ToString(); + iCountErrors++; + Console.WriteLine("Err_56498hkashException was not thrown"); + } + catch (Exception e) + { + if (expectedExceptionMessage != e.Message) + { + iCountErrors++; + Console.WriteLine("Err_13168hsaiuh Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); + } + } + + if (myDict.IsError) + { + iCountErrors++; + Console.WriteLine(myDict.ErrorMsg); + } + else if (!myDict.Contains(f) || myDict[f] != "1") + { + iCountErrors++; + Console.WriteLine("Err_64198ahihos Element was actually Set {0}", myDict.Contains(f)); + } + /////////////////////////// END TESTS ///////////////////////////// + + + } while (false); + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString()); + } + + + //// Finish Diagnostics + if (iCountErrors == 0) + { + return true; + } + else + { + Console.WriteLine("Fail iCountErrors==" + iCountErrors); + return false; + } + } + + + [Fact] + public static void ExecuteDictionaryBase_OnMethods() + { + bool bResult = false; + var cbA = new DictionaryBase_OnMethods(); + + try + { + bResult = cbA.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine(" : FAiL! Error Err_9999zzz! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } + + //DictionaryBase is provided to be used as the base class for strongly typed collections. Lets use one of our own here + public class MyDictionaryBase : DictionaryBase + { + public bool IsError = false; + public string ErrorMsg = String.Empty; + public bool OnValidateCalled, OnSetCalled, OnSetCompleteCalled, OnInsertCalled, OnInsertCompleteCalled, + OnClearCalled, OnClearCompleteCalled, OnRemoveCalled, OnRemoveCompleteCalled; + public bool OnValidateThrow, OnSetThrow, OnSetCompleteThrow, OnInsertThrow, OnInsertCompleteThrow, + OnClearThrow, OnClearCompleteThrow, OnRemoveThrow, OnRemoveCompleteThrow; + + + public MyDictionaryBase() + { + OnValidateCalled = false; + OnSetCalled = false; + OnSetCompleteCalled = false; + OnInsertCalled = false; + OnInsertCompleteCalled = false; + OnClearCalled = false; + OnClearCompleteCalled = false; + OnRemoveCalled = false; + OnRemoveCompleteCalled = false; + + OnValidateThrow = false; + OnSetThrow = false; + OnSetCompleteThrow = false; + OnInsertThrow = false; + OnInsertCompleteThrow = false; + OnClearThrow = false; + OnClearCompleteThrow = false; + OnRemoveThrow = false; + OnRemoveCompleteThrow = false; + } + + public void Add(Foo key, string value) + { + Dictionary.Add(key, value); + } + + public string this[Foo index] + { + get + { + return (string)Dictionary[index]; + } + set + { + Dictionary[index] = value; + } + } + + public Boolean Contains(Foo f) + { + return Dictionary.Contains(f); + } + + public void Remove(Foo f) + { + Dictionary.Remove(f); + } + + protected override void OnSet(Object key, Object oldValue, Object newValue) + { + if (!OnValidateCalled) + { + IsError = true; + ErrorMsg += "Err_0882pxnk OnValidate has not been called\n"; + } + + if (this[(Foo)key] != (string)oldValue) + { + IsError = true; + ErrorMsg += "Err_1204phzn Value was already set\n"; + } + + OnSetCalled = true; + + if (OnSetThrow) + throw new Exception("OnSet"); + } + + protected override void OnInsert(Object key, Object value) + { + if (!OnValidateCalled) + { + IsError = true; + ErrorMsg += "Err_0834halkh OnValidate has not been called\n"; + } + + if (this[(Foo)key] == (string)value) + { + IsError = true; + ErrorMsg += "Err_2702apqh OnInsert called with a bad index\n"; + } + + OnInsertCalled = true; + + if (OnInsertThrow) + throw new Exception("OnInsert"); + } + + protected override void OnClear() + { + if (Count == 0 || Dictionary.Count == 0) + { + //Assumes Clear not called on an empty list + IsError = true; + ErrorMsg += "Err_2247alkhz List already empty\n"; + } + + OnClearCalled = true; + + if (OnClearThrow) + throw new Exception("OnClear"); + } + + protected override void OnRemove(Object key, Object value) + { + if (!OnValidateCalled) + { + IsError = true; + ErrorMsg += "Err_3703pyaa OnValidate has not been called\n"; + } + + if (this[(Foo)key] != (string)value) + { + IsError = true; + ErrorMsg += "Err_1708afsw Value was already set\n"; + } + + OnRemoveCalled = true; + + if (OnRemoveThrow) + throw new Exception("OnRemove"); + } + + protected override void OnValidate(Object key, Object value) + { + OnValidateCalled = true; + + if (OnValidateThrow) + throw new Exception("OnValidate"); + } + + protected override void OnSetComplete(Object key, Object oldValue, Object newValue) + { + if (!OnSetCalled) + { + IsError = true; + ErrorMsg += "Err_0282pyahn OnSet has not been called\n"; + } + + if (this[(Foo)key] != (string)newValue) + { + IsError = true; + ErrorMsg += "Err_2134pyqt Value has not been set\n"; + } + + OnSetCompleteCalled = true; + + if (OnSetCompleteThrow) + throw new Exception("OnSetComplete"); + } + + protected override void OnInsertComplete(Object key, Object value) + { + if (!OnInsertCalled) + { + IsError = true; + ErrorMsg += "Err_5607aspyu OnInsert has not been called\n"; + } + + if (this[(Foo)key] != (string)value) + { + IsError = true; + ErrorMsg += "Err_3407ahpqValue has not been set\n"; + } + + OnInsertCompleteCalled = true; + + if (OnInsertCompleteThrow) + throw new Exception("OnInsertComplete"); + } + + protected override void OnClearComplete() + { + if (!OnClearCalled) + { + IsError = true; + ErrorMsg += "Err_3470sfas OnClear has not been called\n"; + } + + if (Count != 0 || Dictionary.Count != 0) + { + IsError = true; + ErrorMsg += "Err_2507yuznb Value has not been set\n"; + } + + OnClearCompleteCalled = true; + + if (OnClearCompleteThrow) + throw new Exception("OnClearComplete"); + } + + protected override void OnRemoveComplete(Object key, Object value) + { + if (!OnRemoveCalled) + { + IsError = true; + ErrorMsg += "Err_70782sypz OnRemve has not been called\n"; + } + + if (Contains((Foo)key)) + { + IsError = true; + ErrorMsg += "Err_3097saq Value still exists\n"; + } + + OnRemoveCompleteCalled = true; + + if (OnRemoveCompleteThrow) + throw new Exception("OnRemoveComplete"); + } + + public void ClearTest() + { + IsError = false; + ErrorMsg = String.Empty; + + OnValidateCalled = false; + OnSetCalled = false; + OnSetCompleteCalled = false; + OnInsertCalled = false; + OnInsertCompleteCalled = false; + OnClearCalled = false; + OnClearCompleteCalled = false; + OnRemoveCalled = false; + OnRemoveCompleteCalled = false; + + OnValidateThrow = false; + OnSetThrow = false; + OnSetCompleteThrow = false; + OnInsertThrow = false; + OnInsertCompleteThrow = false; + OnClearThrow = false; + OnClearCompleteThrow = false; + OnRemoveThrow = false; + OnRemoveCompleteThrow = false; + } + } + + public class Foo + { + private Int32 _iValue; + private String _strValue; + + public Foo() + { + } + + public Foo(Int32 i, String str) + { + _iValue = i; + _strValue = str; + } + + public Int32 IValue + { + get { return _iValue; } + set { _iValue = value; } + } + + public String SValue + { + get { return _strValue; } + set { _strValue = value; } + } + + public override Boolean Equals(Object obj) + { + if (obj == null) + return false; + if (!(obj is Foo)) + return false; + if ((((Foo)obj).IValue == _iValue) && (((Foo)obj).SValue == _strValue)) + return true; + return false; + } + + public override Int32 GetHashCode() + { + return _iValue; + } + } +} \ No newline at end of file diff --git a/src/System.Collections.NonGeneric/tests/DictionaryBase/DictionaryBase_UnitTests.cs b/src/System.Collections.NonGeneric/tests/DictionaryBase/DictionaryBase_UnitTests.cs new file mode 100644 index 000000000000..865342c8a77c --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/DictionaryBase/DictionaryBase_UnitTests.cs @@ -0,0 +1,691 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Threading; +using System.Collections; +using Xunit; +public class DictionaryBase_UnitTests +{ + public bool runTest() + { + + //////////// Global Variables used for all tests + int iCountErrors = 0; + int iCountTestcases = 0; + + MyDictionaryBase mycol1; + MyDictionaryBase mycol2; + FooKey fk1; + FooValue fv1; + FooKey[] arrFK1; + FooValue[] arrFV1; + IDictionaryEnumerator enu1; + Int32 iCount; + + DictionaryEntry[] arrDicEnt1; + DictionaryEntry dicEnt1; + Object obj1; + + // ICollection icol1; + try + { + do + { + ///////////////////////// START TESTS //////////////////////////// + + //[]DictionaryBase implements IDictionary (which means both ICollection and IEnumerator as well :-() + //To test this class, we will implement our own strongly typed DictionaryBase and call its methods + iCountTestcases++; + + //[] Count property + iCountTestcases++; + mycol1 = new MyDictionaryBase(); + if (mycol1.Count != 0) + { + iCountErrors++; + Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count); + } + for (int i = 0; i < 100; i++) + mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); + if (mycol1.Count != 100) + { + iCountErrors++; + Console.WriteLine("Err_2075sg! Expected value not returned, " + mycol1.Count); + } + //[]CopyTo + iCountTestcases++; + mycol1 = new MyDictionaryBase(); + for (int i = 0; i < 100; i++) + mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); + arrDicEnt1 = new DictionaryEntry[100]; + mycol1.CopyTo(arrDicEnt1, 0); + arrFK1 = new FooKey[100]; + arrFV1 = new FooValue[100]; + for (int i = 0; i < 100; i++) + { + arrFK1[i] = (FooKey)arrDicEnt1[i].Key; + arrFV1[i] = (FooValue)arrDicEnt1[i].Value; + } + Array.Sort(arrFK1); + Array.Sort(arrFV1); + + for (int i = 0; i < 100; i++) + { + if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString())) + { + iCountErrors++; + Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned, " + arrFK1[i].IValue); + } + if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString())) + { + iCountErrors++; + Console.WriteLine("Err_93765dg_" + i + "! Expected value not returned"); + } + } + + + //Argument checking + iCountTestcases++; + mycol1 = new MyDictionaryBase(); + for (int i = 0; i < 100; i++) + mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); + arrDicEnt1 = new DictionaryEntry[100]; + try + { + mycol1.CopyTo(arrDicEnt1, 50); + + iCountErrors++; + Console.WriteLine("Err_2075dfgv! Exception not thrown"); + } + catch (ArgumentException) + { + } + catch (Exception ex) + { + iCountErrors++; + Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); + } + + try + { + mycol1.CopyTo(arrDicEnt1, -1); + + iCountErrors++; + Console.WriteLine("Err_2075dfgv! Exception not thrown"); + } + catch (ArgumentException) + { + } + catch (Exception ex) + { + iCountErrors++; + Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); + } + + arrDicEnt1 = new DictionaryEntry[200]; + mycol1.CopyTo(arrDicEnt1, 100); + arrFK1 = new FooKey[100]; + arrFV1 = new FooValue[100]; + for (int i = 0; i < 100; i++) + { + arrFK1[i] = (FooKey)arrDicEnt1[i + 100].Key; + arrFV1[i] = (FooValue)arrDicEnt1[i + 100].Value; + } + Array.Sort(arrFK1); + Array.Sort(arrFV1); + + for (int i = 0; i < 100; i++) + { + if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString())) + { + iCountErrors++; + Console.WriteLine("Err_974gd_" + i + "! Expected value not returned, " + arrFK1[i].IValue); + } + if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString())) + { + iCountErrors++; + Console.WriteLine("Err_2075sg_" + i + "! Expected value not returned"); + } + } + + //[]GetEnumerator + iCountTestcases++; + mycol1 = new MyDictionaryBase(); + for (int i = 0; i < 100; i++) + mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); + + enu1 = mycol1.GetEnumerator(); + //Calling current should throw here + try + { + //Calling current should throw here + dicEnt1 = (DictionaryEntry)enu1.Current; + + iCountErrors++; + Console.WriteLine("Err_87543! Exception not thrown"); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); + } + + //Calling Key should throw here + try + { + //Calling current should throw here + fk1 = (FooKey)enu1.Key; + + iCountErrors++; + Console.WriteLine("Err_87543! Exception not thrown"); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); + } + + //Calling Value should throw here + try + { + //Calling current should throw here + fv1 = (FooValue)enu1.Value; + + iCountErrors++; + Console.WriteLine("Err_87543! Exception not thrown"); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); + } + + iCount = 0; + arrFK1 = new FooKey[100]; + arrFV1 = new FooValue[100]; + while (enu1.MoveNext()) + { + dicEnt1 = (DictionaryEntry)enu1.Current; + + arrFK1[iCount] = (FooKey)dicEnt1.Key; + arrFV1[iCount] = (FooValue)dicEnt1.Value; + + fk1 = (FooKey)enu1.Key; + if (fk1 != arrFK1[iCount]) + { + iCountErrors++; + Console.WriteLine("Err_8543s_" + iCount + "! Expected value not returned, " + arrFK1[iCount].IValue); + } + + fv1 = (FooValue)enu1.Value; + if (fv1 != arrFV1[iCount]) + { + iCountErrors++; + Console.WriteLine("Err_29075gd_" + iCount + "! Expected value not returned, " + arrFV1[iCount].IValue); + } + + iCount++; + } + if (iCount != 100) + { + iCountErrors++; + Console.WriteLine("Err_87543! doesnot match"); + } + Array.Sort(arrFK1); + Array.Sort(arrFV1); + + for (int i = 0; i < 100; i++) + { + if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString())) + { + iCountErrors++; + Console.WriteLine("Err_89275sgf_" + i + "! Expected value not returned, " + arrFK1[i].IValue); + } + if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString())) + { + iCountErrors++; + Console.WriteLine("Err_275g_" + i + "! Expected value not returned"); + } + } + + try + { + //Calling current should throw here + dicEnt1 = (DictionaryEntry)enu1.Current; + + iCountErrors++; + Console.WriteLine("Err_87543! Exception not thrown"); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); + } + + //Calling Key should throw here + try + { + //Calling current should throw here + fk1 = (FooKey)enu1.Key; + + iCountErrors++; + Console.WriteLine("Err_87543! Exception not thrown"); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); + } + + //Calling Value should throw here + try + { + //Calling current should throw here + fv1 = (FooValue)enu1.Value; + + iCountErrors++; + Console.WriteLine("Err_87543! Exception not thrown"); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); + } + + //[] IEnumerable.GetEnumerator + iCountTestcases++; + mycol1 = new MyDictionaryBase(); + for (int i = 0; i < 100; i++) + mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); + + IEnumerator iEnumerator1 = ((IEnumerable)mycol1).GetEnumerator(); + //Calling current should throw here + try + { + //Calling current should throw here + dicEnt1 = (DictionaryEntry)iEnumerator1.Current; + + iCountErrors++; + Console.WriteLine("Err_87543! Exception not thrown"); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); + } + + iCount = 0; + arrFK1 = new FooKey[100]; + arrFV1 = new FooValue[100]; + while (iEnumerator1.MoveNext()) + { + dicEnt1 = (DictionaryEntry)iEnumerator1.Current; + + arrFK1[iCount] = (FooKey)dicEnt1.Key; + arrFV1[iCount] = (FooValue)dicEnt1.Value; + + if (mycol1[arrFK1[iCount]] != arrFV1[iCount]) + { + iCountErrors++; + Console.WriteLine("Err_8543s_" + iCount + "! Expected value not returned, " + arrFK1[iCount].IValue); + } + + iCount++; + } + if (iCount != 100) + { + iCountErrors++; + Console.WriteLine("Err_87543! doesnot match"); + } + Array.Sort(arrFK1); + Array.Sort(arrFV1); + + for (int i = 0; i < 100; i++) + { + if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString())) + { + iCountErrors++; + Console.WriteLine("Err_89275sgf_" + i + "! Expected value not returned, " + arrFK1[i].IValue); + } + if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString())) + { + iCountErrors++; + Console.WriteLine("Err_275g_" + i + "! Expected value not returned"); + } + } + + try + { + //Calling current should throw here + dicEnt1 = (DictionaryEntry)iEnumerator1.Current; + + iCountErrors++; + Console.WriteLine("Err_87543! Exception not thrown"); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); + } + + //[]IsSynchronized + iCountTestcases++; + mycol1 = new MyDictionaryBase(); + if (mycol1.IsSynchronized) + { + iCountErrors++; + Console.WriteLine("Err_275eg! Expected value not returned, " + mycol1.IsSynchronized); + } + + //[]SyncRoot + iCountTestcases++; + mycol1 = new MyDictionaryBase(); + obj1 = mycol1.SyncRoot; + mycol2 = mycol1; + if (obj1 != mycol2.SyncRoot) + { + iCountErrors++; + Console.WriteLine("Err_9745sg! Expected value not returned"); + } + + //End of ICollection and IEnumerator methods + //Now to IDictionary methods + //[]Add, this, Contains, Remove, Clear + iCountTestcases++; + mycol1 = new MyDictionaryBase(); + for (int i = 0; i < 100; i++) + mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); + for (int i = 0; i < 100; i++) + { + if ((mycol1[new FooKey(i, i.ToString())].IValue != i) || (mycol1[new FooKey(i, i.ToString())].SValue != i.ToString())) + { + iCountErrors++; + Console.WriteLine("Err_2974swsg_" + i + "! Expected value not returned"); + } + } + for (int i = 0; i < 100; i++) + { + mycol1.Remove(new FooKey(i, i.ToString())); + if ((mycol1.Count != (99 - i))) + { + iCountErrors++; + Console.WriteLine("Err_2975sg_" + i + "! Expected value not returned"); + } + if ((mycol1.Contains(new FooKey(i, i.ToString())))) + { + iCountErrors++; + Console.WriteLine("Err_975wg_" + i + "! Expected value not returned"); + } + } + + mycol1 = new MyDictionaryBase(); + for (int i = 0; i < 100; i++) + mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); + mycol1.Clear(); + if (mycol1.Count != 0) + { + iCountErrors++; + Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count); + } + + //[]Rest of the IList methods: this-set, IsFixedSize, IsReadOnly, Keys, Values + iCountTestcases++; + mycol1 = new MyDictionaryBase(); + if (mycol1.IsFixedSize) + { + iCountErrors++; + Console.WriteLine("Err_9753sfg! Expected value not returned, " + mycol1.IsFixedSize); + } + if (mycol1.IsReadOnly) + { + iCountErrors++; + Console.WriteLine("Err_834sg! Expected value not returned, " + mycol1.IsReadOnly); + } + mycol1 = new MyDictionaryBase(); + for (int i = 0; i < 100; i++) + mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString())); + for (int i = 0, j = 100; i < 100; i++, j--) + mycol1[new FooKey(i, i.ToString())] = new FooValue(j, j.ToString()); + for (int i = 0, j = 100; i < 100; i++, j--) + { + if ((mycol1[new FooKey(i, i.ToString())].IValue != j) || (mycol1[new FooKey(i, i.ToString())].SValue != j.ToString())) + { + iCountErrors++; + Console.WriteLine("Err_7342rfg_" + i + "! Expected value not returned"); + } + } + + mycol1 = new MyDictionaryBase(); + mycol1.Add(new FooKey(), new FooValue()); + /////////////////////////////////////////////////////////////////// + /////////////////////////// END TESTS ///////////////////////////// + + + } while (false); + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString()); + } + + //// Finish Diagnostics + if (iCountErrors == 0) + { + return true; + } + else + { + Console.WriteLine("Fail! iCountErrors==" + iCountErrors); + return false; + } + + } + + + [Fact] + public static void ExecuteDictionaryBase_UnitTests() + { + bool bResult = false; + var cbA = new DictionaryBase_UnitTests(); + + try + { + bResult = cbA.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("FAiL! Error Err_9999zzz! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } + + public class FooKey : IComparable + { + private Int32 _iValue; + private String _strValue; + + public FooKey() + { + } + + public FooKey(Int32 i, String str) + { + _iValue = i; + _strValue = str; + } + + public Int32 IValue + { + get { return _iValue; } + set { _iValue = value; } + } + + public String SValue + { + get { return _strValue; } + set { _strValue = value; } + } + + public override Boolean Equals(Object obj) + { + if (obj == null) + return false; + if (!(obj is FooKey)) + return false; + if ((((FooKey)obj).IValue == _iValue) && (((FooKey)obj).SValue == _strValue)) + return true; + return false; + } + + public override Int32 GetHashCode() + { + return _iValue; + } + + public Int32 CompareTo(Object obj) + { + if (!(obj is FooKey)) + throw new ArgumentException("obj must be type FooKey"); + FooKey temp = (FooKey)obj; + if (temp.IValue > _iValue) + return -1; + else if (temp.IValue < _iValue) + return 1; + else + return 0; + } + } + + public class FooValue : IComparable + { + private Int32 _iValue; + private String _strValue; + + public FooValue() + { + } + + public FooValue(Int32 i, String str) + { + _iValue = i; + _strValue = str; + } + + public Int32 IValue + { + get { return _iValue; } + set { _iValue = value; } + } + + public String SValue + { + get { return _strValue; } + set { _strValue = value; } + } + + public override Boolean Equals(Object obj) + { + if (obj == null) + return false; + if (!(obj is FooValue)) + return false; + if ((((FooValue)obj).IValue == _iValue) && (((FooValue)obj).SValue == _strValue)) + return true; + return false; + } + + public override Int32 GetHashCode() + { + return _iValue; + } + + public Int32 CompareTo(Object obj) + { + if (!(obj is FooValue)) + throw new ArgumentException("obj must be type FooValue"); + FooValue temp = (FooValue)obj; + if (temp.IValue > _iValue) + return -1; + else if (temp.IValue < _iValue) + return 1; + else + return 0; + } + } + + //DictionaryBase is provided to be used as the base class for strongly typed collections. Lets use one of our own here + public class MyDictionaryBase : DictionaryBase + { + public void Add(FooKey fk1, FooValue f2) + { + Dictionary.Add(fk1, f2); + } + + public FooValue this[FooKey f1] + { + get { return (FooValue)Dictionary[f1]; } + set { Dictionary[f1] = value; } + } + + public Boolean IsSynchronized + { + get { return ((ICollection)Dictionary).IsSynchronized; } + } + + public Object SyncRoot + { + get { return Dictionary.SyncRoot; } + } + + public Boolean Contains(FooKey f) + { + return ((IDictionary)Dictionary).Contains(f); + } + + public void Remove(FooKey f) + { + ((IDictionary)Dictionary).Remove(f); + } + + public Boolean IsFixedSize + { + get { return Dictionary.IsFixedSize; } + } + + public Boolean IsReadOnly + { + get { return Dictionary.IsReadOnly; } + } + + public ICollection Keys + { + get { return Dictionary.Keys; } + } + + public ICollection Values + { + get { return Dictionary.Values; } + } + + } +} diff --git a/src/System.Collections.NonGeneric/tests/Queue/Queue_Clone.cs b/src/System.Collections.NonGeneric/tests/Queue/Queue_Clone.cs new file mode 100644 index 000000000000..674a414f0cae --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Queue/Queue_Clone.cs @@ -0,0 +1,399 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using System.Globalization; +using Xunit; + +public class Queue_Clone +{ + public bool runTest() + { + //////////// Global Variables used for all tests + + String strValue = String.Empty; + int iCountErrors = 0; + int iCountTestcases = 0; + + Queue que; + Queue queClone; + + Object dequeuedValue; + + A a1; + A a2; + + try + { + ///////////////////////// START TESTS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + //[]vanila + iCountTestcases++; + + que = new Queue(); + + for (int i = 0; i < 100; i++) + que.Enqueue(i); + + queClone = (Queue)que.Clone(); + if (queClone.Count != 100) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned"); + } + + for (int i = 0; i < 100; i++) + { + if (!queClone.Contains(i)) + { + iCountErrors++; + Console.WriteLine("Err_93475sdg! wrong value returned"); + } + } + + //[]making sure that this is shallow + iCountTestcases++; + + que = new Queue(); + + que.Enqueue(new A(10)); + + queClone = (Queue)que.Clone(); + if (queClone.Count != 1) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned"); + } + + a1 = (A)que.Dequeue(); + a1.I = 50; + + if (queClone.Count != 1) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned"); + } + + a2 = (A)queClone.Dequeue(); + + if (a2.I != 50) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned, " + a2.I); + } + + //[]Empty Que + iCountTestcases++; + + que = new Queue(); + queClone = (Queue)que.Clone(); + + if (queClone.Count != 0) + { + iCountErrors++; + Console.WriteLine("Err_4488ajied! Count wrong value returned Expected={0} Actual={1}", 0, queClone.Count); + } + + queClone.Enqueue(100); + + if ((int)(dequeuedValue = queClone.Dequeue()) != 100) + { + iCountErrors++; + Console.WriteLine("Err_45884ajeiod! wrong value returned Expected={0} Actual={1}", 100, dequeuedValue); + } + + //[]After Clear + iCountTestcases++; + + que = new Queue(); + + // Insert 50 items in the Queue + for (int i = 0; i < 100; i++) + { + que.Enqueue(i); + } + + que.Clear(); + queClone = (Queue)que.Clone(); + + if (queClone.Count != 0) + { + iCountErrors++; + Console.WriteLine("Err_4488ajied! Count wrong value returned Expected={0} Actual={1}", 0, queClone.Count); + } + + queClone.Enqueue(100); + + if ((int)(dequeuedValue = queClone.Dequeue()) != 100) + { + iCountErrors++; + Console.WriteLine("Err_51188ajeid! wrong value returned Expected={0} Actual={1}", 100, dequeuedValue); + } + + //[]After Dequeue all items + iCountTestcases++; + + que = new Queue(); + + // Insert 50 items in the Queue + for (int i = 0; i < 100; i++) + { + que.Enqueue(i); + } + + for (int i = 0; i < 100; i++) + { + que.Dequeue(); + } + + queClone = (Queue)que.Clone(); + + if (queClone.Count != 0) + { + iCountErrors++; + Console.WriteLine("Err_418aheid! Count wrong value returned Expected={0} Actual={1}", 0, queClone.Count); + } + + queClone.Enqueue(100); + + if ((int)(dequeuedValue = queClone.Dequeue()) != 100) + { + iCountErrors++; + Console.WriteLine("Err_48088ahide! wrong value returned Expected={0} Actual={1}", 100, dequeuedValue); + } + + //[]Clone then Dequeue then EnQueue + iCountTestcases++; + + que = new Queue(); + + // Insert 50 items in the Queue + for (int i = 0; i < 100; i++) + { + que.Enqueue(i); + } + + queClone = (Queue)que.Clone(); + + if (queClone.Count != 100) + { + iCountErrors++; + Console.WriteLine("Err_418aheid! Count wrong value returned Expected={0} Actual={1}", 100, queClone.Count); + } + + if ((int)(dequeuedValue = queClone.Dequeue()) != 0) + { + iCountErrors++; + Console.WriteLine("Err_48088ahide! wrong value returned Expected={0} Actual={1}", 0, dequeuedValue); + } + + queClone.Enqueue(100); + + if ((int)(dequeuedValue = queClone.Dequeue()) != 1) + { + iCountErrors++; + Console.WriteLine("Err_51084aheid! wrong value returned Expected={0} Actual={1}", 1, dequeuedValue); + } + + //[] Our Clone implementation is not working because we are not copying the pointers - see bug 7447 + iCountTestcases++; + + que = new Queue(); + + for (int i = 0; i < 100; i++) + que.Enqueue(i); + + que.Dequeue(); + queClone = (Queue)que.Clone(); + if ((int)(dequeuedValue = queClone.Dequeue()) != 1) + { + iCountErrors++; + Console.WriteLine("Err_9347sfg! wrong value returned Expected={0} Actual={1}", 1, dequeuedValue); + } + + //[] Wrap the queue Dequeue then Enqueue + iCountTestcases++; + + que = new Queue(100); + + // Insert 50 items in the Queue + for (int i = 0; i < 50; i++) + { + que.Enqueue(i); + } + + // Insert and Remove 75 items in the Queue this should wrap the queue + // Where there is 25 at the end of the array and 25 at the begining + for (int i = 0; i < 75; i++) + { + que.Enqueue(i + 50); + que.Dequeue(); + } + + queClone = (Queue)que.Clone(); + + if (50 != queClone.Count) + { + iCountErrors++; + Console.WriteLine("Err_154488ahjeid! Count wrong value returned Expected={0} Actual={1}", 50, queClone.Count); + } + + if ((int)(dequeuedValue = queClone.Dequeue()) != 75) + { + iCountErrors++; + Console.WriteLine("Err_410848ajeid! wrong value returned Expected={0} Actual={1}", 50, dequeuedValue); + } + + // Add an item to the Queue + queClone.Enqueue(100); + + if (50 != queClone.Count) + { + iCountErrors++; + Console.WriteLine("Err_152180ajekd! Count wrong value returned Expected={0} Actual={1}", 50, queClone.Count); + } + + if ((int)(dequeuedValue = queClone.Dequeue()) != 76) + { + iCountErrors++; + Console.WriteLine("Err_5154ejhae! wrong value returned Expected={0} Actual={1}", 51, dequeuedValue); + } + + //[] Wrap the queue Enqueue then Dequeue + iCountTestcases++; + + que = new Queue(100); + + // Insert 50 items in the Queue + for (int i = 0; i < 50; i++) + { + que.Enqueue(i); + } + + // Insert and Remove 75 items in the Queue this should wrap the queue + // Where there is 25 at the end of the array and 25 at the begining + for (int i = 0; i < 75; i++) + { + que.Enqueue(i + 50); + que.Dequeue(); + } + + queClone = (Queue)que.Clone(); + + if (50 != queClone.Count) + { + iCountErrors++; + Console.WriteLine("Err_20845ajed! Count wrong value returned Expected={0} Actual={1}", 50, queClone.Count); + } + + // Add an item to the Queue + queClone.Enqueue(100); + + if ((int)(dequeuedValue = queClone.Dequeue()) != 75) + { + iCountErrors++; + Console.WriteLine("Err_15684ajed! wrong value returned Expected={0} Actual={1}", 50, dequeuedValue); + } + + // Add an item to the Queue + queClone.Enqueue(101); + + if (51 != queClone.Count) + { + iCountErrors++; + Console.WriteLine("Err_51588jhed! Count wrong value returned Expected={0} Actual={1}", 51, queClone.Count); + } + + if ((int)(dequeuedValue = queClone.Dequeue()) != 76) + { + iCountErrors++; + Console.WriteLine("Err_8089aied! wrong value returned Expected={0} Actual={1}", 51, dequeuedValue); + } + + //[]vanila with synchronized queue + iCountTestcases++; + + que = new Queue(); + + for (int i = 0; i < 100; i++) + que.Enqueue(i); + + queClone = (Queue)(Queue.Synchronized(que)).Clone(); + if (queClone.Count != 100) + { + iCountErrors++; + Console.WriteLine("Err_2072asfd! Expected Count=100 actual={0}", queClone.Count); + } + + if (!queClone.IsSynchronized) + { + iCountErrors++; + Console.WriteLine("Err_1723 Expected Synchronized queue"); + } + + for (int i = 0; i < 100; i++) + { + if (!queClone.Contains(i)) + { + iCountErrors++; + Console.WriteLine("Err_2721saas! wrong value returned"); + } + } + + /////////////////////////////////////////////////////////////////// + /////////////////////////// END TESTS ///////////////////////////// + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==" + exc_general.ToString()); + } + //// Finish Diagnostics + + if (iCountErrors == 0) + { + return true; + } + else + { + return false; + } + } + + + [Fact] + public static void ExecuteQueue_Clone() + { + bool bResult = false; + var test = new Queue_Clone(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } +} + + +class A +{ + private int _i; + public A(int i) + { + this._i = i; + } + internal Int32 I + { + set { _i = value; } + get { return _i; } + } +} diff --git a/src/System.Collections.NonGeneric/tests/Queue/Queue_Contains.cs b/src/System.Collections.NonGeneric/tests/Queue/Queue_Contains.cs new file mode 100644 index 000000000000..760f69a611fb --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Queue/Queue_Contains.cs @@ -0,0 +1,170 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using System.Globalization; +using Xunit; + +public class Queue_Contains +{ + public bool runTest() + { + //////////// Global Variables used for all tests + int iCountErrors = 0; + int iCountTestcases = 0; + + Queue que; + + try + { + ///////////////////////// START TESTS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + //[]vanila - Contains is a straight forward API + iCountTestcases++; + + que = new Queue(); + + for (int i = 0; i < 100; i++) + que.Enqueue(i); + + if (que.Count != 100) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned"); + } + + for (int i = 0; i < 100; i++) + { + if (!que.Contains(i)) + { + iCountErrors++; + Console.WriteLine("Err_93475sdg! wrong value returned"); + } + } + + //[]bogus value + iCountTestcases++; + if (que.Contains(150)) + { + iCountErrors++; + Console.WriteLine("Err_93475sdg! wrong value returned"); + } + + if (que.Contains("Hello World")) + { + iCountErrors++; + Console.WriteLine("Err_93475sdg! wrong value returned"); + } + + //[]null + iCountTestcases++; + if (que.Contains(null)) + { + iCountErrors++; + Console.WriteLine("Err_3276sfg! wrong value returned"); + } + + que.Enqueue(null); + if (!que.Contains(null)) + { + iCountErrors++; + Console.WriteLine("Err_9734sg! wrong value returned"); + } + + + //[]vanila - Contains is a straight forward API SYNCHRONIZED + iCountTestcases++; + + que = new Queue(); + que = Queue.Synchronized(que); + + for (int i = 0; i < 100; i++) + que.Enqueue(i); + + if (que.Count != 100) + { + iCountErrors++; + Console.WriteLine("Err_1168sada! wrong value returned"); + } + + for (int i = 0; i < 100; i++) + { + if (!que.Contains(i)) + { + iCountErrors++; + Console.WriteLine("Err_1659asd! wrong value returned"); + } + } + + //[]bogus value SYNCHRONIZED + iCountTestcases++; + if (que.Contains(150)) + { + iCountErrors++; + Console.WriteLine("Err_9798asdf! wrong value returned"); + } + + if (que.Contains("Hello World")) + { + iCountErrors++; + Console.WriteLine("Err_5648jhjj! wrong value returned"); + } + + //[]null SYNCHRONIZED + iCountTestcases++; + if (que.Contains(null)) + { + iCountErrors++; + Console.WriteLine("Err_64989hjkl! wrong value returned"); + } + + que.Enqueue(null); + if (!que.Contains(null)) + { + iCountErrors++; + Console.WriteLine("Err_9879jhjh! wrong value returned"); + } + /////////////////////////////////////////////////////////////////// + /////////////////////////// END TESTS ///////////////////////////// + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==" + exc_general.ToString()); + } + //// Finish Diagnostics + + if (iCountErrors == 0) + { + return true; + } + else + { + return false; + } + } + + + [Fact] + public static void ExecuteQueue_Contains() + { + bool bResult = false; + var test = new Queue_Contains(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } +} + + diff --git a/src/System.Collections.NonGeneric/tests/Queue/Queue_Dequeue.cs b/src/System.Collections.NonGeneric/tests/Queue/Queue_Dequeue.cs new file mode 100644 index 000000000000..6c453613265c --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Queue/Queue_Dequeue.cs @@ -0,0 +1,140 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using Xunit; + +public class Queue_Dequeue +{ + public virtual bool runTest() + { + // Local variables. + bool bPass = true; + int iCountTestcases = 0; + int iCountErrors = 0; + + //-------------------------------------------------------------------------- + // Variable definitions. + //-------------------------------------------------------------------------- + + Queue myQueue = null; + myQueue = new Queue(); + iCountTestcases++; + if (myQueue == null || myQueue.Count != 0) + { + iCountErrors++; + return false; + } + + // [] Enqueue and Dequeue and object. + for (int ii = 1; ii <= 1000; ++ii) + { + iCountTestcases++; + // Dequeue object onto queue. + myQueue.Enqueue((Int32)(ii)); + + // Dequeue object from stack. + Int32 myInt = (Int32)myQueue.Dequeue(); + if (myQueue.Count != 0 || (int)myInt != ii) + { + bPass = false; + iCountErrors++; + break; + } + } + + // Dequeue: Dequeue 1000 object / Dequeue and verify objects. + for (int ii = 1; ii <= 1000; ++ii) + myQueue.Enqueue((Int32)(ii)); + + iCountTestcases++; + // Verify that 1000 objects has been Dequeued. + if (myQueue.Count != 1000) + { + iCountErrors++; + bPass = false; + } + + // Dequeue and verify objects. + for (int ii = 1; ii <= 1000; ++ii) + { + iCountTestcases++; + Int32 myInt = (Int32)myQueue.Dequeue(); + if ((int)(myInt) != ii) + { + iCountErrors++; + bPass = false; + break; + } + } + + // [] Verify dequeue on an empty collection. + iCountTestcases++; + try + { + while (myQueue.Count != 0) + myQueue.Dequeue(); + + // Dequeue empty collection. should thrown InvalidOperationException + myQueue.Dequeue(); + iCountErrors++; + bPass = false; + } + catch (InvalidOperationException) + { } + catch (Exception ex) + { + Console.Error.Write(ex.ToString()); + Console.Error.WriteLine(" unexpected exception"); + iCountErrors++; + bPass = false; + } + + // + // Dequeue: Verify empty collection exception. + // + try + { + + while (myQueue.Count != 0) + myQueue.Dequeue(); + + iCountTestcases++; + myQueue.Dequeue(); + iCountErrors++; + bPass = false; + } + catch (InvalidOperationException) { } + catch (Exception ex) + { + bPass = false; + iCountErrors++; + Console.Error.Write(ex.ToString()); + Console.Error.WriteLine(" caught"); + } + + return bPass; + } + + + + [Fact] + public static void ExecuteQueue_Dequeue() + { + bool bResult = false; + var test = new Queue_Dequeue(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } +} diff --git a/src/System.Collections.NonGeneric/tests/Queue/Queue_Enqueue.cs b/src/System.Collections.NonGeneric/tests/Queue/Queue_Enqueue.cs new file mode 100644 index 000000000000..f608b17e5b20 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Queue/Queue_Enqueue.cs @@ -0,0 +1,96 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using Xunit; + +public class Queue_Enqueue +{ + + public virtual bool runTest() + { + // Local variables. + bool bPass = true; + int iCountErrors = 0; + int iCountTestcases = 0; + + //-------------------------------------------------------------------------- + // Variable definitions. + //-------------------------------------------------------------------------- + Queue myQueue = null; + + // + // [] Enqueue: Enqueue objects onto the queue. + // + myQueue = new Queue(); + iCountTestcases++; + if (myQueue == null || myQueue.Count != 0) + { + iCountErrors++; + return false; + } + + // Enqueue 1000 integers onto the queue. + for (int ii = 1; ii <= 1000; ++ii) + { + iCountTestcases++; + // Enqueue object on stack. + myQueue.Enqueue(ii); + + // Verify that item got Enqueueed. + if (myQueue.Count != ii) + { + bPass = false; + iCountErrors++; + break; + } + } + + // [] Verify that 1000 object are on the queue + iCountTestcases++; + if (myQueue.Count != 1000) + { + iCountErrors++; + bPass = false; + } + + // + // [] Enqueue: Enqueue null object into the stack. + // + iCountTestcases++; + try + { + // Attempt to enqueue null object. should work! + myQueue.Enqueue(null); + } + catch (Exception) + { + bPass = false; + iCountErrors++; + } + + return bPass; + } + + + [Fact] + public static void ExecuteQueue_Enqueue() + { + bool bResult = false; + var test = new Queue_Enqueue(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } + +} diff --git a/src/System.Collections.NonGeneric/tests/Queue/Queue_Peek.cs b/src/System.Collections.NonGeneric/tests/Queue/Queue_Peek.cs new file mode 100644 index 000000000000..bd4cc786ae9d --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Queue/Queue_Peek.cs @@ -0,0 +1,156 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Text; +using System; +using System.Collections; +using Xunit; + +public class Queue_Peek +{ + public virtual bool runTest() + { + int iCountErrors = 0; + int iCountTestcases = 0; + + //////// Testing Queue \ Peek() + + Queue myQueue = null; + String str1 = null; + String str2 = null; + Boolean mrBool; + byte mrByte = (byte)0; + Int16 mrInt2 = 0; + Int32 mrInt4 = 0; + Int64 mrInt8 = 0L; + Single mrSingle = (float)0.0; + Double mrDouble = (double)0.0; + Char mrChar = (Char)('\0'); + + // [] Should throw InvalidOperationException if Queue empty + myQueue = new Queue(); + iCountTestcases++; + try + { + myQueue.Peek(); + ++iCountErrors; + } + catch (InvalidOperationException) + { } + catch (Exception) + { + ++iCountErrors; + } + + // [] Inserting several object and checking them with peek + str1 = "test1"; + str2 = "test2"; + mrBool = (Boolean)(true); + mrByte = (byte)(127); + // mrByte = (Byte)(Byte.MaxValue); + mrInt2 = (Int16)(Int16.MaxValue); + mrInt4 = (Int32)(Int32.MaxValue); + mrInt8 = (Int64)(Int64.MinValue); + mrSingle = (Single)(Single.MaxValue); + mrDouble = (Double)(Double.MinValue); + + myQueue.Enqueue(str1); + myQueue.Enqueue(str2); + myQueue.Enqueue(mrBool); + myQueue.Enqueue(mrByte); + myQueue.Enqueue(mrInt2); + myQueue.Enqueue(mrInt4); + myQueue.Enqueue(mrInt8); + myQueue.Enqueue(mrSingle); + myQueue.Enqueue(mrDouble); + + iCountTestcases++; + if (!Object.ReferenceEquals(myQueue.Peek(), str1)) + { + iCountErrors++; + } + iCountTestcases++; + myQueue.Dequeue(); + if (!Object.ReferenceEquals(myQueue.Peek(), str2)) + { + iCountErrors++; + } + iCountTestcases++; + myQueue.Dequeue(); + if (Convert.ToBoolean(myQueue.Peek()) != mrBool) + { + iCountErrors++; + } + iCountTestcases++; + myQueue.Dequeue(); + if (Convert.ToByte(myQueue.Peek()) != mrByte) + { + iCountErrors++; + } + iCountTestcases++; + myQueue.Dequeue(); + if (Convert.ToInt16(myQueue.Peek()) != mrInt2) + { + iCountErrors++; + } + iCountTestcases++; + myQueue.Dequeue(); + if (Convert.ToInt32(myQueue.Peek()) != mrInt4) + { + iCountErrors++; + } + iCountTestcases++; + myQueue.Dequeue(); + if (Convert.ToInt64(myQueue.Peek()) != mrInt8) + { + iCountErrors++; + } + myQueue.Dequeue(); + iCountTestcases++; + if (Convert.ToSingle(myQueue.Peek()) != mrSingle) + { + iCountErrors++; + } + myQueue.Dequeue(); + iCountTestcases++; + if (Convert.ToDouble(myQueue.Peek()) != mrDouble) + { + iCountErrors++; + } + + myQueue.Enqueue(mrChar); + iCountTestcases++; + if (Convert.ToDouble(myQueue.Peek()) != mrDouble) + { + iCountErrors++; + } + myQueue.Dequeue(); + iCountTestcases++; + if (Convert.ToChar(myQueue.Dequeue()) != mrChar) + { + iCountTestcases++; + } + + return (iCountErrors == 0); + } + + + [Fact] + public static void ExecuteQueue_Peek() + { + bool bResult = false; + var test = new Queue_Peek(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } +} diff --git a/src/System.Collections.NonGeneric/tests/Queue/Queue_Synchronized.cs b/src/System.Collections.NonGeneric/tests/Queue/Queue_Synchronized.cs new file mode 100644 index 000000000000..8cce3ee76eac --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Queue/Queue_Synchronized.cs @@ -0,0 +1,456 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Threading; +using System.Collections; +using System.Threading.Tasks; +using Xunit; + +public class Queue_Synchronized +{ + public Queue m_Queue; + public Int32 iCountTestcases = 0; + public Int32 iCountErrors = 0; + public Int32 m_ThreadsToUse = 8; + public Int32 m_ThreadAge = 5; //5000; + + public Int32 m_ThreadCount; + + public void StartEnThread() + { + Int32 t_age = m_ThreadAge; + while (t_age > 0) + { // closer to dead + try + { + m_Queue.Enqueue(t_age); + iCountTestcases++; + } + catch (Exception e) + { + iCountErrors++; + Console.WriteLine("Err_EnThread : " + e.GetType().FullName); + } + Interlocked.Decrement(ref t_age); + } + Interlocked.Decrement(ref m_ThreadCount); + } + + + public void StartDeThread() + { + Int32 t_age = m_ThreadAge; + while (t_age > 0) + { // closer to dead + try + { + m_Queue.Dequeue(); + iCountTestcases++; + } + catch (Exception e) + { + iCountErrors++; + Console.WriteLine("Err_DeThread : " + e.GetType().FullName); + } + Interlocked.Decrement(ref t_age); + } + Interlocked.Decrement(ref m_ThreadCount); + } + + public void StartDeEnThread() + { + Int32 t_age = m_ThreadAge; + while (t_age > 0) + { // closer to dead + try + { + m_Queue.Dequeue(); + m_Queue.Enqueue("DeEn"); + iCountTestcases++; + } + catch (Exception e) + { + iCountErrors++; + Console.WriteLine("Err_DeEnThread : " + e.GetType().FullName); + } + Interlocked.Decrement(ref t_age); + } + Interlocked.Decrement(ref m_ThreadCount); + } + + public void StartEnDeThread() + { + Int32 t_age = m_ThreadAge; + while (t_age > 0) + { // closer to dead + try + { + m_Queue.Dequeue(); + m_Queue.Enqueue("EnDe"); + iCountTestcases++; + } + catch (Exception e) + { + iCountErrors++; + Console.WriteLine("Err_EnDeThread : " + e.GetType().FullName); + } + Interlocked.Decrement(ref t_age); + } + Interlocked.Decrement(ref m_ThreadCount); + } + + public Boolean runTest() + { + Queue q1; + Queue q2; + Queue q3; + Boolean fPass; + String[] strArr; + Object[] oArr; + IEnumerator ienm1; + Object oValue; + Int32 iCount; + + ///////////////////////////////////////////////////////////////////// + // Begin Testing run + ///////////////////////////////////////////////////////////////////// + + // Setup Queue Test + //[]Testing Method: Queue.Synchronized( Queue ) + try + { + // Exception Test Cases + String[] expectedExceptions = { + "System.ArgumentNullException", + }; + Queue[] errorValues = { + null, + }; + for (int i = 0; i < expectedExceptions.Length; i++) + { + iCountTestcases++; + try + { + Queue result = Queue.Synchronized(errorValues[i]); + iCountErrors++; + } + catch (Exception e) + { + if (!e.GetType().FullName.Equals(expectedExceptions[i])) + { + iCountErrors++; + Console.WriteLine(" Wrong Exception Thrown " + e.GetType().FullName); + } + } + } + } + catch (Exception e) + { + Console.WriteLine("Uncaught Exception in Queue Queue.Synchronized( Queue )"); + Console.WriteLine("Exception->" + e.GetType().FullName); + } + //////////////////////////////////////////////////////////////////////////////////////// + // Thread testing... + // Enqueue + m_Queue = new Queue(); + m_Queue = Queue.Synchronized(m_Queue); + + Task[] ths = new Task[m_ThreadsToUse]; + + try + { + for (int i = 0; i < m_ThreadsToUse; i++) + { + ths[i] = Task.Factory.StartNew(new Action(this.StartEnThread), TaskCreationOptions.LongRunning); + } + m_ThreadCount = m_ThreadsToUse; + Task.WaitAll(ths); + + Int32 expected = m_ThreadsToUse * m_ThreadAge; + Int32 result = m_Queue.Count; + + if (!expected.Equals(result)) + { + iCountErrors++; + Console.WriteLine("Err_ENQUEUE Race. Expected = " + expected + " Result = " + result); + } + } + catch (Exception e) + { + iCountErrors++; + Console.WriteLine("Err_THREAD threw " + e.GetType().FullName); + } + /////////////////// DeQueue + // Less Threads. + m_ThreadsToUse = (m_ThreadsToUse - 2); // now we can see differences better (2000 entry overhead) + + try + { + m_ThreadCount = m_ThreadsToUse; + for (int i = 0; i < m_ThreadsToUse; i++) + { + ths[i] = Task.Factory.StartNew(new Action(this.StartDeThread), TaskCreationOptions.LongRunning); + } + Task.WaitAll(ths); + + Int32 expected = 2 * m_ThreadAge; + Int32 result = m_Queue.Count; + + if (!expected.Equals(result)) + { + iCountErrors++; + Console.WriteLine("Err_DEQUEUE Race. Expected = " + expected + " Result = " + result); + } + } + catch (Exception e) + { + iCountErrors++; + Console.WriteLine("Err_THREAD threw " + e.GetType().FullName); + } + + /////////////////// Dequeue + Enqueue + // Less Threads. + m_ThreadsToUse = (m_ThreadsToUse + 2); // now we can see differences better (2000 entry overhead) + + try + { + m_ThreadCount = m_ThreadsToUse; + for (int i = 0; i < m_ThreadsToUse; i++) + { + ths[i] = Task.Factory.StartNew(new Action(this.StartDeEnThread), TaskCreationOptions.LongRunning); + } + Task.WaitAll(ths); + + Int32 expected = 2 * m_ThreadAge; + Int32 result = m_Queue.Count; + + if (!expected.Equals(result)) + { + iCountErrors++; + Console.WriteLine("Err_DEQUEUE Race. Expected = " + expected + " Result = " + result); + } + } + catch (Exception e) + { + iCountErrors++; + Console.WriteLine("Err_THREAD threw " + e.GetType().FullName); + } + + /////////////////// Enqueue + Dequeue + // Less Threads. + + try + { + m_ThreadCount = m_ThreadsToUse; + for (int i = 0; i < m_ThreadsToUse; i++) + { + ths[i] = Task.Factory.StartNew(new Action(this.StartEnDeThread), TaskCreationOptions.LongRunning); + } + Task.WaitAll(ths); + + Int32 expected = 2 * m_ThreadAge; + Int32 result = m_Queue.Count; + + if (!expected.Equals(result)) + { + iCountErrors++; + Console.WriteLine("Err_DEQUEUE Race. Expected = " + expected + " Result = " + result); + } + } + catch (Exception e) + { + iCountErrors++; + Console.WriteLine("Err_THREAD threw " + e.GetType().FullName); + } + + + //[] Synchronized returns a wrapper. We will test all the methods here!!! + + iCountTestcases++; + + fPass = true; + q1 = new Queue(); + for (int i = 0; i < 10; i++) + q1.Enqueue("String_" + i); + q2 = Queue.Synchronized(q1); + if (q2.Count != q1.Count) + fPass = false; + q2.Clear(); + if (q2.Count != 0) + fPass = false; + for (int i = 0; i < 10; i++) + q2.Enqueue("String_" + i); + + for (int i = 0; i < 10; i++) + { + if (!((String)q2.Peek()).Equals("String_" + i)) + { + Console.WriteLine(q2.Peek()); + fPass = false; + } + q2.Dequeue(); + } + + if (q2.Count != 0) + fPass = false; + + if (!q2.IsSynchronized) + fPass = false; + + for (int i = 0; i < 10; i++) + q2.Enqueue("String_" + i); + q3 = Queue.Synchronized(q2); + + if (!q3.IsSynchronized || (q2.Count != q3.Count)) + fPass = false; + + strArr = new String[10]; + q2.CopyTo(strArr, 0); + for (int i = 0; i < 10; i++) + { + if (!strArr[i].Equals("String_" + i)) + fPass = false; + } + + strArr = new String[10 + 10]; + q2.CopyTo(strArr, 10); + for (int i = 0; i < 10; i++) + { + if (!strArr[i + 10].Equals("String_" + i)) + fPass = false; + } + + try + { + q2.CopyTo(null, 0); + fPass = false; + } + catch (ArgumentNullException) + { + } + catch (Exception) + { + fPass = false; + } + + oArr = q2.ToArray(); + for (int i = 0; i < 10; i++) + { + if (!((String)oArr[i]).Equals("String_" + i)) + { + fPass = false; + } + } + + ienm1 = q2.GetEnumerator(); + try + { + oValue = ienm1.Current; + fPass = false; + } + catch (InvalidOperationException) + { + } + catch (Exception) + { + fPass = false; + } + + iCount = 0; + while (ienm1.MoveNext()) + { + if (!((String)ienm1.Current).Equals("String_" + iCount)) + { + fPass = false; + } + iCount++; + } + + ienm1.Reset(); + iCount = 0; + while (ienm1.MoveNext()) + { + if (!((String)ienm1.Current).Equals("String_" + iCount)) + { + fPass = false; + } + iCount++; + } + + + ienm1.Reset(); + q2.Dequeue(); + + try + { + oValue = ienm1.Current; + fPass = false; + } + catch (InvalidOperationException) + { + } + catch (Exception) + { + fPass = false; + } + + try + { + ienm1.MoveNext(); + fPass = false; + } + catch (InvalidOperationException) + { + } + catch (Exception) + { + fPass = false; + } + + try + { + ienm1.Reset(); + fPass = false; + } + catch (InvalidOperationException) + { + } + catch (Exception) + { + fPass = false; + } + + if (!fPass) + { + iCountErrors++; + Console.WriteLine("Unexpect result returned!"); + } + + ///////////////////////////////////////////////////////////////////// + // Diagnostics and reporting of results + ///////////////////////////////////////////////////////////////////// + return iCountErrors == 0; + } + + [Fact] + public static void ExecuteQueue_Synchronized() + { + bool bResult = false; + var test = new Queue_Synchronized(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } + + +} \ No newline at end of file diff --git a/src/System.Collections.NonGeneric/tests/Queue/Queue_ToArray.cs b/src/System.Collections.NonGeneric/tests/Queue/Queue_ToArray.cs new file mode 100644 index 000000000000..4031950899f4 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Queue/Queue_ToArray.cs @@ -0,0 +1,188 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Text; +using System; +using System.Collections; +using Xunit; + +public class Queue_ToArray +{ + public virtual bool runTest() + { + int iCountErrors = 0; + int iCountTestcases = 0; + + //////// Testing Queue \ Remove (Object obj) + Queue myQueue = null; + String str1 = null; + String str2 = null; + Boolean mrBool = false; + byte mrByte = Byte.MaxValue; + Int16 mrInt2 = -2; + Int32 mrInt4 = -2; + Int64 mrInt8 = -2; + Single mrSingle = -2; + Double mrDouble = -2; + Char mrChar = ' '; + Object[] @object = null; + + // [] Queue is empty + myQueue = new Queue(); + str1 = "test1"; + iCountTestcases++; + if (myQueue.ToArray().Length != 0) + { + iCountErrors++; + } + + // [] Insert several object and put them into an array without removing them from the Queue + str1 = "test1"; + str2 = "test2"; + mrBool = true; + mrByte = Byte.MaxValue; + mrInt2 = Int16.MaxValue; + mrInt4 = Int32.MaxValue; + mrInt8 = Int64.MinValue; + mrSingle = Single.MaxValue; + mrDouble = Double.MinValue; + mrChar = '\0'; + @object = new Object[10]; + + myQueue.Enqueue(str1); + myQueue.Enqueue(str2); + myQueue.Enqueue(mrBool); + myQueue.Enqueue(mrByte); + myQueue.Enqueue(mrInt2); + myQueue.Enqueue(mrInt4); + myQueue.Enqueue(mrInt8); + myQueue.Enqueue(mrSingle); + myQueue.Enqueue(mrDouble); + myQueue.Enqueue(mrChar); + + @object = myQueue.ToArray(); + iCountTestcases++; + if (myQueue.Count != 10) + { + iCountErrors++; + } + + iCountTestcases++; + if (@object.Length != 10) + { + iCountErrors++; + } + iCountTestcases++; + if (!Object.ReferenceEquals(@object[0], str1)) + { + iCountErrors++; + } + iCountTestcases++; + if (!Object.ReferenceEquals(@object[1], str2)) + { + iCountErrors++; + } + iCountTestcases++; + if ((Boolean)@object[2] != mrBool) + { + iCountErrors++; + } + iCountTestcases++; + if ((byte)@object[3] != mrByte) + { + iCountErrors++; + } + iCountTestcases++; + if ((Int16)@object[4] != mrInt2) + { + iCountErrors++; + } + iCountTestcases++; + if ((Int32)@object[5] != mrInt4) + { + iCountErrors++; + } + iCountTestcases++; + if ((Int64)@object[6] != mrInt8) + { + iCountErrors++; + } + iCountTestcases++; + if ((Single)@object[7] != mrSingle) + { + iCountErrors++; + } + iCountTestcases++; + if ((Double)@object[8] != mrDouble) + { + iCountErrors++; + } + iCountTestcases++; + if ((Char)@object[9] != mrChar) + { + iCountErrors++; + } + + // [] Insert several object, put them into an array and remove them from the Queue + + myQueue = new Queue(); + str1 = "test1"; + str2 = "test2"; + mrBool = true; + mrByte = Byte.MaxValue; + mrInt2 = Int16.MaxValue; + mrInt4 = Int32.MaxValue; + mrInt8 = Int64.MinValue; + mrSingle = Single.MaxValue; + mrDouble = Double.MinValue; + mrChar = '\0'; + @object = new Object[10]; + + myQueue.Enqueue(str1); + myQueue.Enqueue(str2); + myQueue.Enqueue(mrBool); + myQueue.Enqueue(mrByte); + myQueue.Enqueue(mrInt2); + myQueue.Enqueue(mrInt4); + myQueue.Enqueue(mrInt8); + myQueue.Enqueue(mrSingle); + myQueue.Enqueue(mrDouble); + myQueue.Enqueue(mrChar); + + @object = myQueue.ToArray(); + + iCountTestcases++; + if (@object.Length != 10) + { + iCountErrors++; + } + if (myQueue.Count != 10) + { + iCountErrors++; + } + + return iCountErrors == 0; + } + + [Fact] + public static void ExecuteQueue_ToArray() + { + bool bResult = false; + var test = new Queue_ToArray(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } + + + +} diff --git a/src/System.Collections.NonGeneric/tests/Queue/Queue_TrimToSize.cs b/src/System.Collections.NonGeneric/tests/Queue/Queue_TrimToSize.cs new file mode 100644 index 000000000000..279e82c64923 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Queue/Queue_TrimToSize.cs @@ -0,0 +1,344 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using System.Globalization; +using Xunit; + +public class Queue_TrimToSize +{ + public bool runTest() + { + //////////// Global Variables used for all tests + String strValue = String.Empty; + int iCountErrors = 0; + int iCountTestcases = 0; + + Queue que; + Object dequeuedValue; + + try + { + ///////////////////////// START TESTS //////////////////////////// + iCountTestcases++; + que = new Queue(); + + try + { + que.TrimToSize(); + } + catch (Exception) + { + iCountErrors++; + } + + que = new Queue(); + for (int i = 0; i < 1000; i++) + { + que.Enqueue(i); + } + + try + { + que.TrimToSize(); + } + catch (Exception) + { + iCountErrors++; + } + + que = new Queue(100000); + + try + { + que.TrimToSize(); + } + catch (Exception) + { + iCountErrors++; + } + + //[]Empty Queue + iCountTestcases++; + + que = new Queue(); + que.TrimToSize(); + + if (que.Count != 0) + { + iCountErrors++; + } + + que.Enqueue(100); + + if ((int)(dequeuedValue = que.Dequeue()) != 100) + { + iCountErrors++; + } + + //[]After Clear + iCountTestcases++; + + que = new Queue(); + + // Insert 50 items in the Queue + for (int i = 0; i < 100; i++) + { + que.Enqueue(i); + } + + que.Clear(); + que.TrimToSize(); + + if (que.Count != 0) + { + iCountErrors++; + } + + que.Enqueue(100); + if ((int)(dequeuedValue = que.Dequeue()) != 100) + { + iCountErrors++; + } + + //[]After Dequeue all items + iCountTestcases++; + + que = new Queue(); + + // Insert 50 items in the Queue + for (int i = 0; i < 100; i++) + { + que.Enqueue(i); + } + + for (int i = 0; i < 100; i++) + { + que.Dequeue(); + } + + que.TrimToSize(); + + if (que.Count != 0) + { + iCountErrors++; + } + + que.Enqueue(100); + + if ((int)(dequeuedValue = que.Dequeue()) != 100) + { + iCountErrors++; + } + + //[]TrimToSize then Dequeue then EnQueue + iCountTestcases++; + + que = new Queue(); + + // Insert 50 items in the Queue + for (int i = 0; i < 100; i++) + { + que.Enqueue(i); + } + + que.TrimToSize(); + + if (que.Count != 100) + { + iCountErrors++; + } + + if ((int)(dequeuedValue = que.Dequeue()) != 0) + { + iCountErrors++; + } + + que.Enqueue(100); + if ((int)(dequeuedValue = que.Dequeue()) != 1) + { + iCountErrors++; + Console.WriteLine("Err_51084aheid! wrong value returned Expected={0} Actual={1}", 1, dequeuedValue); + } + + //[] Wrap the queue then dequeue and enqueue + iCountTestcases++; + + que = new Queue(100); + + // Insert 50 items in the Queue + for (int i = 0; i < 50; i++) + { + que.Enqueue(i); + } + + // Insert and Remove 75 items in the Queue this should wrap the queue + // Where there is 25 at the end of the array and 25 at the begining + for (int i = 0; i < 75; i++) + { + que.Enqueue(i + 50); + que.Dequeue(); + } + + que.TrimToSize(); + + if (50 != que.Count) + { + iCountErrors++; + Console.WriteLine("Err_154488ahjeid! Count wrong value returned Expected={0} Actual={1}", 50, que.Count); + } + + if ((int)(dequeuedValue = que.Dequeue()) != 75) + { + iCountErrors++; + Console.WriteLine("Err_410848ajeid! wrong value returned Expected={0} Actual={1}", 50, dequeuedValue); + } + + // Add an item to the Queue + que.Enqueue(100); + + if (50 != que.Count) + { + iCountErrors++; + Console.WriteLine("Err_152180ajekd! Count wrong value returned Expected={0} Actual={1}", 50, que.Count); + } + + if ((int)(dequeuedValue = que.Dequeue()) != 76) + { + iCountErrors++; + Console.WriteLine("Err_5154ejhae! wrong value returned Expected={0} Actual={1}", 51, dequeuedValue); + } + + //[] Wrap the queue then enqueue and dequeue + iCountTestcases++; + + que = new Queue(100); + + // Insert 50 items in the Queue + for (int i = 0; i < 50; i++) + { + que.Enqueue(i); + } + + // Insert and Remove 75 items in the Queue this should wrap the queue + // Where there is 25 at the end of the array and 25 at the begining + for (int i = 0; i < 75; i++) + { + que.Enqueue(i + 50); + que.Dequeue(); + } + + que.TrimToSize(); + + if (50 != que.Count) + { + iCountErrors++; + Console.WriteLine("Err_15418ajioed! Count wrong value returned Expected={0} Actual={1}", 50, que.Count); + } + + // Add an item to the Queue + que.Enqueue(100); + + if ((int)(dequeuedValue = que.Dequeue()) != 75) + { + iCountErrors++; + Console.WriteLine("Err_211508ajoied! wrong value returned Expected={0} Actual={1}", 50, dequeuedValue); + } + + // Add an item to the Queue + que.Enqueue(101); + + if (51 != que.Count) + { + iCountErrors++; + Console.WriteLine("Err_4055ajeid! Count wrong value returned Expected={0} Actual={1}", 51, que.Count); + } + + if ((int)(dequeuedValue = que.Dequeue()) != 76) + { + iCountErrors++; + Console.WriteLine("Err_440815ajkejid! wrong value returned Expected={0} Actual={1}", 51, dequeuedValue); + } + + //[]vanila SYNCHRONIZED + + iCountTestcases++; + + que = new Queue(); + que = Queue.Synchronized(que); + + try + { + que.TrimToSize(); + } + catch (Exception ex) + { + iCountErrors++; + Console.WriteLine("Err_1689asdfa! unexpected exception thrown," + ex.GetType().Name); + } + + que = new Queue(); + que = Queue.Synchronized(que); + for (int i = 0; i < 1000; i++) + { + que.Enqueue(i); + } + + try + { + que.TrimToSize(); + } + catch (Exception ex) + { + iCountErrors++; + Console.WriteLine("Err_79446jhjk! unexpected exception thrown," + ex.GetType().Name); + } + + que = new Queue(100000); + que = Queue.Synchronized(que); + + try + { + que.TrimToSize(); + } + catch (Exception ex) + { + iCountErrors++; + Console.WriteLine("Err_4156hjkj! unexpected exception thrown," + ex.GetType().Name); + } + + /////////////////////////////////////////////////////////////////// + /////////////////////////// END TESTS ///////////////////////////// + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==" + exc_general.ToString()); + } + //// Finish Diagnostics + + return iCountErrors == 0; + } + + + [Fact] + public static void ExecuteQueue_TrimToSize() + { + bool bResult = false; + var test = new Queue_TrimToSize(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } +} + diff --git a/src/System.Collections.NonGeneric/tests/Queue/Queue_ctor.cs b/src/System.Collections.NonGeneric/tests/Queue/Queue_ctor.cs new file mode 100644 index 000000000000..fae722a80578 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Queue/Queue_ctor.cs @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Text; +using System; +using System.Collections; +using Xunit; + +public class Queue_ctor +{ + public virtual bool runTest() + { + int iCountErrors = 0; + int iCountTestcases = 0; + + Queue myQueue = null; + String str1 = null; + + // [] Constructor Queue using specified defaults + myQueue = new Queue(); + iCountTestcases++; + if (myQueue == null) + { + iCountErrors++; + print("E_839k"); + } + + // [] Check capacity increase + int defaultCap = 32; + myQueue = new Queue(); + str1 = "test"; + for (int i = 0; i <= defaultCap; i++) + { + myQueue.Enqueue(str1); + } + iCountTestcases++; + if (myQueue.Count != defaultCap + 1) + { + iCountErrors++; + print("E_34aj"); + } + + ///// Finish diagnostics and reporting of results. + return iCountErrors == 0; + } + + ////// Print helper method + private void print(String error) + { + StringBuilder output = new StringBuilder("POINTTOBREAK: find "); + output.Append(error); + output.Append(" (Queue_ctor.cs)"); + Console.Out.WriteLine(output.ToString()); + } + + + [Fact] + public static void ExecuteQueue_ctor() + { + bool bResult = false; + var test = new Queue_ctor(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } + +} diff --git a/src/System.Collections.NonGeneric/tests/Queue/Queue_ctor_int.cs b/src/System.Collections.NonGeneric/tests/Queue/Queue_ctor_int.cs new file mode 100644 index 000000000000..e2775b697b21 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Queue/Queue_ctor_int.cs @@ -0,0 +1,108 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Text; +using System; +using System.Collections; +using Xunit; + +public class Queue_ctor_int +{ + public virtual bool runTest() + { + int iCountErrors = 0; + int iCountTestcases = 0; + + //////// Testing Queue \ Queue(int capacity) + Queue myQueue = null; + String str1 = null; + int defaultCap = 32; + + // [] Constructor Queue using specified defaults + myQueue = new Queue(defaultCap); + iCountTestcases++; + if (myQueue == null) + { + iCountErrors++; + print("E_839k"); + } + + defaultCap = 0; + iCountTestcases++; + try + { + myQueue = new Queue(defaultCap); + } + catch (Exception exc) + { + iCountErrors++; + print("E_2jdd"); + Console.Error.WriteLine(exc); + } + + + // [] Check capacity increase + defaultCap = 32; + myQueue = new Queue(defaultCap); + str1 = "test"; + for (int i = 0; i <= defaultCap; i++) + { + myQueue.Enqueue(str1); + } + iCountTestcases++; + if (myQueue.Count != defaultCap + 1) + { + iCountErrors++; + print("E_34aj"); + } + + // [] Constructing Queue using invalid parameters + defaultCap = -1; + iCountTestcases++; + try + { + myQueue = new Queue(defaultCap); + iCountErrors++; + print("E_3jsd"); + } + catch (ArgumentException) { } + catch (Exception exc2) + { + iCountErrors++; + print("E_24ai"); + Console.Error.WriteLine(exc2); + } + + return iCountErrors == 0; + } + + + ////// Print helper method + private void print(String error) + { + StringBuilder output = new StringBuilder("POINTTOBREAK: find "); + output.Append(error); + output.Append(" (Queue_ctor_int.cs)"); + Console.Out.WriteLine(output.ToString()); + } + + + [Fact] + public static void ExecuteQueue_ctor_int() + { + bool bResult = false; + var test = new Queue_ctor_int(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } +} diff --git a/src/System.Collections.NonGeneric/tests/Queue/Queue_ctor_int_float.cs b/src/System.Collections.NonGeneric/tests/Queue/Queue_ctor_int_float.cs new file mode 100644 index 000000000000..e676d1bd9eb6 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Queue/Queue_ctor_int_float.cs @@ -0,0 +1,99 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using Xunit; + +public class Queue_ctor_int_float +{ + public virtual bool runTest() + { + // Local variables. + int iCountErrors = 0; + int iCountTestcases = 0; + + //-------------------------------------------------------------------------- + // Variable definitions. + //-------------------------------------------------------------------------- + Queue myQueue = null; + int nDefaultCapacity = 32; + float nDefaultGrowFactor = (float)2.0; + + // + // [] Construct queue using the specified defaults. + // + iCountTestcases++; + myQueue = new Queue(nDefaultCapacity, nDefaultGrowFactor); + if (myQueue == null) + { + iCountErrors++; + return false; + } + + // + // [] Construct queue using invalid parameters. + // + iCountTestcases++; + try + { + myQueue = new Queue(0, (float)0.0); + iCountErrors++; + } + catch (System.ArgumentException) + { + } + + iCountTestcases++; + try + { + myQueue = new Queue(-1, nDefaultGrowFactor); + iCountErrors++; + } + catch (System.ArgumentException) + { + } + iCountTestcases++; + try + { + myQueue = new Queue(nDefaultCapacity, (float)30.0); + iCountErrors++; + } + catch (System.ArgumentException) + { + } + iCountTestcases++; + try + { + myQueue = new Queue(nDefaultCapacity, (float)-30.0); + iCountErrors++; + } + catch (System.ArgumentException) + { + } + + return iCountErrors == 0; + } + + + [Fact] + public static void ExecuteQueue_ctor_int_float() + { + bool bResult = false; + var test = new Queue_ctor_int_float(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } + + +} diff --git a/src/System.Collections.NonGeneric/tests/Queue/Queue_get_Count.cs b/src/System.Collections.NonGeneric/tests/Queue/Queue_get_Count.cs new file mode 100644 index 000000000000..84cfd7307df8 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Queue/Queue_get_Count.cs @@ -0,0 +1,81 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using Xunit; + +public class Queue_get_Count +{ + public virtual bool runTest() + { + // Local variables. + int iCountErrors = 0; + int iCountTestcases = 0; + + //-------------------------------------------------------------------------- + // Variable definitions. + //-------------------------------------------------------------------------- + Queue myQueue = null; + int nDefaultCapacity = 32; + + // + // [] GetCount: Validate new Queue is empty. + + iCountTestcases++; + myQueue = new Queue(); + if (myQueue == null) + { + iCountErrors++; + return false; + } + + if (myQueue.Count != 0 || myQueue.Count != 0) + { + iCountErrors++; + } + + // [] GetCount: GetCount objects onto Queue and get size. + for (int ii = 0; ii < nDefaultCapacity; ++ii) + myQueue.Enqueue(ii); + + iCountTestcases++; + if (myQueue.Count == 0 || myQueue.Count != nDefaultCapacity) + { + iCountErrors++; + } + + // + // [] GetCount: Dequeue objects from Queue and get size. + // + iCountTestcases++; + for (int ii = 0; ii < nDefaultCapacity / 2; ++ii) + myQueue.Dequeue(); + + if (myQueue.Count == 0 || myQueue.Count != nDefaultCapacity / 2) + { + iCountErrors++; + } + + return iCountErrors == 0; + } + + [Fact] + public static void ExecuteQueue_get_Count() + { + bool bResult = false; + var test = new Queue_get_Count(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } +} diff --git a/src/System.Collections.NonGeneric/tests/Queue/Queue_get_SyncRoot.cs b/src/System.Collections.NonGeneric/tests/Queue/Queue_get_SyncRoot.cs new file mode 100644 index 000000000000..9f926d050a9e --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Queue/Queue_get_SyncRoot.cs @@ -0,0 +1,144 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Threading; +using System.Collections; +using System.Threading.Tasks; +using Xunit; + +public class Queue_get_SyncRoot +{ + private Queue _arrDaughter; + private Queue _arrGrandDaughter; + + private const Int32 iNumberOfElements = 100; + + public bool runTest() + { + //////////// Global Variables used for all tests + int iCountErrors = 0; + int iCountTestcases = 0; + + Queue arrSon; + Queue arrMother; + + Task[] workers; + Action ts1; + Action ts2; + Int32 iNumberOfWorkers = 1000; + + try + { + do + { + ///////////////////////// START TESTS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + arrMother = new Queue(); + for (int i = 0; i < iNumberOfElements; i++) + { + arrMother.Enqueue(i); + } + + if (arrMother.SyncRoot.GetType() != typeof(Object)) + { + iCountErrors++; + } + + arrSon = Queue.Synchronized(arrMother); + _arrGrandDaughter = Queue.Synchronized(arrSon); + _arrDaughter = Queue.Synchronized(arrMother); + + iCountTestcases++; + if (arrSon.SyncRoot != arrMother.SyncRoot) + { + iCountErrors++; + } + + iCountTestcases++; + if (arrSon.SyncRoot != arrMother.SyncRoot) + { + iCountErrors++; + } + + iCountTestcases++; + if (_arrGrandDaughter.SyncRoot != arrMother.SyncRoot) + { + iCountErrors++; + } + + iCountTestcases++; + if (_arrDaughter.SyncRoot != arrMother.SyncRoot) + { + iCountErrors++; + } + + iCountTestcases++; + if (arrSon.SyncRoot != arrMother.SyncRoot) + { + iCountErrors++; + } + + //we are going to rumble with the Queues with 2 threads + + workers = new Task[iNumberOfWorkers]; + ts1 = new Action(SortElements); + ts2 = new Action(ReverseElements); + for (int iThreads = 0; iThreads < iNumberOfWorkers; iThreads += 2) + { + workers[iThreads] = Task.Factory.StartNew(ts1, TaskCreationOptions.LongRunning); + workers[iThreads + 1] = Task.Factory.StartNew(ts2, TaskCreationOptions.LongRunning); + } + + Task.WaitAll(workers); + } while (false); + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString()); + } + + return iCountErrors == 0; + } + + + void SortElements() + { + _arrGrandDaughter.Clear(); + for (int i = 0; i < iNumberOfElements; i++) + { + _arrGrandDaughter.Enqueue(i); + } + } + + void ReverseElements() + { + _arrDaughter.Clear(); + for (int i = 0; i < iNumberOfElements; i++) + { + _arrDaughter.Enqueue(i); + } + } + + [Fact] + public static void ExecuteQueue_get_SyncRoot() + { + bool bResult = false; + var test = new Queue_get_SyncRoot(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } + +} \ No newline at end of file diff --git a/src/System.Collections.NonGeneric/tests/ReadOnlyCollectionBase/ReadOnlyCollectionBaseTests.cs b/src/System.Collections.NonGeneric/tests/ReadOnlyCollectionBase/ReadOnlyCollectionBaseTests.cs new file mode 100644 index 000000000000..d3dfe65dd7de --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/ReadOnlyCollectionBase/ReadOnlyCollectionBaseTests.cs @@ -0,0 +1,437 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Threading; +using System.Collections; +using Xunit; + +public class ReadOnlyCollectionBaseTests +{ + public bool runTest() + { + //////////// Global Variables used for all tests + int iCountErrors = 0; + int iCountTestcases = 0; + + MyReadOnlyCollectionBase mycol1; + MyReadOnlyCollectionBase mycol2; + Foo f1; + Foo[] arrF1; + Foo[] arrF2; + IEnumerator enu1; + Int32 iCount; + Object obj1; + ReadOnlyCollectionBase collectionBase; + + try + { + do + { + ///////////////////////// START TESTS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + //[]ReadOnlyCollectionBase implements IList (which means both ICollection and IEnumerator as well :-() + //To test this class, we will implement our own strongly typed ReadOnlyCollectionBase and call its methods + iCountTestcases++; + + //[] SyncRoot property + iCountTestcases++; + arrF1 = new Foo[100]; + for (int i = 0; i < 100; i++) + arrF1[i] = new Foo(); + mycol1 = new MyReadOnlyCollectionBase(arrF1); + + if (mycol1.SyncRoot is ArrayList) + { + iCountErrors++; + Console.WriteLine("Error SyncRoot returned ArrayList"); + } + + //[] Count property + iCountTestcases++; + arrF1 = new Foo[100]; + for (int i = 0; i < 100; i++) + arrF1[i] = new Foo(); + mycol1 = new MyReadOnlyCollectionBase(arrF1); + if (mycol1.Count != 100) + { + iCountErrors++; + Console.WriteLine("Error Expected value not returned, " + mycol1.Count); + } + + //[]CopyTo + iCountTestcases++; + arrF2 = new Foo[100]; + for (int i = 0; i < 100; i++) + arrF2[i] = new Foo(i, i.ToString()); + mycol1 = new MyReadOnlyCollectionBase(arrF2); + arrF1 = new Foo[100]; + mycol1.CopyTo(arrF1, 0); + for (int i = 0; i < 100; i++) + { + if ((arrF1[i].IValue != i) || (arrF1[i].SValue != i.ToString())) + { + iCountErrors++; + Console.WriteLine("Error #" + i + "! Expected value not returned"); + } + } + + //Argument checking + arrF2 = new Foo[100]; + for (int i = 0; i < 100; i++) + arrF2[i] = new Foo(i, i.ToString()); + mycol1 = new MyReadOnlyCollectionBase(arrF2); + arrF1 = new Foo[100]; + try + { + mycol1.CopyTo(arrF1, 50); + + iCountErrors++; + Console.WriteLine("Err_2075dfgv! Exception not thrown"); + } + catch (ArgumentException) + { + } + catch (Exception ex) + { + iCountErrors++; + Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); + } + + try + { + mycol1.CopyTo(arrF1, -1); + + iCountErrors++; + Console.WriteLine("Err_2075dfgv! Exception not thrown"); + } + catch (ArgumentException) + { + } + catch (Exception ex) + { + iCountErrors++; + Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); + } + + arrF1 = new Foo[200]; + mycol1.CopyTo(arrF1, 100); + for (int i = 0; i < 100; i++) + { + if ((arrF1[100 + i].IValue != i) || (arrF1[100 + i].SValue != i.ToString())) + { + iCountErrors++; + Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned"); + } + } + + //[]GetEnumerator + iCountTestcases++; + arrF2 = new Foo[100]; + for (int i = 0; i < 100; i++) + arrF2[i] = new Foo(i, i.ToString()); + mycol1 = new MyReadOnlyCollectionBase(arrF2); + + enu1 = mycol1.GetEnumerator(); + //Calling current should throw here + try + { + //Calling current should throw here + f1 = (Foo)enu1.Current; + + iCountErrors++; + Console.WriteLine("Err_87543! Exception not thrown"); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + Console.WriteLine("failure should throw InvalidOperationException, thrown, " + ex.GetType().Name); + } + + iCount = 0; + while (enu1.MoveNext()) + { + f1 = (Foo)enu1.Current; + if ((f1.IValue != iCount) || (f1.SValue != iCount.ToString())) + { + iCountErrors++; + Console.WriteLine("Err_87543! does not match, " + f1.IValue); + } + iCount++; + } + if (iCount != 100) + { + iCountErrors++; + Console.WriteLine("Err_87543! doesnot match"); + } + + //Calling current should throw here + try + { + //Calling current should throw here + f1 = (Foo)enu1.Current; + + iCountErrors++; + Console.WriteLine("Err_438fsfd! Exception not thrown"); + } + catch (InvalidOperationException) + { + } + catch (Exception ex) + { + Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); + } + + //[]IsSynchronized + iCountTestcases++; + arrF2 = new Foo[100]; + for (int i = 0; i < 100; i++) + arrF2[i] = new Foo(i, i.ToString()); + if (((ICollection)mycol1).IsSynchronized) + { + iCountErrors++; + Console.WriteLine("Err_275eg! Expected value not returned, " + ((ICollection)mycol1).IsSynchronized); + } + + //[]SyncRoot + iCountTestcases++; + arrF2 = new Foo[100]; + for (int i = 0; i < 100; i++) + arrF2[i] = new Foo(i, i.ToString()); + obj1 = mycol1.SyncRoot; + mycol2 = mycol1; + if (obj1 != mycol2.SyncRoot) + { + iCountErrors++; + Console.WriteLine("Err_9745sg! Expected value not returned"); + } + + //End of ICollection and IEnumerator methods + //Now to IList methods + //[]this, Contains, IndexOf + iCountTestcases++; + arrF2 = new Foo[100]; + for (int i = 0; i < 100; i++) + arrF2[i] = new Foo(i, i.ToString()); + mycol1 = new MyReadOnlyCollectionBase(arrF2); + for (int i = 0; i < 100; i++) + { + if ((mycol1[i].IValue != i) || (mycol1[i].SValue != i.ToString())) + { + iCountErrors++; + Console.WriteLine("Err_2974swsg_" + i + "! Expected value not returned"); + } + if ((mycol1.IndexOf(new Foo(i, i.ToString())) != i)) + { + iCountErrors++; + Console.WriteLine("Err_205sg_" + i + "! Expected value not returned"); + } + if ((!mycol1.Contains(new Foo(i, i.ToString())))) + { + iCountErrors++; + Console.WriteLine("Err_975wg_" + i + "! Expected value not returned"); + } + } + + //[]Rest of the IList methods: IsFixedSize, IsReadOnly + iCountTestcases++; + arrF2 = new Foo[100]; + for (int i = 0; i < 100; i++) + arrF2[i] = new Foo(i, i.ToString()); + mycol1 = new MyReadOnlyCollectionBase(arrF2); + if (!mycol1.IsFixedSize) + { + iCountErrors++; + Console.WriteLine("Err_9753sfg! Expected value not returned, " + mycol1.IsFixedSize); + } + if (!mycol1.IsReadOnly) + { + iCountErrors++; + Console.WriteLine("Err_834sg! Expected value not returned, " + mycol1.IsReadOnly); + } + + //The following operations are not allowed by the compiler. Hence, commented out + arrF2 = new Foo[100]; + for (int i = 0; i < 100; i++) + arrF2[i] = new Foo(i, i.ToString()); + mycol1 = new MyReadOnlyCollectionBase(arrF2); + + //[] Verify Count is virtual + iCountTestcases++; + collectionBase = new VirtualTestReadOnlyCollection(); + + if (collectionBase.Count != Int32.MinValue) + { + Console.WriteLine("Err_707272hapba Expected Count={0} actual={1}", Int32.MinValue, collectionBase.Count); + } + + //[] Verify Count is virtual + iCountTestcases++; + collectionBase = new VirtualTestReadOnlyCollection(); + + if (collectionBase.GetEnumerator() != null) + { + Console.WriteLine("Err_456548ahpba Expected GetEnumerator()=null actual={1}", null, collectionBase.GetEnumerator()); + } + + + /////////////////////////////////////////////////////////////////// + /////////////////////////// END TESTS ///////////////////////////// + } while (false); + + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine("Error Err_8888yyy! , exc_general==\n" + exc_general.ToString()); + } + + + Assert.Equal(0, iCountErrors); + + //// Finish Diagnostics + if (iCountErrors == 0) + { + Console.WriteLine("Passed: iCountTestcases==" + iCountTestcases); + return true; + } + else + { + Console.WriteLine("Failure! iCountErrors==" + iCountErrors); + return false; + } + + } + + + + [Fact] + public static void ExecuteReadOnlyCollectionBaseTests() + { + bool bResult = false; + var cbA = new ReadOnlyCollectionBaseTests(); + + try + { + bResult = cbA.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("FAiL! Error Err_9999zzz! Uncaught Exception in main(), exc_main==" + exc_main); + } + Assert.Equal(true, bResult); + } +} + +//ReadOnlyCollectionBase is provided to be used as the base class for strongly typed collections. Lets use one of our own here. +//This collection only allows the type Foo +public class MyReadOnlyCollectionBase : ReadOnlyCollectionBase +{ + //we need a way of initializing this collection + public MyReadOnlyCollectionBase(Foo[] values) + { + InnerList.AddRange(values); + } + + public Foo this[int indx] + { + get { return (Foo)InnerList[indx]; } + } + + public void CopyTo(Array array, Int32 index) + { + ((ICollection)this).CopyTo(array, index);// Use the base class explicit implemenation of ICollection.CopyTo + } + + public virtual Object SyncRoot + { + get + { + return ((ICollection)this).SyncRoot;// Use the base class explicit implemenation of ICollection.SyncRoot + } + } + + public Int32 IndexOf(Foo f) + { + return ((IList)InnerList).IndexOf(f); + } + + public Boolean Contains(Foo f) + { + return ((IList)InnerList).Contains(f); + } + + public Boolean IsFixedSize + { + get { return true; } + } + + public Boolean IsReadOnly + { + get { return true; } + } +} + +public class VirtualTestReadOnlyCollection : ReadOnlyCollectionBase +{ + public override int Count + { + get + { + return Int32.MinValue; + } + } + + public override IEnumerator GetEnumerator() + { + return null; + } +} + +public class Foo +{ + private Int32 _iValue; + private String _strValue; + + public Foo() + { + } + + public Foo(Int32 i, String str) + { + _iValue = i; + _strValue = str; + } + + public Int32 IValue + { + get { return _iValue; } + set { _iValue = value; } + } + + public String SValue + { + get { return _strValue; } + set { _strValue = value; } + } + + public override Boolean Equals(Object obj) + { + if (obj == null) + return false; + if (!(obj is Foo)) + return false; + if ((((Foo)obj).IValue == _iValue) && (((Foo)obj).SValue == _strValue)) + return true; + return false; + } + + public override Int32 GetHashCode() + { + return _iValue; + } +} diff --git a/src/System.Collections.NonGeneric/tests/Stack/StackBasicTests.cs b/src/System.Collections.NonGeneric/tests/Stack/StackBasicTests.cs new file mode 100644 index 000000000000..b630db9a9a0c --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Stack/StackBasicTests.cs @@ -0,0 +1,359 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using Xunit; + +public class StackBasicTests +{ + [Fact] + public static void EmptyStackSizeIsZero() + { + Stack stack = new Stack(); + Assert.Equal(stack.Count, 0); + } + + [Fact] + public static void DefaultStackIsNotSynchronized() + { + Stack stack = new Stack(); + Assert.False(stack.IsSynchronized); + } + + [Fact] + public static void NumberOfElementsAddedIsEqualToStackSize() + { + int iNumElementsAdded = 1975; + Stack stack = new Stack(); + + for (int i = 0; i < iNumElementsAdded; i++) + { + stack.Push(new Object()); + } + + Assert.Equal(stack.Count, iNumElementsAdded); + } + + [Fact] + public static void ClearResetsNumberOfElementsToZero() + { + int iNumElementsAdded = 2; + Stack stack = new Stack(); + + for (int i = 0; i < iNumElementsAdded; i++) + { + stack.Push(new Object()); + } + + stack.Clear(); + + Assert.Equal(stack.Count, 0); + } + + [Fact] + public static void PopDecrementsStackSize() + { + int iNumElementsAdded = 25; + Stack stack = new Stack(); + + for (int i = 0; i < iNumElementsAdded; i++) + { + stack.Push(i); + } + + for (int i = 0; i < iNumElementsAdded; i++) + { + Assert.Equal(stack.Count, iNumElementsAdded - i); + Object objTop = stack.Pop(); + Assert.Equal(stack.Count, iNumElementsAdded - i - 1); + } + } + + [Fact] + public static void PeekingEmptyStackThrows() + { + Stack stack = new Stack(); + Assert.Throws(() => { var x = stack.Peek(); }); + } + + [Fact] + public static void PeekingEmptyStackAfterRemovingElementsThrows() + { + object objRet; + Stack stack = new Stack(); + for (int i = 0; i < 1000; i++) + { + stack.Push(i); + } + + for (int i = 0; i < 1000; i++) + { + objRet = stack.Pop(); + } + + Assert.Throws(() => { objRet = stack.Peek(); }); + } + + [Fact] + public static void ICollectionCanBeGivenToStack() + { + int iNumElements = 10000; + + var objArr = new Object[iNumElements]; + for (int i = 0; i < iNumElements; i++) + { + objArr[i] = i; + } + + Stack stack = new Stack(objArr); + + for (int i = 0; i < iNumElements; i++) + { + var objRet = stack.Pop(); + Assert.True(objRet.Equals(iNumElements - i - 1)); + } + } + + [Fact] + public static void PeekingAtElementTwiceGivesSameResults() + { + Stack stack = new Stack(); + stack.Push(1); + Assert.True(stack.Peek().Equals(stack.Peek())); + } + + [Fact] + public static void PushAndPopWorkOnNullElements() + { + Stack stack = new Stack(); + stack.Push(null); + stack.Push(-1); + stack.Push(null); + + Assert.Equal(stack.Pop(), null); + Assert.True((-1).Equals(stack.Pop())); + Assert.Equal(stack.Pop(), null); + } + + [Fact] + public static void CopyingToNullArrayThrows() + { + Stack stack = new Stack(); + stack.Push("hey"); + Assert.Throws(() => stack.CopyTo(null, 0)); + } + + [Fact] + public static void CopyingToMultiDimArrayThrows() + { + Stack stack = new Stack(); + stack.Push("hey"); + Assert.Throws(() => stack.CopyTo(new Object[8, 8], 0)); + } + + [Fact] + public static void CopyingOutOfRangeThrows_1() + { + Stack stack = new Stack(); + var objArr = new Object[0]; + Assert.Throws(() => stack.CopyTo(objArr, 1)); + + stack = new Stack(); + Assert.Throws(() => stack.CopyTo(objArr, Int32.MaxValue)); + + stack = new Stack(); + Assert.Throws(() => stack.CopyTo(objArr, Int32.MinValue)); + + stack = new Stack(); + Assert.Throws(() => stack.CopyTo(objArr, -1)); + } + + [Fact] + public static void CopyingOutOfRangeThrows_2() + { + Stack stack = new Stack(); + stack.Push("MyString"); + + var objArr = new Object[0]; + + Assert.Throws(() => stack.CopyTo(objArr, 0)); + } + + [Fact] + public static void GettingEnumeratorAndLoopingThroughWorks() + { + Stack stack = new Stack(); + stack.Push("hey"); + stack.Push("hello"); + + IEnumerator ienum = stack.GetEnumerator(); + int iCounter = 0; + + while (ienum.MoveNext()) + { + iCounter++; + } + + Assert.Equal(iCounter, stack.Count); + } + + [Fact] + public static void GetBeforeStartingEnumerator() + { + // NOTE: The docs say this behaviour is undefined so if test fails it might be ok + Stack stack = new Stack(); + stack.Push("a"); + stack.Push("b"); + + IEnumerator ienum = stack.GetEnumerator(); + Assert.Throws(() => { Object obj = ienum.Current; }); + } + + [Fact] + public static void EnumeratingBeyondEndOfListThenGetObject() + { + Stack stack = new Stack(); + stack.Push(new Object()); + stack.Push(stack); + + IEnumerator ienum = stack.GetEnumerator(); + + Assert.True(ienum.MoveNext()); + + for (int i = 0; i < 100; i++) + { + Object objTemp1 = ienum.Current; + Assert.True(objTemp1.Equals(stack)); + } + + Assert.True(ienum.MoveNext()); + + for (int i = 0; i < 100; i++) + { + Assert.False(ienum.MoveNext()); + } + + Assert.Throws(() => { var o = ienum.Current; }); + } + + [Fact] + public static void PassingNegativeCapacityThrows() + { + Assert.Throws(() => { Stack stack = new Stack(Int32.MinValue); }); + } + + [Fact] + public static void CreatingStackWithZeroCapacityDoesntThrow() + { + Stack stack = new Stack(0); + } + + [Fact] + public static void PassingValidCapacityCreatesZeroElementsStack() + { + Stack stack = new Stack(1); + Assert.Equal(stack.Count, 0); + } + + [Fact] + public static void SynchronizedStacksIsSynchronizedPropertyReturnsTrue() + { + Stack stack = Stack.Synchronized(new Stack()); + Assert.True(stack.IsSynchronized); + } + + [Fact] + public static void SynchronizingNullStackThrows() + { + Assert.Throws(() => { Stack stack = Stack.Synchronized(null); }); + } + + [Fact] + public static void TestingAllMethodsOfSynchronizedStack() + { + Stack q1 = new Stack(); + for (int i = 0; i < 10; i++) + { + q1.Push("String_" + i); + } + + Stack q2 = Stack.Synchronized(q1); + Assert.Equal(q2.Count, q1.Count); + q2.Clear(); + Assert.Equal(q2.Count, 0); + for (int i = 0; i < 10; i++) + { + q2.Push("String_" + i); + } + + for (int i = 0, j = 9; i < 10; i++, j--) + { + Assert.True(((String)q2.Peek()).Equals("String_" + j)); + Assert.True(((String)q2.Pop()).Equals("String_" + j)); + } + + Assert.Equal(q2.Count, 0); + Assert.True(q2.IsSynchronized); + + for (int i = 0; i < 10; i++) + q2.Push("String_" + i); + Stack q3 = Stack.Synchronized(q2); + + Assert.True(q3.IsSynchronized); + Assert.Equal(q2.Count, q3.Count); + + var strArr = new String[10]; + q2.CopyTo(strArr, 0); + for (int i = 0, j = 9; i < 10; i++, j--) + { + Assert.True(strArr[i].Equals("String_" + j)); + } + + strArr = new String[10 + 10]; + q2.CopyTo(strArr, 10); + for (int i = 0, j = 9; i < 10; i++, j--) + { + Assert.True(strArr[i + 10].Equals("String_" + j)); + } + + Assert.Throws(() => q2.CopyTo(null, 0)); + + var oArr = q2.ToArray(); + for (int i = 0, j = 9; i < 10; i++, j--) + { + Assert.True(((String)oArr[i]).Equals("String_" + j)); + } + + var ienm1 = q2.GetEnumerator(); + Assert.Throws(() => { var oValue = ienm1.Current; }); + + var iCount = 9; + while (ienm1.MoveNext()) + { + Assert.True(((String)ienm1.Current).Equals("String_" + iCount)); + iCount--; + } + + ienm1.Reset(); + iCount = 9; + while (ienm1.MoveNext()) + { + Assert.True(((String)ienm1.Current).Equals("String_" + iCount)); + iCount--; + } + + ienm1.Reset(); + q2.Pop(); + + Assert.Throws(() => { var oValue = ienm1.Current; }); + Assert.Throws(() => ienm1.MoveNext()); + Assert.Throws(() => ienm1.Reset()); + } + + [Fact] + public static void PassingNullCollectionToConstructorThrows() + { + Assert.Throws(() => { Stack stack = new Stack(null); }); + } +} \ No newline at end of file diff --git a/src/System.Collections.NonGeneric/tests/Stack/Stack_Clone.cs b/src/System.Collections.NonGeneric/tests/Stack/Stack_Clone.cs new file mode 100644 index 000000000000..b24a78d97144 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Stack/Stack_Clone.cs @@ -0,0 +1,164 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using System.Globalization; +using Xunit; + +public class Stack_Clone +{ + public bool runTest() + { + //////////// Global Variables used for all tests + int iCountErrors = 0; + int iCountTestcases = 0; + + Stack stk; + Stack stkClone; + + A a1; + A a2; + + try + { + ///////////////////////// START TESTS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + //[]vanila + iCountTestcases++; + + stk = new Stack(); + + for (int i = 0; i < 100; i++) + stk.Push(i); + + stkClone = (Stack)stk.Clone(); + if (stkClone.Count != 100) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned"); + } + + for (int i = 0; i < 100; i++) + { + if (!stkClone.Contains(i)) + { + iCountErrors++; + Console.WriteLine("Err_93475sdg! wrong value returned"); + } + } + + //[]making sure that this is shallow + iCountTestcases++; + + stk = new Stack(); + + stk.Push(new A(10)); + + stkClone = (Stack)stk.Clone(); + if (stkClone.Count != 1) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned"); + } + + a1 = (A)stk.Pop(); + a1.I = 50; + + if (stkClone.Count != 1) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned"); + } + + a2 = (A)stkClone.Pop(); + + if (a2.I != 50) + { + iCountErrors++; + Console.WriteLine("Err_93745sdg! wrong value returned, " + a2.I); + } + + //[]vanila with synchronized stack + iCountTestcases++; + + stk = new Stack(); + + for (int i = 0; i < 100; i++) + stk.Push(i); + + stkClone = (Stack)(Stack.Synchronized(stk)).Clone(); + if (stkClone.Count != 100) + { + iCountErrors++; + Console.WriteLine("Err_2072asfd! Expected Count=100 actual={0}", stkClone.Count); + } + + if (!stkClone.IsSynchronized) + { + iCountErrors++; + Console.WriteLine("Err_1723 Expected Synchronized Stack"); + } + + for (int i = 0; i < 100; i++) + { + if (!stkClone.Contains(i)) + { + iCountErrors++; + Console.WriteLine("Err_2721saas! wrong value returned"); + } + } + /////////////////////////////////////////////////////////////////// + /////////////////////////// END TESTS ///////////////////////////// + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==" + exc_general.ToString()); + } + //// Finish Diagnostics + + if (iCountErrors == 0) + { + return true; + } + else + { + return false; + } + } + + [Fact] + public static void ExecuteStack_Clone() + { + bool bResult = false; + var test = new Stack_Clone(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } +} + +class A +{ + private int _i; + public A(int i) + { + this._i = i; + } + internal Int32 I + { + set { _i = value; } + get { return _i; } + } +} diff --git a/src/System.Collections.NonGeneric/tests/Stack/Stack_Contains_obj.cs b/src/System.Collections.NonGeneric/tests/Stack/Stack_Contains_obj.cs new file mode 100644 index 000000000000..87413793e227 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Stack/Stack_Contains_obj.cs @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Collections; +using Xunit; + +public static class Stack_Contains_obj +{ + [Fact] + public static void ContainsStraightForwardTests() + { + Stack stk = new Stack(); + + for (int i = 0; i < 100; i++) + { + stk.Push(i); + } + + Assert.Equal(stk.Count, 100); + + for (int i = 0; i < 100; i++) + { + Assert.True(stk.Contains(i)); + } + + Assert.False(stk.Contains(150)); + Assert.False(stk.Contains("Hello World")); + Assert.False(stk.Contains(null)); + + stk.Push(null); + Assert.True(stk.Contains(null)); + } + + [Fact] + public static void ContainsStraightForwardApiSynchronizedTests() + { + Stack stk = new Stack(); + stk = Stack.Synchronized(stk); + + for (int i = 0; i < 100; i++) + { + stk.Push(i); + } + + Assert.Equal(stk.Count, 100); + + for (int i = 0; i < 100; i++) + { + Assert.True(stk.Contains(i)); + } + + Assert.False(stk.Contains(150)); + Assert.False(stk.Contains("Hello World")); + Assert.False(stk.Contains(null)); + + stk.Push(null); + Assert.True(stk.Contains(null)); + } +} diff --git a/src/System.Collections.NonGeneric/tests/Stack/Stack_ToArray.cs b/src/System.Collections.NonGeneric/tests/Stack/Stack_ToArray.cs new file mode 100644 index 000000000000..a43596af0eb2 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Stack/Stack_ToArray.cs @@ -0,0 +1,98 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Threading; +using System.Collections; +using Xunit; + +public class Stack_ToArray +{ + public bool runTest() + { + //////////// Global Variables used for all tests + int iCountErrors = 0; + int iCountTestcases = 0; + + Stack stk1; + Object[] oArr; + Int32 iNumberOfElements; + String strValue; + + try + { + do + { + ///////////////////////// START TESTS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + //[] Vanila test case - this gives an object array of the values in the stack + stk1 = new Stack(); + oArr = stk1.ToArray(); + + iCountTestcases++; + if (oArr.Length != 0) + { + iCountErrors++; + Console.WriteLine("Err_752dsg! Expected value not returned, " + oArr.Length); + } + + iNumberOfElements = 10; + for (int i = 0; i < iNumberOfElements; i++) + stk1.Push(i); + + oArr = stk1.ToArray(); + Array.Sort(oArr); + + iCountTestcases++; + for (int i = 0; i < oArr.Length; i++) + { + strValue = "Value_" + i; + if ((Int32)oArr[i] != i) + { + iCountErrors++; + Console.WriteLine("Err_7423fg! Expected value not returned, " + (Int32)oArr[i]); + } + } + /////////////////////////////////////////////////////////////////// + /////////////////////////// END TESTS ///////////////////////////// + } while (false); + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString()); + } + + //// Finish Diagnostics + + if (iCountErrors == 0) + { + return true; + } + else + { + return false; + } + } + + [Fact] + public static void ExecuteStack_ToArray() + { + bool bResult = false; + var test = new Stack_ToArray(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } +} + diff --git a/src/System.Collections.NonGeneric/tests/Stack/Stack_get_SyncRoot.cs b/src/System.Collections.NonGeneric/tests/Stack/Stack_get_SyncRoot.cs new file mode 100644 index 000000000000..f002ead26ede --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/Stack/Stack_get_SyncRoot.cs @@ -0,0 +1,163 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections; +using System.Threading.Tasks; +using Xunit; + +public class Stack_get_SyncRoot +{ + private Stack _arrDaughter; + private Stack _arrGrandDaughter; + + private const Int32 iNumberOfElements = 100; + + public bool runTest() + { + //////////// Global Variables used for all tests + int iCountErrors = 0; + int iCountTestcases = 0; + + Stack arrSon; + Stack arrMother; + + Int32 iNumberOfWorkers = 1000; + + try + { + do + { + ///////////////////////// START TESTS //////////////////////////// + /////////////////////////////////////////////////////////////////// + + //[] Vanila test case - testing SyncRoot is not as simple as its implementation looks like. This is the working + //scenrio we have in mind. + //1) Create your Down to earth mother Stack + //2) Get a Fixed wrapper from it + //3) Get a Synchronized wrapper from 2) + //4) Get a synchronized wrapper of the mother from 1) + //5) all of these should SyncRoot to the mother earth + + arrMother = new Stack(); + for (int i = 0; i < iNumberOfElements; i++) + { + arrMother.Push(i); + } + + if (arrMother.SyncRoot.GetType() != typeof(Object)) + { + iCountErrors++; + Console.WriteLine("Err_47235fsd! Expected SyncRoot to be an object actual={0}", arrMother.SyncRoot.GetType()); + } + + arrSon = Stack.Synchronized(arrMother); + _arrGrandDaughter = Stack.Synchronized(arrSon); + _arrDaughter = Stack.Synchronized(arrMother); + + iCountTestcases++; + if (arrSon.SyncRoot != arrMother.SyncRoot) + { + iCountErrors++; + Console.WriteLine("Err_234dnvf! Expected value not returned, " + (arrSon.SyncRoot == arrMother.SyncRoot)); + } + + iCountTestcases++; + if (arrSon.SyncRoot != arrMother.SyncRoot) + { + iCountErrors++; + Console.WriteLine("Err_8753bdd! Expected value not returned, " + (arrSon.SyncRoot == arrMother)); + } + + iCountTestcases++; + if (_arrGrandDaughter.SyncRoot != arrMother.SyncRoot) + { + iCountErrors++; + Console.WriteLine("Err_4927fd0fd! Expected value not returned, " + (_arrGrandDaughter.SyncRoot == arrMother)); + } + + iCountTestcases++; + if (_arrDaughter.SyncRoot != arrMother.SyncRoot) + { + iCountErrors++; + Console.WriteLine("Err_85390gfg! Expected value not returned, " + (_arrDaughter.SyncRoot == arrMother)); + } + + iCountTestcases++; + if (arrSon.SyncRoot != arrMother.SyncRoot) + { + iCountErrors++; + Console.WriteLine("Err_234dnvf! Expected value not returned, " + (arrSon.SyncRoot == arrMother.SyncRoot)); + } + + //we are going to rumble with the Stacks with 2 threads + var ts1 = new Action(SortElements); + var ts2 = new Action(ReverseElements); + Task[] tasks = new Task[iNumberOfWorkers]; + for (int iThreads = 0; iThreads < iNumberOfWorkers; iThreads += 2) + { + tasks[iThreads] = Task.Factory.StartNew(ts1, TaskCreationOptions.LongRunning); + tasks[iThreads + 1] = Task.Factory.StartNew(ts2, TaskCreationOptions.LongRunning); + } + Task.WaitAll(tasks); + + /////////////////////////////////////////////////////////////////// + /////////////////////////// END TESTS ///////////////////////////// + } while (false); + } + catch (Exception exc_general) + { + ++iCountErrors; + Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString()); + } + + //// Finish Diagnostics + + if (iCountErrors == 0) + { + return true; + } + else + { + return false; + } + } + + void SortElements() + { + _arrGrandDaughter.Clear(); + for (int i = 0; i < iNumberOfElements; i++) + { + _arrGrandDaughter.Push(i); + } + } + + void ReverseElements() + { + _arrDaughter.Clear(); + for (int i = 0; i < iNumberOfElements; i++) + { + _arrDaughter.Push(i); + } + } + + [Fact] + public static void ExecuteStack_get_SyncRoot() + { + bool bResult = false; + var test = new Stack_get_SyncRoot(); + + try + { + bResult = test.runTest(); + } + catch (Exception exc_main) + { + bResult = false; + Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main); + } + + Assert.Equal(true, bResult); + } + +} \ No newline at end of file diff --git a/src/System.Collections.NonGeneric/tests/System.Collections.NonGeneric.Tests.csproj b/src/System.Collections.NonGeneric/tests/System.Collections.NonGeneric.Tests.csproj new file mode 100644 index 000000000000..aa6e885b7117 --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/System.Collections.NonGeneric.Tests.csproj @@ -0,0 +1,57 @@ + + + + + Debug + AnyCPU + Library + System.Collections.NonGeneric.Tests + System.Collections.NonGeneric.Tests + {EE95AE39-845A-42D3-86D0-8065DBE56612} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + System.Collections.NonGeneric + + + + + + + \ No newline at end of file diff --git a/src/System.Collections.NonGeneric/tests/packages.config b/src/System.Collections.NonGeneric/tests/packages.config new file mode 100644 index 000000000000..e79a2aeae2fd --- /dev/null +++ b/src/System.Collections.NonGeneric/tests/packages.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file