Add tests for ReadOnlyCollection and ReadOnlyList
authorTomaž Vajngerl <quikee@gmail.com>
Sun, 6 Sep 2009 20:37:00 +0000 (22:37 +0200)
committerDidier 'Ptitjes <ptitjes@free.fr>
Sun, 6 Sep 2009 22:06:00 +0000 (00:06 +0200)
Fixes part of bug 590677.

Contains missing tests for ReadOnlyCollection and ReadOnlyList following
the new tests implementation.

tests/Makefile.am
tests/testmain.vala
tests/testreadonlycollection.vala [new file with mode: 0644]
tests/testreadonlylist.vala [new file with mode: 0644]

index 9007792..15f0088 100644 (file)
@@ -25,6 +25,8 @@ tests_VALASOURCES = \
        testmain.vala \
        testmultimap.vala \
        testmultiset.vala \
+       testreadonlycollection.vala \
+       testreadonlylist.vala \
        $(NULL)
 
 tests_SOURCES = tests.vala.stamp $(tests_VALASOURCES:.vala=.c)
index ec916f4..90705b0 100644 (file)
@@ -28,6 +28,7 @@ void main (string[] args) {
        TestSuite.get_root ().add_suite (new HashMultiMapTests ().get_suite ());
        TestSuite.get_root ().add_suite (new HashMultiSetTests ().get_suite ());
        TestSuite.get_root ().add_suite (new LinkedListTests ().get_suite ());
+       TestSuite.get_root ().add_suite (new ReadOnlyListTests ().get_suite ());
 
        Test.run ();
 }
diff --git a/tests/testreadonlycollection.vala b/tests/testreadonlycollection.vala
new file mode 100644 (file)
index 0000000..a78d801
--- /dev/null
@@ -0,0 +1,109 @@
+/* testreadonlycollection.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 abstract class ReadOnlyCollectionTests : Gee.TestCase {
+
+       public ReadOnlyCollectionTests (string name) {
+               base (name);
+               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);
+       }
+
+       protected Collection<string> test_collection;
+       protected Collection<string> ro_collection;
+
+       public void test_add () {
+               assert (test_collection.add ("one"));
+
+               assert (ro_collection.size == 1);
+               assert (ro_collection.contains ("one"));
+
+               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"));
+       }
+
+       public void test_clear () {
+               assert (test_collection.add ("one"));
+
+               assert (ro_collection.size == 1);
+               assert (ro_collection.contains ("one"));
+
+               if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+                                      TestTrapFlags.SILENCE_STDERR)) {
+                       ro_collection.clear ();
+                       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"));
+               assert (ro_collection.contains ("one"));
+               assert (test_collection.remove ("one"));
+               assert (! ro_collection.contains ("one"));
+       }
+
+       public void test_remove () {
+               assert (test_collection.add ("one"));
+
+               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"));
+                       return;
+               }
+               Test.trap_assert_failed ();
+
+               assert (ro_collection.size == 1);
+               assert (ro_collection.contains ("one"));
+       }
+
+       public void test_size () {
+               assert (ro_collection.size == 0);
+               assert (test_collection.add ("one"));
+               assert (ro_collection.size == 1);
+               assert (test_collection.add ("two"));
+               assert (ro_collection.size == 2);
+               test_collection.clear ();
+               assert (ro_collection.size == 0);
+       }
+}
diff --git a/tests/testreadonlylist.vala b/tests/testreadonlylist.vala
new file mode 100644 (file)
index 0000000..07d6fc1
--- /dev/null
@@ -0,0 +1,42 @@
+/* testreadonlylist.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 ReadOnlyListTests : ReadOnlyCollectionTests {
+
+       public ReadOnlyListTests () {
+               base ("ReadOnlyList");
+       }
+
+       public override void set_up () {
+               test_collection = new ArrayList<string> ();
+               ro_collection = new ReadOnlyCollection<string> (test_collection);
+       }
+
+       public override void tear_down () {
+               test_collection = null;
+               ro_collection = null;
+       }
+}