* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / corlib / Test / System.Collections.ObjectModel / CollectionTest.cs
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.
27 //
28
29 #if NET_2_0
30
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;
37
38 namespace MonoTests.System.Collections.ObjectModel
39 {
40         [TestFixture]
41         public class CollectionTest
42         {
43                 [Test]
44                 public void UsableSyncLockTest ()
45                 {
46                         List <int> list = new List <int> ();
47                         Collection <int> c = new Collection <int> (list);
48
49                         object listLock = ((ICollection) list).SyncRoot;
50                         object cLock = ((ICollection) c).SyncRoot;
51
52                         Assert.AreSame (listLock, cLock);
53                 }
54
55                 [Test]
56                 public void UnusableSyncLockTest ()
57                 {
58                         UnimplementedList <int> list = new UnimplementedList <int> ();
59                         Collection <int> c = new Collection <int> (list);
60
61                         object cLock = ((ICollection) c).SyncRoot;
62
63                         Assert.IsNotNull (cLock);
64                         Assert.IsTrue (cLock.GetType ().Equals (typeof (object)));
65                 }
66
67                 class UnimplementedList <T> : IList <T>
68                 {
69
70                         #region IList <T> Members
71
72                         int IList <T>.IndexOf (T item)
73                         {
74                                 throw new Exception ("The method or operation is not implemented.");
75                         }
76
77                         void IList <T>.Insert (int index, T item)
78                         {
79                                 throw new Exception ("The method or operation is not implemented.");
80                         }
81
82                         void IList <T>.RemoveAt (int index)
83                         {
84                                 throw new Exception ("The method or operation is not implemented.");
85                         }
86
87                         T IList <T>.this [int index]
88                         {
89                                 get
90                                 {
91                                         throw new Exception ("The method or operation is not implemented.");
92                                 }
93                                 set
94                                 {
95                                         throw new Exception ("The method or operation is not implemented.");
96                                 }
97                         }
98
99                         #endregion
100
101                         #region ICollection <T> Members
102
103                         void ICollection <T>.Add (T item)
104                         {
105                                 throw new Exception ("The method or operation is not implemented.");
106                         }
107
108                         void ICollection <T>.Clear ()
109                         {
110                                 throw new Exception ("The method or operation is not implemented.");
111                         }
112
113                         bool ICollection <T>.Contains (T item)
114                         {
115                                 throw new Exception ("The method or operation is not implemented.");
116                         }
117
118                         void ICollection <T>.CopyTo (T [] array, int arrayIndex)
119                         {
120                                 throw new Exception ("The method or operation is not implemented.");
121                         }
122
123                         int ICollection <T>.Count
124                         {
125                                 get { throw new Exception ("The method or operation is not implemented."); }
126                         }
127
128                         bool ICollection <T>.IsReadOnly
129                         {
130                                 get { throw new Exception ("The method or operation is not implemented."); }
131                         }
132
133                         bool ICollection <T>.Remove (T item)
134                         {
135                                 throw new Exception ("The method or operation is not implemented.");
136                         }
137
138                         #endregion
139
140                         #region IEnumerable <T> Members
141
142                         IEnumerator <T> IEnumerable <T>.GetEnumerator ()
143                         {
144                                 throw new Exception ("The method or operation is not implemented.");
145                         }
146
147                         #endregion
148
149                         #region IEnumerable Members
150
151                         IEnumerator IEnumerable.GetEnumerator ()
152                         {
153                                 throw new Exception ("The method or operation is not implemented.");
154                         }
155
156                         #endregion
157 }
158         }
159 }
160
161 #endif