Commit 67564afc authored by Rich Prohaska's avatar Rich Prohaska

add test case. closes #153

git-svn-id: file:///svn/tokudb@1014 c7de825b-a66e-492c-adef-691d508d4ae1
parent 55243e2e
......@@ -13,8 +13,6 @@
#include "test.h"
void db_put(DB *db, int k, int v) {
DB_TXN * const null_txn = 0;
DBT key, val;
......@@ -22,18 +20,17 @@ void db_put(DB *db, int k, int v) {
assert(r == 0);
}
void test_db_current() {
if (verbose) printf("test_db_current\n");
void test_cursor_current() {
if (verbose) printf("test_cursor_current\n");
DB_ENV * const null_env = 0;
DB *db;
DB_TXN * const null_txn = 0;
const char * const fname = DIR "/" "test.db.current.brt";
const char * const fname = DIR "/" "test.cursor.current.brt";
int r;
unlink(fname);
/* create the dup database file */
r = db_create(&db, null_env, 0);
assert(r == 0);
r = db->open(db, null_txn, fname, "main", DB_BTREE, DB_CREATE, 0666);
......@@ -42,7 +39,7 @@ void test_db_current() {
/* insert <1,1> */
int k = 1, v = 1;
db_put(db, k, v);
DBC *cursor;
r = db->cursor(db, null_txn, &cursor, 0);
......@@ -57,22 +54,28 @@ void test_db_current() {
assert(r == 0);
assert(key.size == sizeof kk);
memcpy(&kk, key.data, sizeof kk);
assert(kk == 1);
assert(kk == k);
assert(data.size == sizeof vv);
memcpy(&vv, data.data, data.size);
assert(vv == 1);
assert(vv == v);
free(key.data); free(data.data);
r = cursor->c_get(cursor, dbt_init_malloc(&key), dbt_init_malloc(&data), DB_CURRENT);
assert(r == 0);
assert(key.size == sizeof kk);
memcpy(&kk, key.data, sizeof kk);
assert(kk == 1);
assert(kk == k);
assert(data.size == sizeof vv);
memcpy(&vv, data.data, data.size);
assert(vv == 1);
assert(vv == v);
free(key.data); free(data.data);
r = cursor->c_del(cursor, 0);
assert(r == 0);
r = cursor->c_get(cursor, dbt_init_malloc(&key), dbt_init_malloc(&data), DB_CURRENT);
assert(r == DB_KEYEMPTY);
r = cursor->c_close(cursor);
assert(r == 0);
......@@ -86,7 +89,7 @@ int main(int argc, const char *argv[]) {
system("rm -rf " DIR);
mkdir(DIR, 0777);
test_db_current();
test_cursor_current();
return 0;
}
......@@ -37,6 +37,14 @@ int db_put(DB *db, int k, int v) {
return r;
}
/* use inserts and cursors to test the brt_nonleaf_expand function
insert keys 0 and n and set cursors to them
then insert keys 1 .. n-1. this should cause leaf splits, new root nodes, nonleaf expands
and nonleaf splits as the tree grows.
the reverse parameter controls where in insertions are made to test the <, =, >
cases in the brt_nonleaf_expand function */
void test_cursor_nonleaf_expand(int n, int reverse) {
if (verbose) printf("test_cursor_nonleaf_expand:%d %d\n", n, reverse);
......@@ -69,6 +77,7 @@ void test_cursor_nonleaf_expand(int n, int reverse) {
}
}
/* make sure the cursors did not move */
expect_cursor_get(cursor0, htonl(0), 0, DB_CURRENT);
expect_cursor_get(cursorn, htonl(n), n, DB_CURRENT);
......
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