[libgee] Add tests for ReadOnlyCollection and ReadOnlyList
- From: Didier 'Ptitjes' Villevalois <dvillevalois src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgee] Add tests for ReadOnlyCollection and ReadOnlyList
- Date: Sun, 6 Sep 2009 23:08:48 +0000 (UTC)
commit 3b54e65639552d6d210893a817cdddddef7c77d8
Author: Tomaž Vajngerl <quikee gmail com>
Date: Sun Sep 6 22:37:00 2009 +0200
Add tests for ReadOnlyCollection and ReadOnlyList
Fixes part of bug 590677.
Contains missing tests for ReadOnlyCollection and ReadOnlyList following
the new tests implementation.
tests/Makefile.am | 2 +
tests/testmain.vala | 1 +
tests/testreadonlycollection.vala | 109 +++++++++++++++++++++++++++++++++++++
tests/testreadonlylist.vala | 42 ++++++++++++++
4 files changed, 154 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9007792..15f0088 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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)
diff --git a/tests/testmain.vala b/tests/testmain.vala
index ec916f4..90705b0 100644
--- a/tests/testmain.vala
+++ b/tests/testmain.vala
@@ -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
index 0000000..a78d801
--- /dev/null
+++ b/tests/testreadonlycollection.vala
@@ -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
index 0000000..07d6fc1
--- /dev/null
+++ b/tests/testreadonlylist.vala
@@ -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;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]