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,29 @@
2010-06-09 Jonathan Pryor <jpryor@novell.com>
* KeyedCollectionTest.cs: Verify exception safety of Insert().
2008-01-20 Juraj Skripsky <js@hotfeet.ch>
* ReadOnlyCollectionTest.cs: Add test to verify that ReadOnlyCollection
is indeed only a simple wrapper for a given IList.
Add tests for ICollection.IsSynchronized, IList.IsFixedSize and
IList.IsReadOnly.
2008-01-13 Gert Driesen <drieseng@users.sourceforge.net>
* CollectionTest.cs: Added test for ICollection.CopyTo.
* ReadOnlyCollectionTest.cs: Added ctor tests, and test for
ICollection.CopyTo.
2005-10-25 Atsushi Enomoto <atsushi@ximian.com>
* KeyedCollectionTest.cs : new file by Carlo Kok (ck@carlo-kok.com).
2005-06-21 Raja R Harinath <rharinath@novell.com>
* CollectionTest.cs (IEnumerable.GetEnumerator): Don't prefix with
System.Collections, since it resolves to the MonoTests namespace.
2005-06-21 David Waite <mass@akuma.org>
* CollectionTest.cs : added

View File

@ -0,0 +1,190 @@
//
// MonoTests.System.Collections.Generic.Test.CollectionTest
//
// Authors:
// David Waite (mass@akuma.org)
//
// Copyright (C) 2005 David Waite
//
// 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_2_0
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using NUnit.Framework;
namespace MonoTests.System.Collections.ObjectModel
{
[TestFixture]
public class CollectionTest
{
[Test]
public void UsableSyncLockTest ()
{
List <int> list = new List <int> ();
Collection <int> c = new Collection <int> (list);
object listLock = ((ICollection) list).SyncRoot;
object cLock = ((ICollection) c).SyncRoot;
Assert.AreSame (listLock, cLock);
}
[Test]
public void UnusableSyncLockTest ()
{
UnimplementedList <int> list = new UnimplementedList <int> ();
Collection <int> c = new Collection <int> (list);
object cLock = ((ICollection) c).SyncRoot;
Assert.IsNotNull (cLock);
Assert.IsTrue (cLock.GetType ().Equals (typeof (object)));
}
[Test]
public void ICollection_CopyTo ()
{
Collection <int> c = new Collection <int> ();
c.Add (10);
c.Add (7);
Array array = Array.CreateInstance (typeof (int), 2);
((ICollection) c).CopyTo (array, 0);
Assert.AreEqual (10, array.GetValue (0), "#A1");
Assert.AreEqual (7, array.GetValue (1), "#A2");
array = Array.CreateInstance (typeof (int), 5);
((ICollection) c).CopyTo (array, 2);
Assert.AreEqual (0, array.GetValue (0), "#B1");
Assert.AreEqual (0, array.GetValue (1), "#B2");
Assert.AreEqual (10, array.GetValue (2), "#B3");
Assert.AreEqual (7, array.GetValue (3), "#B4");
Assert.AreEqual (0, array.GetValue (4), "#B5");
array = Array.CreateInstance (typeof (object), 5);
((ICollection) c).CopyTo (array, 2);
Assert.IsNull (array.GetValue (0), "#C1");
Assert.IsNull (array.GetValue (1), "#C2");
Assert.AreEqual (10, array.GetValue (2), "#C3");
Assert.AreEqual (7, array.GetValue (3), "#C4");
Assert.IsNull (array.GetValue (4), "#C2");
}
class UnimplementedList <T> : IList <T>
{
#region IList <T> Members
int IList <T>.IndexOf (T item)
{
throw new Exception ("The method or operation is not implemented.");
}
void IList <T>.Insert (int index, T item)
{
throw new Exception ("The method or operation is not implemented.");
}
void IList <T>.RemoveAt (int index)
{
throw new Exception ("The method or operation is not implemented.");
}
T IList <T>.this [int index]
{
get
{
throw new Exception ("The method or operation is not implemented.");
}
set
{
throw new Exception ("The method or operation is not implemented.");
}
}
#endregion
#region ICollection <T> Members
void ICollection <T>.Add (T item)
{
throw new Exception ("The method or operation is not implemented.");
}
void ICollection <T>.Clear ()
{
throw new Exception ("The method or operation is not implemented.");
}
bool ICollection <T>.Contains (T item)
{
throw new Exception ("The method or operation is not implemented.");
}
void ICollection <T>.CopyTo (T [] array, int arrayIndex)
{
throw new Exception ("The method or operation is not implemented.");
}
int ICollection <T>.Count
{
get { throw new Exception ("The method or operation is not implemented."); }
}
bool ICollection <T>.IsReadOnly
{
get { throw new Exception ("The method or operation is not implemented."); }
}
bool ICollection <T>.Remove (T item)
{
throw new Exception ("The method or operation is not implemented.");
}
#endregion
#region IEnumerable <T> Members
IEnumerator <T> IEnumerable <T>.GetEnumerator ()
{
throw new Exception ("The method or operation is not implemented.");
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator ()
{
throw new Exception ("The method or operation is not implemented.");
}
#endregion
}
}
}
#endif

View File

@ -0,0 +1,225 @@
// KeyedCollectionTest.cs - NUnit Test Cases for System.Collections.ObjectModel.KeyedCollection
//
// Carlo Kok (ck@carlo-kok.com)
//
// (C) Carlo Kok
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Globalization;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace MonoTests.System.Collections.ObjectModel
{
[TestFixture]
public class KeyedCollectionTest
{
private class CaseInsensitiveComparer : IEqualityComparer<string>
{
public CaseInsensitiveComparer () { }
#region IEqualityComparer<string> Members
public bool Equals (string x, string y)
{
return String.Compare (x, y, true,
CultureInfo.InvariantCulture) == 0;
}
public int GetHashCode (string obj)
{
return obj.ToUpper (CultureInfo.InvariantCulture).GetHashCode ();
}
#endregion
}
private class StrKeyCollection : KeyedCollection<string, string>
{
public StrKeyCollection (
IEqualityComparer<string> comparer,
int dictionaryCreationThreshold):
base (comparer, dictionaryCreationThreshold)
{
}
protected override string GetKeyForItem (string item)
{
return "Key:" + item;
}
public IDictionary<string, string> GetDictionary()
{
return Dictionary;
}
}
public KeyedCollectionTest ()
{
}
[Test]
public void TestDelete ()
{
StrKeyCollection collection =
new StrKeyCollection (EqualityComparer<string>.Default, 2);
collection.Add ("One"); // Key:First
collection.Add ("Two"); // Key:Two
Assert.IsTrue (collection.Remove ("Key:One"));
collection.Add ("Four"); // Key:Four
collection.Insert (2, "Three"); // Key:Three
Assert.IsTrue (collection.Remove ("Key:Three"));
Assert.IsFalse (collection.Remove ("Unknown"));
Assert.AreEqual (collection.GetDictionary ().Count, 2);
Assert.AreEqual (collection.Count, 2, "Collection count not equal to 2");
// check if all items are ordered correctly
Assert.AreEqual (collection [0], "Two");
Assert.AreEqual (collection [1], "Four");
Assert.AreEqual (collection ["Key:Two"], "Two");
Assert.AreEqual (collection ["Key:Four"], "Four");
try {
collection ["Key:One"].ToString();
Assert.Fail ("Unknown key should fail");
} catch (KeyNotFoundException e) {
e.ToString(); // avoid warning
// oke
}
try {
collection ["Key:One"].ToString();
Assert.Fail ("Unknown key should fail");
} catch (KeyNotFoundException e) {
e.ToString (); // avoid warning
// oke
}
}
[Test]
public void Insert_InvalidIndexDoesNotInsert ()
{
StrKeyCollection collection =
new StrKeyCollection(EqualityComparer<string>.Default, 0);
InsertInvalidIndex (collection, -1);
InsertInvalidIndex (collection, 1);
}
void InsertInvalidIndex (StrKeyCollection collection, int index)
{
try {
collection.Insert (index, "One");
Assert.Fail ("Invalid index should fail.");
}
catch (ArgumentOutOfRangeException) {
}
catch (Exception e) {
Assert.Fail ("Invalid exception type: expected ArgumentOutOfRangeException, got " + e.GetType ().Name);
}
IDictionary<string, string> dict = collection.GetDictionary ();
if (dict != null) {
Assert.AreEqual (0, dict.Count);
Assert.IsFalse (dict.ContainsKey ("Key:One"));
}
}
[Test]
public void Insert_DuplicateKey ()
{
StrKeyCollection collection =
new StrKeyCollection(EqualityComparer<string>.Default, 0);
collection.Add ("One");
try {
collection.Add ("One");
Assert.Fail ("Duplicate keys should throw ArgumentException.");
}
catch (ArgumentException) {
}
catch (Exception e) {
Assert.Fail ("Invalid exception type: expected ArgumentOutOfRangeException, got " + e.GetType ().Name);
}
Assert.AreEqual (1, collection.Count);
Assert.AreEqual (1, collection.GetDictionary ().Count);
}
[Test]
public void Insert_DuplicateKey_NoDictionary ()
{
StrKeyCollection collection =
new StrKeyCollection(EqualityComparer<string>.Default, 4);
collection.Add ("One");
try {
collection.Add ("One");
Assert.Fail ("Duplicate keys should throw ArgumentException.");
}
catch (ArgumentException) {
}
catch (Exception e) {
Assert.Fail ("Invalid exception type: expected ArgumentOutOfRangeException, got " + e.GetType ().Name);
}
Assert.AreEqual (1, collection.Count);
Assert.AreEqual (null, collection.GetDictionary ());
}
[Test]
public void TestInsert ()
{
StrKeyCollection collection =
new StrKeyCollection(EqualityComparer<string>.Default, 2);
Assert.IsNull (collection.GetDictionary (),
"Dictionary created too early"); // There can't be a dictionary yet
collection.Add ("One"); // Key:First
Assert.IsNull (collection.GetDictionary(),
"Dictionary created too early"); // There can't be a dictionary yet
collection.Add ("Two"); // Key:Two
Assert.IsNull (collection.GetDictionary (),
"Dictionary created too early"); // There can't be a dictionary yet
collection.Add ("Four"); // Key:Four
Assert.IsNotNull(collection.GetDictionary (),
"Dictionary created too late"); // There must be a dictionary
collection.Insert (2, "Three"); // Key:Three
Assert.AreEqual (collection.Count, 4,
"Collection count not equal to 4");
// check if all items are ordered correctly
Assert.AreEqual (collection [0], "One");
Assert.AreEqual (collection [1], "Two");
Assert.AreEqual (collection [2], "Three");
Assert.AreEqual (collection [3], "Four");
Assert.AreEqual (collection ["Key:One"], "One");
Assert.AreEqual (collection ["Key:Two"], "Two");
Assert.AreEqual (collection ["Key:Three"], "Three");
Assert.AreEqual (collection ["Key:Four"], "Four");
Assert.AreEqual (collection.GetDictionary ().Count, 4);
try {
collection ["UnkownKey"].ToString();
Assert.Fail ("Unknown key should fail");
} catch(KeyNotFoundException e) {
e.ToString(); // avoid warning
// oke
}
}
}
}
#endif

View File

@ -0,0 +1,131 @@
//
// MonoTests.System.Collections.Generic.Test.ReadOnlyCollectionTest
//
// Authors:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// Copyright (C) 2008 Gert Driesen
//
// 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_2_0
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using NUnit.Framework;
namespace MonoTests.System.Collections.ObjectModel
{
class SyncPretendingList<T> : List<T>, ICollection
{
bool ICollection.IsSynchronized {
get { return true; }
}
}
[TestFixture]
public class ReadOnlyCollectionTest
{
[Test]
public void Constructor0 ()
{
Collection <int> c = new Collection <int> ();
c.Add (10);
c.Add (7);
ReadOnlyCollection <int> r = new ReadOnlyCollection <int> (c);
Assert.AreEqual (10, r [0], "#1");
Assert.AreEqual (7, r [1], "#2");
}
[Test]
public void IsSimpleWrapper ()
{
Collection <int> c = new Collection <int> ();
c.Add (1);
ReadOnlyCollection <int> r = new ReadOnlyCollection <int> (c);
Assert.AreEqual (1, r.Count, "#1");
c.Remove (1);
Assert.AreEqual (0, r.Count, "#2");
}
[Test]
public void IList_Properties ()
{
List <int> l = new List <int> ();
ReadOnlyCollection <int> r = new ReadOnlyCollection <int> (l);
Assert.IsTrue (((IList)r).IsReadOnly, "#1");
Assert.IsTrue (((IList)r).IsFixedSize, "#2");
}
[Test]
public void ICollection_Properties ()
{
List <int> l = new SyncPretendingList <int> ();
ReadOnlyCollection <int> r = new ReadOnlyCollection <int> (l);
Assert.IsFalse (((ICollection)r).IsSynchronized, "#1");
}
[Test]
public void Constructor0_List_Null ()
{
try {
new ReadOnlyCollection <int> ((List <int>) 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 ("list", ex.ParamName, "#6");
}
}
[Test]
public void ICollection_CopyTo ()
{
Collection <int> c = new Collection <int> ();
c.Add (10);
c.Add (7);
ReadOnlyCollection <int> r = new ReadOnlyCollection <int> (c);
Array array = Array.CreateInstance (typeof (int), 2);
((ICollection) c).CopyTo (array, 0);
Assert.AreEqual (10, array.GetValue (0), "#A1");
Assert.AreEqual (7, array.GetValue (1), "#A2");
array = Array.CreateInstance (typeof (object), 2);
((ICollection) c).CopyTo (array, 0);
Assert.AreEqual (10, array.GetValue (0), "#B1");
Assert.AreEqual (7, array.GetValue (1), "#B2");
}
}
}
#endif