diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2016-11-23 19:09:09 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2016-11-23 19:09:09 +0900 |
commit | 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (patch) | |
tree | 98110734c91668dfdbb126fcc0e15ddbd93738ca /tests/src/CoreMangLib/cti/system/globalization/compareinfo | |
parent | fa45f57ed55137c75ac870356a1b8f76c84b229c (diff) | |
download | coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.gz coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.bz2 coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.zip |
Imported Upstream version 1.1.0upstream/1.1.0
Diffstat (limited to 'tests/src/CoreMangLib/cti/system/globalization/compareinfo')
4 files changed, 493 insertions, 0 deletions
diff --git a/tests/src/CoreMangLib/cti/system/globalization/compareinfo/CompareInfoCompare2.csproj b/tests/src/CoreMangLib/cti/system/globalization/compareinfo/CompareInfoCompare2.csproj new file mode 100644 index 0000000000..4f954662f2 --- /dev/null +++ b/tests/src/CoreMangLib/cti/system/globalization/compareinfo/CompareInfoCompare2.csproj @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + <ReferenceLocalMscorlib>false</ReferenceLocalMscorlib> + <CLRTestKind>BuildAndRun</CLRTestKind> + <CLRTestPriority>1</CLRTestPriority> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + </PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <ItemGroup> + <!-- Add Compile Object Here --> + <Compile Include="compareinfocompare2.cs" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="../../../../../Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" /> + <ProjectReference Include="../../../../../Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project>
\ No newline at end of file diff --git a/tests/src/CoreMangLib/cti/system/globalization/compareinfo/CompareInfoIndexOf2.csproj b/tests/src/CoreMangLib/cti/system/globalization/compareinfo/CompareInfoIndexOf2.csproj new file mode 100644 index 0000000000..e0e2211392 --- /dev/null +++ b/tests/src/CoreMangLib/cti/system/globalization/compareinfo/CompareInfoIndexOf2.csproj @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + <ReferenceLocalMscorlib>false</ReferenceLocalMscorlib> + <CLRTestKind>BuildAndRun</CLRTestKind> + <CLRTestPriority>1</CLRTestPriority> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + </PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <ItemGroup> + <!-- Add Compile Object Here --> + <Compile Include="compareinfoindexof2.cs" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="../../../../../Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" /> + <ProjectReference Include="../../../../../Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project>
\ No newline at end of file diff --git a/tests/src/CoreMangLib/cti/system/globalization/compareinfo/compareinfocompare2.cs b/tests/src/CoreMangLib/cti/system/globalization/compareinfo/compareinfocompare2.cs new file mode 100644 index 0000000000..f8c05e97b8 --- /dev/null +++ b/tests/src/CoreMangLib/cti/system/globalization/compareinfo/compareinfocompare2.cs @@ -0,0 +1,218 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +using System; +using System.Text; +using System.Globalization; +using TestLibrary; + +public class CompareInfoCompare +{ + public static string[] InterestingStrings = new string[] { null, "", "a", "1", "-", "A", "!", "abc", "aBc", "a\u0400Bc", "I", "i", "\u0130", "\u0131", "A", "\uFF21", "\uFE57"}; + + public bool RunTests() + { + bool retVal = true; + + TestLibrary.TestFramework.LogInformation("[Positive]"); + retVal = PosTest1() && retVal; + retVal = PosTest2() && retVal; + retVal = PosTest3() && retVal; + retVal = PosTest4() && retVal; + return retVal; + } + + + public bool PosTest1() + { + bool retVal = true; + + TestLibrary.TestFramework.BeginScenario("PosTest1: Compare interesting strings ordinally"); + + try + { + foreach (string s in InterestingStrings) + { + foreach (string r in InterestingStrings) + { + retVal &= TestStrings(s, r); + } + } + + } + catch (Exception e) + { + TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e); + retVal = false; + } + return retVal; + } + + public bool PosTest2() + { + bool retVal = true; + + TestLibrary.TestFramework.BeginScenario("PosTest2: Compare many characters"); + + try + { + for (int i = 0; i < 40; i++) // Ok, 40 isn't that many... but this takes way too long + { + char c = Generator.GetChar(-55); + if (Utilities.CurrentCulture.CompareInfo.Compare(new string(new char[] { c }), new string(new char[] { c }), CompareOptions.Ordinal) != 0) + { + TestLibrary.TestFramework.LogError("002.1", "Character " + i.ToString() + " is not equal to itself ordinally!"); + retVal = false; + } + + for (int j = 0; j < (int)c; j++) + { + int compareResult = Utilities.CurrentCulture.CompareInfo.Compare(new string(new char[] { c }), new string(new char[] { (char)j }), CompareOptions.Ordinal); + if (compareResult != 0) compareResult = compareResult / Math.Abs(compareResult); + if (compareResult != 1) + { + TestLibrary.TestFramework.LogError("002.2", "Character " + ((int)c).ToString() + " is not greater than character " + j.ToString() + ", Compare result: " + compareResult.ToString()); + retVal = false; + } + } + } + } + catch (Exception e) + { + TestLibrary.TestFramework.LogError("002.4", "Unexpected exception: " + e); + retVal = false; + } + return retVal; + } + + public bool PosTest3() + { + bool retVal = true; + + TestLibrary.TestFramework.BeginScenario("PosTest3: Compare many strings"); + + try + { + for (int i = 0; i < 1000; i++) + { + string str1 = Generator.GetString(-55, false, 5, 20); + string str2 = Generator.GetString(-55, false, 5, 20); + if (Utilities.CurrentCulture.CompareInfo.Compare(str1, str1, CompareOptions.Ordinal) != 0) + { + TestLibrary.TestFramework.LogError("003.1", "Comparison not as expected! Acutal result: " + Utilities.CurrentCulture.CompareInfo.Compare(str1, str1, CompareOptions.Ordinal).ToString() + ", Expected result: 0"); + TestLibrary.TestFramework.LogInformation("String 1: <" + str1 + "> : " + BytesFromString(str1) + "\nString 2: <" + str1 + "> : " + BytesFromString(str1)); + retVal = false; + } + if (Utilities.CurrentCulture.CompareInfo.Compare(str2, str2, CompareOptions.Ordinal) != 0) + { + TestLibrary.TestFramework.LogError("003.2", "Comparison not as expected! Acutal result: " + Utilities.CurrentCulture.CompareInfo.Compare(str2, str2, CompareOptions.Ordinal).ToString() + ", Expected result: 0"); + TestLibrary.TestFramework.LogInformation("String 1: <" + str2 + "> : " + BytesFromString(str2) + "\nString 2: <" + str2 + "> : " + BytesFromString(str2)); + retVal = false; + } + TestStrings(str1, str2); + } + } + catch (Exception e) + { + TestLibrary.TestFramework.LogError("003.4", "Unexpected exception: " + e); + retVal = false; + } + return retVal; + } + + public bool PosTest4() + { + bool retVal = true; + + TestLibrary.TestFramework.BeginScenario("PosTest4: Specific regression cases"); + + try + { + CultureInfo oldCi = Utilities.CurrentCulture; + Utilities.CurrentCulture = new CultureInfo("hu-HU"); + retVal &= TestStrings("dzsdzs", "ddzs"); + Utilities.CurrentCulture = oldCi; + + retVal &= TestStrings("\u00C0nimal", "A\u0300nimal"); + + } + catch (Exception e) + { + TestLibrary.TestFramework.LogError("004.2", "Unexpected exception: " + e); + retVal = false; + } + return retVal; + } + + public static int Main() + { + CompareInfoCompare test = new CompareInfoCompare(); + + TestLibrary.TestFramework.BeginTestCase("CompareInfoCompare"); + + if (test.RunTests()) + { + TestLibrary.TestFramework.EndTestCase(); + TestLibrary.TestFramework.LogInformation("PASS"); + return 100; + } + else + { + TestLibrary.TestFramework.EndTestCase(); + TestLibrary.TestFramework.LogInformation("FAIL"); + return 0; + } + } + + private bool TestStrings(string str1, string str2) + { + bool retVal = true; + + int expectValue = PredictValue(str1, str2); + int actualValue = Utilities.CurrentCulture.CompareInfo.Compare(str1, str2, CompareOptions.Ordinal); + if (expectValue != 0) expectValue = expectValue / Math.Abs(expectValue); + if (actualValue != 0) actualValue = actualValue / Math.Abs(actualValue); + + if (actualValue != expectValue) + { + TestLibrary.TestFramework.LogError("001.1", "Comparison not as expected! Acutal result: " + actualValue + ", Expected result: " + expectValue); + TestLibrary.TestFramework.LogInformation("String 1: <" + str1 + "> : " + BytesFromString(str1) + "\nString 2: <" + str2 + "> : " + BytesFromString(str2)); + retVal = false; + } + + return retVal; + } + + int PredictValue(string str1, string str2) + { + if (str1 == null) + { + if (str2 == null) return 0; + else return -1; + } + if (str2 == null) return 1; + + for (int i = 0; i < str1.Length; i++) + { + if (i >= str2.Length) return 1; + if ((int)str1[i] > (int)str2[i]) return 1; + if ((int)str1[i] < (int)str2[i]) return -1; + } + + if (str2.Length > str1.Length) return -1; + + return 0; + } + + private static string BytesFromString(string str) + { + if (str == null) return string.Empty; + StringBuilder output = new StringBuilder(); + for (int i = 0; i < str.Length; i++) + { + output.Append(Utilities.ByteArrayToString(BitConverter.GetBytes(str[i]))); + if (i != (str.Length - 1)) output.Append(", "); + } + return output.ToString(); + } +} diff --git a/tests/src/CoreMangLib/cti/system/globalization/compareinfo/compareinfoindexof2.cs b/tests/src/CoreMangLib/cti/system/globalization/compareinfo/compareinfoindexof2.cs new file mode 100644 index 0000000000..4a653b8bc9 --- /dev/null +++ b/tests/src/CoreMangLib/cti/system/globalization/compareinfo/compareinfoindexof2.cs @@ -0,0 +1,185 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +using System; +using System.Text; +using System.Globalization; +using TestLibrary; + +public class CompareInfoIndexOf +{ + public static string[] InterestingStrings = new string[] { "", "a", "1", "-", "A", "!", "abc", "aBc", "a\u0400Bc", "I", "i", "\u0130", "\u0131", "A", "\uFF21", "\uFE57"}; + + public bool RunTests() + { + bool retVal = true; + + TestLibrary.TestFramework.LogInformation("[Positive]"); + retVal = PosTest1() && retVal; + retVal = PosTest2() && retVal; + retVal = PosTest3() && retVal; + return retVal; + } + + + public bool PosTest1() + { + bool retVal = true; + + TestLibrary.TestFramework.BeginScenario("PosTest1: Compare interesting strings ordinally"); + + try + { + foreach (string s in InterestingStrings) + { + foreach (string r in InterestingStrings) + { + retVal &= TestStrings(s, r); + } + } + + } + catch (Exception e) + { + TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e); + retVal = false; + } + return retVal; + } + + public bool PosTest2() + { + bool retVal = true; + + TestLibrary.TestFramework.BeginScenario("PosTest2: Compare many strings"); + + try + { + for (int i = 0; i < 1000; i++) + { + string str1 = Generator.GetString(-55, false, 5, 20); + string str2 = Generator.GetString(-55, false, 5, 20); + if (Utilities.CurrentCulture.CompareInfo.IndexOf(str1, str1, CompareOptions.Ordinal) != 0) + { + TestLibrary.TestFramework.LogError("003.1", "Comparison not as expected! Actual result: " + Utilities.CurrentCulture.CompareInfo.IndexOf(str1, str1, CompareOptions.Ordinal).ToString() + ", Expected result: 0"); + TestLibrary.TestFramework.LogInformation("String 1: <" + str1 + "> : " + BytesFromString(str1) + "\nString 2: <" + str1 + "> : " + BytesFromString(str1)); + retVal = false; + } + if (Utilities.CurrentCulture.CompareInfo.IndexOf(str2, str2, CompareOptions.Ordinal) != 0) + { + TestLibrary.TestFramework.LogError("003.2", "Comparison not as expected! Actual result: " + Utilities.CurrentCulture.CompareInfo.IndexOf(str2, str2, CompareOptions.Ordinal).ToString() + ", Expected result: 0"); + TestLibrary.TestFramework.LogInformation("String 1: <" + str2 + "> : " + BytesFromString(str2) + "\nString 2: <" + str2 + "> : " + BytesFromString(str2)); + retVal = false; + } + TestStrings(str1, str2); + TestStrings(str1 + str2, str2); + } + } + catch (Exception e) + { + TestLibrary.TestFramework.LogError("003.4", "Unexpected exception: " + e); + retVal = false; + } + return retVal; + } + + public bool PosTest3() + { + bool retVal = true; + + TestLibrary.TestFramework.BeginScenario("PosTest3: Specific regression cases"); + + try + { + CultureInfo oldCi = Utilities.CurrentCulture; + Utilities.CurrentCulture = new CultureInfo("hu-HU"); + retVal &= TestStrings("Foodzsdzsbar", "ddzs"); + Utilities.CurrentCulture = oldCi; + + retVal &= TestStrings("\u00C0nimal", "A\u0300"); + + } + catch (Exception e) + { + TestLibrary.TestFramework.LogError("004.2", "Unexpected exception: " + e); + retVal = false; + } + return retVal; + } + + public static int Main() + { + CompareInfoIndexOf test = new CompareInfoIndexOf(); + + TestLibrary.TestFramework.BeginTestCase("CompareInfoIndexOf"); + + if (test.RunTests()) + { + TestLibrary.TestFramework.EndTestCase(); + TestLibrary.TestFramework.LogInformation("PASS"); + return 100; + } + else + { + TestLibrary.TestFramework.EndTestCase(); + TestLibrary.TestFramework.LogInformation("FAIL"); + return 0; + } + } + + private bool TestStrings(string str1, string str2) + { + bool retVal = true; + + int expectValue = PredictValue(str1, str2); + int actualValue = Utilities.CurrentCulture.CompareInfo.IndexOf(str1, str2, CompareOptions.Ordinal); + + if (actualValue != expectValue) + { + TestLibrary.TestFramework.LogError("001.1", "Comparison not as expected! Actual result: " + actualValue + ", Expected result: " + expectValue); + TestLibrary.TestFramework.LogInformation("String 1: <" + str1 + "> : " + BytesFromString(str1) + "\nString 2: <" + str2 + "> : " + BytesFromString(str2)); + retVal = false; + } + + return retVal; + } + + int PredictValue(string str1, string str2) + { + if (str1 == null) + { + if (str2 == null) return 0; + else return -1; + } + if (str2 == null) return -1; + + if (str2.Length > str1.Length) return -1; + + for (int i = 0; i <= str1.Length - str2.Length; i++) + { + bool match = true; + for (int j = 0; j < str2.Length; j++) + { + if ((int)str1[i + j] != (int)str2[j]) + { + match = false; + break; + } + } + if (match) return i; + } + return -1; + } + + private static string BytesFromString(string str) + { + if (str == null) return string.Empty; + StringBuilder output = new StringBuilder(); + for (int i = 0; i < str.Length; i++) + { + output.Append(Utilities.ByteArrayToString(BitConverter.GetBytes(str[i]))); + if (i != (str.Length - 1)) output.Append(", "); + } + return output.ToString(); + } +} |