/** * Tests basic functionality for cuckoo_insert and cuckoo_get with small key/val. Checks that the * commands succeed and that the item returned is well-formed. */ void test_insert_basic(uint32_t policy, bool cas) { #define KEY "key" #define VAL "value" struct bstring key, testval; struct val val; rstatus_i status; struct item *it; test_reset(policy, cas); key.data = KEY; key.len = sizeof(KEY) - 1; val.type = VAL_TYPE_STR; val.vstr.data = VAL; val.vstr.len = sizeof(VAL) - 1; time_update(); status = cuckoo_insert(&key, &val, UINT32_MAX - 1); ck_assert_msg(status == CC_OK, "cuckoo_insert not OK - return status %d", status); it = cuckoo_get(&key); ck_assert_msg(it != NULL, "cuckoo_get returned NULL"); ck_assert_int_eq(it->vlen, sizeof(VAL) - 1); ck_assert_int_eq(it->klen, sizeof(KEY) - 1); item_value_str(&testval, it); ck_assert_int_eq(it->vlen, testval.len); ck_assert_int_eq(cc_memcmp(testval.data, VAL, testval.len), 0); #undef KEY #undef VAL }
static void test_assert_entry_exists(struct bstring *key, struct val *val) { struct item *it = cuckoo_get(key); ck_assert_msg(it != NULL, "cuckoo_get returned NULL"); ck_assert_int_eq(it->vlen, val->vstr.len); ck_assert_int_eq(it->klen, key->len); ck_assert_int_eq(it->vlen, val->vstr.len); struct bstring testval; item_value_str(&testval, it); ck_assert_int_eq(it->vlen, testval.len); ck_assert_int_eq(cc_memcmp(testval.data, val->vstr.data, testval.len), 0); }