Wed, 03 Sep 2025 23:10:36 +0200
add failing tests for when clear/remove are called with destructors in the "opposite" aspect of a kv-list
relates to #461
tests/test_kv_list.c | file | annotate | diff | comparison | revisions |
--- a/tests/test_kv_list.c Wed Sep 03 22:59:09 2025 +0200 +++ b/tests/test_kv_list.c Wed Sep 03 23:10:36 2025 +0200 @@ -124,7 +124,7 @@ kv_list_test_destr_val = *(int*)data; } -CX_TEST(test_kv_list_map_remove_destr_in_list) { +CX_TEST(test_kv_list_list_remove_destr_in_list) { CxList *list = cxKvListCreateSimple(sizeof(int)); int x; CX_TEST_DO { @@ -140,6 +140,37 @@ cxListFree(list); } +CX_TEST(test_kv_list_list_remove_destr_in_map) { + CxList *list = cxKvListCreateSimple(sizeof(int)); + int x; + CX_TEST_DO { + x = 0xabcd; + CX_TEST_ASSERT(0 == cxListAdd(list, &x)); + cxKvListSetKey(list, 0, "xyz"); + CxMap *map = cxKvListAsMap(list); + cxDefineDestructor(map, kv_list_test_destr); + kv_list_test_destr_val = 0; + CX_TEST_ASSERT(0 == cxListRemove(list, 0)); + CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); + } + cxListFree(list); +} + +CX_TEST(test_kv_list_map_remove_destr_in_list) { + CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); + int x; + CX_TEST_DO { + x = 0xabcd; + CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); + CxList *list = cxKvListAsList(map); + cxDefineDestructor(list, kv_list_test_destr); + kv_list_test_destr_val = 0; + CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); + CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); + } + cxMapFree(map); +} + CX_TEST(test_kv_list_map_remove_destr_in_map) { CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); int x; @@ -155,6 +186,68 @@ cxMapFree(map); } +CX_TEST(test_kv_list_list_clear_destr_in_list) { + CxList *list = cxKvListCreateSimple(sizeof(int)); + int x; + CX_TEST_DO { + x = 0xabcd; + CX_TEST_ASSERT(0 == cxListAdd(list, &x)); + cxKvListSetKey(list, 0, "xyz"); + + cxDefineDestructor(list, kv_list_test_destr); + kv_list_test_destr_val = 0; + cxListClear(list); + CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); + } + cxListFree(list); +} + +CX_TEST(test_kv_list_list_clear_destr_in_map) { + CxList *list = cxKvListCreateSimple(sizeof(int)); + int x; + CX_TEST_DO { + x = 0xabcd; + CX_TEST_ASSERT(0 == cxListAdd(list, &x)); + cxKvListSetKey(list, 0, "xyz"); + CxMap *map = cxKvListAsMap(list); + cxDefineDestructor(map, kv_list_test_destr); + kv_list_test_destr_val = 0; + cxListClear(list); + CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); + } + cxListFree(list); +} + +CX_TEST(test_kv_list_map_clear_destr_in_list) { + CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); + int x; + CX_TEST_DO { + x = 0xabcd; + CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); + CxList *list = cxKvListAsList(map); + cxDefineDestructor(list, kv_list_test_destr); + kv_list_test_destr_val = 0; + cxMapClear(map); + CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); + } + cxMapFree(map); +} + +CX_TEST(test_kv_list_map_clear_destr_in_map) { + CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); + int x; + CX_TEST_DO { + x = 0xabcd; + CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); + + cxDefineDestructor(map, kv_list_test_destr); + kv_list_test_destr_val = 0; + cxMapClear(map); + CX_TEST_ASSERT(kv_list_test_destr_val == 0xabcd); + } + cxMapFree(map); +} + CxTestSuite *cx_test_suite_kv_list_specifics(void) { CxTestSuite *suite = cx_test_suite_new("kv_list specifics"); @@ -163,8 +256,14 @@ 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_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); cx_test_register(suite, test_kv_list_map_remove_destr_in_map); + cx_test_register(suite, test_kv_list_list_clear_destr_in_list); + cx_test_register(suite, test_kv_list_list_clear_destr_in_map); + cx_test_register(suite, test_kv_list_map_clear_destr_in_list); + cx_test_register(suite, test_kv_list_map_clear_destr_in_map); return suite; }