Author: dwaite
Date: 2005-06-21 02:39:00 -0400 (Tue, 21 Jun 2005)
New Revision: 46281

Added:
   trunk/mcs/class/corlib/Test/System.Collections.ObjectModel/
   trunk/mcs/class/corlib/Test/System.Collections.ObjectModel/ChangeLog
   trunk/mcs/class/corlib/Test/System.Collections.ObjectModel/CollectionTest.cs
Modified:
   trunk/mcs/class/corlib/ChangeLog
   trunk/mcs/class/corlib/System.Collections.ObjectModel/ChangeLog
   trunk/mcs/class/corlib/System.Collections.ObjectModel/Collection.cs
   trunk/mcs/class/corlib/System.Collections.ObjectModel/ReadOnlyCollection.cs
   trunk/mcs/class/corlib/corlib_test.dll.sources
Log:
2005-06-21  David Waite  <[EMAIL PROTECTED]>

        * Collection.cs ReadonlyCollection.cs: Implement all methods
        * CollectionTest.cs : added
        * corlib_test.dll.sources: Added 
System.Collections.ObjectModel.Collection test


Modified: trunk/mcs/class/corlib/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/ChangeLog    2005-06-21 06:33:00 UTC (rev 46280)
+++ trunk/mcs/class/corlib/ChangeLog    2005-06-21 06:39:00 UTC (rev 46281)
@@ -1,3 +1,7 @@
+2005-06-21  David Waite  <[EMAIL PROTECTED]>
+
+       * corlib_test.dll.sources: Added 
System.Collections.ObjectModel.Collection test
+
 2005-06-19  Zoltan Varga  <[EMAIL PROTECTED]>
 
        * corlib.dll.sources: Add System.Collections.ObjectModel classes.

Modified: trunk/mcs/class/corlib/System.Collections.ObjectModel/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.Collections.ObjectModel/ChangeLog     
2005-06-21 06:33:00 UTC (rev 46280)
+++ trunk/mcs/class/corlib/System.Collections.ObjectModel/ChangeLog     
2005-06-21 06:39:00 UTC (rev 46281)
@@ -1,3 +1,7 @@
+2005-06-19  David Waite  <[EMAIL PROTECTED]>
+
+        * Collection.cs ReadonlyCollection.cs: Implement all methods
+
 2005-06-19  Zoltan Varga  <[EMAIL PROTECTED]>
 
        * Collection.cs KeyedCollection.cs ReadOnlyCollection.cs: New files.

Modified: trunk/mcs/class/corlib/System.Collections.ObjectModel/Collection.cs
===================================================================
--- trunk/mcs/class/corlib/System.Collections.ObjectModel/Collection.cs 
2005-06-21 06:33:00 UTC (rev 46280)
+++ trunk/mcs/class/corlib/System.Collections.ObjectModel/Collection.cs 
2005-06-21 06:39:00 UTC (rev 46281)
@@ -4,12 +4,15 @@
 //
 // Author:
 //    Zoltan Varga ([EMAIL PROTECTED])
+//    David Waite ([EMAIL PROTECTED])
 //
 // (C) 2005 Novell, Inc.
+// (C) 2005 David Waite
 //
 
 //
 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// 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
@@ -39,152 +42,184 @@
 
 namespace System.Collections.ObjectModel
 {
-       [ComVisible(false)]
+       [ComVisible (false)]
        [Serializable]
-       public class Collection<T> : IList<T>, ICollection<T>, IEnumerable<T>, 
IList, ICollection, IEnumerable
+       public class Collection <T> : IList <T>, ICollection <T>, IEnumerable 
<T>, IList, ICollection, IEnumerable
        {
+               IList <T> list;
+               object syncRoot;
+               
                public Collection ()
                {
-                       throw new NotImplementedException ();
+                       List <T> l = new List <T> ();
+                       IList l2 = l as IList;
+                       syncRoot = l2.SyncRoot;
+                       list = l;
                }
 
-               public Collection (IList<T> list)
+               public Collection (IList <T> list)
                {
-                       throw new NotImplementedException ();
+                       if (list == null)
+                               throw new ArgumentNullException ("list");
+                       this.list = list;
+                       ICollection l = list as ICollection;
+                       syncRoot = (l != null) ? l.SyncRoot : new object ();
                }
 
                public void Add (T item)
                {
-                       throw new NotImplementedException ();
+                       list.Add (item);                        
                }
 
                public void Clear ()
                {
-                       throw new NotImplementedException ();
+                       list.Clear ();
                }
 
                public bool Contains (T item)
                {
-                       throw new NotImplementedException ();
+                       return list.Contains (item);
                }
 
-               public void CopyTo (T[] array, int index)
+               public void CopyTo (T [] array, int index)
                {
-                       throw new NotImplementedException ();
+                       list.CopyTo (array, index);
                }
 
-               public IEnumerator<T> GetEnumerator ()
+               public IEnumerator <T> GetEnumerator ()
                {
-                       throw new NotImplementedException ();
+                       return list.GetEnumerator ();
                }
 
                public int IndexOf (T item)
                {
-                       throw new NotImplementedException ();
+                       return list.IndexOf (item);
                }
 
                public void Insert (int index, T item)
                {
-                       throw new NotImplementedException ();
+                       list.Insert (index, item);
                }
 
                public bool Remove (T item)
                {
-                       throw new NotImplementedException ();
+                       return list.Remove (item);
                }
 
                public void RemoveAt (int index)
                {
-                       throw new NotImplementedException ();
+                       list.RemoveAt (index);
                }
 
                public virtual int Count {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return list.Count; }
                }
 
                public virtual T this [int index] {
-                       get {
-                               throw new NotImplementedException ();
-                       }
-                       set {
-                               throw new NotImplementedException ();
-                       }
+                       get { return list [index]; }
+                       set { list [index] = value; }
                }
 
                public bool IsReadOnly {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return list.IsReadOnly; }
                }
+               
+#region Helper methods for non-generic interfaces
+               
+               internal static bool IsValidItem (object item)
+               {
+                       return (item is T || (item == null && ! typeof 
(T).IsValueType));
+               }
+               
+               internal static T ConvertItem (object item)
+               {
+                       if (IsValidItem (item))
+                               return (T)item;
+                       throw new ArgumentException ("item");
+               }
+               
+               internal static void CheckWritable (IList <T> list)
+               {
+                       if (list.IsReadOnly)
+                               throw new NotSupportedException ();
+               }
+               
+               internal static bool IsSynchronized (IList <T> list)
+               {
+                       ICollection c = list as ICollection;
+                       return (c != null) ? c.IsSynchronized : false;
+               }
+               
+               internal static bool IsFixedSize (IList <T> list)
+               {
+                       IList l = list as IList;
+                       return (l != null) ? l.IsFixedSize : false;
+               }
+#endregion
 
 #region Not generic interface implementations
                void ICollection.CopyTo (Array array, int arrayIndex)
                {
-                       throw new NotImplementedException ();
+                       T [] target = array as T [];
+                       if (target == null)
+                               throw new ArgumentException ("array");
+                       list.CopyTo (target, arrayIndex);
                }
                
-               IEnumerator IEnumerable.GetEnumerator()
+               IEnumerator IEnumerable.GetEnumerator ()
                {
-                       throw new NotImplementedException ();
+                       return (IEnumerator) list.GetEnumerator ();
                }
-               
+                               
                int IList.Add (object item)
                {
-                       throw new NotImplementedException ();
+                       list.Add (ConvertItem (item));
+                       return list.Count - 1;
                }
                
                bool IList.Contains (object item)
                {
-                       throw new NotImplementedException ();
+                       if (IsValidItem (item))
+                               return list.Contains ((T) item);
+                       return false;
                }
                
                int IList.IndexOf (object item)
                {
-                       throw new NotImplementedException ();
+                       if (IsValidItem (item))
+                               return list.IndexOf ((T) item);
+                       return -1;
                }
                
                void IList.Insert (int index, object item)
                {
-                       throw new NotImplementedException ();
+                       list.Insert (index, ConvertItem (item));
                }
                
                void IList.Remove (object item)
                {
-                       throw new NotImplementedException ();
+                       CheckWritable (list);
+                       list.Remove (ConvertItem (item));
                }
                
                bool ICollection.IsSynchronized {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return IsSynchronized (list); }
                }
                
                object ICollection.SyncRoot {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return syncRoot; }
                }
                bool IList.IsFixedSize {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return IsFixedSize (list); }
                }
                
                bool IList.IsReadOnly {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return list.IsReadOnly; }
                }
                
                object IList.this [int index] {
-                       get {
-                               throw new NotImplementedException ();
-                       }
-                       set {
-                               throw new NotImplementedException ();
-                       }
+                       get { return list [index]; }
+                       set { list [index] = ConvertItem (value); }
                }
 #endregion
        }

Modified: 
trunk/mcs/class/corlib/System.Collections.ObjectModel/ReadOnlyCollection.cs
===================================================================
--- trunk/mcs/class/corlib/System.Collections.ObjectModel/ReadOnlyCollection.cs 
2005-06-21 06:33:00 UTC (rev 46280)
+++ trunk/mcs/class/corlib/System.Collections.ObjectModel/ReadOnlyCollection.cs 
2005-06-21 06:39:00 UTC (rev 46281)
@@ -4,12 +4,15 @@
 //
 // Author:
 //    Zoltan Varga ([EMAIL PROTECTED])
+//    David Waite ([EMAIL PROTECTED])
 //
 // (C) 2005 Novell, Inc.
+// (C) 2005 David Waite
 //
 
 //
 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// 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
@@ -38,147 +41,142 @@
 
 namespace System.Collections.ObjectModel
 {
-       [ComVisible(false)]
+       [ComVisible (false)]
        [Serializable]
-       public class ReadOnlyCollection<T> : IList<T>, ICollection<T>, 
IEnumerable<T>, IList, ICollection, IEnumerable
+       public class ReadOnlyCollection <T> : IList <T>, ICollection <T>, 
IEnumerable <T>, IList, ICollection, IEnumerable
        {
-               public ReadOnlyCollection (IList<T> list)
+               IList <T> list;
+               object syncRoot;
+               
+               public ReadOnlyCollection (IList <T> list)
                {
-                       throw new NotImplementedException ();
+                       if (list == null)
+                               throw new ArgumentNullException ("list");
+                       this.list = list;
+                       ICollection c = list as ICollection;
+                       syncRoot = (c != null) ? c.SyncRoot : new object ();
                }
 
                public void Add (T item)
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
-
+               
                public void Clear ()
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
 
                public bool Contains (T item)
                {
-                       throw new NotImplementedException ();
+                       return list.Contains (item);
                }
 
-               public void CopyTo (T[] array, int index)
+               public void CopyTo (T [] array, int index)
                {
-                       throw new NotImplementedException ();
+                       list.CopyTo (array, index);
                }
 
-               public IEnumerator<T> GetEnumerator ()
+               public IEnumerator <T> GetEnumerator ()
                {
-                       throw new NotImplementedException ();
+                       return list.GetEnumerator ();
                }
 
                public int IndexOf (T item)
                {
-                       throw new NotImplementedException ();
+                       return list.IndexOf (item);
                }
 
                public void Insert (int index, T item)
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
 
                public bool Remove (T item)
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
 
                public void RemoveAt (int index)
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
 
-               public virtual int Count {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+               public int Count {
+                       get { return list.Count; }
                }
 
-               public virtual T this [int index] {
-                       get {
-                               throw new NotImplementedException ();
-                       }
-                       set {
-                               throw new NotImplementedException ();
-                       }
+               public T this [int index] {
+                       get { return list [index]; }
+                       set { throw new NotSupportedException (); }
                }
 
                public bool IsReadOnly {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return true; }
                }
 
 #region Not generic interface implementations
                void ICollection.CopyTo (Array array, int arrayIndex)
                {
-                       throw new NotImplementedException ();
+                       T [] target = array as T [];
+                       if (target == null)
+                               throw new ArgumentException ("array");
+                       list.CopyTo (target, arrayIndex);
                }
-               
-               IEnumerator IEnumerable.GetEnumerator()
+                               
+               IEnumerator IEnumerable.GetEnumerator ()
                {
-                       throw new NotImplementedException ();
+                       return ((IEnumerable) list).GetEnumerator ();
                }
                
                int IList.Add (object item)
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
                
                bool IList.Contains (object item)
                {
-                       throw new NotImplementedException ();
+                       if (Collection <T>.IsValidItem (item))
+                               return list.Contains ((T) item);
+                       return false;
                }
                
                int IList.IndexOf (object item)
                {
-                       throw new NotImplementedException ();
+                       if (Collection <T>.IsValidItem (item))
+                               return list.IndexOf ((T) item);
+                       return -1;
                }
                
                void IList.Insert (int index, object item)
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
                
                void IList.Remove (object item)
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
                
                bool ICollection.IsSynchronized {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return Collection <T>.IsSynchronized (list); }
                }
                
                object ICollection.SyncRoot {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return syncRoot; }
                }
+
                bool IList.IsFixedSize {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return Collection <T>.IsFixedSize (list); }
                }
                
                bool IList.IsReadOnly {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return true; }
                }
                
                object IList.this [int index] {
-                       get {
-                               throw new NotImplementedException ();
-                       }
-                       set {
-                               throw new NotImplementedException ();
-                       }
+                       get { return list [index]; }
+                       set { throw new NotSupportedException (); }
                }
 #endregion
        }

Added: trunk/mcs/class/corlib/Test/System.Collections.ObjectModel/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System.Collections.ObjectModel/ChangeLog        
2005-06-21 06:33:00 UTC (rev 46280)
+++ trunk/mcs/class/corlib/Test/System.Collections.ObjectModel/ChangeLog        
2005-06-21 06:39:00 UTC (rev 46281)
@@ -0,0 +1,3 @@
+2005-06-21  David Waite  <[EMAIL PROTECTED]>
+
+       * CollectionTest.cs : added

Added: 
trunk/mcs/class/corlib/Test/System.Collections.ObjectModel/CollectionTest.cs
===================================================================
--- 
trunk/mcs/class/corlib/Test/System.Collections.ObjectModel/CollectionTest.cs    
    2005-06-21 06:33:00 UTC (rev 46280)
+++ 
trunk/mcs/class/corlib/Test/System.Collections.ObjectModel/CollectionTest.cs    
    2005-06-21 06:39:00 UTC (rev 46281)
@@ -0,0 +1,161 @@
+//
+// MonoTests.System.Collections.Generic.Test.CollectionTest
+//
+// Authors:
+//     David Waite ([EMAIL PROTECTED])
+//
+// 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)));
+               }
+
+               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
+
+                       System.Collections.IEnumerator 
System.Collections.IEnumerable.GetEnumerator ()
+                       {
+                               throw new Exception ("The method or operation 
is not implemented.");
+                       }
+
+                       #endregion
+}
+       }
+}
+
+#endif


Property changes on: 
trunk/mcs/class/corlib/Test/System.Collections.ObjectModel/CollectionTest.cs
___________________________________________________________________
Name: svn:executable
   + *

Modified: trunk/mcs/class/corlib/corlib_test.dll.sources
===================================================================
--- trunk/mcs/class/corlib/corlib_test.dll.sources      2005-06-21 06:33:00 UTC 
(rev 46280)
+++ trunk/mcs/class/corlib/corlib_test.dll.sources      2005-06-21 06:39:00 UTC 
(rev 46281)
@@ -30,6 +30,7 @@
 System.Collections/StackTest.cs
 System.Collections.Generic/DictionaryTest.cs
 System.Collections.Generic/ListTest.cs
+System.Collections.ObjectModel/CollectionTest.cs
 System/ConsoleTest.cs
 System/ConvertTest.cs
 System/DateTimeTest.cs

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to