[libgee] Add tests for Map.entries
- From: Didier Villevalois <dvillevalois src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgee] Add tests for Map.entries
- Date: Mon, 28 Sep 2009 15:48:20 +0000 (UTC)
commit ab095cc76c6e2d7762c0397ac9f2629b127ac1ec
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date: Mon Sep 28 01:41:53 2009 +0200
Add tests for Map.entries
tests/testmap.vala | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 53 insertions(+), 0 deletions(-)
---
diff --git a/tests/testmap.vala b/tests/testmap.vala
index e416263..f69ee66 100644
--- a/tests/testmap.vala
+++ b/tests/testmap.vala
@@ -34,6 +34,7 @@ public abstract class MapTests : Gee.TestCase {
test_has_key_size_is_empty);
add_test ("[Map] keys", test_keys);
add_test ("[Map] values", test_values);
+ add_test ("[Map] entries", test_entries);
add_test ("[Map] set all", test_set_all);
add_test ("[Map] unset all", test_unset_all);
add_test ("[Map] has all", test_has_all);
@@ -242,6 +243,45 @@ public abstract class MapTests : Gee.TestCase {
assert (valueCollection.size == 0);
}
+ public void test_entries () {
+ // Check entries on empty map
+ var entryCollection = test_map.entries;
+ assert (entryCollection.size == 0);
+
+ // Check entries on map with one item
+ test_map.set ("one", "value_of_one");
+ assert (entryCollection.size == 1);
+ assert (entryCollection.contains (new TestEntry<string,string> ("one", "value_of_one")));
+ entryCollection = test_map.entries;
+ assert (entryCollection.size == 1);
+ assert (entryCollection.contains (new TestEntry<string,string> ("one", "value_of_one")));
+
+ // Check modify entry set directly
+ if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
+ TestTrapFlags.SILENCE_STDERR)) {
+ assert (! entryCollection.add (new TestEntry<string,string> ("two", "value_of_two")));
+ return;
+ }
+ Test.trap_assert_failed ();
+ Test.trap_assert_stderr ("*code should not be reached*");
+
+ // Check entries on map with multiple items
+ test_map.set ("two", "value_of_two");
+ assert (entryCollection.size == 2);
+ assert (entryCollection.contains (new TestEntry<string,string> ("one", "value_of_one")));
+ assert (entryCollection.contains (new TestEntry<string,string> ("two", "value_of_two")));
+ entryCollection = test_map.entries;
+ assert (entryCollection.size == 2);
+ assert (entryCollection.contains (new TestEntry<string,string> ("one", "value_of_one")));
+ assert (entryCollection.contains (new TestEntry<string,string> ("two", "value_of_two")));
+
+ // Check keys on map clear
+ test_map.clear ();
+ assert (entryCollection.size == 0);
+ entryCollection = test_map.entries;
+ assert (entryCollection.size == 0);
+ }
+
public void test_set_all () {
var another_map = new HashMap<string,string> (str_hash,
str_equal,
@@ -462,4 +502,17 @@ public abstract class MapTests : Gee.TestCase {
assert (value.get_int () == test_map.size);
value.unset ();
}
+
+
+
+ public class TestEntry<K,V> : Map.Entry<K,V> {
+ public TestEntry (K key, V value) {
+ this._key = key;
+ this.value = value;
+ }
+
+ public override K key { get {return _key; } }
+ private K _key;
+ public override V value { get; set; }
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]