# HG changeset patch # User Mike Becker # Date 1757614663 -7200 # Node ID 9c176073e771c064e155c88eb4cb892fd9cf9074 # Parent 37dcaeebe5cab9348a78b8e0f400350c55f497a0 kv-list: remove obsolete TODOs and add a test case to prove it relates to #461 diff -r 37dcaeebe5ca -r 9c176073e771 src/kv_list.c --- a/src/kv_list.c Thu Sep 11 20:10:12 2025 +0200 +++ b/src/kv_list.c Thu Sep 11 20:17:43 2025 +0200 @@ -111,7 +111,6 @@ const void *data ) { cx_kv_list *kv_list = (cx_kv_list*)list; - // TODO: trick the base method by adding the required space for the key to the elem_size return kv_list->list_methods->insert_element(list, index, data); } @@ -122,7 +121,6 @@ size_t n ) { cx_kv_list *kv_list = (cx_kv_list*)list; - // TODO: trick the base method by adding the required space for the key to the elem_size return kv_list->list_methods->insert_array(list, index, data, n); } @@ -132,7 +130,6 @@ size_t n ) { cx_kv_list *kv_list = (cx_kv_list*)list; - // TODO: trick the base method by adding the required space for the key to the elem_size return kv_list->list_methods->insert_sorted(list, sorted_data, n); } @@ -142,7 +139,6 @@ int prepend ) { cx_kv_list *kv_list = iter->src_handle.m; - // TODO: trick the base method by adding the required space for the key to the elem_size return kv_list->list_methods->insert_iter(iter, elem, prepend); } @@ -236,7 +232,6 @@ cx_kv_list *kv_list = ((struct cx_kv_list_map_s*)map)->list; // insert the data into the list first (assume that insertion destroys the sorted property) kv_list->list.base.collection.sorted = false; - // TODO: use the same trick as above to increase the element size temporarily to add the key to the data void *node_data = kv_list->list_methods->insert_element( &kv_list->list.base, kv_list->list.base.collection.size, kv_list->list.base.collection.store_pointer ? &value : value); diff -r 37dcaeebe5ca -r 9c176073e771 tests/test_kv_list.c --- a/tests/test_kv_list.c Thu Sep 11 20:10:12 2025 +0200 +++ b/tests/test_kv_list.c Thu Sep 11 20:17:43 2025 +0200 @@ -157,6 +157,29 @@ cxListFree(list); } +CX_TEST(test_kv_list_insert_array_and_set_keys) { + CxList *list = cxKvListCreateSimple(sizeof(int)); + CX_TEST_DO { + int arr[] = { 13, 21, 34, 55, 89 }; + CX_TEST_ASSERT(5 == cxListAddArray(list, arr, 5)); + CX_TEST_ASSERT(5 == cxListSize(list)); + CX_TEST_ASSERT(0 == cxKvListSetKey(list, 0, "xyz")); + CX_TEST_ASSERT(0 == cxKvListSetKey(list, 1, "abc")); + CX_TEST_ASSERT(0 == cxKvListSetKey(list, 2, "def")); + CX_TEST_ASSERT(0 == cxKvListSetKey(list, 3, "ghi")); + CX_TEST_ASSERT(0 == cxKvListSetKey(list, 4, "jkl")); + + CxMap *map = cxKvListAsMap(list); + CX_TEST_ASSERT(5 == cxMapSize(map)); + CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 13); + CX_TEST_ASSERT(*(int*)cxMapGet(map, "abc") == 21); + CX_TEST_ASSERT(*(int*)cxMapGet(map, "def") == 34); + CX_TEST_ASSERT(*(int*)cxMapGet(map, "ghi") == 55); + CX_TEST_ASSERT(*(int*)cxMapGet(map, "jkl") == 89); + } + cxListFree(list); +} + static int kv_list_test_destr_val; static void kv_list_test_destr(void *data) { @@ -312,6 +335,7 @@ cx_test_register(suite, test_kv_list_map_put_ptr); 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_insert_array_and_set_keys); 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);