tests/test_kv_list.c

changeset 1366
70ce877c838a
parent 1363
c9a86bd9e361
--- a/tests/test_kv_list.c	Sun Sep 07 17:08:26 2025 +0200
+++ b/tests/test_kv_list.c	Mon Sep 08 22:48:48 2025 +0200
@@ -119,6 +119,31 @@
     cxListFree(list);
 }
 
+CX_TEST(test_kv_list_set_key) {
+    CxList *list = cxKvListCreateSimple(sizeof(int));
+    int x;
+    CX_TEST_DO {
+        x = 47;
+        cxListAdd(list, &x);
+        CX_TEST_ASSERT(0 == cxKvListSetKey(list, 0, "xyz"));
+
+        CxMap *map = cxKvListAsMap(list);
+
+        CX_TEST_ASSERT(cxMapSize(map) == 1);
+
+        int *y = cxMapGet(map, "xyz");
+        CX_TEST_ASSERT(y != NULL);
+        CX_TEST_ASSERT(*y == 47);
+
+        CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz"));
+        CX_TEST_ASSERT(cxMapGet(map, "xyz") == NULL);
+
+        CX_TEST_ASSERT(cxListSize(list) == 0);
+    }
+    cxListFree(list);
+}
+
+
 static int kv_list_test_destr_val;
 static void kv_list_test_destr(void *data) {
     kv_list_test_destr_val = *(int*)data;
@@ -256,6 +281,7 @@
     cx_test_register(suite, test_kv_list_free_as_list);
     cx_test_register(suite, test_kv_list_map_put);
     cx_test_register(suite, test_kv_list_map_remove);
+    cx_test_register(suite, test_kv_list_set_key);
     cx_test_register(suite, test_kv_list_list_remove_destr_in_list);
     cx_test_register(suite, test_kv_list_list_remove_destr_in_map);
     cx_test_register(suite, test_kv_list_map_remove_destr_in_list);

mercurial