summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2012-03-05 21:14:57 -0500
committerKristian Høgsberg <krh@bitplanet.net>2012-03-05 21:14:57 -0500
commitb4351bc08ef8dca4ebe91b173350e3e8e9b8b14b (patch)
tree8072101104a369f0683b4be4c763cfdddf5803ae
parentbbebd304fba6567cf3475d5f850d26b16ca516fe (diff)
tests: More wl_map tests
-rw-r--r--tests/map-test.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/map-test.c b/tests/map-test.c
index 448afc4..5ef940f 100644
--- a/tests/map-test.c
+++ b/tests/map-test.c
@@ -43,5 +43,51 @@ TEST(map_insert_new)
assert(wl_map_lookup(&map, j) == &b);
assert(wl_map_lookup(&map, k) == &c);
+ i = wl_map_insert_new(&map, WL_MAP_CLIENT_SIDE, &a);
+ assert(i == 0);
+ assert(wl_map_lookup(&map, i) == &a);
+
wl_map_release(&map);
}
+
+TEST(map_insert_at)
+{
+ struct wl_map map;
+ uint32_t a, b, c;
+
+ wl_map_init(&map);
+ assert(wl_map_insert_at(&map, WL_MAP_SERVER_SIDE, &a) == 0);
+ assert(wl_map_insert_at(&map, WL_MAP_SERVER_SIDE + 3, &b) == -1);
+ assert(wl_map_insert_at(&map, WL_MAP_SERVER_SIDE + 1, &c) == 0);
+
+ assert(wl_map_lookup(&map, WL_MAP_SERVER_SIDE) == &a);
+ assert(wl_map_lookup(&map, WL_MAP_SERVER_SIDE + 1) == &c);
+
+ wl_map_release(&map);
+}
+
+TEST(map_remove)
+{
+ struct wl_map map;
+ uint32_t i, j, k, l, a, b, c, d;
+
+ wl_map_init(&map);
+ i = wl_map_insert_new(&map, WL_MAP_SERVER_SIDE, &a);
+ j = wl_map_insert_new(&map, WL_MAP_SERVER_SIDE, &b);
+ k = wl_map_insert_new(&map, WL_MAP_SERVER_SIDE, &c);
+ assert(i == WL_SERVER_ID_START);
+ assert(j == WL_SERVER_ID_START + 1);
+ assert(k == WL_SERVER_ID_START + 2);
+
+ assert(wl_map_lookup(&map, i) == &a);
+ assert(wl_map_lookup(&map, j) == &b);
+ assert(wl_map_lookup(&map, k) == &c);
+
+ wl_map_remove(&map, j);
+ assert(wl_map_lookup(&map, j) == NULL);
+
+ /* Verify that we insert d at the hole left by removing b */
+ l = wl_map_insert_new(&map, WL_MAP_SERVER_SIDE, &d);
+ assert(l == WL_SERVER_ID_START + 1);
+ assert(wl_map_lookup(&map, l) == &d);
+}