return x;
}
-/*! Creates a new, empty critbit map */
-EXPORT map_t map_make(void)
-{
- map_t map;
- map.root = NULL;
- map.malloc = &malloc_std;
- map.free = &free_std;
- map.baton = NULL;
- return map;
-}
-
-/*! Returns non-zero if map contains str */
-EXPORT int map_contains(map_t *map, const char *str)
-{
- return map_get(map, str) != NULL;
-}
-
-EXPORT void *map_get(map_t *map, const char *str)
+static int cbt_get(map_t *map, const char *str, void **value)
{
const uint8_t *ubytes = (void *)str;
const size_t ulen = strlen(str);
cb_data_t *x = NULL;
if (p == NULL) {
- return NULL;
+ return 0;
}
while (ref_is_internal(p)) {
x = (cb_data_t *)p;
if (strcmp(str, (const char *)x->key) == 0) {
- return x->value;
+ if (value != NULL) {
+ *value = x->value;
+ }
+ return 1;
}
- return NULL;
+ return 0;
+}
+
+/*! Creates a new, empty critbit map */
+EXPORT map_t map_make(void)
+{
+ map_t map;
+ map.root = NULL;
+ map.malloc = &malloc_std;
+ map.free = &free_std;
+ map.baton = NULL;
+ return map;
+}
+
+/*! Returns non-zero if map contains str */
+EXPORT int map_contains(map_t *map, const char *str)
+{
+ return cbt_get(map, str, NULL);
+}
+
+EXPORT void *map_get(map_t *map, const char *str)
+{
+ void *v = NULL;
+ cbt_get(map, str, &v);
+ return v;
}
/*! Inserts str into map, returns 0 on success */
assert_int_equal(map_del(tree, "most likely not in tree"), 1);
}
+/* Test null value existence */
+static void test_null_value(void **state)
+{
+ map_t *tree = *state;
+ char *key = "foo";
+
+ assert_int_equal(map_set(tree, key, (void *)0), 0);
+ assert_true(map_contains(tree, key));
+ assert_int_equal(map_del(tree, key), 0);
+}
+
static void test_init(void **state)
{
static map_t tree;
unit_test(test_insert),
unit_test(test_get),
unit_test(test_delete),
+ unit_test(test_null_value),
group_test_teardown(test_deinit)
};
return run_group_tests(tests);
-}
\ No newline at end of file
+}