540 CX_TEST_ASSERT(0 != cxKvListRemoveKey(list, 3)); |
540 CX_TEST_ASSERT(0 != cxKvListRemoveKey(list, 3)); |
541 } |
541 } |
542 cxListFree(list); |
542 cxListFree(list); |
543 } |
543 } |
544 |
544 |
|
545 CX_TEST(test_kv_list_get_key) { |
|
546 CxList *list = cxKvListCreateSimple(sizeof(int)); |
|
547 int x; |
|
548 CX_TEST_DO { |
|
549 CxMap *map = cxKvListAsMap(list); |
|
550 |
|
551 x = 47; |
|
552 cxMapPut(map, "xyz", &x); |
|
553 x = 11; |
|
554 cxMapPut(map, "abc", &x); |
|
555 x = 1337; |
|
556 cxMapPut(map, "efg", &x); |
|
557 CX_TEST_ASSERT(cxMapSize(map) == 3); |
|
558 |
|
559 const CxHashKey *key = cxKvListGetKey(list, 1); |
|
560 int *y = cxMapGet(map, *key); |
|
561 CX_TEST_ASSERT(y != NULL); |
|
562 CX_TEST_ASSERT(*y == 11); |
|
563 |
|
564 // removing the element |
|
565 CX_TEST_ASSERT(0 == cxMapRemove(map, cx_strn(key->data, key->len))); |
|
566 key = cxKvListGetKey(list, 1); |
|
567 CX_TEST_ASSERT(0 == cx_strcmp(CX_STR("efg"), cx_strn(key->data, key->len))); |
|
568 |
|
569 // remove the key of element |
|
570 CX_TEST_ASSERT(0 == cxKvListRemoveKey(list, 1)); |
|
571 CX_TEST_ASSERT(NULL == cxKvListGetKey(list, 1)); |
|
572 |
|
573 // index out of bounds: |
|
574 CX_TEST_ASSERT(NULL == cxKvListGetKey(list, 3)); |
|
575 } |
|
576 cxListFree(list); |
|
577 } |
|
578 |
545 CX_TEST(test_kv_list_insert_with_key) { |
579 CX_TEST(test_kv_list_insert_with_key) { |
546 CxList *list = cxKvListCreateSimple(sizeof(int)); |
580 CxList *list = cxKvListCreateSimple(sizeof(int)); |
547 int x; |
581 int x; |
548 CX_TEST_DO { |
582 CX_TEST_DO { |
549 x = 47; |
583 x = 47; |
991 cx_test_register(suite, test_kv_list_map_remove_and_get); |
1025 cx_test_register(suite, test_kv_list_map_remove_and_get); |
992 cx_test_register(suite, test_kv_list_set_key); |
1026 cx_test_register(suite, test_kv_list_set_key); |
993 cx_test_register(suite, test_kv_list_set_key_already_exists); |
1027 cx_test_register(suite, test_kv_list_set_key_already_exists); |
994 cx_test_register(suite, test_kv_list_set_key_again); |
1028 cx_test_register(suite, test_kv_list_set_key_again); |
995 cx_test_register(suite, test_kv_list_remove_key); |
1029 cx_test_register(suite, test_kv_list_remove_key); |
|
1030 cx_test_register(suite, test_kv_list_get_key); |
996 cx_test_register(suite, test_kv_list_insert_with_key); |
1031 cx_test_register(suite, test_kv_list_insert_with_key); |
997 cx_test_register(suite, test_kv_list_insert_ptr_with_key); |
1032 cx_test_register(suite, test_kv_list_insert_ptr_with_key); |
998 cx_test_register(suite, test_kv_list_insert_array_and_set_keys); |
1033 cx_test_register(suite, test_kv_list_insert_array_and_set_keys); |
999 cx_test_register(suite, test_kv_list_list_remove_destr_in_list); |
1034 cx_test_register(suite, test_kv_list_list_remove_destr_in_list); |
1000 cx_test_register(suite, test_kv_list_list_remove_destr_in_map); |
1035 cx_test_register(suite, test_kv_list_list_remove_destr_in_map); |