Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,316 @@
//
// BitArrayTest.cs - NUnit Test Cases for the System.Collections.BitArray class
//
// Author: David Menestrina (dmenest@yahoo.com)
//
using NUnit.Framework;
using System.Collections;
using System;
namespace MonoTests.System.Collections
{
[TestFixture]
public class BitArrayTest
{
private BitArray testBa;
private bool [] testPattern;
private BitArray op1;
private BitArray op2;
private void verifyPattern(BitArray ba, bool[] pattern)
{
Assert.AreEqual (ba.Length, pattern.Length);
for (int i = 0; i < pattern.Length; i++)
Assert.AreEqual (ba[i], pattern[i]);
}
[SetUp]
public void SetUp()
{
testPattern = new bool[70];
int i;
for(i = 0; i < testPattern.Length/2; i++)
testPattern[i] = ((i % 2) == 0);
for(; i < testPattern.Length; i++)
testPattern[i] = ((i % 2) != 0);
testBa = new BitArray(70);
for(i = 0; i < testBa.Length/2; i++)
testBa[i] = ((i % 2) == 0);
for(; i < testBa.Length; i++)
testBa[i] = ((i % 2) != 0);
// for TestAnd, TestOr, TestNot, TestXor
op1 = new BitArray(new int[] { 0x33333333, 0x33333333 });
op2 = new BitArray(new int[] { 0x66666666, 0x66666666 });
}
[Test]
public void TestBoolConstructor()
{
BitArray ba = new BitArray(testPattern);
verifyPattern(ba, testPattern);
}
[Test]
public void TestCopyConstructor()
{
BitArray ba = new BitArray(testBa);
verifyPattern(ba, testPattern);
}
[Test]
public void TestByteConstructor()
{
byte [] byteArr = new byte[] { 0xaa, 0x55, 0xaa, 0x55, 0x80 };
BitArray ba = new BitArray(byteArr);
Assert.AreEqual (ba.Length, byteArr.Length * 8, "Lengths not equal");
// spot check
Assert.IsTrue (ba[7], "7 not true");
Assert.IsTrue (!ba[6], "6 not false");
Assert.IsTrue (!ba[15], "15 not false");
Assert.IsTrue (ba[14], "14 not true");
Assert.IsTrue (ba[39], "39 not true");
Assert.IsTrue (!ba[35], "35 not false");
}
[Test]
public void TestIntConstructor()
{
int [] intArr = new int[] { ~0x55555555, 0x55555551 };
BitArray ba = new BitArray(intArr);
Assert.AreEqual (ba.Length, intArr.Length * 32);
// spot check
Assert.IsTrue (ba[31]);
Assert.IsTrue (!ba[30]);
Assert.IsTrue (!ba[63]);
Assert.IsTrue (ba[62]);
Assert.IsTrue (ba[32]);
Assert.IsTrue (!ba[35]);
}
[Test]
public void TestValConstructor()
{
BitArray ba = new BitArray(64, false);
Assert.AreEqual (ba.Length, 64);
foreach (bool b in ba)
Assert.IsTrue (!b);
ba = new BitArray(64, true);
Assert.AreEqual (ba.Length, 64);
foreach (bool b in ba)
Assert.IsTrue (b);
}
[Test]
public void TestClone()
{
BitArray ba = (BitArray)testBa.Clone();
verifyPattern(ba, testPattern);
// ensure that changes in ba don't get propagated to testBa
ba[0] = false;
ba[1] = false;
ba[2] = false;
verifyPattern(testBa, testPattern);
}
[Test]
public void TestSetLength()
{
int origLen = testBa.Length;
testBa.Length += 33;
Assert.AreEqual (origLen + 33, testBa.Length);
for (int i = origLen; i < testBa.Length; i++)
testBa[i] = true;
testBa.Length -= 33;
verifyPattern(testBa, testPattern);
}
[Test]
public void TestAnd()
{
BitArray result = op1.And(op2);
Assert.AreEqual (result.Length, op1.Length);
for (int i = 0; i < result.Length; )
{
Assert.IsTrue (!result[i++]);
Assert.IsTrue (result[i++]);
Assert.IsTrue (!result[i++]);
Assert.IsTrue (!result[i++]);
}
}
[Test]
public void TestOr()
{
BitArray result = op1.Or(op2);
Assert.AreEqual (result.Length, op1.Length);
for (int i = 0; i < result.Length; )
{
Assert.IsTrue (result[i++]);
Assert.IsTrue (result[i++]);
Assert.IsTrue (result[i++]);
Assert.IsTrue (!result[i++]);
}
}
[Test]
public void TestNot()
{
BitArray result = op1.Not();
Assert.AreEqual (result.Length, op1.Length);
for (int i = 0; i < result.Length; )
{
Assert.IsTrue (!result[i++]);
Assert.IsTrue (!result[i++]);
Assert.IsTrue (result[i++]);
Assert.IsTrue (result[i++]);
}
}
[Test]
public void TestXor()
{
BitArray result = op1.Xor(op2);
Assert.AreEqual (result.Length, op1.Length);
for (int i = 0; i < result.Length; )
{
Assert.IsTrue (result[i++]);
Assert.IsTrue (!result[i++]);
Assert.IsTrue (result[i++]);
Assert.IsTrue (!result[i++]);
}
}
[Test]
public void TestSetAll()
{
testBa.SetAll(false);
foreach(bool b in testBa)
Assert.IsTrue (!b);
testBa.SetAll(true);
foreach(bool b in testBa)
Assert.IsTrue (b);
}
[Test]
public void TestCopyToBool()
{
try {
bool[] barray = new bool[testBa.Length + 10];
testBa.CopyTo(barray, 5);
for (int i = 0; i < testBa.Length; i++)
Assert.AreEqual (testBa[i], barray[i+5]);
}
catch(Exception e){
Assert.Fail ("Unexpected exception thrown: " + e.ToString());
}
}
[Test]
public void CopyToEmptyEmpty () {
BitArray bitarray = new BitArray(0);
int[] intarray = new int[0];
bitarray.CopyTo(intarray, 0);
}
[Test]
public void TestCopyToByte()
{
try {
testBa.Length = 34;
byte[] barray = new byte[5 + 10];
testBa.CopyTo(barray, 5);
for (int i = 5; i < 9; i++)
Assert.AreEqual (0x55, barray[i] & 0xff);
// FIXME: MS fails on the next line. This is because
// we truncated testBa.Length, and MS's internal array still
// has the old bits set. CopyTo() doesn't say specifically
// whether the "junk" bits (bits past Length, but within Length
// rounded up to 32) will be copied as 0, or if those bits are
// undefined.
//Assert.AreEqual (0x01, barray[9] & 0xff);
}
catch(Exception e){
Assert.Fail ("Unexpected exception thrown: " + e.ToString());
}
}
[Test]
public void TestCopyToInt()
{
try {
testBa.Length = 34;
int[] iarray = new int[2 + 10];
testBa.CopyTo(iarray, 5);
Assert.AreEqual (0x55555555, iarray[5]);
// FIXME: Same thing here as in TestCopyToByte
//Assert.AreEqual (0x01, iarray[6]);
}
catch(Exception e){
Assert.Fail ("Unexpected exception thrown: " + e.ToString());
}
}
[Test]
public void TestEnumerator()
{
try {
IEnumerator e = testBa.GetEnumerator();
for (int i = 0; e.MoveNext(); i++)
Assert.AreEqual (e.Current, testPattern[i]);
Assert.IsTrue (!e.MoveNext());
// read, to make sure reading isn't considered a write.
bool b = testBa[0];
e.Reset();
for (int i = 0; e.MoveNext(); i++)
Assert.AreEqual (e.Current, testPattern[i]);
try
{
e.Reset();
testBa[0] = !testBa[0];
e.MoveNext();
Assert.Fail ("IEnumerator.MoveNext() should throw when collection modified.");
}
catch (InvalidOperationException)
{
}
}
catch(Exception ex){
Assert.Fail ("Unexpected exception thrown: " + ex.ToString());
}
}
}
}

View File

@@ -0,0 +1,494 @@
// CaseInsensitiveComparerTest
using System;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using NUnit.Framework;
namespace MonoTests.System.Collections {
[TestFixture]
public class CaseInsensitiveComparerTest {
[Test]
public void TestDefaultInstance ()
{
// Make sure the instance returned by Default
// is really a CaseInsensitiveComparer.
Assert.IsNotNull ((CaseInsensitiveComparer.Default as CaseInsensitiveComparer));
}
[Test]
public void TestCompare ()
{
CaseInsensitiveComparer cic = new CaseInsensitiveComparer ();
Assert.AreEqual (0, cic.Compare ("WILD WEST", "Wild West"));
Assert.AreEqual (0, cic.Compare ("WILD WEST", "wild west"));
Assert.AreEqual (1, cic.Compare ("Zeus", "Mars"));
Assert.AreEqual (-1, cic.Compare ("Earth", "Venus"));
}
[Test]
public void TestCompare_Culture ()
{
CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
try {
Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
// the default ctor is initialized using Thread.CurrentCulture
CaseInsensitiveComparer cic = new CaseInsensitiveComparer ();
Assert.AreEqual (-1, cic.Compare ("I", "i"), "#A1");
Assert.AreEqual (0, cic.Compare ("A", "a"), "#A2");
// changing the current culture does not affect an already
// initialized CaseInsensitiveComparer
Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE");
Assert.AreEqual (-1, cic.Compare ("I", "i"), "#B1");
Assert.AreEqual (0, cic.Compare ("A", "a"), "#B2");
// but it does affect new instances
cic = new CaseInsensitiveComparer ();
Assert.AreEqual (0, cic.Compare ("I", "i"), "#C1");
Assert.AreEqual (0, cic.Compare ("A", "a"), "#C2");
// if the culture is explicitly set, then the thread culture is
// ignored
cic = new CaseInsensitiveComparer (new CultureInfo ("tr-TR"));
Assert.AreEqual (-1, cic.Compare ("I", "i"), "#D1");
Assert.AreEqual (0, cic.Compare ("A", "a"), "#D2");
} finally {
// restore original culture
Thread.CurrentThread.CurrentCulture = originalCulture;
}
}
[Test]
[Category ("NotWorking")] // bug #80076
public void Default ()
{
CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
try {
Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
// CaseInsensitiveComparer.Default is initialized using
// Thread.CurrentCulture
CaseInsensitiveComparer cic = CaseInsensitiveComparer.Default;
Assert.AreEqual (-1, cic.Compare ("I", "i"), "#A1");
Assert.AreEqual (0, cic.Compare ("A", "a"), "#A2");
// changing the current culture does not affect an already
// initialized CaseInsensitiveComparer
Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE");
Assert.AreEqual (-1, cic.Compare ("I", "i"), "#B1");
Assert.AreEqual (0, cic.Compare ("A", "a"), "#B2");
// but it does affect new instances
cic = CaseInsensitiveComparer.Default;
Assert.AreEqual (0, cic.Compare ("I", "i"), "#C1");
Assert.AreEqual (0, cic.Compare ("A", "a"), "#C2");
} finally {
// restore original culture
Thread.CurrentThread.CurrentCulture = originalCulture;
}
}
[Test]
public void TestIntsNEq()
{
int a =1;
int b =2;
Assert.AreEqual (Comparer.Default.Compare (a, b), CaseInsensitiveComparer.Default.Compare (a, b));
}
[Test]
public void TestIntsEq()
{
int a =1;
int b =1;
Assert.AreEqual (Comparer.Default.Compare (a, b), CaseInsensitiveComparer.Default.Compare(a, b));
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CtorNull()
{
new CaseInsensitiveComparer(null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void TestObject()
{
object a = new object();
object b = new object();
CaseInsensitiveComparer.Default.Compare(a, b);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void TestDiffArgs()
{
int a = 5;
string b = "hola";
CaseInsensitiveComparer.Default.Compare(a, b);
}
[Test]
public void TestNull1()
{
string a = null;
string b = "5";
Assert.AreEqual (Comparer.Default.Compare (a, b), CaseInsensitiveComparer.Default.Compare (a, b));
}
[Test]
public void TestNull2()
{
string a = null;
string b = null;
Assert.AreEqual (Comparer.Default.Compare (a, b), CaseInsensitiveComparer.Default.Compare (a, b));
}
[Test]
public void TestStringsCaps()
{
string a = "AA";
string b = "aa";
Assert.AreEqual (0, CaseInsensitiveComparer.Default.Compare (a, b));
}
// CompareInfo does not have value for win32LCID field, and as a result
// we have no perfect match
[Test]
[Category ("NotWorking")]
public void Serialize_Culture ()
{
CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
try {
Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE");
BinaryFormatter bf = new BinaryFormatter ();
MemoryStream ms = new MemoryStream ();
bf.Serialize (ms, new CaseInsensitiveComparer (new CultureInfo ("tr-TR")));
byte [] buffer = new byte [ms.Length];
ms.Position = 0;
ms.Read (buffer, 0, buffer.Length);
#if NET_2_0
Assert.AreEqual (_serializedCultureV20, buffer);
#else
Assert.AreEqual (_serializedCultureV11, buffer);
#endif
} finally {
// restore original culture
Thread.CurrentThread.CurrentCulture = originalCulture;
}
}
[Test]
#if NET_2_0
[Category ("NotWorking")] // bug #80082
#else
[Category ("NotWorking")] // bug #80076
#endif
public void Deserialize_Culture ()
{
CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
try {
Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE");
MemoryStream ms = new MemoryStream ();
ms.Write (_serializedCultureV11, 0, _serializedCultureV11.Length);
ms.Position = 0;
BinaryFormatter bf = new BinaryFormatter ();
CaseInsensitiveComparer cic = (CaseInsensitiveComparer)
bf.Deserialize (ms);
Assert.IsNotNull (cic, "#1");
#if NET_2_0
ms = new MemoryStream ();
ms.Write (_serializedCultureV20, 0, _serializedCultureV20.Length);
ms.Position = 0;
bf = new BinaryFormatter ();
cic = (CaseInsensitiveComparer) bf.Deserialize (ms);
Assert.IsNotNull (cic, "#2");
#endif
} finally {
// restore original culture
Thread.CurrentThread.CurrentCulture = originalCulture;
}
}
// CompareInfo does not have value for win32LCID field, and as a result
// we have no perfect match
[Test]
[Category ("NotWorking")]
public void Serialize_Default ()
{
CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
try {
Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE");
BinaryFormatter bf = new BinaryFormatter ();
MemoryStream ms = new MemoryStream ();
bf.Serialize (ms, CaseInsensitiveComparer.Default);
byte [] buffer = new byte [ms.Length];
ms.Position = 0;
ms.Read (buffer, 0, buffer.Length);
#if NET_2_0
Assert.AreEqual (_serializedDefaultV20, buffer);
#else
Assert.AreEqual (_serializedDefaultV11, buffer);
#endif
} finally {
// restore original culture
Thread.CurrentThread.CurrentCulture = originalCulture;
}
}
[Test]
#if NET_2_0
[Category ("NotWorking")] // bug #80082
#else
[Category ("NotWorking")] // bug #80076
#endif
public void Deserialize_Default ()
{
CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
try {
Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE");
MemoryStream ms = new MemoryStream ();
ms.Write (_serializedDefaultV11, 0, _serializedDefaultV11.Length);
ms.Position = 0;
BinaryFormatter bf = new BinaryFormatter ();
CaseInsensitiveComparer cic = (CaseInsensitiveComparer)
bf.Deserialize (ms);
Assert.IsNotNull (cic, "#1");
#if NET_2_0
ms = new MemoryStream ();
ms.Write (_serializedDefaultV20, 0, _serializedDefaultV20.Length);
ms.Position = 0;
bf = new BinaryFormatter ();
cic = (CaseInsensitiveComparer) bf.Deserialize (ms);
Assert.IsNotNull (cic, "#2");
#endif
} finally {
// restore original culture
Thread.CurrentThread.CurrentCulture = originalCulture;
}
}
// CompareInfo does not have value for win32LCID field, and as a result
// we have no perfect match
[Test]
[Category ("NotWorking")]
public void Serialize_DefaultInvariant ()
{
CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
try {
Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE");
BinaryFormatter bf = new BinaryFormatter ();
MemoryStream ms = new MemoryStream ();
bf.Serialize (ms, CaseInsensitiveComparer.DefaultInvariant);
byte [] buffer = new byte [ms.Length];
ms.Position = 0;
ms.Read (buffer, 0, buffer.Length);
#if NET_2_0
Assert.AreEqual (_serializedDefaultInvariantV20, buffer);
#else
Assert.AreEqual (_serializedDefaultInvariantV11, buffer);
#endif
} finally {
// restore original culture
Thread.CurrentThread.CurrentCulture = originalCulture;
}
}
[Test]
#if NET_2_0
[Category ("NotWorking")] // bug #80082
#else
[Category ("NotWorking")] // bug #80076
#endif
public void Deserialize_DefaultInvariant ()
{
CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
try {
Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE");
MemoryStream ms = new MemoryStream ();
ms.Write (_serializedDefaultInvariantV11, 0, _serializedDefaultInvariantV11.Length);
ms.Position = 0;
BinaryFormatter bf = new BinaryFormatter ();
CaseInsensitiveComparer cic = (CaseInsensitiveComparer)
bf.Deserialize (ms);
Assert.IsNotNull (cic, "#1");
#if NET_2_0
ms = new MemoryStream ();
ms.Write (_serializedDefaultInvariantV20, 0, _serializedDefaultInvariantV20.Length);
ms.Position = 0;
bf = new BinaryFormatter ();
cic = (CaseInsensitiveComparer) bf.Deserialize (ms);
Assert.IsNotNull (cic, "#2");
#endif
} finally {
// restore original culture
Thread.CurrentThread.CurrentCulture = originalCulture;
}
}
private static byte [] _serializedDefaultV11 = new byte [] {
0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00,
0x2a, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x43, 0x6f, 0x6c,
0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x43, 0x61,
0x73, 0x65, 0x49, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x69, 0x74, 0x69,
0x76, 0x65, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65, 0x72, 0x01,
0x00, 0x00, 0x00, 0x0d, 0x6d, 0x5f, 0x63, 0x6f, 0x6d, 0x70, 0x61,
0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x03, 0x20, 0x53, 0x79, 0x73,
0x74, 0x65, 0x6d, 0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69,
0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70,
0x61, 0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x09, 0x02, 0x00, 0x00,
0x00, 0x04, 0x02, 0x00, 0x00, 0x00, 0x20, 0x53, 0x79, 0x73, 0x74,
0x65, 0x6d, 0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69, 0x7a,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x61,
0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x02, 0x00, 0x00, 0x00, 0x09,
0x77, 0x69, 0x6e, 0x33, 0x32, 0x4c, 0x43, 0x49, 0x44, 0x07, 0x63,
0x75, 0x6c, 0x74, 0x75, 0x72, 0x65, 0x00, 0x00, 0x08, 0x08, 0x13,
0x08, 0x00, 0x00, 0x13, 0x08, 0x00, 0x00, 0x0b };
private static byte [] _serializedCultureV11 = new byte [] {
0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00,
0x2a, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x43, 0x6f, 0x6c,
0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x43, 0x61,
0x73, 0x65, 0x49, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x69, 0x74, 0x69,
0x76, 0x65, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65, 0x72, 0x01,
0x00, 0x00, 0x00, 0x0d, 0x6d, 0x5f, 0x63, 0x6f, 0x6d, 0x70, 0x61,
0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x03, 0x20, 0x53, 0x79, 0x73,
0x74, 0x65, 0x6d, 0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69,
0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70,
0x61, 0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x09, 0x02, 0x00, 0x00,
0x00, 0x04, 0x02, 0x00, 0x00, 0x00, 0x20, 0x53, 0x79, 0x73, 0x74,
0x65, 0x6d, 0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69, 0x7a,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x61,
0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x02, 0x00, 0x00, 0x00, 0x09,
0x77, 0x69, 0x6e, 0x33, 0x32, 0x4c, 0x43, 0x49, 0x44, 0x07, 0x63,
0x75, 0x6c, 0x74, 0x75, 0x72, 0x65, 0x00, 0x00, 0x08, 0x08, 0x1f,
0x04, 0x00, 0x00, 0x1f, 0x04, 0x00, 0x00, 0x0b };
private static byte [] _serializedDefaultInvariantV11 = new byte [] {
0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00,
0x2a, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x43, 0x6f, 0x6c,
0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x43, 0x61,
0x73, 0x65, 0x49, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x69, 0x74, 0x69,
0x76, 0x65, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65, 0x72, 0x01,
0x00, 0x00, 0x00, 0x0d, 0x6d, 0x5f, 0x63, 0x6f, 0x6d, 0x70, 0x61,
0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x03, 0x20, 0x53, 0x79, 0x73,
0x74, 0x65, 0x6d, 0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69,
0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70,
0x61, 0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x09, 0x02, 0x00, 0x00,
0x00, 0x04, 0x02, 0x00, 0x00, 0x00, 0x20, 0x53, 0x79, 0x73, 0x74,
0x65, 0x6d, 0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69, 0x7a,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x61,
0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x02, 0x00, 0x00, 0x00, 0x09,
0x77, 0x69, 0x6e, 0x33, 0x32, 0x4c, 0x43, 0x49, 0x44, 0x07, 0x63,
0x75, 0x6c, 0x74, 0x75, 0x72, 0x65, 0x00, 0x00, 0x08, 0x08, 0x7f,
0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x0b };
#if NET_2_0
private static byte [] _serializedDefaultV20 = new byte [] {
0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00,
0x2a, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x43, 0x6f, 0x6c,
0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x43, 0x61,
0x73, 0x65, 0x49, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x69, 0x74, 0x69,
0x76, 0x65, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65, 0x72, 0x01,
0x00, 0x00, 0x00, 0x0d, 0x6d, 0x5f, 0x63, 0x6f, 0x6d, 0x70, 0x61,
0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x03, 0x20, 0x53, 0x79, 0x73,
0x74, 0x65, 0x6d, 0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69,
0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70,
0x61, 0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x09, 0x02, 0x00, 0x00,
0x00, 0x04, 0x02, 0x00, 0x00, 0x00, 0x20, 0x53, 0x79, 0x73, 0x74,
0x65, 0x6d, 0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69, 0x7a,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x61,
0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x03, 0x00, 0x00, 0x00, 0x09,
0x77, 0x69, 0x6e, 0x33, 0x32, 0x4c, 0x43, 0x49, 0x44, 0x07, 0x63,
0x75, 0x6c, 0x74, 0x75, 0x72, 0x65, 0x06, 0x6d, 0x5f, 0x6e, 0x61,
0x6d, 0x65, 0x00, 0x00, 0x01, 0x08, 0x08, 0x13, 0x08, 0x00, 0x00,
0x13, 0x08, 0x00, 0x00, 0x06, 0x03, 0x00, 0x00, 0x00, 0x05, 0x6e,
0x6c, 0x2d, 0x42, 0x45, 0x0b };
private static byte [] _serializedDefaultInvariantV20 = new byte [] {
0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00,
0x2a, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x43, 0x6f, 0x6c,
0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x43, 0x61,
0x73, 0x65, 0x49, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x69, 0x74, 0x69,
0x76, 0x65, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65, 0x72, 0x01,
0x00, 0x00, 0x00, 0x0d, 0x6d, 0x5f, 0x63, 0x6f, 0x6d, 0x70, 0x61,
0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x03, 0x20, 0x53, 0x79, 0x73,
0x74, 0x65, 0x6d, 0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69,
0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70,
0x61, 0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x09, 0x02, 0x00, 0x00,
0x00, 0x04, 0x02, 0x00, 0x00, 0x00, 0x20, 0x53, 0x79, 0x73, 0x74,
0x65, 0x6d, 0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69, 0x7a,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x61,
0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x03, 0x00, 0x00, 0x00, 0x09,
0x77, 0x69, 0x6e, 0x33, 0x32, 0x4c, 0x43, 0x49, 0x44, 0x07, 0x63,
0x75, 0x6c, 0x74, 0x75, 0x72, 0x65, 0x06, 0x6d, 0x5f, 0x6e, 0x61,
0x6d, 0x65, 0x00, 0x00, 0x01, 0x08, 0x08, 0x7f, 0x00, 0x00, 0x00,
0x7f, 0x00, 0x00, 0x00, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x0b };
private static byte [] _serializedCultureV20 = new byte [] {
0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00,
0x2a, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x43, 0x6f, 0x6c,
0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x43, 0x61,
0x73, 0x65, 0x49, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x69, 0x74, 0x69,
0x76, 0x65, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65, 0x72, 0x01,
0x00, 0x00, 0x00, 0x0d, 0x6d, 0x5f, 0x63, 0x6f, 0x6d, 0x70, 0x61,
0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x03, 0x20, 0x53, 0x79, 0x73,
0x74, 0x65, 0x6d, 0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69,
0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70,
0x61, 0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x09, 0x02, 0x00, 0x00,
0x00, 0x04, 0x02, 0x00, 0x00, 0x00, 0x20, 0x53, 0x79, 0x73, 0x74,
0x65, 0x6d, 0x2e, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x69, 0x7a,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x61,
0x72, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x03, 0x00, 0x00, 0x00, 0x09,
0x77, 0x69, 0x6e, 0x33, 0x32, 0x4c, 0x43, 0x49, 0x44, 0x07, 0x63,
0x75, 0x6c, 0x74, 0x75, 0x72, 0x65, 0x06, 0x6d, 0x5f, 0x6e, 0x61,
0x6d, 0x65, 0x00, 0x00, 0x01, 0x08, 0x08, 0x1f, 0x04, 0x00, 0x00,
0x1f, 0x04, 0x00, 0x00, 0x06, 0x03, 0x00, 0x00, 0x00, 0x05, 0x74,
0x72, 0x2d, 0x54, 0x52, 0x0b };
#endif
}
}

View File

@@ -0,0 +1,277 @@
//
// CaseInsensitiveHashCodeProviderTest
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
using System;
using System.Collections;
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
{
private CultureInfo old_culture;
[SetUp]
public void SetUp ()
{
old_culture = Thread.CurrentThread.CurrentCulture;
}
[TearDown]
public void TearDown ()
{
Thread.CurrentThread.CurrentCulture = old_culture;
}
[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");
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");
}
[Test]
[Category ("NotDotNet")]
public void Default_Mono ()
{
// we return same instance if current culture did not change
CaseInsensitiveHashCodeProvider cih1 = CaseInsensitiveHashCodeProvider.Default;
CaseInsensitiveHashCodeProvider cih2 = CaseInsensitiveHashCodeProvider.Default;
Assert.IsTrue (object.ReferenceEquals (cih1, cih2));
}
[Test]
[Category ("NotWorking")]
public void Default_MS ()
{
// MS always returns new instance
CaseInsensitiveHashCodeProvider cih1 = CaseInsensitiveHashCodeProvider.Default;
CaseInsensitiveHashCodeProvider cih2 = CaseInsensitiveHashCodeProvider.Default;
Assert.IsFalse (object.ReferenceEquals (cih1, cih2));
}
#if NET_2_0
[Test]
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));
}
#endif
[Test]
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);
}
[Test]
public void Constructor0_Serialization ()
{
CaseInsensitiveHashCodeProvider cihcp = new CaseInsensitiveHashCodeProvider ();
BinaryFormatter bf = new BinaryFormatter ();
MemoryStream ms = new MemoryStream ();
bf.Serialize (ms, cihcp);
byte[] ser1 = ms.ToArray ();
cihcp = new CaseInsensitiveHashCodeProvider (CultureInfo.CurrentCulture);
ms = new MemoryStream ();
bf.Serialize (ms, cihcp);
byte[] ser2 = ms.ToArray ();
cihcp = CaseInsensitiveHashCodeProvider.Default;
ms = new MemoryStream ();
bf.Serialize (ms, cihcp);
byte[] ser3 = ms.ToArray ();
Assert.AreEqual (ser1, ser2, "#1");
Assert.AreEqual (ser2, ser3, "#2");
}
[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)vmw.@internal.remoting.BinaryFormatterUtils.CreateBinaryFormatter (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,
0x43, 0x61, 0x73, 0x65, 0x49, 0x6E, 0x73, 0x65, 0x6E, 0x73, 0x69, 0x74, 0x69, 0x76, 0x65, 0x48,
0x61, 0x73, 0x68, 0x43, 0x6F, 0x64, 0x65, 0x50, 0x72, 0x6F, 0x76, 0x69, 0x64, 0x65, 0x72, 0x01,
0x00, 0x00, 0x00, 0x06, 0x6D, 0x5F, 0x74, 0x65, 0x78, 0x74, 0x03, 0x1D, 0x53, 0x79, 0x73, 0x74,
0x65, 0x6D, 0x2E, 0x47, 0x6C, 0x6F, 0x62, 0x61, 0x6C, 0x69, 0x7A, 0x61, 0x74, 0x69, 0x6F, 0x6E,
0x2E, 0x54, 0x65, 0x78, 0x74, 0x49, 0x6E, 0x66, 0x6F, 0x09, 0x02, 0x00, 0x00, 0x00, 0x04, 0x02,
0x00, 0x00, 0x00, 0x1D, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x47, 0x6C, 0x6F, 0x62, 0x61,
0x6C, 0x69, 0x7A, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x2E, 0x54, 0x65, 0x78, 0x74, 0x49, 0x6E, 0x66,
0x6F, 0x06, 0x00, 0x00, 0x00, 0x0F, 0x6D, 0x5F, 0x6C, 0x69, 0x73, 0x74, 0x53, 0x65, 0x70, 0x61,
0x72, 0x61, 0x74, 0x6F, 0x72, 0x0C, 0x6D, 0x5F, 0x69, 0x73, 0x52, 0x65, 0x61, 0x64, 0x4F, 0x6E,
0x6C, 0x79, 0x11, 0x63, 0x75, 0x73, 0x74, 0x6F, 0x6D, 0x43, 0x75, 0x6C, 0x74, 0x75, 0x72, 0x65,
0x4E, 0x61, 0x6D, 0x65, 0x0B, 0x6D, 0x5F, 0x6E, 0x44, 0x61, 0x74, 0x61, 0x49, 0x74, 0x65, 0x6D,
0x11, 0x6D, 0x5F, 0x75, 0x73, 0x65, 0x55, 0x73, 0x65, 0x72, 0x4F, 0x76, 0x65, 0x72, 0x72, 0x69,
0x64, 0x65, 0x0D, 0x6D, 0x5F, 0x77, 0x69, 0x6E, 0x33, 0x32, 0x4C, 0x61, 0x6E, 0x67, 0x49, 0x44,
0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x01, 0x08, 0x0A, 0x00, 0x0A, 0x29, 0x00, 0x00,
0x00, 0x01, 0x09, 0x04, 0x00, 0x00, 0x0B
#else
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, 0x43, 0x61, 0x73, 0x65, 0x49, 0x6E,
0x73, 0x65, 0x6E, 0x73, 0x69, 0x74, 0x69, 0x76, 0x65, 0x48, 0x61, 0x73, 0x68, 0x43, 0x6F, 0x64,
0x65, 0x50, 0x72, 0x6F, 0x76, 0x69, 0x64, 0x65, 0x72, 0x01, 0x00, 0x00, 0x00, 0x06, 0x6D, 0x5F,
0x74, 0x65, 0x78, 0x74, 0x03, 0x1D, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x47, 0x6C, 0x6F,
0x62, 0x61, 0x6C, 0x69, 0x7A, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x2E, 0x54, 0x65, 0x78, 0x74, 0x49,
0x6E, 0x66, 0x6F, 0x09, 0x02, 0x00, 0x00, 0x00, 0x04, 0x02, 0x00, 0x00, 0x00, 0x1D, 0x53, 0x79,
0x73, 0x74, 0x65, 0x6D, 0x2E, 0x47, 0x6C, 0x6F, 0x62, 0x61, 0x6C, 0x69, 0x7A, 0x61, 0x74, 0x69,
0x6F, 0x6E, 0x2E, 0x54, 0x65, 0x78, 0x74, 0x49, 0x6E, 0x66, 0x6F, 0x03, 0x00, 0x00, 0x00, 0x0B,
0x6D, 0x5F, 0x6E, 0x44, 0x61, 0x74, 0x61, 0x49, 0x74, 0x65, 0x6D, 0x11, 0x6D, 0x5F, 0x75, 0x73,
0x65, 0x55, 0x73, 0x65, 0x72, 0x4F, 0x76, 0x65, 0x72, 0x72, 0x69, 0x64, 0x65, 0x0D, 0x6D, 0x5F,
0x77, 0x69, 0x6E, 0x33, 0x32, 0x4C, 0x61, 0x6E, 0x67, 0x49, 0x44, 0x00, 0x00, 0x00, 0x08, 0x01,
0x08, 0x29, 0x00, 0x00, 0x00, 0x01, 0x09, 0x04, 0x00, 0x00, 0x0B
#endif
};
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,
0x74, 0x65, 0x6D, 0x2E, 0x43, 0x6F, 0x6C, 0x6C, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x73, 0x2E,
0x43, 0x61, 0x73, 0x65, 0x49, 0x6E, 0x73, 0x65, 0x6E, 0x73, 0x69, 0x74, 0x69, 0x76, 0x65, 0x48,
0x61, 0x73, 0x68, 0x43, 0x6F, 0x64, 0x65, 0x50, 0x72, 0x6F, 0x76, 0x69, 0x64, 0x65, 0x72, 0x01,
0x00, 0x00, 0x00, 0x06, 0x6D, 0x5F, 0x74, 0x65, 0x78, 0x74, 0x03, 0x1D, 0x53, 0x79, 0x73, 0x74,
0x65, 0x6D, 0x2E, 0x47, 0x6C, 0x6F, 0x62, 0x61, 0x6C, 0x69, 0x7A, 0x61, 0x74, 0x69, 0x6F, 0x6E,
0x2E, 0x54, 0x65, 0x78, 0x74, 0x49, 0x6E, 0x66, 0x6F, 0x09, 0x02, 0x00, 0x00, 0x00, 0x04, 0x02,
0x00, 0x00, 0x00, 0x1D, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x47, 0x6C, 0x6F, 0x62, 0x61,
0x6C, 0x69, 0x7A, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x2E, 0x54, 0x65, 0x78, 0x74, 0x49, 0x6E, 0x66,
0x6F, 0x06, 0x00, 0x00, 0x00, 0x0F, 0x6D, 0x5F, 0x6C, 0x69, 0x73, 0x74, 0x53, 0x65, 0x70, 0x61,
0x72, 0x61, 0x74, 0x6F, 0x72, 0x0C, 0x6D, 0x5F, 0x69, 0x73, 0x52, 0x65, 0x61, 0x64, 0x4F, 0x6E,
0x6C, 0x79, 0x11, 0x63, 0x75, 0x73, 0x74, 0x6F, 0x6D, 0x43, 0x75, 0x6C, 0x74, 0x75, 0x72, 0x65,
0x4E, 0x61, 0x6D, 0x65, 0x0B, 0x6D, 0x5F, 0x6E, 0x44, 0x61, 0x74, 0x61, 0x49, 0x74, 0x65, 0x6D,
0x11, 0x6D, 0x5F, 0x75, 0x73, 0x65, 0x55, 0x73, 0x65, 0x72, 0x4F, 0x76, 0x65, 0x72, 0x72, 0x69,
0x64, 0x65, 0x0D, 0x6D, 0x5F, 0x77, 0x69, 0x6E, 0x33, 0x32, 0x4C, 0x61, 0x6E, 0x67, 0x49, 0x44,
0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x01, 0x08, 0x0A, 0x00, 0x0A, 0x50, 0x00, 0x00,
0x00, 0x01, 0x0C, 0x0C, 0x00, 0x00, 0x0B
#else
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, 0x43, 0x61, 0x73, 0x65, 0x49, 0x6E,
0x73, 0x65, 0x6E, 0x73, 0x69, 0x74, 0x69, 0x76, 0x65, 0x48, 0x61, 0x73, 0x68, 0x43, 0x6F, 0x64,
0x65, 0x50, 0x72, 0x6F, 0x76, 0x69, 0x64, 0x65, 0x72, 0x01, 0x00, 0x00, 0x00, 0x06, 0x6D, 0x5F,
0x74, 0x65, 0x78, 0x74, 0x03, 0x1D, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x47, 0x6C, 0x6F,
0x62, 0x61, 0x6C, 0x69, 0x7A, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x2E, 0x54, 0x65, 0x78, 0x74, 0x49,
0x6E, 0x66, 0x6F, 0x09, 0x02, 0x00, 0x00, 0x00, 0x04, 0x02, 0x00, 0x00, 0x00, 0x1D, 0x53, 0x79,
0x73, 0x74, 0x65, 0x6D, 0x2E, 0x47, 0x6C, 0x6F, 0x62, 0x61, 0x6C, 0x69, 0x7A, 0x61, 0x74, 0x69,
0x6F, 0x6E, 0x2E, 0x54, 0x65, 0x78, 0x74, 0x49, 0x6E, 0x66, 0x6F, 0x03, 0x00, 0x00, 0x00, 0x0B,
0x6D, 0x5F, 0x6E, 0x44, 0x61, 0x74, 0x61, 0x49, 0x74, 0x65, 0x6D, 0x11, 0x6D, 0x5F, 0x75, 0x73,
0x65, 0x55, 0x73, 0x65, 0x72, 0x4F, 0x76, 0x65, 0x72, 0x72, 0x69, 0x64, 0x65, 0x0D, 0x6D, 0x5F,
0x77, 0x69, 0x6E, 0x33, 0x32, 0x4C, 0x61, 0x6E, 0x67, 0x49, 0x44, 0x00, 0x00, 0x00, 0x08, 0x01,
0x08, 0x50, 0x00, 0x00, 0x00, 0x01, 0x0C, 0x0C, 0x00, 0x00, 0x0B
#endif
};
}
}

View File

@@ -0,0 +1,440 @@
2009-07-14 Gonzalo Paniagua Javier <gonzalo@novell.com>
* SortedListTest.cs: new tests by Kevin Fitzgerald.
2009-06-30 Zoltan Varga <vargaz@gmail.com>
* ReadOnlyCollectionBaseTest.cs NewArrayListTest.cs: Convert all tests
to new-style nunit classes/methods.
2009-06-26 Robert Jordan <robertj@gmx.net>
* BitArrayTest.cs: Upgrade to new NUnit style. Enable
16 tests that were disabled after the NUnit 2.4 update.
2009-06-24 Robert Jordan <robertj@gmx.net>
* ArrayListTest.cs, CollectionBaseTest.cs, DictionaryEntryTest.cs,
HashtableTest.cs: Convert all tests to new-style nunit methods.
* QueueTest.cs: likewise. Conversion revealed 25 test that were
disabled after the NUnit 2.4 update.
* StackTest.cs: likewise. Conversion revealed 24 test that were
disabled after the NUnit 2.4 update.
2008-08-31 Zoltan Varga <vargaz@gmail.com>
* BitArrayTest.cs: Add a test for #421803.
2008-05-08 Robert Jordan <robertj@gmx.net>
* DictionaryEntryTest.cs: Add tests for key's argument validation.
2008-03-24 Gert Driesen <drieseng@users.sourceforge.net>
* DictionaryBaseTest.cs: Improved existing tests, and use Assert class
instead of deriving from deprecated Assertion class. Code formatting.
2008-03-21 Sebastien Pouliot <sebastien@ximian.com>
* DictionaryBaseTest.cs: Add test case to see when and how OnGet
is being called.
2007-11-06 Jb Evain <jbevain@novell.com>
* HashtableTest.cs: Add test case for #324761.
2007-11-05 Sebastien Pouliot <sebastien@ximian.com>
* QueueTest.cs: Test cases for #321657. Based on the test case
supplied by Benjamin Lutz.
2007-10-27 Gert Driesen <drieseng@users.sourceforge.net>
* SortedListTest.cs: Fixed deserialization test to pass on MS.
2007-10-23 Gert Driesen <drieseng@users.sourceforge.net>
* SortedListTest.cs: No longer derive from deprecated Assertion class.
Added serialization tests, and a (NotWorking) deserialization test.
2007-07-05 Gert Driesen <drieseng@users.sourceforge.net>
* CaseInsensitiveHashCodeProviderTest.cs: Reworked test for Default
instance to pass on both Mono and MS. Added separate tests that
verify the specific Mono and MS behavior.
2007-07-05 Gert Driesen <drieseng@users.sourceforge.net>
* 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 <drieseng@users.sourceforge.net>
* ArrayListTest.cs: Code formatting (indenting, spaces to tabs). Added
tests for bugs fixed in .NET 2.0.
2007-02-13 Boris Kirzner <borisk@mainsoft.com>
* CaseInsensitiveHashCodeProviderTest.cs, HashtableTest.cs:
test ifdefs for TARGET_JVM.
2006-11-28 Gert Driesen <drieseng@users.sourceforge.net>
* CaseInsensitiveComparerTest.cs: Added tests for bug #80082 and bug
#80076. Improved existing tests.
2006-08-08 Duncan Mak <duncan@novell.com>
* ReadOnlyCollectionBaseTest.cs (TestZeroCountOnNew): Add test for
overriding Count in NET_2_0 for #79033.
2006-04-25 Atsushi Enomoto <atsushi@ximian.com>
* QueueTest.cs, SortedListTest.cs : many capacity-related tests are
written under improper assumption. As a result they don't pass when
we run make PROFILE=net_2_0 run-test-ondotnet, so got rid of them.
2006-01-04 Sebastien Pouliot <sebastien@ximian.com>
* HashtableTest.cs: Added test case to check if all subclasses are
serializable.
2005-12-19 Sebastien Pouliot <sebastien@ximian.com>
* ArrayListTest.cs: Added test cases for a binary search with an empty
list (bug #77030). Fixed other test cases so they execute without
failures under MS 2.0.
2005-12-07 Sebastien Pouliot <sebastien@ximian.com>
* SortedTestList.cs: Added more test for the constructor accepting an
IComparer and to avoid regression of bug #76750.
2005-12-06 Sebastien Pouliot <sebastien@ximian.com>
* CaseInsensitiveHashCodeProviderTest: Added test cases for the
default ctor, roudtripping serialization and deserializing data
generated on MS 1.1 and 2.0.
2005-12-05 Sebastien Pouliot <sebastien@ximian.com>
* ComparerTest.cs: Removed "NotWorking" from "Invariant" test case
(it's now working). Added new test cases for ISerializable (added in
SP1 and present in 2.0) and completed coverage with tests for ctor.
2005-09-01 Atsushi Enomoto <atsushi@ximian.com>
* HashtableTest.cs : testcase for #75790.
2005-09-01 Atsushi Enomoto <atsushi@ximian.com>
* SortedListTest.cs : testcase for #59694.
2005-07-19 Ben Maurer <bmaurer@ximian.com>
* ArrayListTest.cs: The patch below was not committed with the
same text as the patch on the bug. There was an s/1/3. Doing the
patch as specified on the bug makes buildbot work and the test
work on msft
2005-07-17 Florian Gross <flgr@ccan.de>
* ArrayListTest.cs: Test for #75545.
2005-06-23 Ben Maurer <bmaurer@ximian.com>
* QueueTest.cs, StackTest.cs: Test for #75369.
2005-05-26 Ben Maurer <bmaurer@ximian.com>
* QueueTest.cs: New test.
2005-05-09 Atsushi Enomoto <atsushi@ximian.com>
* StackTest.cs : test for CopyTo() on an empty stack.
2005-01-05 Nick Drochak <ndrochak@ieee.org>
* ComparerTest.cs: Modernize and fix line endings. Test is failing with
mono, see if this change has any effect.
2004-12-16 Lluis Sanchez Gual <lluis@novell.com>
* HashtableTest.cs: Added test for bug #70570.
2004-08-24 Nick Drochak <ndrochak@ieee.org>
* ComparerTest.cs: On MS.NET 1.1 Compare("a", "A") returns < 0.
2004-07-28 Dick Porter <dick@ximian.com>
* ComparerTest.cs: Test for invariant compares (bug 61458.)
2004-06-14 Sebastien Pouliot <sebastien@ximian.com>
* HashtableTest.cs: Added new case to CopyTo(Array,int) an empty
hashtable.
* SortedListTest.cs: Un-ignored TestCapacity4 test case as it now
works correctly under Mono.
2004-06-01 Sebastien Pouliot <sebastien@ximian.com>
* SortedListTest.cs: Added new test when initial capacity is set to 0
(so it never returns to default, 16, when Capacity is set to 0) unless
Clear is called. Cleaned up unused SetUp/TearDown.
2004-05-31 Sebastien Pouliot <sebastien@ximian.com>
* ArrayListTest.cs: Added new test for null in BinarySearch.
* HashtableTest.cs: Added null checking fro GetObjectData.
2004-05-27 Sebastien Pouliot <sebastien@ximian.com>
* HashtableTest.cs: Added case where a cloned hashtable must also be
synchronized (if the original was).
* QueueTest.cs: Added case where we try to get Current after the last
MoveNext. Added case to ensure that MoveNext always return false
(after the first time). Test for synchronized clones.
* SortedListTest.cs: Added cases for synchronized capacity and testing
the interface from the internal enumerator. Test that setting Capacity
to zero return the capacity to it's initial default (16).
2004-05-26 Sebastien Pouliot <sebastien@ximian.com>
* ArrayListTest.cs: Added tests for integer overflows.
2003-12-01 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* QueueTest.cs: added more tests. Patch from Carlos Barcenilla.
2003-11-10 Zoltan Varga <vargaz@freemail.hu>
* StackTest.cs: Applied patch from Carlos A. Barcenilla to fix minor
bugs (#50755).
2003-10-10 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* HashtableTest.cs: patch from Carlos A. Barcenilla
(barce@frlp.utn.edu.ar) that includes some fixes for Hashtable +
NUnit2 tests.
2003-10-07 Nick Drochak <ndrochak@gol.com>
* DictionaryBaseTest.cs:
* NewArrayListTest.cs: Clean up warnings that were annoying me.
2003-08-12 Nick Drochak <ndrochak@gol.com>
* NewArrayListTest.cs: Disable part that was failing on .NET. Marked
with FIXME.
2003-08-11 Duncan Mak <duncan@ximian.com>
* ArrayListTest.cs: Added test case submitted by Tum in bug #45036.
* DictionaryBaseTest.cs: added new test provided by Carlos Barcenilla
(barce@frlp.utn.edu.ar).
2003-08-10 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* CollectionBaseTest.cs: added new test provided by Carlos Barcenilla
(barce@frlp.utn.edu.ar).
2003-08-03 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* CollectionBaseTest.cs: added a few more tests. Now derives from
Assertion.
2003-06-20 Nick Drochak <ndrochak@gol.com>
* SortedListTest.cs: Make it pass on .NET 1.1.
2003-06-14 Duncan Mak <duncan@ximian.com>
* SortedListTest.cs
(TestIndexer):
(TestEnumerator): Incorporated these two tests from Philippe
Lavoie <philippe.lavoie@cactus.ca>.
2003-06-12 Duncan Mak <duncan@ximian.com>
* HashtableTest.cs: Converted it to the new style of NUnit tests.
(TestCtor3):
(TestCtor4): new tests for the constructor.
2003-06-11 Duncan Mak <duncan@ximian.com>
* SortedListTest.cs: Convert it to the new style of NUnit tests.
(TestCapacity2):
(TestCapacity3):
(TestCapacity4): new tests for the Capacity property.
(TestIndexOfValue2):
(TestIndexOfValue3): new tests for the IndexOfValue method.
2003-06-11 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* HashtableTest.cs: removed duplicate tests and unneeded inner class.
2003-06-07 Ben Maurer <bmaurer@users.sourceforge.net>
* StackTest.cs: Added test for Contains (null)
2003-05-13 Nick Drochak <ndrochak@gol.com>
* DictionaryEntry.cs: Added test
2003-05-03 Ben Maurer <bmaurer@users.sourceforge.net>
* ArrayListTest.cs:
Tests for the above* ArrayList.cs
Added methods to support IList wrappers
2003-04-15 Eduardo Garcia Cebollero <kiwnix@yahoo.es>
* CaseInsensitiveComparerTest.cs: Added Some Tests.
2003-04-09 Ville Palo <vi64pa@kolumbus.fi>
* ArraListTest.cs: Added little test for Sort ().
2003-02-15 Nick Drochak <ndrochak@gol.com>
* CollectionBaseTest.cs: Make it a better NUnit v2 example
2003-02-15 Pedro Martínez Juliá <yoros@wanadoo.es>
* HashtableTest.cs: Add serialization test.
2002-12-21 Nick Drochak <ndrochak@gol.com>
* all: make tests build and run under nunit2
2002-10-16 Nick Drochak <ndrochak@gol.com>
* QueueTest.cs: Add test from tetsuo via Vladimir Vukicevic
(vladimir@pobox.com).
2002-10-09 Nick Drochak <ndrochak@gol.com>
* SortedListTest.cs: Re-enable test for IsSyncronized
2002-09-24 Nick Drochak <ndrochak@gol.com>
* ArrayListTest.cs: Add test for InsertRange() for the case where an
ArrayList is passed to itself to be insterted.
2002-09-24 Nick Drochak <ndrochak@gol.com>
* ArrayListTest.cs: Add check that enumerator is invalidated after a
method that changes the list, such as Add(), Remove(), etc.
2002-07-02 Nick Drochak <ndrochak@gol.com>
* SortedListTest.cs: Fix some expected/actual value parameters for
AssertEquals().
2002-06-30 Nick Drochak <ndrochak@gol.com>
* SortedListTest.cs: Fix some expected/actual value parameters in the
Assert()'s. Disable a part of test until the class is finished.
2002-06-25 Nick Drochak <ndrochak@gol.com>
* QueueTest.cs: Trap some unexpected exceptions and add a bit of
verbosity to some assert messages.
2002-06-20 Nick Drochak <ndrochak@gol.com>
* SortedListTest.cs: Make tests pass against ms.net.
* QueueTest.cs: Make tests pass against ms.net.
2002-06-19 Nick Drochak <ndrochak@gol.com>
* AllTests.cs: Sort names and include missing tests.
* SortedListTest.cs: Change Console.WriteLine() into Fail().
2002-05-27 Nick Drochak <ndrochak@gol.com>
* ArrayListTest.cs (TestLastIndexOf): Add try-catch block to report
where we are throwing.
2002-05-21 Lawrence Pit <loz@cable.a2000.nl>
* ArrayListTest.cs: Added several tests to test for 0 capacity
2002-05-05 Nick Drochak <ndrochak@gol.com>
* ArrayListTest.cs: Test for RankException when constructing from a
multi-dimensional array. Confirmed behavior from MS.NET
2002-05-01 Nick Drochak <ndrochak@gol.com>
* ArrayListTest.cs (TestBinarySearch) : accomodate possible bug in
.NET runtime.
2002/05/01 Nick Drochak <ndrochak@gol.com>
* ArrayListTest.cs (TestCopyTo) : Make assert messages unique and
avoid possible MS.NET bug when test is run on .NET.
2002/04/30 Nick Drochak <ndrochak@gol.com>
* ArrayListTest.cs (TestInsertRange) : Make assert messages unique.
2002-04-30 Nick Drochak <ndrochak@gol.com>
* ArrayListTest.cs (TestTrimToSize): Change test so that it doesn't
rely on the specific timing of a capacity change. Our corlib doubles
capacity sooner than the reference system does.
2002-04-30 Nick Drochak <ndrochak@gol.com>
* ArrayListTest.cs: Catch unexpected exception typs and report as
failures.
2002-04-29 Nick Drochak <ndrochak@gol.com>
* ArrayListTest.cs (TestBinarySearch): Catch the correct exception here.
2002-04-29 Nick Drochak <ndrochak@gol.com>
* ArrayListTest.cs (): Remove test on unsorted array. Behavior is
undefined according to docs. Re-added test that was commented out.
2002-03-24 Duncan Mak <duncan@ximian.com>
* SortedListTest.cs: Committed to CVS for Jaak Simm <jaaksimm@firm.ee>.
2002-02-28 Nick Drochak <ndrochak@gol.com>
* HashtableTest.cs: make the second test class public. The was showing
as an error whe run against the mscorlib. Might be because of the
new NUnit that was just checked in.
2002-02-20 Nick Drochak <ndrochak@gol.com>
* ArrayListTest.cs: Add a small assert for a bug that I found and fixed
in ArrayList. Make sure it doesn't come up again.
2002-02-10 Nick Drochak <ndrochak@gol.com>
* QueueTest.cs: Put in correct namespace.
2002-02-09 Nick Drochak <ndrochak@gol.com>
* StackTest.cs: Removed test for IsReadonly. Doesn't exist in .NET 1.0
2002-01-20 Nick Drochak <ndrochak@gol.com>
* BitArrayTest.cs: wrapped try-catch blocks around several of the tests.
NUnit doesn't properly catch exception here anymore. Must be something
to do with upgrading to .NET.1.0.

View File

@@ -0,0 +1,340 @@
//
// System.Collections.CollectionBase
// Test suite for System.Collections.CollectionBase
//
// Authors:
// Nick D. Drochak II
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
// (C) 2001 Nick D. Drochak II
// (c) 2003 Ximian, Inc. (http://www.ximian.com)
//
using System;
using System.Collections;
using NUnit.Framework;
namespace MonoTests.System.Collections
{
[TestFixture]
public class CollectionBaseTest
{
// We need a concrete class to test the abstract base class
public class ConcreteCollection : CollectionBase
{
// These fields are used as markers to test the On* hooks.
public bool onClearFired;
public bool onClearCompleteFired;
public bool onInsertFired;
public int onInsertIndex;
public bool onInsertCompleteFired;
public int onInsertCompleteIndex;
public bool onRemoveFired;
public int onRemoveIndex;
public bool onRemoveCompleteFired;
public int onRemoveCompleteIndex;
public bool onSetFired;
public int onSetOldValue;
public int onSetNewValue;
public bool onSetCompleteFired;
public int onSetCompleteOldValue;
public int onSetCompleteNewValue;
public int mustThrowException;
public bool onValidateFired;
// This constructor is used to test OnValid()
public ConcreteCollection()
{
IList listObj;
listObj = this;
listObj.Add(null);
}
// This constructor puts consecutive integers into the list
public ConcreteCollection(int i) {
IList listObj;
listObj = this;
int j;
for (j = 0; j< i; j++) {
listObj.Add(j);
}
}
void CheckIfThrow ()
{
if (mustThrowException > 0) {
mustThrowException--;
if (mustThrowException == 0)
throw new Exception ();
}
}
// A helper method to look at a value in the list at a specific index
public int PeekAt(int index)
{
IList listObj;
listObj = this;
return (int) listObj[index];
}
protected override void OnValidate (object value) {
this.onValidateFired = true;
CheckIfThrow ();
base.OnValidate (value);
}
// Mark the flag if this hook is fired
protected override void OnClear() {
this.onClearFired = true;
CheckIfThrow ();
}
// Mark the flag if this hook is fired
protected override void OnClearComplete()
{
this.onClearCompleteFired = true;
CheckIfThrow ();
}
// Mark the flag, and save the paramter if this hook is fired
protected override void OnInsert(int index, object value)
{
this.onInsertFired = true;
this.onInsertIndex = index;
CheckIfThrow ();
}
// Mark the flag, and save the paramter if this hook is fired
protected override void OnInsertComplete(int index, object value)
{
this.onInsertCompleteFired = true;
this.onInsertCompleteIndex = index;
CheckIfThrow ();
}
// Mark the flag, and save the paramter if this hook is fired
protected override void OnRemove(int index, object value)
{
this.onRemoveFired = true;
this.onRemoveIndex = index;
CheckIfThrow ();
}
// Mark the flag, and save the paramter if this hook is fired
protected override void OnRemoveComplete(int index, object value)
{
this.onRemoveCompleteFired = true;
this.onRemoveCompleteIndex = index;
CheckIfThrow ();
}
// Mark the flag, and save the paramters if this hook is fired
protected override void OnSet(int index, object oldValue, object newValue)
{
this.onSetFired = true;
this.onSetOldValue = (int) oldValue;
this.onSetNewValue = (int) newValue;
CheckIfThrow ();
}
// Mark the flag, and save the paramters if this hook is fired
protected override void OnSetComplete(int index, object oldValue, object newValue)
{
this.onSetCompleteFired = true;
this.onSetCompleteOldValue = (int) oldValue;
this.onSetCompleteNewValue = (int) newValue;
CheckIfThrow ();
}
public IList BaseList {
get { return base.List; }
}
} // public class ConcreteCollection
// Check the count property
[Test]
public void Count() {
ConcreteCollection myCollection;
myCollection = new ConcreteCollection(4);
Assert.IsTrue (4 == myCollection.Count);
}
// Make sure GetEnumerator returns an object
[Test]
public void GetEnumerator() {
ConcreteCollection myCollection;
myCollection = new ConcreteCollection(4);
Assert.IsTrue (null != myCollection.GetEnumerator());
}
// OnValid disallows nulls
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void OnValid() {
ConcreteCollection myCollection;
myCollection = new ConcreteCollection();
}
// Test various Insert paths
[Test]
public void Insert() {
ConcreteCollection myCollection;
int numberOfItems;
numberOfItems = 3;
// The constructor inserts
myCollection = new ConcreteCollection(numberOfItems);
Assert.IsTrue (myCollection.onInsertFired);
Assert.IsTrue (myCollection.onInsertCompleteFired);
// Using the IList interface, check inserts in the middle
IList listObj = myCollection;
listObj.Insert(1, 9);
Assert.IsTrue (myCollection.onInsertIndex == 1);
Assert.IsTrue (myCollection.onInsertCompleteIndex == 1);
Assert.IsTrue (myCollection.PeekAt(1) == 9);
}
// Test Clear and it's hooks
[Test]
public void Clear()
{
ConcreteCollection myCollection;
int numberOfItems;
numberOfItems = 1;
myCollection = new ConcreteCollection(numberOfItems);
myCollection.Clear();
Assert.IsTrue (myCollection.Count == 0);
Assert.IsTrue (myCollection.onClearFired);
Assert.IsTrue (myCollection.onClearCompleteFired);
}
// Test RemoveAt, other removes and the hooks
[Test]
public void Remove()
{
ConcreteCollection myCollection;
int numberOfItems;
numberOfItems = 3;
// Set up a test collection
myCollection = new ConcreteCollection(numberOfItems);
// The list is 0-based. So if we remove the second one
myCollection.RemoveAt(1);
// We should see the original third one in it's place
Assert.IsTrue (myCollection.PeekAt(1) == 2);
Assert.IsTrue (myCollection.onRemoveFired);
Assert.IsTrue (myCollection.onRemoveIndex == 1);
Assert.IsTrue (myCollection.onRemoveCompleteFired);
Assert.IsTrue (myCollection.onRemoveCompleteIndex == 1);
IList listObj = myCollection;
listObj.Remove(0);
// Confirm parameters are being passed to the hooks
Assert.IsTrue (myCollection.onRemoveIndex == 0);
Assert.IsTrue (myCollection.onRemoveCompleteIndex == 0);
}
// Test the random access feature
[Test]
public void Set()
{
ConcreteCollection myCollection;
int numberOfItems;
numberOfItems = 3;
myCollection = new ConcreteCollection(numberOfItems);
IList listObj = myCollection;
listObj[0] = 99;
Assert.IsTrue ((int) listObj[0] == 99);
Assert.IsTrue (myCollection.onSetFired);
Assert.IsTrue (myCollection.onSetCompleteFired);
Assert.IsTrue (myCollection.onSetOldValue == 0);
Assert.IsTrue (myCollection.onSetCompleteOldValue == 0);
Assert.IsTrue (myCollection.onSetNewValue == 99);
Assert.IsTrue (myCollection.onSetCompleteNewValue == 99);
}
[Test]
public void InsertComplete_Add ()
{
ConcreteCollection coll = new ConcreteCollection (0);
coll.mustThrowException = 1;
try {
coll.BaseList.Add (0);
} catch {
}
Assert.AreEqual (0, coll.Count);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void ValidateCalled ()
{
ConcreteCollection coll = new ConcreteCollection (0);
coll.mustThrowException = 1;
try {
coll.BaseList [5] = 8888;
} catch (ArgumentOutOfRangeException) {
throw;
} finally {
Assert.AreEqual (false, coll.onValidateFired);
}
}
[Test]
public void SetCompleteCalled ()
{
ConcreteCollection coll = new ConcreteCollection (0);
coll.BaseList.Add (88);
coll.mustThrowException = 1;
try {
coll.BaseList [0] = 11;
} catch {
} finally {
Assert.AreEqual (false, coll.onSetCompleteFired);
}
}
[Test]
public void SetCompleteUndo ()
{
ConcreteCollection coll = new ConcreteCollection (0);
bool throwsException = true;
coll.BaseList.Add (88);
coll.onValidateFired = false;
coll.onInsertFired = false;
coll.onSetCompleteFired = false;
coll.mustThrowException = 3;
try {
coll.BaseList [0] = 11;
throwsException = false;
} catch {
} finally {
Assert.IsTrue (throwsException);
Assert.IsTrue (coll.onValidateFired);
Assert.IsTrue (coll.onSetFired);
Assert.IsTrue (coll.onSetCompleteFired);
Assert.AreEqual (88, coll.BaseList [0]);
}
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void InvalidRemove ()
{
ConcreteCollection coll = new ConcreteCollection (0);
coll.BaseList.Remove (10);
}
}
}

View File

@@ -0,0 +1,110 @@
// ComparerTest
using System;
using System.Collections;
using System.Globalization;
using System.Runtime.Serialization;
using NUnit.Framework;
namespace MonoTests.System.Collections {
[TestFixture]
public class ComparerTest {
[Test]
public void TestDefaultInstance ()
{
// Make sure the instance returned by Default
// is really a Comparer.
Assert.IsNotNull (Comparer.Default as Comparer);
}
[Test]
public void TestCompare ()
{
Comparer c = Comparer.Default;
Assert.IsTrue (c.Compare (1, 2) < 0, "1,2");
Assert.IsTrue (c.Compare (2, 2) == 0, "2,2");
Assert.IsTrue (c.Compare (3, 2) > 0, "3,2");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Compare_FirstIComparer ()
{
Assert.IsTrue (Comparer.Default.Compare (1, new object ()) > 0, "int,object");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Compare_SecondIComparer ()
{
Assert.IsTrue (Comparer.Default.Compare (new object (), 1) > 0, "object,int");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Compare_BothNonIComparer ()
{
Comparer.Default.Compare (new object (), new object ());
}
[Test]
public void Invariant ()
{
Comparer c = Comparer.DefaultInvariant;
Assert.IsTrue (c.Compare ("a", "A") < 0);
}
[Test]
public void Invariant2 ()
{
Assert.IsTrue (CultureInfo.InvariantCulture.CompareInfo.Compare ("a", "A", CompareOptions.Ordinal) > 0);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor_Null ()
{
new Comparer (null);
}
[Test]
public void Constructor ()
{
Comparer c = new Comparer (CultureInfo.InvariantCulture);
Assert.IsTrue (c.Compare ("a", "A") < 0);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void GetObjectData_Null ()
{
Comparer c = Comparer.DefaultInvariant;
c.GetObjectData (null, new StreamingContext ());
}
[Test]
public void GetObjectData ()
{
Comparer c = Comparer.DefaultInvariant;
SerializationInfo si = new SerializationInfo (typeof (Comparer), new FormatterConverter ());
c.GetObjectData (si, new StreamingContext ());
foreach (SerializationEntry se in si) {
switch (se.Name) {
case "CompareInfo":
CompareInfo ci = (se.Value as CompareInfo);
Assert.IsNotNull (ci, "CompareInfo");
Assert.AreEqual (127, ci.LCID, "LCID");
break;
default:
string msg = String.Format ("Unexpected {0} information of type {1} with value '{2}'.",
se.Name, se.ObjectType, se.Value);
Assert.Fail (msg);
break;
}
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,53 @@
// DictionaryEntryTest
using System;
using System.Collections;
using NUnit.Framework;
namespace MonoTests.System.Collections {
[TestFixture]
public class DictionaryEntryTest {
[Test]
public void Ctor () {
DictionaryEntry d = new DictionaryEntry (1, "something");
Assert.IsNotNull (d);
Assert.AreEqual (1, d.Key, "#01");
Assert.AreEqual ("something", d.Value, "#02");
}
[Test]
public void Key () {
DictionaryEntry d = new DictionaryEntry (1, "something");
d.Key = 77.77;
Assert.AreEqual (77.77, d.Key, "#03");
}
[Test]
public void Value () {
DictionaryEntry d = new DictionaryEntry (1, "something");
d.Value = 'p';
Assert.AreEqual ('p', d.Value, "#04");
}
[Test]
#if ONLY_1_1
[ExpectedException (typeof (ArgumentNullException))]
#endif
public void NullKeyCtor ()
{
DictionaryEntry d = new DictionaryEntry (null, "bar");
}
[Test]
#if ONLY_1_1
[ExpectedException (typeof (ArgumentNullException))]
#endif
public void NullKeySetter ()
{
DictionaryEntry d = new DictionaryEntry ("foo", "bar");
d.Key = null;
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,48 @@
//
// System.Collections.ReadOnlyCollectionBase
// Test suite for System.Collections.ReadOnlyCollectionBase
//
// Author:
// Nick D. Drochak II
//
// (C) 2001 Nick D. Drochak II
//
using System;
using System.Collections;
using NUnit.Framework;
namespace MonoTests.System.Collections {
public class ReadOnlyCollectionBaseTest {
// We need a concrete class to test the abstract base class
public class ConcreteReadOnlyCollection : ReadOnlyCollectionBase
{
#if NET_2_0
public override int Count { get { return -1; }}
#endif
}
// Make sure that the Count is 0 for a new object
[Test]
public void TestZeroCountOnNew()
{
ConcreteReadOnlyCollection myCollection;
myCollection = new ConcreteReadOnlyCollection();
#if NET_2_0
Assert.IsTrue (-1 == myCollection.Count);
#else
Assert.IsTrue ( 0 == myCollection.Count);
#endif
}
// Make sure we get an object from GetEnumerator()
[Test]
public void TestGetEnumerator()
{
ConcreteReadOnlyCollection myCollection;
myCollection = new ConcreteReadOnlyCollection();
Assert.IsTrue (null != myCollection.GetEnumerator());
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,420 @@
//
// StackTest.cs
//
// Author:
// Chris Hynes <chrish@assistedsolutions.com>
//
// (C) 2001 Chris Hynes
//
using System;
using System.Collections;
using NUnit.Framework;
namespace MonoTests.System.Collections
{
[TestFixture]
public class StackTest
{
private Stack stack1;
private Stack stackInt;
[Test]
public void TestConstructor()
{
Assert.AreEqual (stack1 == null, false);
}
[Test]
public void TestICollectionConstructor1()
{
Stack stackTest = new Stack(new int[] {0, 1, 2, 3, 4});
for (int i = 4; i >= 0; i--)
Assert.AreEqual (stackTest.Pop(), i);
Assert.AreEqual (stackTest.Count, 0);
}
[Test]
public void TestICollectionConstructor2()
{
bool exceptionThrown = false;
try {
Stack stackTest = new Stack(null);
} catch (ArgumentNullException e) {
exceptionThrown = true;
Assert.AreEqual ("col", e.ParamName, "ParamName must be \"col\"");
}
Assert.IsTrue (exceptionThrown, "null argument must throw ArgumentNullException");
}
[Test]
public void TestIntConstructor1()
{
Stack stackTest = new Stack(50);
Assert.IsTrue (stackTest != null);
}
[Test]
public void TestIntConstructor2()
{
bool exceptionThrown = false;
try {
Stack stackTest = new Stack(-1);
}
catch (ArgumentOutOfRangeException e)
{
exceptionThrown = true;
Assert.AreEqual ("initialCapacity", e.ParamName, "ParamName must be \"initialCapacity\"");
}
Assert.IsTrue (exceptionThrown, "negative argument must throw ArgumentOutOfRangeException");
}
[Test]
public void TestCount()
{
Stack stackTest = new Stack();
stackTest.Push(50);
stackTest.Push(5);
stackTest.Push(0);
stackTest.Push(50);
Assert.AreEqual (stackTest.Count, 4);
}
[Test]
public void TestIsSyncronized()
{
Assert.AreEqual (stack1.IsSynchronized, false);
Assert.AreEqual (Stack.Synchronized(stack1).IsSynchronized, true);
}
[Test]
public void TestSyncRoot()
{
Assert.AreEqual (stack1.SyncRoot == null, false);
}
[Test]
public void TestGetEnumerator1()
{
stackInt.Pop();
int j = 3;
foreach (int i in stackInt)
{
Assert.AreEqual (i, j--);
}
stackInt.Clear();
IEnumerator e = stackInt.GetEnumerator();
Assert.AreEqual (e.MoveNext(), false);
}
[Test]
public void TestGetEnumerator2()
{
IEnumerator e = stackInt.GetEnumerator();
try
{
// Tests InvalidOperationException if enumerator is uninitialized
Object o = e.Current;
Assert.Fail ("InvalidOperationException should be thrown");
} catch (InvalidOperationException) {}
}
[Test]
public void TestGetEnumerator3()
{
IEnumerator e = stack1.GetEnumerator();
e.MoveNext();
try
{
// Tests InvalidOperationException if enumeration has ended
Object o = e.Current;
Assert.Fail ("InvalidOperationException should be thrown");
} catch (InvalidOperationException) {}
}
[Test]
public void TestEnumeratorReset1()
{
IEnumerator e = stackInt.GetEnumerator();
e.MoveNext();
Assert.AreEqual (4, e.Current, "current value");
e.MoveNext();
e.Reset();
e.MoveNext();
Assert.AreEqual (4, e.Current, "current value after reset");
}
[Test]
public void TestEnumeratorReset2()
{
IEnumerator e = stackInt.GetEnumerator();
e.MoveNext();
Assert.AreEqual (4, e.Current, "current value");
// modifies underlying the stack. Reset must throw InvalidOperationException
stackInt.Push(5);
try
{
e.Reset();
Assert.Fail ("InvalidOperationException should be thrown");
}
catch (InvalidOperationException) {}
}
[Test]
public void TestEnumeratorMoveNextException()
{
IEnumerator e = stackInt.GetEnumerator();
// modifies underlying the stack. MoveNext must throw InvalidOperationException
stackInt.Push(5);
try
{
e.MoveNext();
Assert.Fail ("InvalidOperationException should be thrown");
}
catch (InvalidOperationException) {}
}
[Test]
public void TestClear()
{
stackInt.Clear();
Assert.AreEqual (stackInt.Count, 0);
}
[Test]
public void TestClone()
{
Stack clone = (Stack)stackInt.Clone();
while (stackInt.Count > 0)
{
Assert.AreEqual (clone.Pop(), stackInt.Pop());
}
}
[Test]
public void TestContains()
{
string toLocate = "test";
stackInt.Push(toLocate);
stackInt.Push("chaff");
stackInt.Push(null);
Assert.IsTrue (stackInt.Contains(toLocate));
Assert.IsTrue (stackInt.Contains(null), "must contain null");
stackInt.Pop();
stackInt.Pop();
Assert.IsTrue (stackInt.Contains(toLocate));
stackInt.Pop();
Assert.IsTrue (!stackInt.Contains(toLocate));
stackInt.Push(null);
Assert.IsTrue (stackInt.Contains(null));
stackInt.Pop();
Assert.IsTrue (!stackInt.Contains(null));
}
[Test]
public void TestCopyTo()
{
int[] arr = new int[stackInt.Count - 1];
int[,] arrMulti;
try
{
stackInt.CopyTo(null, 0);
Assert.Fail ("Should throw an ArgumentNullException");
} catch (ArgumentNullException e) {
Assert.AreEqual ("array", e.ParamName, "ParamName must be \"array\"");
}
try
{
stackInt.CopyTo(arr, -1);
Assert.Fail ("Should throw an ArgumentOutOfRangeException");
}
catch (ArgumentOutOfRangeException e)
{
Assert.AreEqual ("index", e.ParamName, "ParamName must be \"index\"");
}
try
{
stackInt.CopyTo(arrMulti = new int[1, 1], 1);
Assert.Fail ("Should throw an ArgumentException");
}
catch (ArgumentException) {}
try
{
stackInt.CopyTo(arr = new int[2], 3);
Assert.Fail ("Should throw an ArgumentException");
}
catch (ArgumentException) {}
try
{
stackInt.CopyTo(arr = new int[3], 2);
Assert.Fail ("Should throw an ArgumentException");
}
catch (ArgumentException) {}
try
{
stackInt.CopyTo(arr = new int[2], 3);
Assert.Fail ("Should throw an ArgumentException");
}
catch (ArgumentException) {}
arr = new int[stackInt.Count];
stackInt.CopyTo(arr, 0);
int j = 4;
for (int i = 0; i < 4; i++)
{
Assert.AreEqual (arr[i], j--);
}
}
[Test]
public void TestSyncronized()
{
Stack syncStack = Stack.Synchronized(stackInt);
syncStack.Push(5);
for (int i = 5; i >= 0; i--)
Assert.AreEqual (syncStack.Pop(), i);
}
[Test]
public void TestPushPeekPop()
{
stackInt.Pop();
int topVal = (int)stackInt.Peek();
Assert.AreEqual (topVal, 3);
Assert.AreEqual (stackInt.Count, 4);
Assert.AreEqual (stackInt.Pop(), topVal);
Assert.AreEqual (stackInt.Pop(), 2);
Stack test = new Stack();
test.Push(null);
Assert.AreEqual (test.Pop(), null);
}
[Test]
public void TestPop()
{
for (int i = 4; i >= 0; i--)
{
Assert.AreEqual (stackInt.Pop(), i);
}
try {
stackInt.Pop();
Assert.Fail ("must throw InvalidOperationException");
} catch (InvalidOperationException){
}
}
[Test]
public void TestToArray()
{
object[] arr = stackInt.ToArray();
Assert.AreEqual (arr.Length, stackInt.Count);
for (int i = 0; i < 5; i++)
Assert.AreEqual (stackInt.Pop(), arr[i]);
}
[Test]
public void TestResize()
{
Stack myStack = new Stack(20);
for (int i = 0; i < 500; i++)
{
myStack.Push(i);
Assert.AreEqual (i+1, myStack.Count, "push count test");
}
for (int i = 499; i >= 0; i--)
{
Assert.AreEqual (myStack.Pop(), i);
Assert.AreEqual (i, myStack.Count, "pop count test");
}
}
[Test]
public void TestEmptyCopyTo ()
{
Stack stack = new Stack ();
string [] arr = new string [0];
stack.CopyTo (arr, 0);
}
[Test]
public void TestICollectionCtorUsesEnum ()
{
BitArray x = new BitArray (10, true);
Stack s = new Stack (x);
}
[SetUp]
protected void SetUp()
{
stack1 = new Stack();
stackInt = new Stack();
for (int i = 0; i < 5; i++)
stackInt.Push(i);
}
}
}

View File

@@ -0,0 +1,55 @@
//
// StructuralComparisonsTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2013 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_4_0
using System.Collections;
using NUnit.Framework;
namespace MonoTests.System.Collections
{
[TestFixture]
public class StructuralComparisonsTest
{
[Test]
public void EqualsTest ()
{
int[] a1 = new[] { 9, 1, 3, 4 };
int[] a2 = new[] { 9, 1, 3, 4 };
Assert.IsTrue (StructuralComparisons.StructuralEqualityComparer.Equals (a1, a2), "#1");
Assert.IsFalse (StructuralComparisons.StructuralEqualityComparer.Equals (null, a2), "#2");
Assert.IsFalse (StructuralComparisons.StructuralEqualityComparer.Equals (a1, null), "#3");
Assert.IsTrue (StructuralComparisons.StructuralEqualityComparer.Equals (null, null), "#4");
Assert.IsTrue (StructuralComparisons.StructuralEqualityComparer.Equals (4, 4), "#5");
Assert.IsFalse (StructuralComparisons.StructuralEqualityComparer.Equals (4, 5), "#6");
}
}
}
#endif