public void Ctor_CultureInfo_GetHashCodeCompare_TurkishI() { var cultureNames = Helpers.TestCultureNames; foreach (string cultureName in cultureNames) { CultureInfo culture; try { culture = new CultureInfo(cultureName); } catch (CultureNotFoundException) { continue; } var provider = new CaseInsensitiveHashCodeProvider(culture); // 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. Assert.Equal( culture.Name != "tr-TR", provider.GetHashCode("file") == provider.GetHashCode("FILE")); } }
public void Ctor_CultureInfo_GetHashCodeCompare_TurkishI() { var cultureNames = 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 cultureNames) { CultureInfo culture; try { culture = new CultureInfo(cultureName); } catch (CultureNotFoundException) { continue; } var provider = new CaseInsensitiveHashCodeProvider(culture); // 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. Assert.Equal( culture.Name != "tr-TR", provider.GetHashCode("file") == provider.GetHashCode("FILE")); } }
public void SerializationRoundtrip() { CaseInsensitiveHashCodeProvider enus = new CaseInsensitiveHashCodeProvider(new CultureInfo("en-US")); BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); bf.Serialize(ms, enus); ms.Position = 0; CaseInsensitiveHashCodeProvider clone = (CaseInsensitiveHashCodeProvider)bf.Deserialize(ms); Assert.AreEqual(enus.GetHashCode(String.Empty), clone.GetHashCode(String.Empty), "GetHashCode(string)"); Assert.AreEqual(enus.GetHashCode(Int32.MinValue), clone.GetHashCode(Int32.MinValue), "GetHashCode(int)"); }
public void HashCode() { CaseInsensitiveHashCodeProvider cih = new CaseInsensitiveHashCodeProvider(); int h1 = cih.GetHashCode("Test String"); int h2 = cih.GetHashCode("test string"); int h3 = cih.GetHashCode("TEST STRING"); Assert.IsTrue(h1 == h2, "Mixed Case != lower case"); Assert.IsTrue(h1 == h3, "Mixed Case != UPPER CASE"); h1 = cih.GetHashCode("one"); h2 = cih.GetHashCode("another"); // Actually this is quite possible. Assert.IsFalse(h1 == h2); }
public void DefaultInvariant() { CaseInsensitiveHashCodeProvider cih = new CaseInsensitiveHashCodeProvider( CultureInfo.InvariantCulture); int h1 = cih.GetHashCode("Test String"); cih = CaseInsensitiveHashCodeProvider.DefaultInvariant; int h2 = cih.GetHashCode("Test String"); Assert.AreEqual(h1, h2, "#1"); CaseInsensitiveHashCodeProvider cih1 = CaseInsensitiveHashCodeProvider.DefaultInvariant; CaseInsensitiveHashCodeProvider cih2 = CaseInsensitiveHashCodeProvider.DefaultInvariant; Assert.IsTrue(object.ReferenceEquals(cih1, cih2)); }
public void Default() { CaseInsensitiveHashCodeProvider cih = new CaseInsensitiveHashCodeProvider( CultureInfo.CurrentCulture); int h1 = cih.GetHashCode("Test String"); cih = CaseInsensitiveHashCodeProvider.Default; int h2 = cih.GetHashCode("Test String"); Assert.AreEqual(h1, h2, "#1"); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); CaseInsensitiveHashCodeProvider cih1 = CaseInsensitiveHashCodeProvider.Default; Thread.CurrentThread.CurrentCulture = new CultureInfo("nl-BE"); CaseInsensitiveHashCodeProvider cih2 = CaseInsensitiveHashCodeProvider.Default; Assert.IsFalse(object.ReferenceEquals(cih1, cih2), "#2"); }
public void Ctor_Empty_ChangeCurrentCulture_GetHashCodeCompare(object a, object b, bool expected) { var cultureNames = Helpers.TestCultureNames; foreach (string cultureName in cultureNames) { CultureInfo newCulture; try { newCulture = new CultureInfo(cultureName); } catch (CultureNotFoundException) { continue; } using (new ThreadCultureChange(newCulture)) { var provider = new CaseInsensitiveHashCodeProvider(); Assert.Equal(provider.GetHashCode(a), provider.GetHashCode(a)); Assert.Equal(provider.GetHashCode(b), provider.GetHashCode(b)); Assert.Equal(expected, provider.GetHashCode(a) == provider.GetHashCode(b)); } } }
public void Ctor_CultureInfo_ChangeCurrentCulture_GetHashCodeCompare(object a, object b, bool expected) { var cultureNames = 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 cultureNames) { CultureInfo culture; try { culture = new CultureInfo(cultureName); } catch (CultureNotFoundException) { continue; } var provider = new CaseInsensitiveHashCodeProvider(culture); Assert.Equal(provider.GetHashCode(a), provider.GetHashCode(a)); Assert.Equal(provider.GetHashCode(b), provider.GetHashCode(b)); Assert.Equal(expected, provider.GetHashCode(a) == provider.GetHashCode(b)); } }
public static void Ctor_Empty_GetHashCodeCompare(object a, object b, bool expected) { var provider = new CaseInsensitiveHashCodeProvider(); Assert.Equal(provider.GetHashCode(a), provider.GetHashCode(a)); Assert.Equal(provider.GetHashCode(b), provider.GetHashCode(b)); Assert.Equal(expected, provider.GetHashCode(a) == provider.GetHashCode(b)); }
public void Ctor_Empty_GetHashCodeCompare(object a, object b, bool expected) { var provider = new CaseInsensitiveHashCodeProvider(); Assert.Equal(provider.GetHashCode(a), provider.GetHashCode(a)); Assert.Equal(provider.GetHashCode(b), provider.GetHashCode(b)); Assert.Equal(expected, provider.GetHashCode(a) == provider.GetHashCode(b)); }
// We need a HashCodeProvider for Case, Kana and Width insensitive internal Int32 GetSpecialHashCode(string name) { int i = 0; for (i = 0; i < name.Length; i++) { if (name[i] >= 0x3000) { break; } } if (i >= name.Length) { return(hashCodeProvider.GetHashCode(name)); } else { return(0); } }
public static void Ctor_Empty_ChangeCurrentCulture_GetHashCodeCompare(object a, object b, bool expected) { var cultureNames = 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 cultureNames) { CultureInfo newCulture; try { newCulture = new CultureInfo(cultureName); } catch (CultureNotFoundException) { continue; } CultureInfo origCulture = CultureInfo.CurrentCulture; try { CultureInfo.CurrentCulture = newCulture; var provider = new CaseInsensitiveHashCodeProvider(); Assert.Equal(provider.GetHashCode(a), provider.GetHashCode(a)); Assert.Equal(provider.GetHashCode(b), provider.GetHashCode(b)); Assert.Equal(expected, provider.GetHashCode(a) == provider.GetHashCode(b)); } finally { CultureInfo.CurrentCulture = origCulture; } } }
public void Ctor_Empty_ChangeCurrentCulture_GetHashCodeCompare(object a, object b, bool expected) { RemoteExecutorForUap.Invoke((ra, rb, rexpected) => { var cultureNames = 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" }; bool.TryParse(rexpected, out bool expectedResult); foreach (string cultureName in cultureNames) { CultureInfo newCulture; try { newCulture = new CultureInfo(cultureName); } catch (CultureNotFoundException) { continue; } using (new ThreadCultureChange(newCulture)) { var provider = new CaseInsensitiveHashCodeProvider(); Assert.Equal(provider.GetHashCode(ra), provider.GetHashCode(ra)); Assert.Equal(provider.GetHashCode(rb), provider.GetHashCode(rb)); Assert.Equal(expectedResult, provider.GetHashCode(ra) == provider.GetHashCode(rb)); } } }, a.ToString(), b.ToString(), expected.ToString()).Dispose(); }
private void SerializeObject(object objectToSerialize, object parent, string elementName, BinaryWriter writer) { if (objectToSerialize == null) { return; } if (parent != null) { PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(parent)[elementName]; if (propertyDescriptor != null) { SerializationVisibilityAttribute serializationVisibilityAttribute = (SerializationVisibilityAttribute)propertyDescriptor.Attributes[typeof(SerializationVisibilityAttribute)]; if (serializationVisibilityAttribute != null && serializationVisibilityAttribute.Visibility == SerializationVisibility.Hidden) { return; } } } if (objectToSerialize is ICollection) { SerializeCollection(objectToSerialize, elementName, writer); return; } writer.Write((short)hashCodeProvider.GetHashCode(elementName)); long num = writer.Seek(0, SeekOrigin.Current); ArrayList arrayList = new ArrayList(); PropertyInfo[] properties = objectToSerialize.GetType().GetProperties(); if (properties != null) { PropertyInfo[] array = properties; foreach (PropertyInfo propertyInfo in array) { if (IsGaugeBaseProperty(objectToSerialize, parent, propertyInfo)) { continue; } if (propertyInfo.CanRead && propertyInfo.PropertyType.GetInterface("ICollection", ignoreCase: true) != null) { bool flag = true; if (objectToSerialize != null) { PropertyDescriptor propertyDescriptor2 = TypeDescriptor.GetProperties(objectToSerialize)[propertyInfo.Name]; if (propertyDescriptor2 != null) { SerializationVisibilityAttribute serializationVisibilityAttribute2 = (SerializationVisibilityAttribute)propertyDescriptor2.Attributes[typeof(SerializationVisibilityAttribute)]; if (serializationVisibilityAttribute2 != null && serializationVisibilityAttribute2.Visibility == SerializationVisibility.Hidden) { flag = false; } } } if (flag) { arrayList.Add(propertyInfo.Name); SerializeCollection(propertyInfo.GetValue(objectToSerialize, null), propertyInfo.Name, writer); } } else { if (!propertyInfo.CanRead || !propertyInfo.CanWrite || propertyInfo.Name == "Item") { continue; } if (ShouldSerializeAsAttribute(propertyInfo, objectToSerialize)) { if (IsSerializableContent(propertyInfo.Name, objectToSerialize)) { SerializeProperty(propertyInfo.GetValue(objectToSerialize, null), objectToSerialize, propertyInfo.Name, writer); } } else { SerializeObject(propertyInfo.GetValue(objectToSerialize, null), objectToSerialize, propertyInfo.Name, writer); } arrayList.Add(propertyInfo.Name); } } CheckPropertiesID(arrayList); } if (writer.Seek(0, SeekOrigin.Current) == num) { writer.Seek(-2, SeekOrigin.Current); writer.Write((short)0); writer.Seek(-2, SeekOrigin.Current); } else { writer.Write((short)0); } }
internal static short GetStringHashCode(string str) { return((short)(hashCodeProvider.GetHashCode(str) + str.Length * 2)); }
public static void Ctor_CultureInfo_GetHashCodeCompare_TurkishI() { var cultureNames = 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 cultureNames) { CultureInfo culture; try { culture = new CultureInfo(cultureName); } catch (CultureNotFoundException) { continue; } var provider = new CaseInsensitiveHashCodeProvider(culture); // 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) Assert.Equal( culture.Name != "tr-TR", provider.GetHashCode("file") == provider.GetHashCode("FILE")); } }
public bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; CaseInsensitiveHashCodeProvider cis; CultureInfo[] cultures; try { do { strLoc = "Loc_384sdg"; cultures = CultureInfo.GetCultures(CultureTypes.AllCultures); for(int i=0; i<cultures.Length; i++) { iCountTestcases++; cis = new CaseInsensitiveHashCodeProvider(cultures[i]); if(cis.GetHashCode("hello") != cis.GetHashCode("HELLO")) { iCountErrors++; Console.WriteLine( "Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>", cis.GetHashCode("hello"), cis.GetHashCode("HELLO")); } if(cis.GetHashCode("hello") != cis.GetHashCode("hello")) { iCountErrors++; Console.WriteLine( "Err_4953rewg! wrong value returned. Expected - <{0}>, Returned - <{1}>", cis.GetHashCode("hello"), cis.GetHashCode("HELLO")); } if(cis.GetHashCode("hello") == cis.GetHashCode("mello")) { iCountErrors++; Console.WriteLine( "Err_94375sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>", cis.GetHashCode("hello"), cis.GetHashCode("HELLO")); } if(cis.GetHashCode(5) != cis.GetHashCode(5)) { iCountErrors++; Console.WriteLine( "Err_9745sdg! wrong value returned"); } if(cis.GetHashCode(5) == cis.GetHashCode(10)) { iCountErrors++; Console.WriteLine( "Err_9745sdg! wrong value returned"); } } strLoc = "Loc_dfyusg"; iCountTestcases++; try { cis = new CaseInsensitiveHashCodeProvider(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); } } while (false); } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "paSs. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("FAiL! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
public bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; CaseInsensitiveHashCodeProvider cis; String strValue1; String strValue2; Int32 iValue; try { do { cis = new CaseInsensitiveHashCodeProvider(); iCountTestcases++; if (cis == null) { iCountErrors++; Console.WriteLine("Err_8753bdd! Expected value not returned, "); } strValue1 = "hello world"; strValue2 = strValue1.ToUpper(); iCountTestcases++; if (cis.GetHashCode(strValue1) != cis.GetHashCode(strValue2)) { iCountErrors++; Console.WriteLine("Err_8753bdd! Expected value not returned, " + cis.GetHashCode(strValue1) + " " + cis.GetHashCode(strValue2)); } strValue2 = "Completely different"; iCountTestcases++; if (cis.GetHashCode(strValue1) == cis.GetHashCode(strValue2)) { iCountErrors++; Console.WriteLine("Err_87453gdg! Expected value not returned, " + cis.GetHashCode(strValue1) + " " + cis.GetHashCode(strValue2)); } iValue = 5; iCountTestcases++; if (cis.GetHashCode(iValue) != iValue.GetHashCode()) { iCountErrors++; Console.WriteLine("Err_752dsg! Expected value not returned, " + cis.GetHashCode(iValue) + " " + iValue.GetHashCode()); } try { iCountTestcases++; cis.GetHashCode(null); iCountErrors++; Console.WriteLine("Err_7439dg! Exception not thrown"); } catch (ArgumentNullException) { } catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_6572fdg! Unexpected exception thrown, " + ex); } } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==\n" + exc_general.ToString()); } if (iCountErrors == 0) { Console.WriteLine("paSs. " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases); return(true); } else { Console.WriteLine("FAiL! " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums); return(false); } }
public bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; CaseInsensitiveHashCodeProvider cis; String strValue1; String strValue2; Int32 iValue; try { do { cis = new CaseInsensitiveHashCodeProvider(); iCountTestcases++; if(cis==null) { iCountErrors++; Console.WriteLine("Err_8753bdd! Expected value not returned, "); } strValue1 = "hello world"; strValue2 = strValue1.ToUpper(); iCountTestcases++; if(cis.GetHashCode(strValue1)!=cis.GetHashCode(strValue2)) { iCountErrors++; Console.WriteLine("Err_8753bdd! Expected value not returned, " + cis.GetHashCode(strValue1) + " " + cis.GetHashCode(strValue2)); } strValue2 = "Completely different"; iCountTestcases++; if(cis.GetHashCode(strValue1)==cis.GetHashCode(strValue2)) { iCountErrors++; Console.WriteLine("Err_87453gdg! Expected value not returned, " + cis.GetHashCode(strValue1) + " " + cis.GetHashCode(strValue2)); } iValue = 5; iCountTestcases++; if(cis.GetHashCode(iValue)!=iValue.GetHashCode()) { iCountErrors++; Console.WriteLine("Err_752dsg! Expected value not returned, " + cis.GetHashCode(iValue) + " " + iValue.GetHashCode()); } try { iCountTestcases++; cis.GetHashCode(null); iCountErrors++; Console.WriteLine("Err_7439dg! Exception not thrown"); } catch(ArgumentNullException) { } catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_6572fdg! Unexpected exception thrown, " + ex); } } while (false); } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "paSs. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("FAiL! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
public bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; CaseInsensitiveHashCodeProvider cis; CultureInfo[] cultures; try { do { strLoc = "Loc_384sdg"; cultures = CultureInfo.GetCultures(CultureTypes.AllCultures); for (int i = 0; i < cultures.Length; i++) { iCountTestcases++; cis = new CaseInsensitiveHashCodeProvider(cultures[i]); if (cis.GetHashCode("hello") != cis.GetHashCode("HELLO")) { iCountErrors++; Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>", cis.GetHashCode("hello"), cis.GetHashCode("HELLO")); } if (cis.GetHashCode("hello") != cis.GetHashCode("hello")) { iCountErrors++; Console.WriteLine("Err_4953rewg! wrong value returned. Expected - <{0}>, Returned - <{1}>", cis.GetHashCode("hello"), cis.GetHashCode("HELLO")); } if (cis.GetHashCode("hello") == cis.GetHashCode("mello")) { iCountErrors++; Console.WriteLine("Err_94375sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>", cis.GetHashCode("hello"), cis.GetHashCode("HELLO")); } if (cis.GetHashCode(5) != cis.GetHashCode(5)) { iCountErrors++; Console.WriteLine("Err_9745sdg! wrong value returned"); } if (cis.GetHashCode(5) == cis.GetHashCode(10)) { iCountErrors++; Console.WriteLine("Err_9745sdg! wrong value returned"); } } strLoc = "Loc_dfyusg"; iCountTestcases++; try { cis = new CaseInsensitiveHashCodeProvider(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); } } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==\n" + exc_general.ToString()); } if (iCountErrors == 0) { Console.WriteLine("paSs. " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases); return(true); } else { Console.WriteLine("FAiL! " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums); return(false); } }