Skip to content

Commit f2dee12

Browse files
committed
Merge pull request dotnet#407 from joshfree/master
Initial commit of tests for System.Collections.NonGeneric
2 parents 8763c76 + d7f54bd commit f2dee12

38 files changed

+9369
-0
lines changed

src/System.Collections.NonGeneric.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 12.0.31101.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Collections.NonGeneric", "System.Collections.NonGeneric\src\System.Collections.NonGeneric.csproj", "{585E3764-534B-4A12-8BD5-8578CB826A45}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Collections.NonGeneric.Tests", "System.Collections.NonGeneric\tests\System.Collections.NonGeneric.Tests.csproj", "{D857AA4D-7D23-4EAF-8367-C548604F587F}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
1517
{585E3764-534B-4A12-8BD5-8578CB826A45}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{585E3764-534B-4A12-8BD5-8578CB826A45}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{585E3764-534B-4A12-8BD5-8578CB826A45}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{D857AA4D-7D23-4EAF-8367-C548604F587F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{D857AA4D-7D23-4EAF-8367-C548604F587F}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{D857AA4D-7D23-4EAF-8367-C548604F587F}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{D857AA4D-7D23-4EAF-8367-C548604F587F}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Collections;
6+
using System.Globalization;
7+
using Xunit;
8+
9+
public class CaseInsensitiveComparer_CultureInfo
10+
{
11+
12+
public bool runTest()
13+
{
14+
//////////// Global Variables used for all tests
15+
int iCountErrors = 0;
16+
int iCountTestcases = 0;
17+
18+
CaseInsensitiveComparer comparer;
19+
20+
try
21+
{
22+
///////////////////////// START TESTS ////////////////////////////
23+
///////////////////////////////////////////////////////////////////
24+
25+
//[]vanila - the ctor simply sets the ComapreInfo to the current culture - CultureInfo.CurrentCulture.CompareInfo
26+
//There is no easy way to test this other than make sure that string comparison is case insenstive
27+
28+
iCountTestcases++;
29+
iCountTestcases++;
30+
iCountTestcases++;
31+
32+
var somePopularCultureNames = new string[] {
33+
"cs-CZ","da-DK","de-DE","el-GR","en-US",
34+
"es-ES","fi-FI","fr-FR","hu-HU","it-IT",
35+
"ja-JP","ko-KR","nb-NO","nl-NL","pl-PL",
36+
"pt-BR","pt-PT","ru-RU","sv-SE","tr-TR",
37+
"zh-CN","zh-HK","zh-TW" };
38+
foreach (string cultureName in somePopularCultureNames)
39+
{
40+
CultureInfo culture = new CultureInfo(cultureName);
41+
if (culture == null)
42+
{
43+
continue;
44+
}
45+
comparer = new CaseInsensitiveComparer(culture);
46+
47+
if (comparer.Compare("hello", "HELLO") != 0)
48+
{
49+
iCountErrors++;
50+
Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>, Culture: {2}", 0, comparer.Compare("hello", "HELLO"), culture.Name);
51+
}
52+
53+
//same strings should work ok
54+
if (comparer.Compare("hello", "hello") != 0)
55+
{
56+
iCountErrors++;
57+
Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>, Culture: {2}", 0, comparer.Compare("hello", "hello"), culture.Name);
58+
}
59+
60+
//different strings should return false
61+
if (comparer.Compare("hello", "mello") == 0)
62+
{
63+
iCountErrors++;
64+
Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>, Culture: {2}", "non-zero", comparer.Compare("hello", "mello"), culture.Name);
65+
}
66+
67+
// "tr-TR" = "Turkish (Turkey)"
68+
// 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).
69+
if (culture.Name != "tr-TR")
70+
{
71+
if (comparer.Compare("file", "FILE") != 0)
72+
{
73+
iCountErrors++;
74+
Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>, Culture: {2}", 0, comparer.Compare("file", "FILE"), culture.Name);
75+
}
76+
}
77+
else
78+
{
79+
if (comparer.Compare("file", "FILE") == 0)
80+
{
81+
iCountErrors++;
82+
Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>, Culture: {2}", "non-zero", comparer.Compare("file", "FILE"), culture.Name);
83+
}
84+
}
85+
86+
//[]Other data types should work as is
87+
iCountTestcases++;
88+
if (comparer.Compare(5, 5) != 0)
89+
{
90+
iCountErrors++;
91+
Console.WriteLine("Err_347tsfg! wrong value returned");
92+
}
93+
94+
if (comparer.Compare(5, 10) == 0)
95+
{
96+
iCountErrors++;
97+
Console.WriteLine("Err_973425sdg! wrong value returned");
98+
}
99+
}
100+
101+
//[]parm test
102+
iCountTestcases++;
103+
try
104+
{
105+
106+
107+
comparer = new CaseInsensitiveComparer(null);
108+
109+
iCountErrors++;
110+
Console.WriteLine("Err_9745sdg! Exception not thrown");
111+
}
112+
catch (ArgumentNullException)
113+
{
114+
}
115+
catch (Exception ex)
116+
{
117+
iCountErrors++;
118+
Console.WriteLine("Err_9745sdg! Unexpected exception thrown, " + ex.GetType().Name);
119+
}
120+
///////////////////////////////////////////////////////////////////
121+
/////////////////////////// END TESTS /////////////////////////////
122+
}
123+
catch (Exception exc_general)
124+
{
125+
++iCountErrors;
126+
Console.WriteLine(" : Error Err_8888yyy! exc_general==" + exc_general.ToString());
127+
}
128+
//// Finish Diagnostics
129+
130+
if (iCountErrors == 0)
131+
{
132+
return true;
133+
}
134+
else
135+
{
136+
return false;
137+
}
138+
}
139+
140+
141+
142+
[Fact]
143+
public static void ExecuteCaseInsensitiveComparer_CultureInfo()
144+
{
145+
bool bResult = false;
146+
var test = new CaseInsensitiveComparer_CultureInfo();
147+
148+
try
149+
{
150+
bResult = test.runTest();
151+
}
152+
catch (Exception exc_main)
153+
{
154+
bResult = false;
155+
Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main);
156+
}
157+
158+
Assert.Equal(true, bResult);
159+
}}
160+
161+
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Threading;
6+
using System.Collections;
7+
using System.Globalization;
8+
using Xunit;
9+
10+
public class CaseInsensitiveComparer_Default
11+
{
12+
public bool runTest()
13+
{
14+
//////////// Global Variables used for all tests
15+
int iCountErrors = 0;
16+
int iCountTestcases = 0;
17+
18+
CaseInsensitiveComparer comparer;
19+
CaseInsensitiveComparer defaultComparer;
20+
21+
try
22+
{
23+
///////////////////////// START TESTS ////////////////////////////
24+
///////////////////////////////////////////////////////////////////
25+
26+
//[]vanila - Default sets the ComapreInfo to the current culture - CultureInfo.CurrentCulture.CompareInfo
27+
//There is no easy way to test this other than make sure that string comparison is case insenstive
28+
29+
iCountTestcases++;
30+
iCountTestcases++;
31+
32+
var somePopularCultureNames = new string[] {
33+
"cs-CZ","da-DK","de-DE","el-GR","en-US",
34+
"es-ES","fi-FI","fr-FR","hu-HU","it-IT",
35+
"ja-JP","ko-KR","nb-NO","nl-NL","pl-PL",
36+
"pt-BR","pt-PT","ru-RU","sv-SE","tr-TR",
37+
"zh-CN","zh-HK","zh-TW" };
38+
foreach (string cultureName in somePopularCultureNames)
39+
{
40+
CultureInfo culture = new CultureInfo(cultureName);
41+
if (culture == null)
42+
{
43+
continue;
44+
}
45+
comparer = new CaseInsensitiveComparer(culture);
46+
defaultComparer = CaseInsensitiveComparer.Default;
47+
48+
if (defaultComparer.Compare("hello", "HELLO") != 0)
49+
{
50+
iCountErrors++;
51+
Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultComparer.Compare("hello", "HELLO"));
52+
}
53+
54+
//same strings should work ok
55+
if (defaultComparer.Compare("hello", "hello") != 0)
56+
{
57+
iCountErrors++;
58+
Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultComparer.Compare("hello", "hello"));
59+
}
60+
61+
//different strings should return false
62+
if (defaultComparer.Compare("hello", "mello") == 0)
63+
{
64+
iCountErrors++;
65+
Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultComparer.Compare("hello", "mello"));
66+
}
67+
68+
//What would turkey do? - Since we are comparing with the default culture, unless this is run on a turkish machine, this will pass
69+
if (CultureInfo.CurrentCulture.Name != "tr-TR")
70+
{
71+
if (defaultComparer.Compare("file", "FILE") != 0)
72+
{
73+
iCountErrors++;
74+
Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultComparer.Compare("file", "FILE"));
75+
}
76+
}
77+
else
78+
{
79+
if (defaultComparer.Compare("file", "FILE") == 0)
80+
{
81+
iCountErrors++;
82+
Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultComparer.Compare("file", "FILE"));
83+
}
84+
}
85+
86+
//[]Other data types should work as is
87+
iCountTestcases++;
88+
if (defaultComparer.Compare(5, 5) != 0)
89+
{
90+
iCountErrors++;
91+
Console.WriteLine("Err_347tsfg! wrong value returned");
92+
}
93+
94+
if (defaultComparer.Compare(5, 10) == 0)
95+
{
96+
iCountErrors++;
97+
Console.WriteLine("Err_973425sdg! wrong value returned");
98+
}
99+
}
100+
101+
///////////////////////////////////////////////////////////////////
102+
/////////////////////////// END TESTS /////////////////////////////
103+
}
104+
catch (Exception exc_general)
105+
{
106+
++iCountErrors;
107+
Console.WriteLine(" : Error Err_8888yyy! exc_general==" + exc_general.ToString());
108+
}
109+
//// Finish Diagnostics
110+
111+
if (iCountErrors == 0)
112+
{
113+
return true;
114+
}
115+
else
116+
{
117+
return false;
118+
}
119+
}
120+
121+
122+
123+
[Fact]
124+
public static void ExecuteCaseInsensitiveComparer_Default()
125+
{
126+
bool bResult = false;
127+
var test = new CaseInsensitiveComparer_Default();
128+
129+
try
130+
{
131+
bResult = test.runTest();
132+
}
133+
catch (Exception exc_main)
134+
{
135+
bResult = false;
136+
Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main);
137+
}
138+
139+
Assert.Equal(true, bResult);
140+
}
141+
}

0 commit comments

Comments
 (0)