tests/test_hash_map.c

changeset 1653
6a842bd49fea
parent 1638
14ae6a039af7
equal deleted inserted replaced
1652:db8299984bfe 1653:6a842bd49fea
1609 keys[keyiter.index] = *elem; 1609 keys[keyiter.index] = *elem;
1610 } 1610 }
1611 CX_TEST_ASSERT(keyiter.index == map->collection.size); 1611 CX_TEST_ASSERT(keyiter.index == map->collection.size);
1612 // verify that all keys are mapped to values in reference map 1612 // verify that all keys are mapped to values in reference map
1613 for (size_t i = 0 ; i < map->collection.size ; i++) { 1613 for (size_t i = 0 ; i < map->collection.size ; i++) {
1614 cxmutstr ksz = cx_strdup(cx_strn(keys[i].data, keys[i].len)); 1614 // need to create a zero-terminated string from the key
1615 cxmutstr ksz = cx_strdup(cx_hash_key_as_string(&keys[i]));
1615 CX_TEST_ASSERT(test_map_reference_get(ksz.ptr) != NULL); 1616 CX_TEST_ASSERT(test_map_reference_get(ksz.ptr) != NULL);
1616 cx_strfree(&ksz); 1617 cx_strfree(&ksz);
1617 } 1618 }
1618 free(keys); 1619 free(keys);
1619 } 1620 }
1650 CX_TEST_ASSERT(pairiter.elem_size == sizeof(CxMapEntry)); 1651 CX_TEST_ASSERT(pairiter.elem_size == sizeof(CxMapEntry));
1651 CX_TEST_ASSERT(pairiter.elem_count == map->collection.size); 1652 CX_TEST_ASSERT(pairiter.elem_count == map->collection.size);
1652 struct test_map_kv *pairs = calloc(map->collection.size, sizeof(struct test_map_kv)); 1653 struct test_map_kv *pairs = calloc(map->collection.size, sizeof(struct test_map_kv));
1653 cx_foreach(CxMapEntry*, entry, pairiter) { 1654 cx_foreach(CxMapEntry*, entry, pairiter) {
1654 const CxHashKey *key = entry->key; 1655 const CxHashKey *key = entry->key;
1655 pairs[pairiter.index].key = cx_strdup(cx_strn(key->data, key->len)).ptr; 1656 pairs[pairiter.index].key = cx_strdup(cx_hash_key_as_string(key)).ptr;
1656 pairs[pairiter.index].value = entry->value; 1657 pairs[pairiter.index].value = entry->value;
1657 } 1658 }
1658 CX_TEST_ASSERT(pairiter.index == map->collection.size); 1659 CX_TEST_ASSERT(pairiter.index == map->collection.size);
1659 // verify that all pairs are present in the reference map 1660 // verify that all pairs are present in the reference map
1660 for (size_t i = 0 ; i < map->collection.size ; i++) { 1661 for (size_t i = 0 ; i < map->collection.size ; i++) {

mercurial