tests/test_kv_list.c

changeset 1382
f61119884dcd
parent 1380
bf5866e47b15
child 1383
3db28cb1e5ec
equal deleted inserted replaced
1381:ee421d6b95ef 1382:f61119884dcd
422 CX_TEST_ASSERT(cxListSize(list) == 0); 422 CX_TEST_ASSERT(cxListSize(list) == 0);
423 } 423 }
424 cxListFree(list); 424 cxListFree(list);
425 } 425 }
426 426
427 CX_TEST(test_kv_list_set_key_already_exists) {
428 CxList *list = cxKvListCreateSimple(sizeof(int));
429 int x;
430 CX_TEST_DO {
431 x = 47;
432 cxListAdd(list, &x);
433 x = 11;
434 cxListAdd(list, &x);
435 CX_TEST_ASSERT(0 == cxKvListSetKey(list, 1, "xyz"));
436 // already exists
437 CX_TEST_ASSERT(0 != cxKvListSetKey(list, 0, "xyz"));
438
439 CxMap *map = cxKvListAsMap(list);
440
441 CX_TEST_ASSERT(cxMapSize(map) == 1);
442
443 int *y = cxMapGet(map, "xyz");
444 CX_TEST_ASSERT(y != NULL);
445 CX_TEST_ASSERT(*y == 11);
446
447 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz"));
448 CX_TEST_ASSERT(cxMapGet(map, "xyz") == NULL);
449 CX_TEST_ASSERT(cxListSize(list) == 1);
450
451 // now we can assign the key again
452 CX_TEST_ASSERT(0 == cxKvListSetKey(list, 0, "xyz"));
453 y = cxMapGet(map, "xyz");
454 CX_TEST_ASSERT(y != NULL);
455 CX_TEST_ASSERT(*y == 47);
456 }
457 cxListFree(list);
458 }
459
427 CX_TEST(test_kv_list_remove_key) { 460 CX_TEST(test_kv_list_remove_key) {
428 CxList *list = cxKvListCreateSimple(sizeof(int)); 461 CxList *list = cxKvListCreateSimple(sizeof(int));
429 int x; 462 int x;
430 CX_TEST_DO { 463 CX_TEST_DO {
431 CxMap *map = cxKvListAsMap(list); 464 CxMap *map = cxKvListAsMap(list);
763 cx_test_register(suite, test_kv_list_map_put_ptr); 796 cx_test_register(suite, test_kv_list_map_put_ptr);
764 cx_test_register(suite, test_kv_list_map_put_not_hashed); 797 cx_test_register(suite, test_kv_list_map_put_not_hashed);
765 cx_test_register(suite, test_kv_list_map_remove); 798 cx_test_register(suite, test_kv_list_map_remove);
766 cx_test_register(suite, test_kv_list_map_remove_and_get); 799 cx_test_register(suite, test_kv_list_map_remove_and_get);
767 cx_test_register(suite, test_kv_list_set_key); 800 cx_test_register(suite, test_kv_list_set_key);
801 cx_test_register(suite, test_kv_list_set_key_already_exists);
768 cx_test_register(suite, test_kv_list_remove_key); 802 cx_test_register(suite, test_kv_list_remove_key);
769 cx_test_register(suite, test_kv_list_insert_with_key); 803 cx_test_register(suite, test_kv_list_insert_with_key);
770 cx_test_register(suite, test_kv_list_insert_ptr_with_key); 804 cx_test_register(suite, test_kv_list_insert_ptr_with_key);
771 cx_test_register(suite, test_kv_list_insert_array_and_set_keys); 805 cx_test_register(suite, test_kv_list_insert_array_and_set_keys);
772 cx_test_register(suite, test_kv_list_list_remove_destr_in_list); 806 cx_test_register(suite, test_kv_list_list_remove_destr_in_list);

mercurial