2008-01-20 Juraj Skripsky <js@hotfeet.ch>
authorJuraj Skripsky <js@hotfeet.ch>
Sun, 20 Jan 2008 20:44:34 +0000 (20:44 -0000)
committerJuraj Skripsky <js@hotfeet.ch>
Sun, 20 Jan 2008 20:44:34 +0000 (20:44 -0000)
* ReadOnlyCollection.cs: Fix the getters for ICollection.IsSynchronized,
ICollection.SyncRoot and IList.IsFixedSize to match MS.NET.

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.

svn path=/trunk/mcs/; revision=93357

mcs/class/corlib/System.Collections.ObjectModel/ChangeLog
mcs/class/corlib/System.Collections.ObjectModel/ReadOnlyCollection.cs
mcs/class/corlib/Test/System.Collections.ObjectModel/ChangeLog
mcs/class/corlib/Test/System.Collections.ObjectModel/ReadOnlyCollectionTest.cs

index 9672338330580931dadb3b88d773e91756736d52..10604bf55c35cb30017a6a356cf024d4e54a7ebe 100644 (file)
@@ -1,3 +1,8 @@
+2008-01-20  Juraj Skripsky  <js@hotfeet.ch>
+
+       * ReadOnlyCollection.cs: Fix the getters for ICollection.IsSynchronized,
+       ICollection.SyncRoot and IList.IsFixedSize to match MS.NET.
+
 2008-01-13  Juraj Skripsky  <js@hotfeet.ch>
 
        * Collection.cs, ReadonlyCollection.cs (ICollection.CopyTo):
index 7bdfb1e99013f3575098f6524011668f43616665..1e290eb421238b52e6fdcb3df3b89c97f6c57b8e 100644 (file)
@@ -46,15 +46,12 @@ namespace System.Collections.ObjectModel
        public class ReadOnlyCollection <T> : IList <T>, ICollection <T>, IEnumerable <T>, IList, ICollection, IEnumerable
        {
                IList <T> list;
-               object syncRoot;
                
                public ReadOnlyCollection (IList <T> list)
                {
                        if (list == null)
                                throw new ArgumentNullException ("list");
                        this.list = list;
-                       ICollection c = list as ICollection;
-                       syncRoot = (c != null) ? c.SyncRoot : new object ();
                }
 
                void ICollection<T>.Add (T item)
@@ -174,15 +171,15 @@ namespace System.Collections.ObjectModel
                }
 
                bool ICollection.IsSynchronized {
-                       get { return Collection <T>.IsSynchronized (list); }
+                       get { return false; }
                }
                
                object ICollection.SyncRoot {
-                       get { return syncRoot; }
+                       get { return this; }
                }
 
                bool IList.IsFixedSize {
-                       get { return Collection <T>.IsFixedSize (list); }
+                       get { return true; }
                }
                
                bool IList.IsReadOnly {
index 392cca664598b5bed857ad7a355b1d647e128994..16e8e1561501ba8faa7570a81995deeb4ac5ecd5 100644 (file)
@@ -1,3 +1,10 @@
+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.
index 78dacf17ebe8c68649cc14a35c5e009e9a40d61c..390526cc5b53337124bdc2d0d5e826634443a1ff 100644 (file)
@@ -38,6 +38,13 @@ using NUnit.Framework;
 
 namespace MonoTests.System.Collections.ObjectModel
 {
+       class SyncPretendingList<T> : List<T>, ICollection
+       {
+               bool ICollection.IsSynchronized {
+                       get { return true; }
+               }
+       }
+
        [TestFixture]
        public class ReadOnlyCollectionTest
        {
@@ -52,6 +59,38 @@ namespace MonoTests.System.Collections.ObjectModel
                        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 ()