// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0
using System;
using System.Globalization;
{
private CultureInfo old_culture;
+ private BinaryFormatter CreateBinaryFormatter()
+ {
+ return new BinaryFormatter();
+ }
+
[SetUp]
public void SetUp ()
{
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);
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);
}
[Test]
public void Serialize_CurrentCultureIgnoreCase ()
{
- BinaryFormatter bf = new BinaryFormatter ();
+ BinaryFormatter bf = CreateBinaryFormatter();
MemoryStream ms = new MemoryStream ();
bf.Serialize (ms, StringComparer.CurrentCultureIgnoreCase);
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);
}
[Test]
public void Serialize_InvariantCulture ()
{
- BinaryFormatter bf = new BinaryFormatter ();
+ BinaryFormatter bf = CreateBinaryFormatter();
MemoryStream ms = new MemoryStream ();
bf.Serialize (ms, StringComparer.InvariantCulture);
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);
}
[Test]
public void Serialize_InvariantCultureIgnoreCase ()
{
- BinaryFormatter bf = new BinaryFormatter ();
+ BinaryFormatter bf = CreateBinaryFormatter();
MemoryStream ms = new MemoryStream ();
bf.Serialize (ms, StringComparer.InvariantCultureIgnoreCase);
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);
}
[Test]
public void Serialize_Ordinal ()
{
- BinaryFormatter bf = new BinaryFormatter ();
+ BinaryFormatter bf = CreateBinaryFormatter();
MemoryStream ms = new MemoryStream ();
bf.Serialize (ms, StringComparer.Ordinal);
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);
}
[Test]
public void Serialize_OrdinalIgnoreCase ()
{
- BinaryFormatter bf = new BinaryFormatter ();
+ BinaryFormatter bf = CreateBinaryFormatter();
MemoryStream ms = new MemoryStream ();
bf.Serialize (ms, StringComparer.OrdinalIgnoreCase);
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,
}
}
-#endif