2010-04-15 Jb Evain <jbevain@novell.com>
[mcs.git] / class / corlib / Test / System.Collections.ObjectModel / CollectionTest.cs
blobfcb088c203e866ba8334a025268ab5291c6e90b3
1 //
2 // MonoTests.System.Collections.Generic.Test.CollectionTest
3 //
4 // Authors:
5 // David Waite (mass@akuma.org)
6 //
7 // Copyright (C) 2005 David Waite
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #if NET_2_0
31 using System;
32 using System.Collections;
33 using System.Collections.Generic;
34 using System.Collections.ObjectModel;
35 using System.Text;
36 using NUnit.Framework;
38 namespace MonoTests.System.Collections.ObjectModel
40 [TestFixture]
41 public class CollectionTest
43 [Test]
44 public void UsableSyncLockTest ()
46 List <int> list = new List <int> ();
47 Collection <int> c = new Collection <int> (list);
49 object listLock = ((ICollection) list).SyncRoot;
50 object cLock = ((ICollection) c).SyncRoot;
52 Assert.AreSame (listLock, cLock);
55 [Test]
56 public void UnusableSyncLockTest ()
58 UnimplementedList <int> list = new UnimplementedList <int> ();
59 Collection <int> c = new Collection <int> (list);
61 object cLock = ((ICollection) c).SyncRoot;
63 Assert.IsNotNull (cLock);
64 Assert.IsTrue (cLock.GetType ().Equals (typeof (object)));
67 [Test]
68 public void ICollection_CopyTo ()
70 Collection <int> c = new Collection <int> ();
71 c.Add (10);
72 c.Add (7);
74 Array array = Array.CreateInstance (typeof (int), 2);
75 ((ICollection) c).CopyTo (array, 0);
76 Assert.AreEqual (10, array.GetValue (0), "#A1");
77 Assert.AreEqual (7, array.GetValue (1), "#A2");
79 array = Array.CreateInstance (typeof (int), 5);
80 ((ICollection) c).CopyTo (array, 2);
81 Assert.AreEqual (0, array.GetValue (0), "#B1");
82 Assert.AreEqual (0, array.GetValue (1), "#B2");
83 Assert.AreEqual (10, array.GetValue (2), "#B3");
84 Assert.AreEqual (7, array.GetValue (3), "#B4");
85 Assert.AreEqual (0, array.GetValue (4), "#B5");
87 array = Array.CreateInstance (typeof (object), 5);
88 ((ICollection) c).CopyTo (array, 2);
89 Assert.IsNull (array.GetValue (0), "#C1");
90 Assert.IsNull (array.GetValue (1), "#C2");
91 Assert.AreEqual (10, array.GetValue (2), "#C3");
92 Assert.AreEqual (7, array.GetValue (3), "#C4");
93 Assert.IsNull (array.GetValue (4), "#C2");
96 class UnimplementedList <T> : IList <T>
99 #region IList <T> Members
101 int IList <T>.IndexOf (T item)
103 throw new Exception ("The method or operation is not implemented.");
106 void IList <T>.Insert (int index, T item)
108 throw new Exception ("The method or operation is not implemented.");
111 void IList <T>.RemoveAt (int index)
113 throw new Exception ("The method or operation is not implemented.");
116 T IList <T>.this [int index]
120 throw new Exception ("The method or operation is not implemented.");
124 throw new Exception ("The method or operation is not implemented.");
128 #endregion
130 #region ICollection <T> Members
132 void ICollection <T>.Add (T item)
134 throw new Exception ("The method or operation is not implemented.");
137 void ICollection <T>.Clear ()
139 throw new Exception ("The method or operation is not implemented.");
142 bool ICollection <T>.Contains (T item)
144 throw new Exception ("The method or operation is not implemented.");
147 void ICollection <T>.CopyTo (T [] array, int arrayIndex)
149 throw new Exception ("The method or operation is not implemented.");
152 int ICollection <T>.Count
154 get { throw new Exception ("The method or operation is not implemented."); }
157 bool ICollection <T>.IsReadOnly
159 get { throw new Exception ("The method or operation is not implemented."); }
162 bool ICollection <T>.Remove (T item)
164 throw new Exception ("The method or operation is not implemented.");
167 #endregion
169 #region IEnumerable <T> Members
171 IEnumerator <T> IEnumerable <T>.GetEnumerator ()
173 throw new Exception ("The method or operation is not implemented.");
176 #endregion
178 #region IEnumerable Members
180 IEnumerator IEnumerable.GetEnumerator ()
182 throw new Exception ("The method or operation is not implemented.");
185 #endregion
190 #endif