Enhance the tests for the ReadOnly* implementations
authorDidier 'Ptitjes <ptitjes@free.fr>
Sun, 20 Sep 2009 01:03:00 +0000 (03:03 +0200)
committerDidier 'Ptitjes <ptitjes@free.fr>
Mon, 21 Sep 2009 21:23:37 +0000 (23:23 +0200)
tests/Makefile.am
tests/testmain.vala
tests/testreadonlycollection.vala
tests/testreadonlylist.vala
tests/testreadonlymap.vala [new file with mode: 0644]
tests/testreadonlyset.vala [new file with mode: 0644]

index 8a91b63..d483fcb 100644 (file)
@@ -35,6 +35,8 @@ tests_VALASOURCES = \
        testqueue.vala \
        testreadonlycollection.vala \
        testreadonlylist.vala \
+       testreadonlymap.vala \
+       testreadonlyset.vala \
        testset.vala \
        testtreemap.vala \
        testtreeset.vala \
index 525d3cf..41709d5 100644 (file)
@@ -25,6 +25,7 @@ void main (string[] args) {
        Test.init (ref args);
 
        TestSuite.get_root ().add_suite (new ArrayListTests ().get_suite ());
+       TestSuite.get_root ().add_suite (new ComparableTests ().get_suite ());
        TestSuite.get_root ().add_suite (new HashMapTests ().get_suite ());
        TestSuite.get_root ().add_suite (new HashMultiMapTests ().get_suite ());
        TestSuite.get_root ().add_suite (new HashMultiSetTests ().get_suite ());
@@ -32,7 +33,10 @@ void main (string[] args) {
        TestSuite.get_root ().add_suite (new LinkedListTests ().get_suite ());
        TestSuite.get_root ().add_suite (new LinkedListAsDequeTests ().get_suite ());
        TestSuite.get_root ().add_suite (new PriorityQueueTests ().get_suite ());
+       TestSuite.get_root ().add_suite (new ReadOnlyCollectionTests ().get_suite ());
        TestSuite.get_root ().add_suite (new ReadOnlyListTests ().get_suite ());
+       TestSuite.get_root ().add_suite (new ReadOnlyMapTests ().get_suite ());
+       TestSuite.get_root ().add_suite (new ReadOnlySetTests ().get_suite ());
        TestSuite.get_root ().add_suite (new TreeMapTests ().get_suite ());
        TestSuite.get_root ().add_suite (new TreeSetTests ().get_suite ());
 
index 6340abc..6c09f86 100644 (file)
 
 using Gee;
 
-public abstract class ReadOnlyCollectionTests : Gee.TestCase {
+public class ReadOnlyCollectionTests : Gee.TestCase {
 
-       public ReadOnlyCollectionTests (string name) {
+       public ReadOnlyCollectionTests () {
+               this.with_name ("ReadOnlyCollection");
+       }
+
+       public ReadOnlyCollectionTests.with_name (string name) {
                base (name);
                add_test ("[ReadOnlyCollection] unique read-only view instance",
                          test_unique_read_only_view_instance);
-               add_test ("[ReadOnlyCollection] add", test_add);
-               add_test ("[ReadOnlyCollection] clear", test_clear);
-               add_test ("[ReadOnlyCollection] remove", test_remove);
-               add_test ("[ReadOnlyCollection] contains", test_contains);
-               add_test ("[ReadOnlyCollection] size", test_size);
+               add_test ("[ReadOnlyCollection] immutable iterator", test_immutable_iterator);
+               add_test ("[ReadOnlyCollection] immutable", test_immutable);
+               add_test ("[ReadOnlyCollection] accurate view", test_accurate_view);
        }
 
        protected Collection<string> test_collection;
        protected Collection<string> ro_collection;
 
+       public override void set_up () {
+               test_collection = new HashMultiSet<string> ();
+               ro_collection = get_ro_view (test_collection);
+       }
+
+       public override void tear_down () {
+               test_collection = null;
+               ro_collection = null;
+       }
+
+       protected virtual Collection<string> get_ro_view (Collection<string> collection) {
+               return collection.read_only_view;
+       }
+
        public void test_unique_read_only_view_instance () {
-               var another_ro_collection = test_collection.read_only_view;
+               var another_ro_collection = get_ro_view (test_collection);
                assert (ro_collection == another_ro_collection);
 
                ro_collection.set_data ("marker", new Object ());
@@ -50,30 +66,64 @@ public abstract class ReadOnlyCollectionTests : Gee.TestCase {
                another_ro_collection = null;
                ro_collection = null;
 
-               another_ro_collection = test_collection.read_only_view;
+               another_ro_collection = get_ro_view (test_collection);
                assert (another_ro_collection.get_data ("marker") == null);
+
+               // Check that the read-only view of the view is itself
+               assert (another_ro_collection == get_ro_view (another_ro_collection));
        }
 
-       public void test_add () {
+       public void test_immutable_iterator () {
                assert (test_collection.add ("one"));
+               assert (test_collection.add ("two"));
 
-               assert (ro_collection.size == 1);
+               assert (ro_collection.size == 2);
                assert (ro_collection.contains ("one"));
+               assert (ro_collection.contains ("two"));
+
+               Iterator<string> iterator = ro_collection.iterator ();
+
+               assert (iterator.has_next ());
+               assert (iterator.next ());
+               assert (iterator.get () == "one");
+
+               assert (iterator.has_next ());
+               assert (iterator.next ());
+               assert (iterator.get () == "two");
+
+               assert (! iterator.has_next ());
+               assert (! iterator.next ());
+
+               assert (iterator.first ());
+               assert (iterator.get () == "one");
 
                if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
                                       TestTrapFlags.SILENCE_STDERR)) {
-                       assert (ro_collection.add ("two"));
+                       iterator.remove ();
                        return;
                }
                Test.trap_assert_failed ();
 
-               assert (ro_collection.size == 1);
+               assert (ro_collection.size == 2);
                assert (ro_collection.contains ("one"));
+               assert (ro_collection.contains ("two"));
        }
 
-       public void test_clear () {
+       public void test_immutable () {
                assert (test_collection.add ("one"));
+               assert (ro_collection.size == 1);
+               assert (ro_collection.contains ("one"));
 
+               Collection<string> dummy = new ArrayList<string> ();
+               assert (dummy.add ("one"));
+               assert (dummy.add ("two"));
+
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       assert (ro_collection.add ("two"));
+                       return;
+               }
+               Test.trap_assert_failed ();
                assert (ro_collection.size == 1);
                assert (ro_collection.contains ("one"));
 
@@ -83,43 +133,81 @@ public abstract class ReadOnlyCollectionTests : Gee.TestCase {
                        return;
                }
                Test.trap_assert_failed ();
-
                assert (ro_collection.size == 1);
                assert (ro_collection.contains ("one"));
-       }
 
-       public void test_contains () {
-               assert (! ro_collection.contains ("one"));
-               assert (test_collection.add ("one"));
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       assert (ro_collection.remove ("one"));
+                       return;
+               }
+               Test.trap_assert_failed ();
+               assert (ro_collection.size == 1);
                assert (ro_collection.contains ("one"));
-               assert (test_collection.remove ("one"));
-               assert (! ro_collection.contains ("one"));
-       }
-
-       public void test_remove () {
-               assert (test_collection.add ("one"));
 
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       assert (ro_collection.add_all (dummy));
+                       return;
+               }
+               Test.trap_assert_failed ();
                assert (ro_collection.size == 1);
                assert (ro_collection.contains ("one"));
 
                if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
                                       TestTrapFlags.SILENCE_STDERR)) {
-                       assert (ro_collection.remove ("one"));
+                       assert (ro_collection.remove_all (dummy));
                        return;
                }
                Test.trap_assert_failed ();
+               assert (ro_collection.size == 1);
+               assert (ro_collection.contains ("one"));
 
+               assert (dummy.remove ("one"));
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       assert (ro_collection.retain_all (dummy));
+                       return;
+               }
+               Test.trap_assert_failed ();
                assert (ro_collection.size == 1);
                assert (ro_collection.contains ("one"));
        }
 
-       public void test_size () {
+       public void test_accurate_view () {
+               Collection<string> dummy = new ArrayList<string> ();
+               assert (dummy.add ("one"));
+               assert (dummy.add ("two"));
+
+               assert (ro_collection.element_type == typeof (string));
+
                assert (ro_collection.size == 0);
+               assert (ro_collection.is_empty);
+               assert (! ro_collection.contains ("one"));
+
                assert (test_collection.add ("one"));
                assert (ro_collection.size == 1);
+               assert (! ro_collection.is_empty);
+               assert (ro_collection.contains ("one"));
+
                assert (test_collection.add ("two"));
                assert (ro_collection.size == 2);
+               assert (! ro_collection.is_empty);
+               assert (ro_collection.contains ("one"));
+               assert (ro_collection.contains ("two"));
+               assert (ro_collection.contains_all (dummy));
+
+               assert (test_collection.remove ("one"));
+               assert (ro_collection.size == 1);
+               assert (! ro_collection.is_empty);
+               assert (! ro_collection.contains ("one"));
+               assert (ro_collection.contains ("two"));
+               assert (! ro_collection.contains_all (dummy));
+
                test_collection.clear ();
                assert (ro_collection.size == 0);
+               assert (ro_collection.is_empty);
+               assert (! ro_collection.contains ("one"));
+               assert (! ro_collection.contains ("two"));
        }
 }
index 41482c5..f10d0f6 100644 (file)
@@ -20,6 +20,7 @@
  * Author:
  *     Tomaž Vajngerl <quikee@gmail.com>
  *     Julien Peeters <contact@julienpeeters.fr>
+ *     Didier 'Ptitjes' Villevalois <ptitjes@free.fr>
  */
 
 using Gee;
@@ -27,16 +28,216 @@ using Gee;
 public class ReadOnlyListTests : ReadOnlyCollectionTests {
 
        public ReadOnlyListTests () {
-               base ("ReadOnlyList");
+               base.with_name ("ReadOnlyList");
+               add_test ("[ReadOnlyList] immutable iterator", test_immutable_iterator);
+               add_test ("[ReadOnlyList] immutable", test_immutable);
+               add_test ("[ReadOnlyList] accurate view", test_accurate_view);
        }
 
        public override void set_up () {
                test_collection = new ArrayList<string> ();
-               ro_collection = test_collection.read_only_view;
+               ro_collection = get_ro_view (test_collection);
        }
 
        public override void tear_down () {
                test_collection = null;
                ro_collection = null;
        }
+
+       protected override Collection<string> get_ro_view (Collection<string> collection) {
+               return ((Gee.List) collection).read_only_view;
+       }
+
+       public new void test_immutable_iterator () {
+               var test_list = test_collection as Gee.List<string>;
+               var ro_list = ro_collection as Gee.List<string>;
+
+               assert (test_list.add ("one"));
+               assert (test_list.add ("two"));
+
+               assert (ro_list.size == 2);
+               assert (ro_list.get (0) == "one");
+               assert (ro_list.get (1) == "two");
+
+               ListIterator<string> iterator = ro_list.list_iterator ();
+
+               assert (iterator.has_next ());
+               assert (iterator.next ());
+               assert (iterator.get () == "one");
+               assert (iterator.index () == 0);
+
+               assert (iterator.has_next ());
+               assert (iterator.next ());
+               assert (iterator.get () == "two");
+               assert (iterator.index () == 1);
+
+               assert (! iterator.has_next ());
+               assert (! iterator.next ());
+
+               assert (iterator.has_previous ());
+               assert (iterator.previous ());
+               assert (iterator.get () == "one");
+               assert (iterator.index () == 0);
+
+               assert (iterator.last ());
+               assert (iterator.get () == "two");
+               assert (iterator.index () == 1);
+
+               assert (iterator.first ());
+               assert (iterator.get () == "one");
+               assert (iterator.index () == 0);
+
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       iterator.remove ();
+                       return;
+               }
+               Test.trap_assert_failed ();
+               assert (ro_list.size == 2);
+               assert (ro_list.get (0) == "one");
+               assert (ro_list.get (1) == "two");
+               assert (iterator.index () == 0);
+
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       iterator.set ("three");
+                       return;
+               }
+               Test.trap_assert_failed ();
+               assert (ro_list.size == 2);
+               assert (ro_list.get (0) == "one");
+               assert (ro_list.get (1) == "two");
+               assert (iterator.index () == 0);
+
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       iterator.insert ("three");
+                       return;
+               }
+               Test.trap_assert_failed ();
+               assert (ro_list.size == 2);
+               assert (ro_list.get (0) == "one");
+               assert (ro_list.get (1) == "two");
+               assert (iterator.index () == 0);
+
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       iterator.add ("three");
+                       return;
+               }
+               Test.trap_assert_failed ();
+               assert (ro_list.size == 2);
+               assert (ro_list.get (0) == "one");
+               assert (ro_list.get (1) == "two");
+               assert (iterator.index () == 0);
+       }
+
+       public new void test_immutable () {
+               var test_list = test_collection as Gee.List<string>;
+               var ro_list = ro_collection as Gee.List<string>;
+
+               assert (test_list.add ("one"));
+               assert (ro_list.size == 1);
+               assert (ro_list.contains ("one"));
+
+               Collection<string> dummy = new ArrayList<string> ();
+               assert (dummy.add ("one"));
+               assert (dummy.add ("two"));
+
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       ro_list.set (0, "two");
+                       return;
+               }
+               Test.trap_assert_failed ();
+               assert (ro_list.size == 1);
+               assert (ro_list.contains ("one"));
+
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       ro_list.insert (1, "two");
+                       return;
+               }
+               Test.trap_assert_failed ();
+               assert (ro_list.size == 1);
+               assert (ro_list.contains ("one"));
+
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       ro_list.remove_at (1);
+                       return;
+               }
+               Test.trap_assert_failed ();
+               assert (ro_list.size == 1);
+               assert (ro_list.contains ("one"));
+
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       ro_list.insert_all (1, dummy);
+                       return;
+               }
+               Test.trap_assert_failed ();
+               assert (ro_list.size == 1);
+               assert (ro_list.contains ("one"));
+
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       ro_list.sort ();
+                       return;
+               }
+               Test.trap_assert_failed ();
+               assert (ro_list.size == 1);
+               assert (ro_list.contains ("one"));
+       }
+
+       public new void test_accurate_view () {
+               var test_list = test_collection as Gee.List<string>;
+               var ro_list = ro_collection as Gee.List<string>;
+
+               Collection<string> dummy = new ArrayList<string> ();
+               assert (dummy.add ("one"));
+               assert (dummy.add ("two"));
+
+               assert (ro_list.element_type == typeof (string));
+
+               assert (ro_list.size == 0);
+               assert (ro_list.is_empty);
+               assert (! ro_list.contains ("one"));
+               assert (ro_list.index_of ("one") == -1);
+
+               assert (test_list.add ("one"));
+               assert (ro_list.size == 1);
+               assert (! ro_list.is_empty);
+               assert (ro_list.get (0) == "one");
+               assert (ro_list.index_of ("one") == 0);
+               assert (ro_list.first () == "one");
+               assert (ro_list.last () == "one");
+
+               assert (test_list.add ("two"));
+               assert (ro_list.size == 2);
+               assert (! ro_list.is_empty);
+               assert (ro_list.get (0) == "one");
+               assert (ro_list.index_of ("one") == 0);
+               assert (ro_list.get (1) == "two");
+               assert (ro_list.index_of ("two") == 1);
+               assert (ro_list.first () == "one");
+               assert (ro_list.last () == "two");
+
+               assert (test_list.remove ("one"));
+               assert (ro_list.size == 1);
+               assert (! ro_list.is_empty);
+               assert (! ro_list.contains ("one"));
+               assert (ro_list.index_of ("one") == -1);
+               assert (ro_list.contains ("two"));
+               assert (ro_list.get (0) == "two");
+               assert (ro_list.index_of ("two") == 0);
+               assert (ro_list.first () == "two");
+               assert (ro_list.last () == "two");
+
+               test_list.clear ();
+               assert (ro_list.size == 0);
+               assert (ro_list.is_empty);
+               assert (ro_list.index_of ("one") == -1);
+               assert (ro_list.index_of ("two") == -1);
+       }
 }
diff --git a/tests/testreadonlymap.vala b/tests/testreadonlymap.vala
new file mode 100644 (file)
index 0000000..217079e
--- /dev/null
@@ -0,0 +1,216 @@
+/* testreadonlymap.vala
+ *
+ * Copyright (C) 2008  Jürg Billeter
+ * Copyright (C) 2009  Didier Villevalois
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Didier 'Ptitjes' Villevalois <ptitjes@free.fr>
+ */
+
+using Gee;
+
+public class ReadOnlyMapTests : Gee.TestCase {
+
+       public ReadOnlyMapTests () {
+               base ("ReadOnlyMap");
+               add_test ("[ReadOnlyMap] unique read-only view instance",
+                         test_unique_read_only_view_instance);
+               add_test ("[ReadOnlyMap] immutable iterator", test_immutable_iterator);
+               add_test ("[ReadOnlyMap] immutable", test_immutable);
+               add_test ("[ReadOnlyMap] accurate view", test_accurate_view);
+       }
+
+       protected Map<string,string> test_map;
+       protected Map<string,string> ro_map;
+
+       public override void set_up () {
+               test_map = new TreeMap<string,string> ();
+               ro_map = test_map.read_only_view;
+       }
+
+       public override void tear_down () {
+               test_map = null;
+               ro_map = null;
+       }
+
+       public void test_unique_read_only_view_instance () {
+               var another_ro_map = test_map.read_only_view;
+               assert (ro_map == another_ro_map);
+
+               ro_map.set_data ("marker", new Object ());
+               assert (another_ro_map.get_data ("marker") != null);
+
+               another_ro_map = null;
+               ro_map = null;
+
+               another_ro_map = test_map.read_only_view;
+               assert (another_ro_map.get_data ("marker") == null);
+
+               // Check that the read-only view of the view is itself
+               assert (another_ro_map == another_ro_map.read_only_view);
+       }
+
+       public void test_immutable_iterator () {
+               test_map.set ("one", "one");
+               test_map.set ("two", "two");
+
+               assert (ro_map.size == 2);
+               assert (ro_map.has_key ("one"));
+               assert (ro_map.has ("one", "one"));
+               assert (ro_map.has_key ("two"));
+               assert (ro_map.has ("two", "two"));
+
+               Iterator<string> iterator = ro_map.keys.iterator ();
+
+               assert (iterator.has_next ());
+               assert (iterator.next ());
+               assert (iterator.get () == "one");
+
+               assert (iterator.has_next ());
+               assert (iterator.next ());
+               assert (iterator.get () == "two");
+
+               assert (! iterator.has_next ());
+               assert (! iterator.next ());
+
+               assert (iterator.first ());
+               assert (iterator.get () == "one");
+
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       iterator.remove ();
+                       return;
+               }
+               Test.trap_assert_failed ();
+
+               assert (ro_map.size == 2);
+               assert (ro_map.has_key ("one"));
+               assert (ro_map.has ("one", "one"));
+               assert (ro_map.has_key ("two"));
+               assert (ro_map.has ("two", "two"));
+       }
+
+       public void test_immutable () {
+               test_map.set ("one", "one");
+               assert (ro_map.size == 1);
+               assert (ro_map.has_key ("one"));
+               assert (ro_map.has ("one", "one"));
+
+               Map<string,string> dummy = new HashMap<string,string> ();
+               dummy.set ("one", "one");
+               dummy.set ("two", "two");
+
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       ro_map.set ("two", "two");
+                       return;
+               }
+               Test.trap_assert_failed ();
+               assert (ro_map.size == 1);
+               assert (ro_map.has_key ("one"));
+               assert (ro_map.has ("one", "one"));
+
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       ro_map.clear ();
+                       return;
+               }
+               Test.trap_assert_failed ();
+               assert (ro_map.size == 1);
+               assert (ro_map.has_key ("one"));
+               assert (ro_map.has ("one", "one"));
+
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       assert (ro_map.unset ("one"));
+                       return;
+               }
+               Test.trap_assert_failed ();
+               assert (ro_map.size == 1);
+               assert (ro_map.has_key ("one"));
+               assert (ro_map.has ("one", "one"));
+
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       ro_map.set_all (dummy);
+                       return;
+               }
+               Test.trap_assert_failed ();
+               assert (ro_map.size == 1);
+               assert (ro_map.has_key ("one"));
+               assert (ro_map.has ("one", "one"));
+
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       assert (ro_map.unset_all (dummy));
+                       return;
+               }
+               Test.trap_assert_failed ();
+               assert (ro_map.size == 1);
+               assert (ro_map.has_key ("one"));
+               assert (ro_map.has ("one", "one"));
+       }
+
+       public void test_accurate_view () {
+               Map<string,string> dummy = new HashMap<string,string> ();
+               dummy.set ("one", "one");
+               dummy.set ("two", "two");
+
+               assert (ro_map.size == 0);
+               assert (ro_map.is_empty);
+               assert (! ro_map.has_key ("one"));
+               assert (! ro_map.has ("one", "one"));
+               assert (ro_map.get ("one") == null);
+
+               test_map.set ("one", "one");
+               assert (ro_map.size == 1);
+               assert (! ro_map.is_empty);
+               assert (ro_map.has_key ("one"));
+               assert (ro_map.has ("one", "one"));
+               assert (ro_map.get ("one") == "one");
+
+               test_map.set ("two", "two");
+               assert (ro_map.size == 2);
+               assert (! ro_map.is_empty);
+               assert (ro_map.has_key ("one"));
+               assert (ro_map.has ("one", "one"));
+               assert (ro_map.get ("one") == "one");
+               assert (ro_map.has_key ("two"));
+               assert (ro_map.has ("two", "two"));
+               assert (ro_map.get ("two") == "two");
+               assert (ro_map.has_all (dummy));
+
+               assert (test_map.unset ("one"));
+               assert (ro_map.size == 1);
+               assert (! ro_map.is_empty);
+               assert (! ro_map.has_key ("one"));
+               assert (! ro_map.has ("one", "one"));
+               assert (ro_map.get ("one") == null);
+               assert (ro_map.has_key ("two"));
+               assert (ro_map.has ("two", "two"));
+               assert (ro_map.get ("two") == "two");
+               assert (! ro_map.has_all (dummy));
+
+               test_map.clear ();
+               assert (ro_map.size == 0);
+               assert (ro_map.is_empty);
+               assert (! ro_map.has ("one", "one"));
+               assert (! ro_map.has ("two", "two"));
+               assert (ro_map.get ("one") == null);
+               assert (ro_map.get ("two") == null);
+       }
+}
diff --git a/tests/testreadonlyset.vala b/tests/testreadonlyset.vala
new file mode 100644 (file)
index 0000000..a573cda
--- /dev/null
@@ -0,0 +1,46 @@
+/* testreadonlyset.vala
+ *
+ * Copyright (C) 2008  Jürg Billeter
+ * Copyright (C) 2009  Didier Villevalois
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Tomaž Vajngerl <quikee@gmail.com>
+ *     Julien Peeters <contact@julienpeeters.fr>
+ */
+
+using Gee;
+
+public class ReadOnlySetTests : ReadOnlyCollectionTests {
+
+       public ReadOnlySetTests () {
+               base.with_name ("ReadOnlySet");
+       }
+
+       public override void set_up () {
+               test_collection = new HashSet<string> ();
+               ro_collection = get_ro_view (test_collection);
+       }
+
+       public override void tear_down () {
+               test_collection = null;
+               ro_collection = null;
+       }
+
+       protected override Collection<string> get_ro_view (Collection<string> collection) {
+               return ((Gee.Set) collection).read_only_view;
+       }
+}