Commit f362644e authored by Rich Prohaska's avatar Rich Prohaska

add boundary tests. addresses #121

git-svn-id: file:///svn/tokudb@940 c7de825b-a66e-492c-adef-691d508d4ae1
parent 93e1f7df
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <assert.h> #include <assert.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <db.h> #include <db.h>
...@@ -78,19 +79,21 @@ void expect_cursor_set(DBC *cursor, int k, int expectv) { ...@@ -78,19 +79,21 @@ void expect_cursor_set(DBC *cursor, int k, int expectv) {
assert(expectv == vv); assert(expectv == vv);
} }
void expect_cursor_get(DBC *cursor, int expectk, int expectv, int op) { int expect_cursor_get(DBC *cursor, int expectk, int expectv, int op) {
DBT key, val; DBT key, val;
int r = cursor->c_get(cursor, dbt_init_zero(&key), dbt_init_zero(&val), op); int r = cursor->c_get(cursor, dbt_init_zero(&key), dbt_init_zero(&val), op);
assert(r == 0); if (r == 0) {
assert(key.size == sizeof expectk); assert(key.size == sizeof expectk);
int kk; int kk;
memcpy(&kk, key.data, key.size); memcpy(&kk, key.data, key.size);
assert(val.size == sizeof expectv); assert(val.size == sizeof expectv);
int vv; int vv;
memcpy(&vv, val.data, val.size); memcpy(&vv, val.data, val.size);
if (kk != expectk || vv != expectv) printf("expect key %d got %d - %d %d\n", htonl(expectk), htonl(kk), htonl(expectv), htonl(vv)); if (kk != expectk || vv != expectv) printf("expect key %d got %d - %d %d\n", htonl(expectk), htonl(kk), htonl(expectv), htonl(vv));
assert(kk == expectk); assert(kk == expectk);
assert(vv == expectv); assert(vv == expectv);
}
return r;
} }
void test_dup_next(int n, int dup_mode) { void test_dup_next(int n, int dup_mode) {
...@@ -124,12 +127,16 @@ void test_dup_next(int n, int dup_mode) { ...@@ -124,12 +127,16 @@ void test_dup_next(int n, int dup_mode) {
DBC *cursor; DBC *cursor;
r = db->cursor(db, null_txn, &cursor, 0); assert(r == 0); r = db->cursor(db, null_txn, &cursor, 0); assert(r == 0);
r = expect_cursor_get(cursor, htonl(1), htonl(0), DB_NEXT_DUP); assert(r == EINVAL);
expect_cursor_set(cursor, htonl(1), htonl(0)); expect_cursor_set(cursor, htonl(1), htonl(0));
for (i=1; i<n; i++) { for (i=1; i<n; i++) {
expect_cursor_get(cursor, htonl(1), htonl(i), DB_NEXT_DUP); r = expect_cursor_get(cursor, htonl(1), htonl(i), DB_NEXT_DUP); assert(r == 0);
} }
r = expect_cursor_get(cursor, htonl(1), htonl(i), DB_NEXT_DUP); assert(r == DB_NOTFOUND);
r = cursor->c_close(cursor); assert(r == 0); r = cursor->c_close(cursor); assert(r == 0);
r = db->close(db, 0); assert(r == 0); r = db->close(db, 0); assert(r == 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