Commit d65552f3 authored by Rich Prohaska's avatar Rich Prohaska

increase test coverage. addresses #277

git-svn-id: file:///svn/tokudb@1695 c7de825b-a66e-492c-adef-691d508d4ae1
parent ec74f2c8
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h>
#include <assert.h>
#include <db_cxx.h>
......@@ -39,6 +40,23 @@ void load(Db *db, int n) {
}
}
void test_cursor_flags(Db *db) {
int r;
Dbc *cursor;
r = db->cursor(0, &cursor, 0); assert(r == 0);
Dbt key; key.set_flags(DB_DBT_MALLOC);
Dbt val; val.set_flags(DB_DBT_MALLOC);
r = cursor->get(&key, &val, DB_FIRST); assert(r == 0);
if (key.get_data()) free(key.get_data());
if (val.get_data()) free(val.get_data());
db_recno_t n;
r = cursor->count(&n, 1); assert(r == EINVAL);
r = cursor->count(&n, 0); assert(r == 0);
printf("n=%d\n", n);
r = cursor->close(); assert(r == 0);
}
int my_cursor_count(Dbc *cursor, db_recno_t *count, Db *db) {
int r;
Dbt key; key.set_flags(DB_DBT_REALLOC);
......@@ -275,6 +293,7 @@ int main(int argc, char *argv[]) {
r = db.open(0, "test.db", 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0);
load(&db, 10);
test_cursor_flags(&db);
walk(&db, 10);
test_next_nodup(&db, 10);
test_next_dup(&db, 10);
......
......@@ -52,8 +52,8 @@ void expect(DBC *cursor, int k, int v) {
free(val.data);
}
void test_reverse_compare(int n) {
if (verbose) printf("test_reverse_compare:%d\n", n);
void test_reverse_compare(int n, int dup_flags) {
if (verbose) printf("test_reverse_compare:%d %d\n", n, dup_flags);
DB_ENV * const null_env = 0;
DB *db;
......@@ -69,12 +69,14 @@ void test_reverse_compare(int n) {
/* create the dup database file */
r = db_create(&db, null_env, 0);
CKERR(r);
r = db->set_flags(db, 0);
r = db->set_flags(db, dup_flags);
CKERR(r);
r = db->set_pagesize(db, 4096);
CKERR(r);
r = db->set_bt_compare(db, reverse_compare);
CKERR(r);
r = db->set_dup_compare(db, reverse_compare);
CKERR(r);
r = db->open(db, null_txn, fname, "main", DB_BTREE, DB_CREATE, 0666);
CKERR(r);
......@@ -82,11 +84,11 @@ void test_reverse_compare(int n) {
for (i=0; i<n; i++) {
DBT key, val;
int k, v;
k = htonl(i);
k = htonl(dup_flags ? n : i);
dbt_init(&key, &k, sizeof k);
v = i;
v = htonl(i);
dbt_init(&val, &v, sizeof v);
r = db->put(db, null_txn, &key, &val, 0);
r = db->put(db, null_txn, &key, &val, DB_YESOVERWRITE);
CKERR(r);
}
......@@ -95,12 +97,14 @@ void test_reverse_compare(int n) {
CKERR(r);
r = db_create(&db, null_env, 0);
CKERR(r);
r = db->set_flags(db, 0);
r = db->set_flags(db, dup_flags);
CKERR(r);
r = db->set_pagesize(db, 4096);
CKERR(r);
r = db->set_bt_compare(db, reverse_compare);
CKERR(r);
r = db->set_dup_compare(db, reverse_compare);
CKERR(r);
r = db->open(db, null_txn, fname, "main", DB_BTREE, 0, 0666);
CKERR(r);
......@@ -108,11 +112,11 @@ void test_reverse_compare(int n) {
for (i=n; i<2*n; i++) {
DBT key, val;
int k, v;
k = htonl(i);
k = htonl(dup_flags ? n : i);
dbt_init(&key, &k, sizeof k);
v = i;
v = htonl(i);
dbt_init(&val, &v, sizeof v);
r = db->put(db, null_txn, &key, &val, 0);
r = db->put(db, null_txn, &key, &val, DB_YESOVERWRITE);
CKERR(r);
}
......@@ -123,7 +127,7 @@ void test_reverse_compare(int n) {
//for (i=0; i<2*n; i++)
for (i=2*n-1; i>=0; i--)
expect(cursor, htonl(i), i);
expect(cursor, htonl(dup_flags ? n : i), htonl(i));
r = cursor->c_close(cursor);
CKERR(r);
......@@ -138,7 +142,8 @@ int main(int argc, const char *argv[]) {
int i;
for (i = 1; i <= (1<<16); i *= 2) {
test_reverse_compare(i);
test_reverse_compare(i, 0);
test_reverse_compare(i, DB_DUP + DB_DUPSORT);
}
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment