Author: gert
Date: 2007-07-05 12:40:03 -0400 (Thu, 05 Jul 2007)
New Revision: 81408
Modified:
trunk/mcs/class/corlib/System.Collections/CaseInsensitiveHashCodeProvider.cs
trunk/mcs/class/corlib/System.Collections/ChangeLog
trunk/mcs/class/corlib/Test/System.Collections/CaseInsensitiveHashCodeProviderTest.cs
trunk/mcs/class/corlib/Test/System.Collections/ChangeLog
trunk/mcs/class/corlib/Test/System.Globalization/ChangeLog
trunk/mcs/class/corlib/Test/System.Globalization/CultureInfoTest.cs
Log:
* CaseInsensitiveHashCodeProvider.cs: In default ctor, do not save
TextInfo if current culture is invariant. Remoted private ctor.
In Default, always construct new instance since the current culture
may change.
* CaseInsensitiveHashCodeProviderTest.cs: Improved test for
Default property to show the a new intance is constructed. Added test
for DefaultInvariant. Improved serialization tests. Added ctor test
for null CultureInfo. Code formatting.
* CultureInfoTest.cs: Fixed UseUserOverride tests to pass on systems
where invariant culture is default locale.
Modified:
trunk/mcs/class/corlib/System.Collections/CaseInsensitiveHashCodeProvider.cs
===================================================================
---
trunk/mcs/class/corlib/System.Collections/CaseInsensitiveHashCodeProvider.cs
2007-07-05 16:02:04 UTC (rev 81407)
+++
trunk/mcs/class/corlib/System.Collections/CaseInsensitiveHashCodeProvider.cs
2007-07-05 16:40:03 UTC (rev 81408)
@@ -40,29 +40,25 @@
#endif
public class CaseInsensitiveHashCodeProvider : IHashCodeProvider
{
- static readonly CaseInsensitiveHashCodeProvider singleton = new
CaseInsensitiveHashCodeProvider ();
- static readonly CaseInsensitiveHashCodeProvider
singletonInvariant = new CaseInsensitiveHashCodeProvider (true);
+ static readonly CaseInsensitiveHashCodeProvider
singletonInvariant = new CaseInsensitiveHashCodeProvider (
+ CultureInfo.InvariantCulture);
TextInfo m_text; // must match MS name for serialization
// Public instance constructor
public CaseInsensitiveHashCodeProvider ()
{
- m_text = CultureInfo.CurrentCulture.TextInfo;
+ CultureInfo culture = CultureInfo.CurrentCulture;
+ if (culture.LCID != CultureInfo.InvariantCulture.LCID)
+ m_text = CultureInfo.CurrentCulture.TextInfo;
}
- private CaseInsensitiveHashCodeProvider (bool invariant)
- {
- // leave m_text == null
- }
-
public CaseInsensitiveHashCodeProvider (CultureInfo culture)
{
if (culture == null)
throw new ArgumentNullException ("culture");
if (culture.LCID != CultureInfo.InvariantCulture.LCID)
m_text = culture.TextInfo;
- // else leave m_text == null
}
//
@@ -71,7 +67,7 @@
public static CaseInsensitiveHashCodeProvider Default {
get {
- return singleton;
+ return new CaseInsensitiveHashCodeProvider ();
}
}
Modified: trunk/mcs/class/corlib/System.Collections/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.Collections/ChangeLog 2007-07-05 16:02:04 UTC
(rev 81407)
+++ trunk/mcs/class/corlib/System.Collections/ChangeLog 2007-07-05 16:40:03 UTC
(rev 81408)
@@ -1,3 +1,10 @@
+2007-07-05 Gert Driesen <[EMAIL PROTECTED]>
+
+ * CaseInsensitiveHashCodeProvider.cs: In default ctor, do not save
+ TextInfo if current culture is invariant. Remoted private ctor.
+ In Default, always construct new instance since the current culture
+ may change.
+
2007-06-08 Ankit Jain <[EMAIL PROTECTED]>
* ArrayList.cs (Shift): Clear the unused part of the array when
Modified:
trunk/mcs/class/corlib/Test/System.Collections/CaseInsensitiveHashCodeProviderTest.cs
===================================================================
---
trunk/mcs/class/corlib/Test/System.Collections/CaseInsensitiveHashCodeProviderTest.cs
2007-07-05 16:02:04 UTC (rev 81407)
+++
trunk/mcs/class/corlib/Test/System.Collections/CaseInsensitiveHashCodeProviderTest.cs
2007-07-05 16:40:03 UTC (rev 81408)
@@ -9,23 +9,53 @@
using System.Globalization;
using System.IO;
using System.Runtime.Serialization;
+using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
+using System.Threading;
using NUnit.Framework;
namespace MonoTests.System.Collections {
[TestFixture]
- public class CaseInsensitiveHashCodeProviderTest {
+ public class CaseInsensitiveHashCodeProviderTest
+ {
+ [Test]
+ 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");
+
+ // Default always returns new instance
+ CaseInsensitiveHashCodeProvider cih1 =
CaseInsensitiveHashCodeProvider.Default;
+ CaseInsensitiveHashCodeProvider cih2 =
CaseInsensitiveHashCodeProvider.Default;
+ Assert.IsFalse (object.ReferenceEquals (cih1, cih2),
"#2");
+ }
+
+#if NET_2_0
[Test]
- public void DefaultInstance ()
+ public void DefaultInvariant ()
{
- // Make sure the instance returned by Default
- // is really a CaseInsensitiveHashCodeProvider.
- Assert.IsTrue ((CaseInsensitiveHashCodeProvider.Default
- as CaseInsensitiveHashCodeProvider) != null);
+ 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));
}
+#endif
[Test]
public void HashCode ()
@@ -45,24 +75,96 @@
}
[Test]
- public void DefaultCtor ()
+ public void Constructor0_Serialization ()
{
CaseInsensitiveHashCodeProvider cihcp = new
CaseInsensitiveHashCodeProvider ();
BinaryFormatter bf = new BinaryFormatter ();
MemoryStream ms = new MemoryStream ();
bf.Serialize (ms, cihcp);
- byte[] def = ms.ToArray ();
+ byte[] ser1 = ms.ToArray ();
cihcp = new CaseInsensitiveHashCodeProvider
(CultureInfo.CurrentCulture);
ms = new MemoryStream ();
bf.Serialize (ms, cihcp);
- byte[] current = ms.ToArray ();
+ byte[] ser2 = ms.ToArray ();
- Assert.AreEqual (def, current, "default=current");
+ cihcp = CaseInsensitiveHashCodeProvider.Default;
+ ms = new MemoryStream ();
+ bf.Serialize (ms, cihcp);
+ byte[] ser3 = ms.ToArray ();
+
+ Assert.AreEqual (ser1, ser2, "#1");
+ Assert.AreEqual (ser2, ser3, "#2");
}
- private static byte[] serialized_en_us = new byte[] {
+ [Test]
+ public void Constructor1_Culture_Null ()
+ {
+ try {
+ new CaseInsensitiveHashCodeProvider
((CultureInfo) null);
+ Assert.Fail ("#1");
+ } catch (ArgumentNullException ex) {
+ Assert.AreEqual (typeof
(ArgumentNullException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsNotNull (ex.ParamName, "#5");
+ Assert.AreEqual ("culture", ex.ParamName, "#6");
+ }
+ }
+
#if NET_2_0
+ [Test]
+ public void Constructor1_Serialization ()
+ {
+ CaseInsensitiveHashCodeProvider cihcp = new
CaseInsensitiveHashCodeProvider (CultureInfo.InvariantCulture);
+ BinaryFormatter bf = new BinaryFormatter ();
+ MemoryStream ms = new MemoryStream ();
+ bf.Serialize (ms, cihcp);
+ byte[] ser1 = ms.ToArray ();
+
+ cihcp =
CaseInsensitiveHashCodeProvider.DefaultInvariant;
+ ms = new MemoryStream ();
+ bf.Serialize (ms, cihcp);
+ byte[] ser2 = ms.ToArray ();
+
+ Assert.AreEqual (ser1, ser2, "#1");
+ }
+#endif
+
+ [Test]
+ 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)");
+ }
+
+ [Test]
+ public void Deserialize ()
+ {
+#if TARGET_JVM
+ BinaryFormatter bf = (BinaryFormatter)[EMAIL PROTECTED]
(false);
+#else
+ BinaryFormatter bf = new BinaryFormatter ();
+#endif // TARGET_JVM
+
+ MemoryStream ms = new MemoryStream (serialized_en_us);
+ CaseInsensitiveHashCodeProvider enus =
(CaseInsensitiveHashCodeProvider) bf.Deserialize (ms);
+ Assert.IsNotNull (enus, "en-US");
+
+ ms = new MemoryStream (serialized_fr_ca);
+ CaseInsensitiveHashCodeProvider frca =
(CaseInsensitiveHashCodeProvider) bf.Deserialize (ms);
+ Assert.IsNotNull (frca, "fr-CA");
+ }
+
+ private static byte [] serialized_en_us = new byte [] {
+#if NET_2_0
0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01,
0x00, 0x00, 0x00, 0x32, 0x53, 0x79, 0x73,
0x74, 0x65, 0x6D, 0x2E, 0x43, 0x6F, 0x6C, 0x6C, 0x65,
0x63, 0x74, 0x69, 0x6F, 0x6E, 0x73, 0x2E,
@@ -99,7 +201,7 @@
#endif
};
- private static byte[] serialized_fr_ca = new byte[] {
+ private static byte [] serialized_fr_ca = new byte [] {
#if NET_2_0
0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01,
0x00, 0x00, 0x00, 0x32, 0x53, 0x79, 0x73,
@@ -136,37 +238,5 @@
0x08, 0x50, 0x00, 0x00, 0x00, 0x01, 0x0C, 0x0C, 0x00,
0x00, 0x0B
#endif
};
-
- [Test]
- 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)");
- }
-
- [Test]
- public void Deserialize ()
- {
-#if TARGET_JVM
- BinaryFormatter bf = (BinaryFormatter)[EMAIL PROTECTED]
(false);
-#else
- BinaryFormatter bf = new BinaryFormatter ();
-#endif // TARGET_JVM
-
- MemoryStream ms = new MemoryStream (serialized_en_us);
- CaseInsensitiveHashCodeProvider enus =
(CaseInsensitiveHashCodeProvider) bf.Deserialize (ms);
- Assert.IsNotNull (enus, "en-US");
-
- ms = new MemoryStream (serialized_fr_ca);
- CaseInsensitiveHashCodeProvider frca =
(CaseInsensitiveHashCodeProvider) bf.Deserialize (ms);
- Assert.IsNotNull (frca, "fr-CA");
- }
}
}
Modified: trunk/mcs/class/corlib/Test/System.Collections/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System.Collections/ChangeLog 2007-07-05
16:02:04 UTC (rev 81407)
+++ trunk/mcs/class/corlib/Test/System.Collections/ChangeLog 2007-07-05
16:40:03 UTC (rev 81408)
@@ -1,3 +1,10 @@
+2007-07-05 Gert Driesen <[EMAIL PROTECTED]>
+
+ * CaseInsensitiveHashCodeProviderTest.cs: Improved test for
+ Default property to show the a new intance is constructed. Added test
+ for DefaultInvariant. Improved serialization tests. Added ctor test
+ for null CultureInfo. Code formatting.
+
2007-04-19 Gert Driesen <[EMAIL PROTECTED]>
* ArrayListTest.cs: Code formatting (indenting, spaces to tabs). Added
Modified: trunk/mcs/class/corlib/Test/System.Globalization/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System.Globalization/ChangeLog 2007-07-05
16:02:04 UTC (rev 81407)
+++ trunk/mcs/class/corlib/Test/System.Globalization/ChangeLog 2007-07-05
16:40:03 UTC (rev 81408)
@@ -1,3 +1,8 @@
+2007-07-05 Gert Driesen <[EMAIL PROTECTED]>
+
+ * CultureInfoTest.cs: Fixed UseUserOverride tests to pass on systems
+ where invariant culture is default locale.
+
2007-07-03 Gert Driesen <[EMAIL PROTECTED]>
* CultureInfoTest.cs: Added extra info in order to troubleshoot
Modified: trunk/mcs/class/corlib/Test/System.Globalization/CultureInfoTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Globalization/CultureInfoTest.cs
2007-07-05 16:02:04 UTC (rev 81407)
+++ trunk/mcs/class/corlib/Test/System.Globalization/CultureInfoTest.cs
2007-07-05 16:40:03 UTC (rev 81408)
@@ -425,20 +425,22 @@
public void UseUserOverride_CurrentCulture ()
{
CultureInfo ci = CultureInfo.CurrentCulture;
- Assert.IsTrue (ci.UseUserOverride, "#1:" +
ci.DisplayName + "|" + ci.LCID);
+ bool expected = (ci.LCID !=
CultureInfo.InvariantCulture.LCID);
+ Assert.AreEqual (expected, ci.UseUserOverride, "#1");
ci = (CultureInfo) ci.Clone ();
- Assert.IsTrue (ci.UseUserOverride, "#2");
+ Assert.AreEqual (expected, ci.UseUserOverride, "#2");
}
[Test]
public void UseUserOverride_CurrentUICulture ()
{
CultureInfo ci = CultureInfo.CurrentCulture;
- Assert.IsTrue (ci.UseUserOverride, "#1:" +
ci.DisplayName + "|" + ci.LCID);
+ bool expected = (ci.LCID !=
CultureInfo.InvariantCulture.LCID);
+ Assert.AreEqual (expected, ci.UseUserOverride, "#1");
ci = (CultureInfo) ci.Clone ();
- Assert.IsTrue (ci.UseUserOverride, "#2");
+ Assert.AreEqual (expected, ci.UseUserOverride, "#2");
}
#if NET_2_0
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches