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

View File

@@ -0,0 +1,169 @@
// created on 7/21/2001 at 2:36 PM
//
// Author: Martin Willemoes Hansen <mwh@sysrq.dk>
//
// (C) 2003 Martin Willemoes Hansen
//
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using NUnit.Framework;
namespace MonoTests.System.Collections.Specialized {
[TestFixture]
public class BasicOperationsTest {
protected NameValueCollection nvc;
private static Random rnd;
[SetUp]
public void GetReady()
{
nvc = new NameValueCollection();
rnd=new Random();
}
private void SetDefaultData()
{
nvc.Clear();
nvc.Add("k1","this");
nvc.Add("k2","test");
nvc.Add("k3","is");
nvc.Add("k4","silly");
}
private static string FormatForPrinting (NameValueCollection nv)
{
if (nv==null)
return null;
int max = nv.Count;
StringBuilder sb = new StringBuilder("-\t-Key-\t-Value-\n");
for (int i=0; i<max; i++){
sb.Append("\t"+nv.GetKey(i)+"\t"+nv[i]+"\n");
}
return sb.ToString();
}
[Test]
public void AddRemoveClearSetGet()
{
nvc.Clear();
Assert.AreEqual (0, nvc.Count);
Assert.IsFalse(nvc.HasKeys());
SetDefaultData();
Assert.AreEqual(4, nvc.Count);
Assert.IsTrue((nvc.Get(0).Equals("this"))&&(nvc.Get("k1").Equals("this")), "Get operation returns wrong result.\n"+FormatForPrinting(nvc));
nvc.Add("k2","programmer");
Assert.AreEqual("test,programmer", nvc["k2"]);
nvc["k2"]="project";
nvc.Add("k2","project");
Assert.AreEqual(4, nvc.Count);
Assert.AreEqual("project,project", nvc["k2"], "Wrong effect of add(samekey,samevalue)\n"+FormatForPrinting(nvc));
// TODO: add Remove test
nvc.Remove("k4");
Assert.AreEqual(3, nvc.Count);
Assert.IsNull(nvc["k4"]);
NameValueCollection nvc1 = new NameValueCollection();
nvc1["k1"]="these";
nvc1["k5"]="!";
nvc.Add(nvc1);
Assert.AreEqual (4, nvc.Count, FormatForPrinting(nvc)+"Count is wrong after Add(nvc1)");
Assert.IsTrue((nvc["k1"].Equals("this,these"))&&(nvc["k5"].Equals("!")), "Values are wrong after Add(nvc1)");
nvc.Set("k3","accomplished");
Assert.AreEqual("accomplished", nvc["k3"], "Wrong result of Set operation");
}
[Test]
public void GetKeyGetValues()
{
SetDefaultData();
Assert.AreEqual ("k1", nvc.GetKey(0));
string[] values = nvc.GetValues(0);
Assert.AreEqual ("this", values[0]);
}
[Test]
public void CopyTo() {
SetDefaultData();
string[] entries=new string[nvc.Count];
nvc.CopyTo(entries,0);
//Message(FormatForPrinting(nvc));
//Assert("Not an entry.",entries[0] is DictionaryEntry);
}
[Test]
public void UnderHeavyLoad() {
//TODO: add memory and time measurement
nvc.Clear();
#if MOBILE
const int max=100;
#else
const int max=1000;
#endif
String[] cache=new String[max*2];
int n=0;
for (int i=0;i<max;i++) {
int id=rnd.Next()&0xFFFF;
String key=""+id+"-key-"+id;
String val="value-"+id;
if (nvc[key]==null) {
nvc[key]=val;
cache[n]=key;
cache[n+max]=val;
n++;
}
}
Assert.AreEqual (n, nvc.Count);
for (int i=0;i<n;i++) {
String key=cache[i];
String val=nvc[key] as String;
String err="nvc[\""+key+"\"]=\""+val+
"\", expected \""+cache[i+max]+"\"";
Assert.IsNotNull (val);
Assert.AreEqual (val, cache[i+max], err);
}
int r1=(n/3);
int r2=r1+(n/5);
for (int i=r1;i<r2;i++) {
nvc.Remove(cache[i]);
}
for (int i=0;i<n;i++) {
if (i>=r1 && i<r2) {
Assert.IsNull (nvc[cache[i]]);
} else {
String key=cache[i];
String val=nvc[key] as String;
String err="ht[\""+key+"\"]=\""+val+
"\", expected \""+cache[i+max]+"\"";
Assert.AreEqual (val, cache[i+max], err);
}
}
}
}
}

View File

@@ -0,0 +1,78 @@
//
// BitVector32Cas.cs
// - CAS unit tests for System.Collections.Specialized.BitVector32
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
using NUnit.Framework;
using System;
using System.Collections.Specialized;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using MonoTests.System.Collections.Specialized;
namespace MonoCasTests.System.Collections.Specialized {
[TestFixture]
[Category ("CAS")]
public class BitVector32Cas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ReuseUnitTests_Deny_Unrestricted ()
{
BitVector32Test unit = new BitVector32Test ();
unit.Constructors ();
unit.Constructors_MaxValue ();
unit.Constructors_MinValue ();
unit.Indexers ();
unit.CreateMask ();
unit.CreateSection ();
unit.Section ();
unit.TestSectionIndexer ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
Type[] types = new Type[1] { typeof (int) };
ConstructorInfo ci = typeof (BitVector32).GetConstructor (types);
Assert.IsNotNull (ci, ".ctor(int)");
Assert.IsNotNull (ci.Invoke (new object[1] { 1 }), "invoke");
}
}
}

View File

@@ -0,0 +1,249 @@
//
// BitVector32Test.cs - NUnit Test Cases for System.Net.BitVector32
//
// Authors:
// Lawrence Pit (loz@cable.a2000.nl)
// Martin Willemoes Hansen (mwh@sysrq.dk)
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Martin Willemoes Hansen
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Specialized;
namespace MonoTests.System.Collections.Specialized
{
[TestFixture]
public class BitVector32Test
{
[Test]
public void Constructors ()
{
BitVector32 b = new BitVector32 (31);
Assert.AreEqual (31, b.Data, "Data");
Assert.IsTrue (b.Equals (b), "Equals(self)");
Assert.IsTrue (b[31], "31");
Assert.IsFalse (b[32], "32");
Assert.AreEqual (b.ToString (), "BitVector32{00000000000000000000000000011111}", b.ToString ());
BitVector32 b2 = new BitVector32 (b);
Assert.IsTrue (b.Equals (b2), "Equals(b2)");
Assert.AreEqual (b.GetHashCode (), b2.GetHashCode (), "GetHashCode==");
b2[32] = true;
Assert.IsFalse (b.Equals (b2), "Equals(b32)");
Assert.IsFalse (b.GetHashCode () == b2.GetHashCode (), "GetHashCode!=");
}
[Test]
public void Constructors_MaxValue ()
{
BitVector32 b = new BitVector32 (Int32.MaxValue);
Assert.AreEqual (Int32.MaxValue, b.Data, "Data");
Assert.AreEqual ("BitVector32{01111111111111111111111111111111}", BitVector32.ToString (b), "ToString(BitVector)");
}
[Test]
public void Constructors_MinValue ()
{
BitVector32 b = new BitVector32 (Int32.MinValue);
Assert.AreEqual (Int32.MinValue, b.Data, "Data");
Assert.AreEqual ("BitVector32{10000000000000000000000000000000}", BitVector32.ToString (b), "ToString(BitVector)");
}
[Test]
public void Indexers ()
{
BitVector32 b = new BitVector32 (7);
Assert.IsTrue (b [0], "#1");
Assert.IsTrue (b [1], "#2");
Assert.IsTrue (b [2], "#3");
Assert.IsTrue (b [4], "#4");
Assert.IsTrue (!b [8], "#5");
Assert.IsTrue (!b [16], "#6");
b [8] = true;
Assert.IsTrue (b [4], "#7");
Assert.IsTrue (b [8], "#8");
Assert.IsTrue (!b [16], "#9");
b [8] = false;
Assert.IsTrue (b [4], "#10");
Assert.IsTrue (!b [8], "#11");
Assert.IsTrue (!b [16], "#12");
BitVector32.Section s = BitVector32.CreateSection (31);
s = BitVector32.CreateSection (64, s);
// Print (s);
// b = new BitVector32 (0x777777);
BitVector32 b1 = new BitVector32 (0xffff77);
BitVector32 b2 = new BitVector32 (b1 [s]);
//Console.WriteLine (b1.ToString ());
//Console.WriteLine (b2.ToString ());
Assert.AreEqual (123, b1 [s], "#14");
// b1 [s] = 15;
//Console.WriteLine (b1.ToString ());
}
[Test]
public void CreateMask ()
{
Assert.AreEqual (1, BitVector32.CreateMask (), "#1");
Assert.AreEqual (1, BitVector32.CreateMask (0), "#2");
Assert.AreEqual (2, BitVector32.CreateMask (1), "#3");
Assert.AreEqual (32, BitVector32.CreateMask (16), "#4");
Assert.AreEqual (-2, BitVector32.CreateMask (Int32.MaxValue), "#5");
Assert.AreEqual (-4, BitVector32.CreateMask (-2), "#6");
Assert.AreEqual (2, BitVector32.CreateMask (Int32.MinValue + 1), "#7");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void CreateMask_MinValue ()
{
BitVector32.CreateMask (Int32.MinValue);
}
[Test]
public void CreateSection ()
{
BitVector32.Section s = BitVector32.CreateSection (1);
Assert.AreEqual ((short) 1, s.Mask, "#1");
s = BitVector32.CreateSection (2);
Assert.AreEqual ((short) 3, s.Mask, "#2");
s = BitVector32.CreateSection (3);
Assert.AreEqual ((short) 3, s.Mask, "#3");
s = BitVector32.CreateSection (5);
Assert.AreEqual ((short) 7, s.Mask, "#4");
s = BitVector32.CreateSection (20);
Assert.AreEqual ((short) 0x1f, s.Mask, "#4");
s = BitVector32.CreateSection (Int16.MaxValue);
Assert.AreEqual ((short) 0x7fff, s.Mask, "#5");
s = BitVector32.CreateSection (Int16.MaxValue - 100);
Assert.AreEqual ((short) 0x7fff, s.Mask, "#6");
try {
BitVector32.Section s2 = BitVector32.CreateSection (0);
Assert.Fail ("#7");
} catch (ArgumentException) {}
try {
BitVector32.Section s2 = BitVector32.CreateSection (-1);
Assert.Fail ("#8");
} catch (ArgumentException) {}
try {
BitVector32.Section s2 = BitVector32.CreateSection (Int16.MinValue);
Assert.Fail ("#9");
} catch (ArgumentException) {}
s = BitVector32.CreateSection (20);
Assert.AreEqual ((short) 0x1f, s.Mask, "#10a");
Assert.AreEqual ((short) 0x00, s.Offset, "#10b");
s = BitVector32.CreateSection (120, s);
Assert.AreEqual ((short) 0x7f, s.Mask, "#10c");
Assert.AreEqual ((short) 0x05, s.Offset, "#10d");
s = BitVector32.CreateSection (1000, s);
Assert.AreEqual ((short) 0x3ff, s.Mask, "#10e");
Assert.AreEqual ((short) 0x0c, s.Offset, "#10f");
}
[Test]
public void Section ()
{
BitVector32.Section s1 = BitVector32.CreateSection (20);
Assert.AreEqual (31, s1.Mask, "1.Mask");
Assert.AreEqual (0, s1.Offset, "1.Offset");
Assert.AreEqual ("Section{0x1f, 0x0}", BitVector32.Section.ToString (s1), "ToString(Section)");
BitVector32.Section s2 = BitVector32.CreateSection (20);
Assert.IsTrue (s1.Equals (s2), "s1==s2");
Assert.IsTrue (s2.Equals ((object)s1), "s2==s1");
Assert.AreEqual (s1.GetHashCode (), s2.GetHashCode (), "GetHashCode");
Assert.AreEqual ("Section{0x1f, 0x0}", s2.ToString (), "ToString()");
}
[Test]
public void SectionCorrectSize ()
{
BitVector32.Section s1 = BitVector32.CreateSection (32767);
BitVector32.Section s2 = BitVector32.CreateSection (32767, s1);
BitVector32.Section s3 = BitVector32.CreateSection (3, s2);
BitVector32 v1 = new BitVector32 (0);
v1[s3] = 3;
Assert.AreEqual (v1[s3], 3);
}
[Test]
public void SectionIncorrectSize ()
{
BitVector32.Section s1 = BitVector32.CreateSection (32767);
BitVector32.Section s2 = BitVector32.CreateSection (32767, s1);
try {
BitVector32.Section s3 = BitVector32.CreateSection (4, s2);
Assert.Fail("Illegal section created");
} catch (ArgumentException) {}
}
[Test]
public void NegativeIndexer ()
{
BitVector32 bv = new BitVector32 (-1);
#if NET_2_0
Assert.IsTrue (bv [Int32.MinValue], "Int32.MinValue");
#else
Assert.IsFalse (bv [Int32.MinValue], "Int32.MinValue");
#endif
}
[Test]
public void TestSectionIndexer ()
{
BitVector32 bv = new BitVector32 (-1);
BitVector32.Section sect = BitVector32.CreateSection (1);
sect = BitVector32.CreateSection (Int16.MaxValue, sect);
sect = BitVector32.CreateSection (Int16.MaxValue, sect);
sect = BitVector32.CreateSection (1, sect);
Assert.AreEqual (1, bv[sect], "bv[sect]");
bv [sect] = 0;
Assert.AreEqual (Int32.MaxValue, bv.Data, "#12a");
}
[Test, ExpectedException (typeof (ArgumentException))]
public void TestCreateSection1 ()
{
BitVector32.Section section = BitVector32.CreateSection (Int16.MaxValue);
section = BitVector32.CreateSection (0, section);
}
[Test, ExpectedException (typeof (ArgumentException))]
public void TestCreateSection2 ()
{
BitVector32.Section section = BitVector32.CreateSection (Int16.MaxValue);
section = BitVector32.CreateSection (-1, section);
}
[Test, ExpectedException (typeof (ArgumentException))]
public void TestCreateSection3 ()
{
BitVector32.Section section = BitVector32.CreateSection (Int16.MaxValue);
section = BitVector32.CreateSection (Int16.MinValue, section);
}
private void Print (BitVector32.Section s)
{
Console.WriteLine (s.ToString () + " : "+ s.Mask + " : " + s.Offset);
}
}
}

View File

@@ -0,0 +1,84 @@
2009-06-26 Robert Jordan <robertj@gmx.net>
* BitVector32Test.cs, NameValueCollectionTest.cs:
Upgrade to new NUnit style.
2008-08-21 Scott Peterson <lunchtimemama@gmail.com>
* BitVector32Test.cs: Added test to make sure illegal sections cannot
be created.
2008-01-07 Gert Driesen <drieseng@users.sourceforge.net>
* NameObjectCollectionBaseTest.cs: Add tests for argument checking in
GetObjectData, Add, Clear, Remove, RemoveAt, Set and CopyTo.
2007-04-29 Ilya Kharmatsky <ilyak@mainsoft.com>
* NameValueCollectionTest.cs: Added test which checks proper exception
handling in several constructors and CopyTo method, under NET_2_0
target.
2005-11-30 Sebastien Pouliot <sebastien@ximian.com>
* BitVector32Cas.cs: New. CAS unit tests.
* BitVector32Test.cs: More test cases to increase coverage.
* CollectionsUtilCas.cs: New. CAS unit tests.
* HybridDictionaryCas.cs: New. CAS unit tests.
* HybridDictionaryTest.cs: More test cases to increase coverage.
* ListDictionaryCas.cs: New. CAS unit tests.
* ListDictionaryTest.cs: More test cases to increase coverage.
* NameObjectCollectionBaseCas.cs: New. CAS unit tests.
* NameObjectCollectionBaseTest.cs: New. Unit tests.
* NameValueCollectionCas.cs: New. CAS unit tests.
* NameValueCollectionTest.cs: More test cases to increase coverage.
* OrderedDictionaryCas.cs: New. CAS unit tests.
* OrderedDictionaryTest.cs: New. Unit tests.
* StringCollectionCas.cs: New. CAS unit tests.
* StringCollectionTest.cs: More test cases to increase coverage.
* StringDictionaryCas.cs: New. CAS unit tests.
* StringDictionaryTest.cs: New. Unit tests.
2004-06-14 Sebastien Pouliot <sebastien@ximian.com>
* HybridDictionaryTest.cs: Added cases with an non-empty dictionary.
* NameValueCollectionTest.cs: Added tests for CopyTo(Array,int). Added
test for remove (case insensitive).
2004-06-05 Sebastien Pouliot <sebastien@ximian.com>
* HybridDictionaryTest.cs: Added cases with an empty dictionary.
* NameValueCollectionTest.cs: Added tests to add and replace (set)
existing values in collection. Added tests for CopyTo.
2004-01-01 Nick Drochak <ndrochak@gol.com>
* BitVector32Test.cs: Test some more values less than 1.
2003-09-04 Duncan Mak <duncan@ximian.com>
* BitVector32Test.cs (TestNegativeIndexer, TestSectionIndexer,
TestCreateSection): new tests from Alon Gazit <along@mainsoft.com>.
* ListDictionaryTest.cs (CopyTo1, CopyTo2, Remove): New file, with
tests from Alon Gazit <along@mainsoft.com>.
2002-06-24 Nick Drochak <ndrochak@gol.com>
* BasicOperationsTest.cs: Make test pass on .NET 1.1.
2002-03-29 Nick Drochak <ndrochak@gol.com>
* BasicOperationsTest.cs: Moved file here from root of Test dir
2002-06-24 Andrew Birkett <adb@tardis.ed.ac.uk>
* BitVector32Test.cs: New tests for sections and removed ^M's.
2002-05-11 Lawrence Pit <loz@cable.a2000.nl>
* Added NameValueCollectionTest.TestGetValues
2002-05-09 Lawrence Pit <loz@cable.a2000.nl>
* Moved StringCollectionTest.cs and NameValueCollectionTest to this dir

View File

@@ -0,0 +1,77 @@
//
// CollectionsUtilCas.cs
// - CAS unit tests for System.Collections.Specialized.CollectionsUtil
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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 !MOBILE
using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using MonoTests.System.Collections.Specialized;
namespace MonoCasTests.System.Collections.Specialized {
[TestFixture]
[Category ("CAS")]
public class CollectionsUtilCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ReuseUnitTests_Deny_Unrestricted ()
{
Assert.IsNotNull (CollectionsUtil.CreateCaseInsensitiveHashtable (), "CreateCaseInsensitiveHashtable()");
Assert.IsNotNull (CollectionsUtil.CreateCaseInsensitiveHashtable (1), "CreateCaseInsensitiveHashtable(int)");
Assert.IsNotNull (CollectionsUtil.CreateCaseInsensitiveHashtable (new Hashtable ()), "CreateCaseInsensitiveHashtable(IDictionary)");
Assert.IsNotNull (CollectionsUtil.CreateCaseInsensitiveSortedList (), "CreateCaseInsensitiveSortedList");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
ConstructorInfo ci = typeof (CollectionsUtil).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}
#endif

View File

@@ -0,0 +1,71 @@
//
// HybridDictionaryCas.cs - CAS unit tests for
// System.Collections.Specialized.HybridDictionary
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
using NUnit.Framework;
using System;
using System.Collections.Specialized;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using MonoTests.System.Collections.Specialized;
namespace MonoCasTests.System.Collections.Specialized {
[TestFixture]
[Category ("CAS")]
public class HybridDictionaryCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ReuseUnitTests_Deny_Unrestricted ()
{
HybridDictionaryTest unit = new HybridDictionaryTest ();
unit.DefaultValues ();
unit.All ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
ConstructorInfo ci = typeof (HybridDictionary).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}

View File

@@ -0,0 +1,98 @@
//
// HybridDictionaryTest.cs - NUnit Test Cases for System.Net.HybridDictionary
//
// Authors:
// Lawrence Pit (loz@cable.a2000.nl)
// Martin Willemoes Hansen (mwh@sysrq.dk)
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Martin Willemoes Hansen
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Specialized;
namespace MonoTests.System.Collections.Specialized
{
[TestFixture]
public class HybridDictionaryTest {
[Test]
public void DefaultValues ()
{
HybridDictionary hd = new HybridDictionary (100);
Assert.AreEqual (0, hd.Count, "Count");
Assert.IsFalse (hd.IsFixedSize, "IsFixedSize");
Assert.IsFalse (hd.IsReadOnly, "IsReadOnly");
Assert.IsFalse (hd.IsSynchronized, "IsSynchronized");
Assert.AreEqual (0, hd.Keys.Count, "Keys");
Assert.AreEqual (0, hd.Values.Count, "Values");
Assert.AreSame (hd, hd.SyncRoot, "SyncRoot");
Assert.IsNotNull (hd.GetEnumerator (), "GetEnumerator");
Assert.IsNotNull ((hd as IEnumerable).GetEnumerator (), "IEnumerable.GetEnumerator");
}
[Test]
public void All ()
{
HybridDictionary dict = new HybridDictionary (true);
dict.Add ("CCC", "ccc");
dict.Add ("BBB", "bbb");
dict.Add ("fff", "fff");
dict ["EEE"] = "eee";
dict ["ddd"] = "ddd";
Assert.AreEqual (5, dict.Count, "#1");
Assert.AreEqual ("eee", dict["eee"], "#2");
dict.Add ("CCC2", "ccc");
dict.Add ("BBB2", "bbb");
dict.Add ("fff2", "fff");
dict ["EEE2"] = "eee";
dict ["ddd2"] = "ddd";
dict ["xxx"] = "xxx";
dict ["yyy"] = "yyy";
Assert.AreEqual (12, dict.Count, "#3");
Assert.AreEqual ("eee", dict["eee"], "#4");
dict.Remove ("eee");
Assert.AreEqual (11, dict.Count, "Removed/Count");
Assert.IsFalse (dict.Contains ("eee"), "Removed/Contains(xxx)");
DictionaryEntry[] entries = new DictionaryEntry [11];
dict.CopyTo (entries, 0);
Assert.IsTrue (dict.Contains ("xxx"), "Contains(xxx)");
dict.Clear ();
Assert.AreEqual (0, dict.Count, "Cleared/Count");
Assert.IsFalse (dict.Contains ("xxx"), "Cleared/Contains(xxx)");
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#endif
public void Empty ()
{
HybridDictionary hd = new HybridDictionary ();
Assert.AreEqual (0, hd.Count, "Count");
Assert.IsFalse (hd.Contains ("unexisting"), "unexisting");
// under 1.x no exception, under 2.0 ArgumentNullException
Assert.IsFalse (hd.Contains (null), "Contains(null)");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void NotEmpty ()
{
HybridDictionary hd = new HybridDictionary (1, false);
hd.Add ("CCC", "ccc");
Assert.AreEqual (1, hd.Count, "Count");
// ArgumentNullException under all fx versions
Assert.IsFalse (hd.Contains (null), "Contains(null)");
}
}
}

View File

@@ -0,0 +1,72 @@
//
// ListDictionaryCas.cs - CAS unit tests for
// System.Collections.Specialized.ListDictionary
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
using NUnit.Framework;
using System;
using System.Collections.Specialized;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using MonoTests.System.Collections.Specialized;
namespace MonoCasTests.System.Collections.Specialized {
[TestFixture]
[Category ("CAS")]
public class ListDictionaryCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ReuseUnitTests_Deny_Unrestricted ()
{
ListDictionaryTest unit = new ListDictionaryTest ();
unit.Constructor_Default ();
unit.Constructor_IComparer_Null ();
unit.Constructor_IComparer ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
ConstructorInfo ci = typeof (ListDictionary).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}

View File

@@ -0,0 +1,99 @@
//
// ListDictionaryTest.cs
// - NUnit Test Cases for System.Collections.Specialized.ListDictionary.cs
//
// Authors:
// Duncan Mak (duncan@ximian.com)
// Alon Gazit (along@mainsoft.com)
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2003 Ximian Inc.
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Specialized;
namespace MonoTests.System.Collections.Specialized {
[TestFixture]
public class ListDictionaryTest {
private void BasicTests (ListDictionary ld)
{
Assert.AreEqual (0, ld.Count, "Count");
Assert.IsFalse (ld.IsFixedSize, "IsFixedSize");
Assert.IsFalse (ld.IsReadOnly, "IsReadOnly");
Assert.IsFalse (ld.IsSynchronized, "IsSynchronized");
Assert.AreEqual (0, ld.Keys.Count, "Keys");
Assert.AreEqual (0, ld.Values.Count, "Values");
Assert.IsNotNull (ld.SyncRoot, "SyncRoot");
Assert.IsNotNull (ld.GetEnumerator (), "GetEnumerator");
Assert.IsNotNull ((ld as IEnumerable).GetEnumerator (), "IEnumerable.GetEnumerator");
ld.Add ("a", "1");
Assert.AreEqual (1, ld.Count, "Count-1");
Assert.IsTrue (ld.Contains ("a"), "Contains(a)");
Assert.IsFalse (ld.Contains ("1"), "Contains(1)");
ld.Add ("b", null);
Assert.AreEqual (2, ld.Count, "Count-2");
Assert.IsNull (ld["b"], "this[b]");
DictionaryEntry[] entries = new DictionaryEntry[2];
ld.CopyTo (entries, 0);
ld["b"] = "2";
Assert.AreEqual ("2", ld["b"], "this[b]2");
ld.Remove ("b");
Assert.AreEqual (1, ld.Count, "Count-3");
ld.Clear ();
Assert.AreEqual (0, ld.Count, "Count-4");
}
[Test]
public void Constructor_Default ()
{
ListDictionary ld = new ListDictionary ();
BasicTests (ld);
}
[Test]
public void Constructor_IComparer_Null ()
{
ListDictionary ld = new ListDictionary (null);
BasicTests (ld);
}
[Test]
public void Constructor_IComparer ()
{
ListDictionary ld = new ListDictionary (new CaseInsensitiveComparer ());
BasicTests (ld);
}
[Test, ExpectedException (typeof (ArgumentNullException))]
public void CopyTo1 ()
{
ListDictionary ld = new ListDictionary ();
ld.CopyTo (null, 0);
}
[Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
public void CopyTo2 ()
{
ListDictionary ld = new ListDictionary ();
ld.CopyTo (new int[1],-1);
}
[Test, ExpectedException (typeof (ArgumentNullException))]
public void Remove ()
{
ListDictionary ld = new ListDictionary ();
ld.Remove (null);
}
}
}

View File

@@ -0,0 +1,81 @@
//
// NameObjectCollectionBaseCas.cs - CAS unit tests for
// System.Collections.Specialized.NameObjectCollectionBase
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
using NUnit.Framework;
using System;
using System.Collections.Specialized;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using MonoTests.System.Collections.Specialized;
namespace MonoCasTests.System.Collections.Specialized {
[TestFixture]
[Category ("CAS")]
public class NameObjectCollectionBaseCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ReuseUnitTests_Deny_Unrestricted ()
{
NameObjectCollectionBaseTest unit = new NameObjectCollectionBaseTest ();
unit.Constructor_Default ();
unit.Constructor_Int ();
unit.Constructor_Provider_Comparer ();
unit.Constructor_Int_Provider_Comparer ();
unit.GetObjectData ();
unit.GetAllValues_Type ();
unit.GetAllValues ();
#if NET_2_0
unit.Constructor_IEqualityComparer ();
unit.Constructor_Int_IEqualityComparer ();
unit.GetObjectData_IEqualityComparer ();
#endif
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
ConstructorInfo ci = typeof (UnitTestNameObjectCollectionBase).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}

View File

@@ -0,0 +1,88 @@
//
// NameValueCollectionCas.cs - CAS unit tests for
// System.Collections.Specialized.NameValueCollection
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
using NUnit.Framework;
using System;
using System.Collections.Specialized;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using MonoTests.System.Collections.Specialized;
namespace MonoCasTests.System.Collections.Specialized {
[TestFixture]
[Category ("CAS")]
public class NameValueCollectionCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ReuseUnitTests_Deny_Unrestricted ()
{
NameValueCollectionTest unit = new NameValueCollectionTest ();
unit.GetValues ();
unit.Get ();
unit.GetKey ();
unit.HasKeys ();
unit.Clear ();
unit.Add ();
unit.Add_Multiples ();
unit.Add_Multiples_Null ();
unit.Add_NVC ();
unit.Add_NVC_Null2 ();
unit.Set_New ();
unit.Set_Replace ();
unit.CaseInsensitive ();
unit.CopyTo ();
unit.Remove ();
#if NET_2_0
unit.Constructor_IEqualityComparer ();
unit.Constructor_Int_IEqualityComparer ();
#endif
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
ConstructorInfo ci = typeof (NameValueCollection).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,79 @@
//
// OrderedDictionaryCas.cs -
// CAS unit tests for System.Collections.Specialized.OrderedDictionary
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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 !MOBILE
using NUnit.Framework;
using System;
using System.Collections.Specialized;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using MonoTests.System.Collections.Specialized;
namespace MonoCasTests.System.Collections.Specialized {
[TestFixture]
[Category ("CAS")]
public class OrderedDictionaryCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ReuseUnitTests_Deny_Unrestricted ()
{
OrderedDictionaryTest unit = new OrderedDictionaryTest ();
unit.Constructor_Default ();
unit.Constructor_Int ();
unit.Constructor_IEqualityComparer ();
unit.Constructor_Int_IEqualityComparer ();
unit.GetObjectData ();
unit.GetObjectData_IEqualityComparer ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
ConstructorInfo ci = typeof (OrderedDictionary).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}
#endif

View File

@@ -0,0 +1,270 @@
//
// OrderedDictionaryTest.cs -
// Unit tests for System.Collections.Specialized.OrderedDictionary
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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 !MOBILE
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Runtime.Serialization;
using NUnit.Framework;
namespace MonoTests.System.Collections.Specialized {
[TestFixture]
public class OrderedDictionaryTest {
private void Common (OrderedDictionary od)
{
Assert.IsNotNull (od.GetEnumerator (), "GetEnumerator");
Assert.AreEqual (0, od.Count, "Count-0");
Assert.IsFalse (od.IsReadOnly, "IsReadOnly");
od.Add ("a", "1");
Assert.AreEqual (1, od.Count, "Count-1");
od["a"] = "11";
Assert.AreEqual ("11", od["a"], "this[string]");
od[0] = "111";
Assert.AreEqual ("111", od[0], "this[int]");
DictionaryEntry[] array = new DictionaryEntry[2];
od.CopyTo (array, 1);
Assert.AreEqual ("111", ((DictionaryEntry)array[1]).Value, "CopyTo");
Assert.AreEqual (1, od.Keys.Count, "Keys");
Assert.AreEqual (1, od.Values.Count, "Values");
Assert.IsTrue (od.Contains ("a"), "Contains(a)");
Assert.IsFalse (od.Contains ("111"), "Contains(111)");
od.Insert (0, "b", "2");
Assert.AreEqual (2, od.Count, "Count-2");
od.Add ("c", "3");
Assert.AreEqual (3, od.Count, "Count-3");
OrderedDictionary ro = od.AsReadOnly ();
od.RemoveAt (2);
Assert.AreEqual (2, od.Count, "Count-4");
Assert.IsFalse (od.Contains ("c"), "Contains(c)");
od.Remove ("b");
Assert.AreEqual (1, od.Count, "Count-5");
Assert.IsFalse (od.Contains ("b"), "Contains(b)");
od.Clear ();
Assert.AreEqual (0, od.Count, "Count-6");
Assert.IsTrue (ro.IsReadOnly, "IsReadOnly-2");
// it's a read-only reference
Assert.AreEqual (0, od.Count, "Count-7");
}
[Test]
public void Constructor_Default ()
{
OrderedDictionary od = new OrderedDictionary ();
Common (od);
}
[Test]
public void Constructor_Int ()
{
OrderedDictionary od = new OrderedDictionary ();
Common (od);
}
[Test]
// [ExpectedException (typeof (ArgumentOutOfRangeException))]
public void Constructor_IntNegative ()
{
new OrderedDictionary (-1);
}
[Test]
public void Constructor_IEqualityComparer ()
{
OrderedDictionary od = new OrderedDictionary (new EqualityComparer ());
Common (od);
}
[Test]
public void Constructor_Int_IEqualityComparer ()
{
OrderedDictionary od = new OrderedDictionary (5, new EqualityComparer ());
Common (od);
}
[Test]
public void Constructor_NoCase_IEqualityComparer ()
{
OrderedDictionary od = new OrderedDictionary (StringComparer.InvariantCultureIgnoreCase);
od ["Original_PhotoID"] = null;
od ["original_PhotoID"] = 12;
Assert.AreEqual (1, od.Count);
}
[Test]
// [ExpectedException (typeof (ArgumentOutOfRangeException))]
public void Constructor_IntNegative_IEqualityComparer ()
{
new OrderedDictionary (-1, new EqualityComparer ());
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ReadOnly_This_String ()
{
OrderedDictionary od = new OrderedDictionary ().AsReadOnly ();
od["a"] = 1;
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ReadOnly_This_int ()
{
OrderedDictionary od = new OrderedDictionary ().AsReadOnly ();
od[0] = 1;
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ReadOnly_Add ()
{
OrderedDictionary od = new OrderedDictionary ().AsReadOnly ();
od.Add ("a", "1");
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ReadOnly_Clear ()
{
OrderedDictionary od = new OrderedDictionary ().AsReadOnly ();
od.Clear ();
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ReadOnly_Insert ()
{
OrderedDictionary od = new OrderedDictionary ().AsReadOnly ();
od.Insert (0, "a", "1");
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ReadOnly_Remove ()
{
OrderedDictionary od = new OrderedDictionary ().AsReadOnly ();
od.Remove ("a");
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ReadOnly_RemoveAt ()
{
OrderedDictionary od = new OrderedDictionary ().AsReadOnly ();
od.RemoveAt (0);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void GetObjectData_Null ()
{
OrderedDictionary coll = new OrderedDictionary ();
coll.GetObjectData (null, new StreamingContext ());
}
[Test]
public void GetObjectData ()
{
OrderedDictionary coll = new OrderedDictionary (99);
coll.Add ("a", "1");
SerializationInfo si = new SerializationInfo (typeof (OrderedDictionary), new FormatterConverter ());
coll.GetObjectData (si, new StreamingContext ());
foreach (SerializationEntry se in si) {
switch (se.Name) {
case "KeyComparer":
Assert.IsNull (se.Value, se.Name);
break;
case "ReadOnly":
Assert.IsFalse ((bool) se.Value, se.Name);
break;
case "InitialCapacity":
Assert.AreEqual (99, se.Value, se.Name);
break;
case "ArrayList":
Assert.AreEqual ("1", ((DictionaryEntry)((object[]) se.Value)[0]).Value, se.Name);
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;
}
}
}
[Test]
public void GetObjectData_IEqualityComparer ()
{
EqualityComparer comparer = new EqualityComparer ();
OrderedDictionary coll = new OrderedDictionary (comparer);
coll.Add ("a", "1");
coll.Add ("b", "2");
coll = coll.AsReadOnly ();
SerializationInfo si = new SerializationInfo (typeof (OrderedDictionary), new FormatterConverter ());
coll.GetObjectData (si, new StreamingContext ());
foreach (SerializationEntry se in si) {
switch (se.Name) {
case "KeyComparer":
Assert.AreSame (comparer, se.Value, se.Name);
break;
case "ReadOnly":
Assert.IsTrue ((bool) se.Value, se.Name);
break;
case "InitialCapacity":
Assert.AreEqual (0, se.Value, se.Name);
break;
case "ArrayList":
Assert.AreEqual (2, ((object[]) se.Value).Length, se.Name);
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;
}
}
}
}
}
#endif

View File

@@ -0,0 +1,91 @@
//
// StringCollectionCas.cs - CAS unit tests for
// System.Collections.Specialized.StringCollection
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using MonoTests.System.Collections.Specialized;
namespace MonoCasTests.System.Collections.Specialized {
[TestFixture]
[Category ("CAS")]
public class StringCollectionCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ReuseUnitTest_Deny_Unrestricted ()
{
StringCollectionTest unit = new StringCollectionTest ();
unit.GetReady ();
unit.SimpleCount ();
unit.SimpleIsReadOnly ();
unit.SimpleIsSynchronized ();
unit.SimpleIndexOf ();
unit.SimpleCopyTo ();
unit.SimpleGetEnumerator ();
unit.SimpleContains ();
unit.SimpleItemGet ();
unit.SimpleAdd ();
unit.SimpleInsert ();
unit.SimpleRemove ();
unit.SimpleRemoveAt ();
unit.SimpleItemSet ();
unit.SimpleAddRange ();
unit.SimpleClear ();
unit.IList ();
unit.ICollection ();
unit.IEnumerable ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
ConstructorInfo ci = typeof (StringCollection).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}

View File

@@ -0,0 +1,234 @@
// System.Collections.Specialized.StringCollection.cs
//
// Authors:
// John Barnette (jbarn@httcb.net)
// Martin Willemoes Hansen (mwh@sysrq.dk)
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) Copyright 2001 John Barnette
// (C) Copyright 2003 Martin Willemoes Hansen
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
using NUnit.Framework;
using System.Collections;
using System.Collections.Specialized;
namespace MonoTests.System.Collections.Specialized {
[TestFixture]
public class StringCollectionTest {
private StringCollection sc;
string[] strings = {
"foo",
"bar",
"baz",
"john",
"paul",
"george",
"ringo"
};
[SetUp]
public void GetReady()
{
sc = new StringCollection();
sc.AddRange(strings);
}
// Simple Tests
[Test]
public void SimpleCount()
{
Assert.AreEqual(7, sc.Count);
}
[Test]
public void SimpleIsReadOnly()
{
Assert.IsFalse(sc.IsReadOnly);
}
[Test]
public void SimpleIsSynchronized()
{
Assert.IsFalse(sc.IsSynchronized);
}
[Test]
public void SimpleItemGet()
{
for(int i = 0; i < strings.Length; i++) {
Assert.AreEqual(strings[i], sc[i]);
}
}
[Test]
public void SimpleItemSet()
{
sc[0] = "bob";
Assert.AreEqual("bob", sc[0]);
}
[Test]
public void SimpleSyncRoot()
{
Assert.AreEqual(sc, sc.SyncRoot);
}
[Test]
public void SimpleAdd()
{
int index = sc.Add("chuck");
Assert.AreEqual(strings.Length, index);
Assert.AreEqual("chuck", sc[strings.Length]);
}
[Test]
public void SimpleAddRange()
{
string[] newStrings = {
"peter",
"paul",
"mary"
};
int index = sc.Count;
sc.AddRange(newStrings);
Assert.AreEqual(index + newStrings.Length, sc.Count);
for (int i = 0; i+index <= sc.Count-1; i++) {
Assert.AreEqual(newStrings[i], sc[i+index]);
}
}
[Test]
public void SimpleClear()
{
sc.Clear();
Assert.AreEqual(0, sc.Count);
}
[Test]
public void SimpleContains()
{
Assert.IsTrue(sc.Contains(strings[0]));
Assert.IsFalse(sc.Contains("NOT CONTAINED"));
}
[Test]
public void SimpleCopyTo()
{
string[] copyArray = new string[sc.Count];
sc.CopyTo(copyArray, 0);
for (int i = 0; i < copyArray.Length; i++) {
Assert.AreEqual(copyArray[i], sc[i]);
}
}
[Test]
public void SimpleGetEnumerator()
{
int index = 0;
foreach(string s in sc) {
Assert.AreEqual(s, strings[index]);
index++;
}
}
[Test]
public void SimpleIndexOf()
{
Assert.AreEqual(0, sc.IndexOf(strings[0]));
}
[Test]
public void SimpleInsert()
{
int index = 3;
int oldCount = sc.Count;
string before = sc[index - 1];
string current = sc[index];
string after = sc[index + 1];
string newStr = "paco";
sc.Insert(index, newStr);
Assert.AreEqual(oldCount + 1, sc.Count);
Assert.AreEqual(newStr, sc[index]);
Assert.AreEqual(before, sc[index-1]);
Assert.AreEqual(current, sc[index+1]);
Assert.AreEqual(after, sc[index+2]);
}
[Test]
public void SimpleRemove()
{
int oldCount = sc.Count;
sc.Remove(strings[0]);
Assert.AreEqual(sc.Count + 1, oldCount);
Assert.IsFalse(sc.Contains(strings[0]));
}
[Test]
public void SimpleRemoveAt()
{
int index = 3;
int oldCount = sc.Count;
string after = sc[index+1];
sc.RemoveAt(index);
Assert.AreEqual(sc.Count + 1, oldCount);
Assert.AreEqual(after, sc[index]);
}
[Test]
public void IList ()
{
IList list = (IList) new StringCollection ();
Assert.AreEqual (0, list.Count, "Count-0");
Assert.IsFalse (list.IsFixedSize, "IsFixedSize");
Assert.IsFalse (list.IsFixedSize, "IsReadOnly");
list.Add ("a");
Assert.AreEqual (1, list.Count, "Count-1");
Assert.IsTrue (list.Contains ("a"), "Contains(b)");
Assert.IsFalse (list.Contains ("b"), "Contains(b)");
Assert.AreEqual (0, list.IndexOf ("a"), "IndexOf(a)");
Assert.AreEqual (-1, list.IndexOf ("b"), "IndexOf(b)");
list.Insert (0, "b");
Assert.AreEqual (2, list.Count, "Count-2");
list.Remove ("b");
Assert.AreEqual (1, list.Count, "Count-3");
list.Add ("b");
list.RemoveAt (0);
Assert.AreEqual (1, list.Count, "Count-4");
list.Clear ();
Assert.AreEqual (0, list.Count, "Count-5");
}
[Test]
public void ICollection ()
{
ICollection coll = (ICollection) new StringCollection ();
Assert.AreEqual (0, coll.Count, "Count");
Assert.IsNotNull (coll.GetEnumerator (), "GetEnumerator");
coll.CopyTo (new string[0], 0);
Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
Assert.IsNotNull (coll.SyncRoot, "SyncRoot");
}
[Test]
public void IEnumerable ()
{
IEnumerable e = (IEnumerable) new StringCollection ();
Assert.IsNotNull (e.GetEnumerator (), "GetEnumerator");
}
}
}

View File

@@ -0,0 +1,73 @@
//
// StringDictionaryCas.cs - CAS unit tests for
// System.Collections.Specialized.StringDictionary
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using MonoTests.System.Collections.Specialized;
namespace MonoCasTests.System.Collections.Specialized {
[TestFixture]
[Category ("CAS")]
public class StringDictionaryCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ReuseUnitTest_Deny_Unrestricted ()
{
StringDictionaryTest unit = new StringDictionaryTest ();
unit.Empty ();
unit.This_Empty ();
unit.SomeElements ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
ConstructorInfo ci = typeof (StringDictionary).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}

View File

@@ -0,0 +1,138 @@
//
// OrderedDictionaryTest.cs -
// Unit tests for System.Collections.Specialized.OrderedDictionary
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.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.
//
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Runtime.Serialization;
using NUnit.Framework;
namespace MonoTests.System.Collections.Specialized {
[TestFixture]
public class StringDictionaryTest {
[Test]
public void Empty ()
{
StringDictionary sd = new StringDictionary ();
Assert.AreEqual (0, sd.Count, "Count");
Assert.IsFalse (sd.IsSynchronized, "IsSynchronized");
Assert.AreEqual (0, sd.Keys.Count, "Keys");
Assert.AreEqual (0, sd.Values.Count, "Values");
Assert.IsNotNull (sd.SyncRoot, "SyncRoot");
Assert.IsFalse (sd.ContainsKey ("a"), "ContainsKey");
Assert.IsFalse (sd.ContainsValue ("1"), "ContainsValue");
sd.CopyTo (new DictionaryEntry[0], 0);
Assert.IsNotNull (sd.GetEnumerator (), "GetEnumerator");
sd.Remove ("a"); // doesn't exists
sd.Clear ();
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#else
[ExpectedException (typeof (NullReferenceException))]
#endif
public void This_Null ()
{
StringDictionary sd = new StringDictionary ();
sd[null] = "1";
}
[Test]
public void This_Empty ()
{
StringDictionary sd = new StringDictionary ();
sd[String.Empty] = null;
Assert.IsNull (sd[String.Empty], "this[String.Empty]");
Assert.AreEqual (1, sd.Count, "Count-1");
Assert.IsTrue (sd.ContainsKey (String.Empty), "ContainsKey");
Assert.IsTrue (sd.ContainsValue (null), "ContainsValue");
}
[Test]
public void SomeElements ()
{
StringDictionary sd = new StringDictionary ();
for (int i = 0; i < 10; i++)
sd.Add (i.ToString (), (i * 10).ToString ());
Assert.AreEqual ("10", sd["1"], "this[1]");
Assert.AreEqual (10, sd.Count, "Count-10");
Assert.AreEqual (10, sd.Keys.Count, "Keys");
Assert.AreEqual (10, sd.Values.Count, "Values");
Assert.IsTrue (sd.ContainsKey ("2"), "ContainsKey");
Assert.IsTrue (sd.ContainsValue ("20"), "ContainsValue");
DictionaryEntry[] array = new DictionaryEntry[10];
sd.CopyTo (array, 0);
sd.Remove ("1");
Assert.AreEqual (9, sd.Count, "Count-9");
sd.Clear ();
Assert.AreEqual (0, sd.Count, "Count-0");
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#else
[ExpectedException (typeof (NullReferenceException))]
#endif
public void Add_NullKey ()
{
StringDictionary sd = new StringDictionary ();
sd.Add (null, "a");
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#else
[ExpectedException (typeof (NullReferenceException))]
#endif
public void ContainsKey_Null ()
{
StringDictionary sd = new StringDictionary ();
sd.ContainsKey (null);
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#else
[ExpectedException (typeof (NullReferenceException))]
#endif
public void Remove_Null ()
{
StringDictionary sd = new StringDictionary ();
sd.Remove (null);
}
}
}