--- a/tests/test_hash_map.c Sat Nov 01 19:48:50 2025 +0100 +++ b/tests/test_hash_map.c Sun Nov 02 18:04:35 2025 +0100 @@ -515,11 +515,14 @@ cx_testing_allocator_destroy(&talloc); } +static bool test_hash_map_clone_func_max_enabled = false; static unsigned test_hash_map_clone_func_max_clones; static void *test_hash_map_clone_func(void *dst, const void *src, const CxAllocator *al, void *data) { - if (test_hash_map_clone_func_max_clones == 0) return NULL; - test_hash_map_clone_func_max_clones--; + if (test_hash_map_clone_func_max_enabled) { + if (test_hash_map_clone_func_max_clones == 0) return NULL; + test_hash_map_clone_func_max_clones--; + } if (dst == NULL) { dst = cxMalloc(al, sizeof(int)); } @@ -540,7 +543,6 @@ } CX_TEST_DO { int c = 4; - test_hash_map_clone_func_max_clones = 100; // no limit CX_TEST_ASSERT(0 == cxMapClone(dst, src, test_hash_map_clone_func, NULL, &c)); CX_TEST_ASSERT(cxMapSize(dst) == 5); CX_TEST_ASSERT(*((int*)cxMapGet(dst, "k1")) == 1); @@ -570,8 +572,10 @@ } CX_TEST_DO { int c = 4; + test_hash_map_clone_func_max_enabled = true; test_hash_map_clone_func_max_clones = 2; CX_TEST_ASSERT(0 != cxMapClone(dst, src, test_hash_map_clone_func, NULL, &c)); + test_hash_map_clone_func_max_enabled = false; CX_TEST_ASSERT(cxMapSize(dst) == 4); CX_TEST_ASSERT(*((int*)cxMapGet(dst, "k1")) == 1); CX_TEST_ASSERT(*((int*)cxMapGet(dst, "k2")) == 13); @@ -607,7 +611,6 @@ } CX_TEST_DO { int c = 4; - test_hash_map_clone_func_max_clones = 100; // no limit CX_TEST_ASSERT(0 == cxMapClone(dst, src, test_hash_map_clone_func, allocator, &c)); CX_TEST_ASSERT(cxMapSize(dst) == 5); CX_TEST_ASSERT(*((int*)cxMapGet(dst, "k1")) == 1); @@ -643,7 +646,6 @@ } CX_TEST_DO { int c = 4; - test_hash_map_clone_func_max_clones = 100; // no limit CX_TEST_ASSERT(0 == cxMapDifference(dst, s1, s2, test_hash_map_clone_func, NULL, &c)); CX_TEST_ASSERT(cxMapSize(dst) == 2); CX_TEST_ASSERT(*((int*)cxMapGet(dst, "k1")) == 5); @@ -670,8 +672,10 @@ } CX_TEST_DO { int c = 4; + test_hash_map_clone_func_max_enabled = true; test_hash_map_clone_func_max_clones = 1; CX_TEST_ASSERT(1 == cxMapDifference(dst, s1, s2, test_hash_map_clone_func, NULL, &c)); + test_hash_map_clone_func_max_enabled = false; CX_TEST_ASSERT(cxMapSize(dst) == 1); // the concrete element which is affected might change when the hash function changes CX_TEST_ASSERT(cxMapGet(dst, "k1") == NULL); @@ -700,7 +704,6 @@ } CX_TEST_DO { int c = 4; - test_hash_map_clone_func_max_clones = 100; // no limit CX_TEST_ASSERT(0 == cxMapListDifference(dst, src, keys, test_hash_map_clone_func, NULL, &c)); CX_TEST_ASSERT(cxMapSize(dst) == 2); CX_TEST_ASSERT(*((int*)cxMapGet(dst, "k1")) == 5); @@ -729,8 +732,10 @@ } CX_TEST_DO { int c = 4; + test_hash_map_clone_func_max_enabled = true; test_hash_map_clone_func_max_clones = 1; CX_TEST_ASSERT(1 == cxMapListDifference(dst, src, keys, test_hash_map_clone_func, NULL, &c)); + test_hash_map_clone_func_max_enabled = false; CX_TEST_ASSERT(cxMapSize(dst) == 1); // the concrete element which is affected might change when the hash function changes CX_TEST_ASSERT(cxMapGet(dst, "k1") == NULL); @@ -757,20 +762,19 @@ cxMapPut(s2, s2_keys[i], &s2_values[i]); } - // add k5 to dst which is not in src, but shall also be not in the difference + // add k5 to dst which is not in src, and also not in the difference int *k5 = cxMallocDefault(sizeof(int)); *k5 = 1337; cxMapPut(dst, "k5",k5); CX_TEST_DO { int c = 4; - test_hash_map_clone_func_max_clones = 100; // no limit CX_TEST_ASSERT(0 == cxMapDifference(dst, s1, s2, test_hash_map_clone_func, NULL, &c)); - CX_TEST_ASSERT(cxMapSize(dst) == 2); + CX_TEST_ASSERT(cxMapSize(dst) == 3); CX_TEST_ASSERT(*((int*)cxMapGet(dst, "k1")) == 5); CX_TEST_ASSERT(cxMapGet(dst, "k2") == NULL); CX_TEST_ASSERT(*((int*)cxMapGet(dst, "k3")) == 8); - CX_TEST_ASSERT(cxMapGet(dst, "k5") == NULL); + CX_TEST_ASSERT(*(int*)cxMapGet(dst, "k5") == 1337); } cxMapFree(dst); cxMapFree(s1); @@ -794,20 +798,19 @@ cxListAdd(keys, &key); } - // add k5 to dst which is not in src, but shall also be not in the difference + // add k5 to dst which is not in src, and also not in the difference int *k5 = cxMallocDefault(sizeof(int)); *k5 = 1337; cxMapPut(dst, "k5",k5); CX_TEST_DO { int c = 4; - test_hash_map_clone_func_max_clones = 100; // no limit CX_TEST_ASSERT(0 == cxMapListDifference(dst, src, keys, test_hash_map_clone_func, NULL, &c)); - CX_TEST_ASSERT(cxMapSize(dst) == 2); + CX_TEST_ASSERT(cxMapSize(dst) == 3); CX_TEST_ASSERT(*((int*)cxMapGet(dst, "k1")) == 5); CX_TEST_ASSERT(cxMapGet(dst, "k2") == NULL); CX_TEST_ASSERT(*((int*)cxMapGet(dst, "k3")) == 8); - CX_TEST_ASSERT(cxMapGet(dst, "k5") == NULL); + CX_TEST_ASSERT(*(int*)cxMapGet(dst, "k5") == 1337); } cxMapFree(dst); cxMapFree(src);