tests/test_kv_list.c

changeset 1378
1b4fa55f7caa
parent 1377
1562bdf948da
equal deleted inserted replaced
1377:1562bdf948da 1378:1b4fa55f7caa
384 CX_TEST_ASSERT(*y == 1337); 384 CX_TEST_ASSERT(*y == 1337);
385 } 385 }
386 cxListFree(list); 386 cxListFree(list);
387 } 387 }
388 388
389 CX_TEST(test_kv_list_insert_with_key) {
390 CxList *list = cxKvListCreateSimple(sizeof(int));
391 int x;
392 CX_TEST_DO {
393 x = 47;
394 cxKvListAdd(list, "xyz", &x);
395 x = 11;
396 cxKvListAdd(list, "abc", &x);
397 x = 1337;
398 cxKvListInsert(list, 1, "efg", &x);
399
400 CX_TEST_ASSERT(cxListSize(list) == 3);
401 CX_TEST_ASSERT(*(int*)cxListAt(list, 0) == 47);
402 CX_TEST_ASSERT(*(int*)cxListAt(list, 1) == 1337);
403 CX_TEST_ASSERT(*(int*)cxListAt(list, 2) == 11);
404
405 CxMap *map = cxKvListAsMap(list);
406 CX_TEST_ASSERT(cxMapSize(map) == 3);
407 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 47);
408 CX_TEST_ASSERT(*(int*)cxMapGet(map, "abc") == 11);
409 CX_TEST_ASSERT(*(int*)cxMapGet(map, "efg") == 1337);
410 }
411 cxListFree(list);
412 }
413
414 CX_TEST(test_kv_list_insert_ptr_with_key) {
415 CxList *list = cxKvListCreateSimple(CX_STORE_POINTERS);
416 int x, y, z;
417 CX_TEST_DO {
418 x = 15;
419 cxKvListAdd(list, "xyz", &x);
420 y = 16;
421 cxKvListAdd(list, "abc", &y);
422 z = 17;
423 cxKvListInsert(list, 1, "efg", &z);
424 x = 47;
425 y = 11;
426 z = 1337;
427
428 CX_TEST_ASSERT(cxListSize(list) == 3);
429 CX_TEST_ASSERT(*(int*)cxListAt(list, 0) == 47);
430 CX_TEST_ASSERT(*(int*)cxListAt(list, 1) == 1337);
431 CX_TEST_ASSERT(*(int*)cxListAt(list, 2) == 11);
432
433 CxMap *map = cxKvListAsMap(list);
434 CX_TEST_ASSERT(cxMapSize(map) == 3);
435 CX_TEST_ASSERT(*(int*)cxMapGet(map, "xyz") == 47);
436 CX_TEST_ASSERT(*(int*)cxMapGet(map, "abc") == 11);
437 CX_TEST_ASSERT(*(int*)cxMapGet(map, "efg") == 1337);
438 }
439 cxListFree(list);
440 }
441
389 CX_TEST(test_kv_list_insert_array_and_set_keys) { 442 CX_TEST(test_kv_list_insert_array_and_set_keys) {
390 CxList *list = cxKvListCreateSimple(sizeof(int)); 443 CxList *list = cxKvListCreateSimple(sizeof(int));
391 CX_TEST_DO { 444 CX_TEST_DO {
392 int arr[] = { 13, 21, 34, 55, 89 }; 445 int arr[] = { 13, 21, 34, 55, 89 };
393 CX_TEST_ASSERT(5 == cxListAddArray(list, arr, 5)); 446 CX_TEST_ASSERT(5 == cxListAddArray(list, arr, 5));
568 cx_test_register(suite, test_kv_list_map_put); 621 cx_test_register(suite, test_kv_list_map_put);
569 cx_test_register(suite, test_kv_list_map_put_ptr); 622 cx_test_register(suite, test_kv_list_map_put_ptr);
570 cx_test_register(suite, test_kv_list_map_remove); 623 cx_test_register(suite, test_kv_list_map_remove);
571 cx_test_register(suite, test_kv_list_set_key); 624 cx_test_register(suite, test_kv_list_set_key);
572 cx_test_register(suite, test_kv_list_remove_key); 625 cx_test_register(suite, test_kv_list_remove_key);
626 cx_test_register(suite, test_kv_list_insert_with_key);
627 cx_test_register(suite, test_kv_list_insert_ptr_with_key);
573 cx_test_register(suite, test_kv_list_insert_array_and_set_keys); 628 cx_test_register(suite, test_kv_list_insert_array_and_set_keys);
574 cx_test_register(suite, test_kv_list_list_remove_destr_in_list); 629 cx_test_register(suite, test_kv_list_list_remove_destr_in_list);
575 cx_test_register(suite, test_kv_list_list_remove_destr_in_map); 630 cx_test_register(suite, test_kv_list_list_remove_destr_in_map);
576 cx_test_register(suite, test_kv_list_map_remove_destr_in_list); 631 cx_test_register(suite, test_kv_list_map_remove_destr_in_list);
577 cx_test_register(suite, test_kv_list_map_remove_destr_in_map); 632 cx_test_register(suite, test_kv_list_map_remove_destr_in_map);

mercurial