Merge pull request #2274 from esdrubal/udpclientreceive
[mono.git] / mcs / class / corlib / Test / System / StringComparerTest.cs
index d915b6298dbad21305277a566583e4517dba8655..97c8153bfd57fa5e94fd32117d344a6b0e418411 100644 (file)
@@ -26,7 +26,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
 
 using System;
 using System.Globalization;
@@ -43,6 +42,11 @@ namespace MonoTests.System
        {
                private CultureInfo old_culture;
 
+               private BinaryFormatter CreateBinaryFormatter()
+               {
+                       return new BinaryFormatter();
+               }
+
                [SetUp]
                public void SetUp ()
                {
@@ -59,7 +63,7 @@ namespace MonoTests.System
                public void Serialize_CurrentCulture ()
                {
                        Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE");
-                       BinaryFormatter bf = new BinaryFormatter ();
+                       BinaryFormatter bf = CreateBinaryFormatter();
                        MemoryStream ms = new MemoryStream ();
                        bf.Serialize (ms, StringComparer.CurrentCulture);
 
@@ -73,7 +77,7 @@ namespace MonoTests.System
                        ms.Write (_serializedCurrentCulture, 0, _serializedCurrentCulture.Length);
                        ms.Position = 0;
 
-                       BinaryFormatter bf = new BinaryFormatter ();
+                       BinaryFormatter bf = CreateBinaryFormatter();
                        StringComparer sc = (StringComparer) bf.Deserialize (ms);
                        Assert.IsNotNull (sc);
                }
@@ -81,7 +85,7 @@ namespace MonoTests.System
                [Test]
                public void Serialize_CurrentCultureIgnoreCase ()
                {
-                       BinaryFormatter bf = new BinaryFormatter ();
+                       BinaryFormatter bf = CreateBinaryFormatter();
                        MemoryStream ms = new MemoryStream ();
                        bf.Serialize (ms, StringComparer.CurrentCultureIgnoreCase);
 
@@ -95,7 +99,7 @@ namespace MonoTests.System
                        ms.Write (_serializedCurrentCultureIgnoreCase, 0, _serializedCurrentCultureIgnoreCase.Length);
                        ms.Position = 0;
 
-                       BinaryFormatter bf = new BinaryFormatter ();
+                       BinaryFormatter bf = CreateBinaryFormatter();
                        StringComparer sc = (StringComparer) bf.Deserialize (ms);
                        Assert.IsNotNull (sc);
                }
@@ -103,7 +107,7 @@ namespace MonoTests.System
                [Test]
                public void Serialize_InvariantCulture ()
                {
-                       BinaryFormatter bf = new BinaryFormatter ();
+                       BinaryFormatter bf = CreateBinaryFormatter();
                        MemoryStream ms = new MemoryStream ();
                        bf.Serialize (ms, StringComparer.InvariantCulture);
 
@@ -121,7 +125,7 @@ namespace MonoTests.System
                        ms.Write (_serializedInvariantCulture, 0, _serializedInvariantCulture.Length);
                        ms.Position = 0;
 
-                       BinaryFormatter bf = new BinaryFormatter ();
+                       BinaryFormatter bf = CreateBinaryFormatter();
                        StringComparer sc = (StringComparer) bf.Deserialize (ms);
                        Assert.IsNotNull (sc);
                }
@@ -129,7 +133,7 @@ namespace MonoTests.System
                [Test]
                public void Serialize_InvariantCultureIgnoreCase ()
                {
-                       BinaryFormatter bf = new BinaryFormatter ();
+                       BinaryFormatter bf = CreateBinaryFormatter();
                        MemoryStream ms = new MemoryStream ();
                        bf.Serialize (ms, StringComparer.InvariantCultureIgnoreCase);
 
@@ -147,7 +151,7 @@ namespace MonoTests.System
                        ms.Write (_serializedInvariantCultureIgnoreCase, 0, _serializedInvariantCultureIgnoreCase.Length);
                        ms.Position = 0;
 
-                       BinaryFormatter bf = new BinaryFormatter ();
+                       BinaryFormatter bf = CreateBinaryFormatter();
                        StringComparer sc = (StringComparer) bf.Deserialize (ms);
                        Assert.IsNotNull (sc);
                }
@@ -155,7 +159,7 @@ namespace MonoTests.System
                [Test]
                public void Serialize_Ordinal ()
                {
-                       BinaryFormatter bf = new BinaryFormatter ();
+                       BinaryFormatter bf = CreateBinaryFormatter();
                        MemoryStream ms = new MemoryStream ();
                        bf.Serialize (ms, StringComparer.Ordinal);
 
@@ -173,7 +177,7 @@ namespace MonoTests.System
                        ms.Write (_serializedOrdinal, 0, _serializedOrdinal.Length);
                        ms.Position = 0;
 
-                       BinaryFormatter bf = new BinaryFormatter ();
+                       BinaryFormatter bf = CreateBinaryFormatter();
                        StringComparer sc = (StringComparer) bf.Deserialize (ms);
                        Assert.IsNotNull (sc);
                }
@@ -181,7 +185,7 @@ namespace MonoTests.System
                [Test]
                public void Serialize_OrdinalIgnoreCase ()
                {
-                       BinaryFormatter bf = new BinaryFormatter ();
+                       BinaryFormatter bf = CreateBinaryFormatter();
                        MemoryStream ms = new MemoryStream ();
                        bf.Serialize (ms, StringComparer.OrdinalIgnoreCase);
 
@@ -199,11 +203,32 @@ namespace MonoTests.System
                        ms.Write (_serializedOrdinalIgnoreCase, 0, _serializedOrdinalIgnoreCase.Length);
                        ms.Position = 0;
 
-                       BinaryFormatter bf = new BinaryFormatter ();
+                       BinaryFormatter bf = CreateBinaryFormatter();
                        StringComparer sc = (StringComparer) bf.Deserialize (ms);
                        Assert.IsNotNull (sc);
                }
 
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void GetNullOrdinalHashCode ()
+               {
+                       StringComparer.Ordinal.GetHashCode (null);
+               }
+
+               [Test]
+               [SetCulture("en-us")]
+               public void OrdinarCultureSwitch ()
+               {
+                       var cmp1 = StringComparer.OrdinalIgnoreCase;
+                       var h1 = cmp1.GetHashCode ("w");
+
+                       global::System.Threading.Thread.CurrentThread.CurrentCulture = new global::System.Globalization.CultureInfo ("fi");
+
+                       var cmp2 = StringComparer.OrdinalIgnoreCase;
+                       var h2 = cmp2.GetHashCode ("w");
+                       Assert.AreEqual (h1, h2);
+               }
+
                private static readonly byte [] _serializedCurrentCulture = new byte [] {
                        0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00,
@@ -309,4 +334,3 @@ namespace MonoTests.System
        }
 }
 
-#endif