802 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); |
802 CX_TEST_ASSERT(0 == cxMapPut(map, "xyz", &x)); |
803 x = 0xef89; |
803 x = 0xef89; |
804 kv_list_test_destr_val = 0; |
804 kv_list_test_destr_val = 0; |
805 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); |
805 CX_TEST_ASSERT(0 == cxMapRemove(map, "xyz")); |
806 CX_TEST_ASSERT(kv_list_test_destr_val == 0xef89); |
806 CX_TEST_ASSERT(kv_list_test_destr_val == 0xef89); |
|
807 } |
|
808 cxMapFree(map); |
|
809 } |
|
810 |
|
811 CX_TEST(test_kv_list_map_iterator) { |
|
812 CxMap *map = cxKvListCreateAsMapSimple(sizeof(int)); |
|
813 CX_TEST_DO { |
|
814 int x; |
|
815 x = 0xc0ffee; // this element shall be skipped |
|
816 cxListAdd(cxKvListAsList(map), &x); |
|
817 x = 815; |
|
818 cxMapPut(map, "xyz", &x); |
|
819 x = 8016; |
|
820 cxMapPut(map, "abcd", &x); |
|
821 x = 0xbeef; |
|
822 cxListAdd(cxKvListAsList(map), &x); |
|
823 x = 80017; |
|
824 cxMapPut(map, "efghi", &x); |
|
825 |
|
826 const CxMapEntry *entry; |
|
827 CxMapIterator it = cxMapIterator(map); |
|
828 CX_TEST_ASSERT(it.elem_count == 3); |
|
829 CX_TEST_ASSERT(it.elem_size == sizeof(CxMapEntry)); |
|
830 |
|
831 CX_TEST_ASSERT(cxIteratorValid(it)); |
|
832 CX_TEST_ASSERT(it.index == 0); |
|
833 entry = cxIteratorCurrent(it); |
|
834 CX_TEST_ASSERT(*(int*)entry->value == 815); |
|
835 CX_TEST_ASSERT(entry->key->len == 3); |
|
836 CX_TEST_ASSERT(strncmp(entry->key->data, "xyz", 3) == 0); |
|
837 |
|
838 cxIteratorNext(it); |
|
839 CX_TEST_ASSERT(cxIteratorValid(it)); |
|
840 CX_TEST_ASSERT(it.index == 1); |
|
841 entry = cxIteratorCurrent(it); |
|
842 CX_TEST_ASSERT(*(int*)entry->value == 8016); |
|
843 CX_TEST_ASSERT(entry->key->len == 4); |
|
844 CX_TEST_ASSERT(strncmp(entry->key->data, "abcd", 4) == 0); |
|
845 |
|
846 cxIteratorNext(it); |
|
847 CX_TEST_ASSERT(cxIteratorValid(it)); |
|
848 CX_TEST_ASSERT(it.index == 2); |
|
849 entry = cxIteratorCurrent(it); |
|
850 CX_TEST_ASSERT(*(int*)entry->value == 80017); |
|
851 CX_TEST_ASSERT(entry->key->len == 5); |
|
852 CX_TEST_ASSERT(strncmp(entry->key->data, "efghi", 5) == 0); |
|
853 |
|
854 cxIteratorNext(it); |
|
855 CX_TEST_ASSERT(!cxIteratorValid(it)); |
|
856 |
|
857 // remove the first element (which was skipped anyway) and try again |
|
858 cxListRemove(cxKvListAsList(map), 0); |
|
859 it = cxMapIterator(map); |
|
860 CX_TEST_ASSERT(it.elem_count == 3); |
|
861 CX_TEST_ASSERT(it.elem_size == sizeof(CxMapEntry)); |
|
862 |
|
863 CX_TEST_ASSERT(cxIteratorValid(it)); |
|
864 CX_TEST_ASSERT(it.index == 0); |
|
865 entry = cxIteratorCurrent(it); |
|
866 CX_TEST_ASSERT(*(int*)entry->value == 815); |
|
867 CX_TEST_ASSERT(entry->key->len == 3); |
|
868 CX_TEST_ASSERT(strncmp(entry->key->data, "xyz", 3) == 0); |
807 } |
869 } |
808 cxMapFree(map); |
870 cxMapFree(map); |
809 } |
871 } |
810 |
872 |
811 CxTestSuite *cx_test_suite_kv_list_specifics(void) { |
873 CxTestSuite *cx_test_suite_kv_list_specifics(void) { |
842 cx_test_register(suite, test_kv_list_list_clear_destr_in_list); |
904 cx_test_register(suite, test_kv_list_list_clear_destr_in_list); |
843 cx_test_register(suite, test_kv_list_list_clear_destr_in_map); |
905 cx_test_register(suite, test_kv_list_list_clear_destr_in_map); |
844 cx_test_register(suite, test_kv_list_map_clear_destr_in_list); |
906 cx_test_register(suite, test_kv_list_map_clear_destr_in_list); |
845 cx_test_register(suite, test_kv_list_map_clear_destr_in_map); |
907 cx_test_register(suite, test_kv_list_map_clear_destr_in_map); |
846 cx_test_register(suite, test_kv_list_destr_ptr); |
908 cx_test_register(suite, test_kv_list_destr_ptr); |
|
909 cx_test_register(suite, test_kv_list_map_iterator); |
847 |
910 |
848 return suite; |
911 return suite; |
849 } |
912 } |