static int test_cmp2_internal(int expected_cmp, long position) { unsigned char data[CMP_SIZE], data2[CMP_SIZE]; long size = CMP_SIZE, i; int retval, cmp; long p1; rlite *db = NULL; RL_CALL_VERBOSE(rl_open, RL_OK, ":memory:", &db, RLITE_OPEN_READWRITE | RLITE_OPEN_CREATE); for (i = 0; i < CMP_SIZE; i++) { data[i] = data2[i] = i % CHAR_MAX; } if (expected_cmp != 0) { if (data[position] == CHAR_MAX && expected_cmp > 0) { data2[position]--; } else if (data[position] == 0 && expected_cmp < 0) { data2[position]++; } else if (expected_cmp > 0) { data[position]++; } else { data[position]--; } } RL_CALL_VERBOSE(rl_multi_string_set, RL_OK, db, &p1, data, size); RL_CALL_VERBOSE(rl_multi_string_cmp_str, RL_OK, db, p1, data2, size, &cmp); EXPECT_INT(cmp, expected_cmp); rl_close(db); PASS(); }
TEST basic_test_ltrim(int _commit) { int retval; unsigned char *key = UNSIGN("my key"); long keylen = strlen((char *)key); long i, size; unsigned char **values; long *valueslen; rlite *db = NULL; RL_CALL_VERBOSE(setup_db, RL_OK, &db, _commit, 1); RL_CALL_VERBOSE(create, RL_OK, db, key, keylen, 200, _commit, 1); RL_CALL_VERBOSE(rl_ltrim, RL_OK, db, key, keylen, 50, -50); RL_BALANCED(); RL_CALL_VERBOSE(rl_lrange, RL_OK, db, key, keylen, 0, -1, &size, &values, &valueslen); EXPECT_LONG(size, 101); for (i = 0; i < size; i++) { EXPECT_LONG(valueslen[i], 2); EXPECT_INT(values[i][0], ((50 + i) % CHAR_MAX)); EXPECT_INT(values[i][1], 0); rl_free(values[i]); } rl_free(values); rl_free(valueslen); RL_CALL_VERBOSE(rl_ltrim, RL_DELETED, db, key, keylen, 1, 0); RL_BALANCED(); rl_close(db); PASS(); }
TEST basic_test_rpush_lpop(int maxsize, int _commit) { int retval; rlite *db = NULL; unsigned char *value = malloc(sizeof(unsigned char) * 2); RL_CALL_VERBOSE(setup_db, RL_OK, &db, _commit, 1); unsigned char *key = UNSIGN("my key"); long keylen = strlen((char *)key); unsigned char *testvalue; long testvaluelen; value[1] = 0; int i; RL_CALL_VERBOSE(create, RL_OK, db, key, keylen, maxsize, _commit, 0); for (i = maxsize - 1; i >= 0; i--) { value[0] = i % CHAR_MAX; RL_CALL_VERBOSE(rl_pop, RL_OK, db, key, keylen, &testvalue, &testvaluelen, 1); EXPECT_BYTES(value, 2, testvalue, testvaluelen); rl_free(testvalue); RL_BALANCED(); } free(value); rl_close(db); PASS(); }
TEST basic_test_lpushx(int _commit) { int retval; rlite *db = NULL; unsigned char *value = malloc(sizeof(unsigned char) * 2); RL_CALL_VERBOSE(setup_db, RL_OK, &db, _commit, 1); unsigned char *key = UNSIGN("my key"); long keylen = strlen((char *)key); value[1] = 0; long size; RL_CALL_VERBOSE(rl_push, RL_NOT_FOUND, db, key, keylen, 0, 1, 1, &key, &keylen, NULL); RL_CALL_VERBOSE(rl_llen, RL_NOT_FOUND, db, key, keylen, &size); RL_CALL_VERBOSE(create, RL_OK, db, key, keylen, 1, _commit, 1); RL_CALL_VERBOSE(rl_push, RL_OK, db, key, keylen, 0, 1, 1, &key, &keylen, NULL); RL_CALL_VERBOSE(rl_llen, RL_OK, db, key, keylen, &size); EXPECT_LONG(size, 2); free(value); rl_close(db); PASS(); }
TEST basic_test_lrange(int _commit) { int retval; rlite *db = NULL; unsigned char *value = malloc(sizeof(unsigned char) * 2); RL_CALL_VERBOSE(setup_db, RL_OK, &db, _commit, 1); unsigned char *key = UNSIGN("my key"); long keylen = strlen((char *)key); value[1] = 0; RL_CALL_VERBOSE(create, RL_OK, db, key, keylen, 10, _commit, 1); RL_CALL_VERBOSE(test_lrange, RL_OK, db, key, keylen, 0, -1, 0, 10); RL_CALL_VERBOSE(test_lrange, RL_OK, db, key, keylen, -100, 100, 0, 10); RL_CALL_VERBOSE(test_lrange, RL_OK, db, key, keylen, -1, -1, 9, 10); RL_CALL_VERBOSE(test_lrange, RL_OK, db, key, keylen, -1, 100, 9, 10); RL_CALL_VERBOSE(test_lrange, RL_OK, db, key, keylen, -1, 0, 0, 0); RL_CALL_VERBOSE(test_lrange, RL_OK, db, key, keylen, 0, -1000, 0, 0); RL_CALL_VERBOSE(test_lrange, RL_OK, db, key, keylen, -5, -4, 5, 7); free(value); rl_close(db); PASS(); }
TEST sort_set_sortby_alpha_test(int _commit) { int retval; rlite *db = NULL; RL_CALL_VERBOSE(setup_db, RL_OK, &db, _commit, 1); unsigned char *key = (unsigned char *)"key"; long keylen = 3; char *values[] = {"a", "s", "d"}; long valueslen[] = {1, 1, 1}; RL_CALL_VERBOSE(rl_sadd, RL_OK, db, key, keylen, 3, (unsigned char **)values, valueslen, NULL); RL_CALL_VERBOSE(rl_set, RL_OK, db, (unsigned char *)"wa", 2, (unsigned char *)"1", 1, 1, 0); RL_CALL_VERBOSE(rl_set, RL_OK, db, (unsigned char *)"ws", 2, (unsigned char *)"0", 1, 1, 0); RL_CALL_VERBOSE(rl_set, RL_OK, db, (unsigned char *)"wd", 2, (unsigned char *)"2", 1, 1, 0); long objc; unsigned char **objv; long *objvlen; RL_CALL_VERBOSE(rl_sort, RL_OK, db, key, keylen, (unsigned char *)"w*", 2, 0, 0, 1, 0, 0, -1, 0, NULL, NULL, NULL, 0, &objc, &objv, &objvlen); EXPECT_LONG(objc, 3); EXPECT_BYTES(objv[0], objvlen[0], "s", 1); EXPECT_BYTES(objv[1], objvlen[1], "a", 1); EXPECT_BYTES(objv[2], objvlen[2], "d", 1); rl_free(objv[0]); rl_free(objv[1]); rl_free(objv[2]); rl_free(objv); rl_free(objvlen); rl_close(db); PASS(); }
TEST sort_nosort_list_test(int _commit) { int retval; rlite *db = NULL; RL_CALL_VERBOSE(setup_db, RL_OK, &db, _commit, 1); unsigned char *key = (unsigned char *)"key"; long keylen = 3; char *values[] = {"1", "0", "2"}; long valueslen[] = {1, 1, 1}; RL_CALL_VERBOSE(rl_push, RL_OK, db, key, keylen, 1, 0, 3, (unsigned char **)values, valueslen, NULL); long objc; unsigned char **objv; long *objvlen; RL_CALL_VERBOSE(rl_sort, RL_OK, db, key, keylen, NULL, 0, 1, 0, 0, 0, 0, -1, 0, NULL, NULL, NULL, 0, &objc, &objv, &objvlen); EXPECT_LONG(objc, 3); EXPECT_BYTES(objv[0], objvlen[0], "1", 1); EXPECT_BYTES(objv[1], objvlen[1], "0", 1); EXPECT_BYTES(objv[2], objvlen[2], "2", 1); rl_free(objv[0]); rl_free(objv[1]); rl_free(objv[2]); rl_free(objv); rl_free(objvlen); rl_close(db); PASS(); }
TEST test_setrange(long initialsize, long index, long updatesize) { int retval; long finalsize = index + updatesize > initialsize ? index + updatesize : initialsize; long newlength, testdatalen; unsigned char *testdata; unsigned char *finaldata = calloc(finalsize, sizeof(unsigned char)); unsigned char *initialdata = malloc(sizeof(unsigned char) * initialsize); unsigned char *updatedata = malloc(sizeof(unsigned char) * updatesize); rlite *db = NULL; RL_CALL_VERBOSE(rl_open, RL_OK, ":memory:", &db, RLITE_OPEN_READWRITE | RLITE_OPEN_CREATE); long page, i; for (i = 0; i < initialsize; i++) { finaldata[i] = initialdata[i] = i % 123; } for (i = 0; i < updatesize; i++) { finaldata[index + i] = updatedata[i] = i % 151; } RL_CALL_VERBOSE(rl_multi_string_set, RL_OK, db, &page, initialdata, initialsize); RL_CALL_VERBOSE(rl_multi_string_setrange, RL_OK, db, page, updatedata, updatesize, index, &newlength); EXPECT_LONG(finalsize, newlength); RL_CALL_VERBOSE(rl_multi_string_get, RL_OK, db, page, &testdata, &testdatalen); EXPECT_BYTES(finaldata, finalsize, testdata, testdatalen); rl_free(testdata); free(finaldata); free(initialdata); free(updatedata); rl_close(db); PASS(); }
TEST test_append(long size, long append_size) { int retval; unsigned char *data = malloc(sizeof(unsigned char) * size); unsigned char *append_data = malloc(sizeof(unsigned char) * append_size); unsigned char *testdata; long testdatalen; rlite *db = NULL; RL_CALL_VERBOSE(rl_open, RL_OK, ":memory:", &db, RLITE_OPEN_READWRITE | RLITE_OPEN_CREATE); long page, i; for (i = 0; i < size; i++) { data[i] = i % 123; } for (i = 0; i < append_size; i++) { append_data[i] = i % 123; } RL_CALL_VERBOSE(rl_multi_string_set, RL_OK, db, &page, data, size); RL_CALL_VERBOSE(rl_multi_string_append, RL_OK, db, page, append_data, append_size, &testdatalen); EXPECT_LONG(testdatalen, size + append_size); RL_CALL_VERBOSE(rl_multi_string_get, RL_OK, db, page, &testdata, &testdatalen); EXPECT_LONG(testdatalen, size + append_size); EXPECT_BYTES(testdata, size, data, size); EXPECT_BYTES(&testdata[size], append_size, append_data, append_size); rl_free(testdata); rl_free(data); rl_free(append_data); rl_close(db); PASS(); }
TEST btree_create_oom() { rl_btree *btree = NULL; int i, retval; long btree_node_size = 10; rlite *db = NULL; RL_CALL_VERBOSE(setup_db, RL_OK, &db, 0, 1); for (i = 1; ;i++) { test_mode = 1; test_mode_caller = "rl_btree_create_size"; test_mode_counter = i; retval = rl_btree_create_size(db, &btree, &rl_btree_type_hash_long_long, btree_node_size); if (retval == RL_OK) { if (i == 1) { fprintf(stderr, "No OOM triggered\n"); test_mode = 0; FAIL(); } break; } EXPECT_INT(retval, RL_OUT_OF_MEMORY); } rl_btree_destroy(db, btree); rl_close(db); PASS(); }
TEST basic_set_get() { int retval, i, j; long size, size2, number; unsigned char *data, *data2; rlite *db = NULL; RL_CALL_VERBOSE(rl_open, RL_OK, ":memory:", &db, RLITE_OPEN_READWRITE | RLITE_OPEN_CREATE); for (i = 0; i < 2; i++) { srand(1); size = i == 0 ? 20 : 1020; data = malloc(sizeof(unsigned char) * size); for (j = 0; j < size; j++) { data[j] = (unsigned char)(rand() / CHAR_MAX); } RL_CALL_VERBOSE(rl_multi_string_set, RL_OK, db, &number, data, size); RL_CALL_VERBOSE(rl_multi_string_get, RL_OK, db, number, &data2, &size2); EXPECT_BYTES(data, size, data2, size2); rl_free(data); rl_free(data2); } rl_close(db); PASS(); }
TEST basic_test_sadd_srem(int _commit) { int retval; rlite *db = NULL; RL_CALL_VERBOSE(setup_db, RL_OK, &db, _commit, 1); unsigned char *key = UNSIGN("my key"); long keylen = strlen((char *)key); unsigned char *data = UNSIGN("my data"); long datalen = strlen((char *)data); unsigned char *data2 = UNSIGN("other data2"); long data2len = strlen((char *)data2); unsigned char *datas[2] = {data, data2}; long dataslen[2] = {datalen, data2len}; long count; RL_CALL_VERBOSE(rl_sadd, RL_OK, db, key, keylen, 2, datas, dataslen, NULL); RL_BALANCED(); RL_CALL_VERBOSE(rl_srem, RL_OK, db, key, keylen, 1, datas, dataslen, &count); RL_BALANCED(); EXPECT_LONG(count, 1); RL_CALL_VERBOSE(rl_srem, RL_OK, db, key, keylen, 2, datas, dataslen, &count); RL_BALANCED(); EXPECT_LONG(count, 1); RL_CALL_VERBOSE(rl_key_get, RL_NOT_FOUND, db, key, keylen, NULL, NULL, NULL, NULL, NULL); rl_close(db); PASS(); }
TEST basic_test_sadd_sunionstore(int _commit) { int retval; rlite *db = NULL; RL_CALL_VERBOSE(setup_db, RL_OK, &db, _commit, 1); unsigned char *key = UNSIGN("my key"); long keylen = strlen((char *)key); unsigned char *key2 = UNSIGN("my key2"); long key2len = strlen((char *)key2); unsigned char *target = UNSIGN("my target"); long targetlen = strlen((char *)target); unsigned char *datas[2] = {UNSIGN("my data"), UNSIGN("my data2")}; long dataslen[2] = {strlen((char *)datas[0]), strlen((char *)datas[1]) }; unsigned char *datas2[3] = {UNSIGN("other data2"), UNSIGN("yet another data"), UNSIGN("my data")}; long datas2len[3] = {strlen((char *)datas2[0]), strlen((char *)datas2[1]), strlen((char *)datas2[2])}; unsigned char *keys[2] = {key, key2}; long keyslen[2] = {keylen, key2len}; unsigned char **datasunion; long *datasunionlen, datasc, i; long added; RL_CALL_VERBOSE(rl_sadd, RL_OK, db, key, keylen, 2, datas, dataslen, NULL); RL_BALANCED(); RL_CALL_VERBOSE(rl_sadd, RL_OK, db, key2, key2len, 3, datas2, datas2len, NULL); RL_BALANCED(); RL_CALL_VERBOSE(rl_sunionstore, RL_OK, db, target, targetlen, 2, keys, keyslen, &added); EXPECT_LONG(added, 4); datasc = added; RL_CALL_VERBOSE(rl_srandmembers, RL_OK, db, target, targetlen, 0, &datasc, &datasunion, &datasunionlen); #define ASSERT_IN_4(s, l)\ if (!IS_EQUAL(s, l, datasunion[0], datasunionlen[0]) &&\ !IS_EQUAL(s, l, datasunion[1], datasunionlen[1]) &&\ !IS_EQUAL(s, l, datasunion[2], datasunionlen[2]) &&\ !IS_EQUAL(s, l, datasunion[3], datasunionlen[3])\ ) {\ fprintf(stderr, "Expected union to contains \"%s\" (%ld) on line %d\n", datas[0], dataslen[0], __LINE__);\ FAIL();\ } ASSERT_IN_4(datas[0], dataslen[0]); ASSERT_IN_4(datas[1], dataslen[1]); ASSERT_IN_4(datas2[0], datas2len[0]); ASSERT_IN_4(datas2[1], datas2len[1]); for (i = 0; i < datasc; i++) { rl_free(datasunion[i]); } rl_free(datasunion); rl_free(datasunionlen); rl_close(db); PASS(); }
TEST test_string() { INIT(); RL_CALL_VERBOSE(rl_set, RL_OK, db, key, keylen, UNSIGN("asd"), 3, 0, 0); RL_CALL_VERBOSE(rl_dump, RL_OK, db, key, keylen, &testvalue, &testvaluelen); EXPECT_BYTES(UNSIGN("\x00\x80\x00\x00\x00\x03\x61sd\x06\x00\xa4\xed\x80\xcb:7\x89\xd7"), 19, testvalue, testvaluelen); rl_free(testvalue); rl_close(db); PASS(); }
TEST test_zset() { INIT(); RL_CALL_VERBOSE(rl_zadd, RL_OK, db, key, keylen, 1.23, UNSIGN("a"), 1); RL_CALL_VERBOSE(rl_zadd, RL_OK, db, key, keylen, 4.5, UNSIGN("b"), 1); RL_CALL_VERBOSE(rl_dump, RL_OK, db, key, keylen, &testvalue, &testvaluelen); EXPECT_BYTES(UNSIGN("\x03\x80\x00\x00\x00\x02\x80\x00\x00\x00\x01\x61\x08\x31\x2e\x32\x33\x30\x30\x30\x30\x80\x00\x00\x00\x01\x62\x08\x34\x2e\x35\x30\x30\x30\x30\x30\x06\x00\x62\xf2\xc1\x8b\x73\x18\x51\xe6"), 46, testvalue, testvaluelen); rl_free(testvalue); rl_close(db); PASS(); }
TEST test_hash() { INIT(); RL_CALL_VERBOSE(rl_hset, RL_OK, db, key, keylen, UNSIGN("field"), 5, UNSIGN("value"), 5, NULL, 0); RL_CALL_VERBOSE(rl_hset, RL_OK, db, key, keylen, UNSIGN("field2"), 6, UNSIGN("value2"), 6, NULL, 0); RL_CALL_VERBOSE(rl_dump, RL_OK, db, key, keylen, &testvalue, &testvaluelen); EXPECT_BYTES(UNSIGN("\x04\x80\x00\x00\x00\x02\x80\x00\x00\x00\x05\x66\x69\x65\x6c\x64\x80\x00\x00\x00\x05\x76\x61\x6c\x75\x65\x80\x00\x00\x00\x06\x66\x69\x65\x6c\x64\x32\x80\x00\x00\x00\x06\x76\x61\x6c\x75\x65\x32\x06\x00\x74\xaf\xd2\x25\x1d\x50\x0c\xee"), 58, testvalue, testvaluelen); rl_free(testvalue); rl_close(db); PASS(); }
TEST test_set() { INIT(); unsigned char *values[2] = {UNSIGN("b"), UNSIGN("a")}; long valueslen[2] = {1, 1}; RL_CALL_VERBOSE(rl_sadd, RL_OK, db, key, keylen, 2, values, valueslen, NULL); RL_CALL_VERBOSE(rl_dump, RL_OK, db, key, keylen, &testvalue, &testvaluelen); EXPECT_BYTES(UNSIGN("\x02\x80\x00\x00\x00\x02\x80\x00\x00\x00\x01\x61\x80\x00\x00\x00\x01\x62\x06\x00\xbb\x8c\x8c\xcf\x86{ \xfd"), 28, testvalue, testvaluelen); rl_free(testvalue); rl_close(db); PASS(); }
TEST test_list() { INIT(); unsigned char *values[2] = {UNSIGN("b"), UNSIGN("a")}; long valueslen[2] = {1, 1}; RL_CALL_VERBOSE(rl_push, RL_OK, db, key, keylen, 1, 0, 2, values, valueslen, NULL); RL_CALL_VERBOSE(rl_dump, RL_OK, db, key, keylen, &testvalue, &testvaluelen); EXPECT_BYTES(UNSIGN("\x01\x80\x00\x00\x00\x02\x80\x00\x00\x00\x01\x62\x80\x00\x00\x00\x01\x61\x06\x00\x94\x46\xb5\x94\x1e\x1e_K"), 28, testvalue, testvaluelen); rl_free(testvalue); rl_close(db); PASS(); }
TEST test_string() { int retval; rlite *db = NULL; unsigned char *key = UNSIGN("mykey"), *testvalue; long keylen = 5, testvaluelen; RL_CALL_VERBOSE(rl_open, RL_OK, ":memory:", &db, RLITE_OPEN_READWRITE | RLITE_OPEN_CREATE); RL_CALL_VERBOSE(rl_set, RL_OK, db, key, keylen, UNSIGN("asd"), 3, 0, 0); RL_CALL_VERBOSE(rl_dump, RL_OK, db, key, keylen, &testvalue, &testvaluelen); EXPECT_BYTES(UNSIGN("\x00\x80\x00\x00\x00\x03\x61sd\x06\x00\xa4\xed\x80\xcb:7\x89\xd7"), 19, testvalue, testvaluelen); rl_free(testvalue); rl_close(db); PASS(); }
TEST test_zset() { int retval; rlite *db = NULL; unsigned char *key = UNSIGN("mykey"), *testvalue; long keylen = 5, testvaluelen; RL_CALL_VERBOSE(rl_open, RL_OK, ":memory:", &db, RLITE_OPEN_READWRITE | RLITE_OPEN_CREATE); RL_CALL_VERBOSE(rl_zadd, RL_OK, db, key, keylen, 1.23, UNSIGN("a"), 1); RL_CALL_VERBOSE(rl_zadd, RL_OK, db, key, keylen, 4.5, UNSIGN("b"), 1); RL_CALL_VERBOSE(rl_dump, RL_OK, db, key, keylen, &testvalue, &testvaluelen); EXPECT_BYTES(UNSIGN("\x03\x80\x00\x00\x00\x02\x80\x00\x00\x00\x01\x61\x08\x31\x2e\x32\x33\x30\x30\x30\x30\x80\x00\x00\x00\x01\x62\x08\x34\x2e\x35\x30\x30\x30\x30\x30\x06\x00\x62\xf2\xc1\x8b\x73\x18\x51\xe6"), 46, testvalue, testvaluelen); rl_free(testvalue); rl_close(db); PASS(); }
TEST test_hash() { int retval; rlite *db = NULL; unsigned char *key = UNSIGN("mykey"), *testvalue; long keylen = 5, testvaluelen; RL_CALL_VERBOSE(rl_open, RL_OK, ":memory:", &db, RLITE_OPEN_READWRITE | RLITE_OPEN_CREATE); RL_CALL_VERBOSE(rl_hset, RL_OK, db, key, keylen, UNSIGN("field"), 5, UNSIGN("value"), 5, NULL, 0); RL_CALL_VERBOSE(rl_hset, RL_OK, db, key, keylen, UNSIGN("field2"), 6, UNSIGN("value2"), 6, NULL, 0); RL_CALL_VERBOSE(rl_dump, RL_OK, db, key, keylen, &testvalue, &testvaluelen); EXPECT_BYTES(UNSIGN("\x04\x80\x00\x00\x00\x02\x80\x00\x00\x00\x05\x66\x69\x65\x6c\x64\x80\x00\x00\x00\x05\x76\x61\x6c\x75\x65\x80\x00\x00\x00\x06\x66\x69\x65\x6c\x64\x32\x80\x00\x00\x00\x06\x76\x61\x6c\x75\x65\x32\x06\x00\x74\xaf\xd2\x25\x1d\x50\x0c\xee"), 58, testvalue, testvaluelen); rl_free(testvalue); rl_close(db); PASS(); }
TEST empty_set_get() { int retval; long size, number; unsigned char *data; rlite *db = NULL; RL_CALL_VERBOSE(rl_open, RL_OK, ":memory:", &db, RLITE_OPEN_READWRITE | RLITE_OPEN_CREATE); RL_CALL_VERBOSE(rl_multi_string_set, RL_OK, db, &number, NULL, 0); RL_CALL_VERBOSE(rl_multi_string_get, RL_OK, db, number, &data, &size); EXPECT_INT(size, 0); EXPECT_PTR(data, NULL); rl_close(db); PASS(); }
int main(int argc, char *argv[]) { int len = atoi(argv[1]); RL *rl = rl_open(0, len); char *buf = (char *) malloc(len + 1); while (1) { int rc = rl_readline(rl, buf, len); if (rc == 0) break; else if (rc > 0) { write_line(buf, rc); } } free(buf); rl_close(rl); return 0; }
TEST test_set() { int retval; rlite *db = NULL; unsigned char *key = UNSIGN("mykey"), *testvalue; long keylen = 5, testvaluelen; RL_CALL_VERBOSE(rl_open, RL_OK, ":memory:", &db, RLITE_OPEN_READWRITE | RLITE_OPEN_CREATE); unsigned char *values[2] = {UNSIGN("b"), UNSIGN("a")}; long valueslen[2] = {1, 1}; RL_CALL_VERBOSE(rl_sadd, RL_OK, db, key, keylen, 2, values, valueslen, NULL); RL_CALL_VERBOSE(rl_dump, RL_OK, db, key, keylen, &testvalue, &testvaluelen); EXPECT_BYTES(UNSIGN("\x02\x80\x00\x00\x00\x02\x80\x00\x00\x00\x01\x61\x80\x00\x00\x00\x01\x62\x06\x00\xbb\x8c\x8c\xcf\x86{ \xfd"), 28, testvalue, testvaluelen); rl_free(testvalue); rl_close(db); PASS(); }
TEST btree_insert_oom() { long btree_node_size = 2; rl_btree *btree = NULL; int retval; rlite *db = NULL; RL_CALL_VERBOSE(setup_db, RL_OK, &db, 0, 1); long *key; long *val; long j, i; int finished = 0; for (j = 1; !finished; j++) { for (i = 0; i < 7; i++) { test_mode = 0; RL_CALL_VERBOSE(rl_btree_create_size, RL_OK, db, &btree, &rl_btree_type_hash_long_long, btree_node_size); long btree_page = db->next_empty_page; RL_CALL_VERBOSE(rl_write, RL_OK, db, btree->type->btree_type, btree_page, btree); test_mode = 1; test_mode_caller = "rl_btree_add_element"; test_mode_counter = j; key = malloc(sizeof(long)); val = malloc(sizeof(long)); *key = i + 1; *val = i * 10; CHECK_RETVAL(rl_btree_add_element(db, btree, btree_page, key, val)); if (i == 6 && retval == RL_OK) { if (j == 1) { fprintf(stderr, "No OOM triggered\n"); test_mode = 0; FAIL(); } finished = 1; break; } } test_mode = 0; rl_discard(db); } test_mode = 0; rl_close(db); PASS(); }
TEST basic_test_sadd_sunion(int _commit) { int retval; rlite *db = NULL; RL_CALL_VERBOSE(setup_db, RL_OK, &db, _commit, 1); unsigned char *key = UNSIGN("my key"); long keylen = strlen((char *)key); unsigned char *key2 = UNSIGN("my key2"); long key2len = strlen((char *)key2); unsigned char *datas[2] = {UNSIGN("my data"), UNSIGN("my data2")}; long dataslen[2] = {strlen((char *)datas[0]), strlen((char *)datas[1]) }; unsigned char *datas2[3] = {UNSIGN("other data2"), UNSIGN("yet another data"), UNSIGN("my data")}; long datas2len[3] = {strlen((char *)datas2[0]), strlen((char *)datas2[1]), strlen((char *)datas2[2])}; unsigned char *keys[2] = {key, key2}; long keyslen[2] = {keylen, key2len}; unsigned char **datasunion; long *datasunionlen, datasc, i; RL_CALL_VERBOSE(rl_sadd, RL_OK, db, key, keylen, 2, datas, dataslen, NULL); RL_BALANCED(); RL_CALL_VERBOSE(rl_sadd, RL_OK, db, key2, key2len, 3, datas2, datas2len, NULL); RL_BALANCED(); RL_CALL_VERBOSE(rl_sunion, RL_OK, db, 2, keys, keyslen, &datasc, &datasunion, &datasunionlen); EXPECT_LONG(datasc, 4); EXPECT_BYTES(datas[1], dataslen[1], datasunion[0], datasunionlen[0]); EXPECT_BYTES(datas[0], dataslen[0], datasunion[1], datasunionlen[1]); EXPECT_BYTES(datas2[1], datas2len[1], datasunion[2], datasunionlen[2]); EXPECT_BYTES(datas2[0], datas2len[0], datasunion[3], datasunionlen[3]); for (i = 0; i < datasc; i++) { rl_free(datasunion[i]); } rl_free(datasunion); rl_free(datasunionlen); rl_close(db); PASS(); }
TEST test_substr(long strsize, long start, long stop, long startindex, long expectedsize) { int retval; unsigned char *data = malloc(sizeof(unsigned char) * strsize), *data2; rlite *db = NULL; RL_CALL_VERBOSE(rl_open, RL_OK, ":memory:", &db, RLITE_OPEN_READWRITE | RLITE_OPEN_CREATE); long page, i, size2; for (i = 0; i < strsize; i++) { data[i] = i % 123; } RL_CALL_VERBOSE(rl_multi_string_set, RL_OK, db, &page, data, strsize); RL_CALL_VERBOSE(rl_multi_string_getrange, RL_OK, db, page, &data2, &size2, start, stop); EXPECT_BYTES(&data[startindex], size2, data2, expectedsize); rl_free(data2); free(data); rl_close(db); PASS(); }
TEST basic_test_sadd_smove(int _commit) { int retval; rlite *db = NULL; RL_CALL_VERBOSE(setup_db, RL_OK, &db, _commit, 1); unsigned char *key = UNSIGN("my key"); long keylen = strlen((char *)key); unsigned char *key2 = UNSIGN("my key2"); long key2len = strlen((char *)key2); unsigned char *data = UNSIGN("my data"); long datalen = strlen((char *)data); unsigned char *data2 = UNSIGN("other data2"); long data2len = strlen((char *)data2); unsigned char *datas[2] = {data, data2}; long dataslen[2] = {datalen, data2len}; RL_CALL_VERBOSE(rl_sadd, RL_OK, db, key, keylen, 2, datas, dataslen, NULL); RL_BALANCED(); RL_CALL_VERBOSE(rl_smove, RL_NOT_FOUND, db, key, keylen, key2, key2len, (unsigned char *)"new data", 8); RL_BALANCED(); RL_CALL_VERBOSE(rl_smove, RL_OK, db, key, keylen, key2, key2len, data, datalen); RL_BALANCED(); RL_CALL_VERBOSE(rl_sismember, RL_NOT_FOUND, db, key, keylen, data, datalen); RL_CALL_VERBOSE(rl_sismember, RL_FOUND, db, key2, key2len, data, datalen); RL_CALL_VERBOSE(rl_smove, RL_OK, db, key, keylen, key2, key2len, data2, data2len); RL_BALANCED(); RL_CALL_VERBOSE(rl_sismember, RL_NOT_FOUND, db, key, keylen, data2, data2len); RL_CALL_VERBOSE(rl_sismember, RL_FOUND, db, key2, key2len, data2, data2len); RL_CALL_VERBOSE(rl_smove, RL_NOT_FOUND, db, key, keylen, key2, key2len, data, datalen); RL_CALL_VERBOSE(rl_key_get, RL_NOT_FOUND, db, key, keylen, NULL, NULL, NULL, NULL, NULL); rl_close(db); PASS(); }
TEST basic_test_sadd_sunionstore_empty(int _commit) { int retval; rlite *db = NULL; RL_CALL_VERBOSE(setup_db, RL_OK, &db, _commit, 1); unsigned char *key = UNSIGN("my key"); long keylen = strlen((char *)key); unsigned char *key2 = UNSIGN("my key2"); long key2len = strlen((char *)key2); long added; RL_CALL_VERBOSE(rl_sunionstore, RL_OK, db, key, keylen, 1, &key2, &key2len, &added); RL_BALANCED(); EXPECT_LONG(added, 0); RL_CALL_VERBOSE(rl_key_get, RL_NOT_FOUND, db, key, keylen, NULL, NULL, NULL, NULL, NULL); rl_close(db); PASS(); }
TEST test_has_key() { rlite *db = NULL; int retval; const char *filepath = "rlite-test.rld"; if (access(filepath, F_OK) == 0) { unlink(filepath); } RL_CALL_VERBOSE(rl_open, RL_OK, filepath, &db, RLITE_OPEN_CREATE | RLITE_OPEN_READWRITE); unsigned char type = 'C', type2; const unsigned char *key = (unsigned char *)"random key"; long keylen = strlen((char *) key); long value = 529, value2; RL_CALL_VERBOSE(rl_key_get, RL_NOT_FOUND, db, key, keylen, NULL, NULL, NULL, NULL, NULL); RL_CALL_VERBOSE(rl_key_set, RL_OK, db, key, keylen, type, value, 0, 0); RL_CALL_VERBOSE(rl_key_get, RL_FOUND, db, key, keylen, &type2, NULL, &value2, NULL, NULL); EXPECT_LONG(value, value2); EXPECT_INT(type, type2); rl_close(db); PASS(); }