Commit f945194b authored by Yoni Fogel's avatar Yoni Fogel

Added tests for c_put

Addresses #15

git-svn-id: file:///svn/tokudb@1181 c7de825b-a66e-492c-adef-691d508d4ae1
parent e7d13a1a
...@@ -12,9 +12,38 @@ ...@@ -12,9 +12,38 @@
// DIR is defined in the Makefile // DIR is defined in the Makefile
typedef struct { typedef struct {
int pkey; int skip_bdb;
int skey; u_int32_t db_flags;
} RECORD; u_int32_t flags;
int r_expect;
int key;
int data;
} PUT_TEST;
typedef struct {
PUT_TEST put;
u_int32_t flags;
int r_expect;
int key;
int data;
} GET_TEST;
enum testtype {NONE=0, TGET=1, TPUT=2};
typedef struct {
enum testtype kind;
u_int32_t flags;
int r_expect;
int key;
int data;
} TEST;
typedef struct {
int skip_bdb;
u_int32_t db_flags;
TEST tests[4];
} CPUT_TEST;
DB *dbp; DB *dbp;
DB_TXN *const null_txn = 0; DB_TXN *const null_txn = 0;
...@@ -49,6 +78,17 @@ void insert_bad_flags(u_int32_t flags, int r_expect, int keyint, int dataint) { ...@@ -49,6 +78,17 @@ void insert_bad_flags(u_int32_t flags, int r_expect, int keyint, int dataint) {
CKERR2(r, r_expect); CKERR2(r, r_expect);
} }
void cinsert_bad_flags(DBC* dbc, u_int32_t flags, int r_expect, int keyint, int dataint) {
DBT key;
DBT data;
int r;
dbt_init(&key, &keyint, sizeof(keyint));
dbt_init(&data,&dataint,sizeof(dataint));
r = dbc->c_put(dbc, &key, &data, flags);
CKERR2(r, r_expect);
}
void get_bad_flags(u_int32_t flags, int r_expect, int keyint, int dataint) { void get_bad_flags(u_int32_t flags, int r_expect, int keyint, int dataint) {
DBT key; DBT key;
DBT data; DBT data;
...@@ -60,29 +100,60 @@ void get_bad_flags(u_int32_t flags, int r_expect, int keyint, int dataint) { ...@@ -60,29 +100,60 @@ void get_bad_flags(u_int32_t flags, int r_expect, int keyint, int dataint) {
CKERR2(r, r_expect); CKERR2(r, r_expect);
} }
typedef struct { void cinsert_test(TEST tests[4]) {
int skip_bdb; int r;
u_int32_t db_flags; int i;
u_int32_t flags; DBC *dbc;
int r_expect;
int key; r = dbp->cursor(dbp, null_txn, &dbc, 0); CKERR(r);
int data;
} PUT_TEST; for (i = 0; i < 4; i++) {
if (tests[i].kind == NONE) break;
else if (tests[i].kind == TPUT) {
cinsert_bad_flags(dbc, tests[i].flags, tests[i].r_expect, tests[i].key, tests[i].data);
}
else if (tests[i].kind == TGET) {
get_bad_flags(tests[i].flags, tests[i].r_expect, tests[i].key, tests[i].data);
}
else assert(0);
}
r = dbc->c_close(dbc); CKERR(r);
}
#ifndef USE_TDB
#define DB_YESOVERWRITE 0 //This is just so test numbers stay the same.
#endif
typedef struct {
PUT_TEST put;
u_int32_t flags;
int r_expect;
int key;
int data;
} GET_TEST;
PUT_TEST put_tests[] = { PUT_TEST put_tests[] = {
{0, 0, DB_NODUPDATA, EINVAL, 0, 0}, {0, 0, DB_NODUPDATA, EINVAL, 0, 0}, //r_expect must change to 0, once implemented.
{1, DB_DUP|DB_DUPSORT, DB_NODUPDATA, EINVAL, 0, 0}, //r_expect must change to 0, and don't skip with BDB once implemented. {1, DB_DUP|DB_DUPSORT, DB_NODUPDATA, EINVAL, 0, 0}, //r_expect must change to 0, and don't skip with BDB once implemented.
{1, 0, DB_YESOVERWRITE, 0, 0, 0},
{1, DB_DUP|DB_DUPSORT, DB_YESOVERWRITE, 0, 0, 0},
{0, 0, DB_NOOVERWRITE, 0, 0, 0},
{0, DB_DUP|DB_DUPSORT, DB_NOOVERWRITE, 0, 0, 0},
{0, 0, 0, 0, 0, 0}, //r_expect must change to EINVAL when/if we no longer accept 0 as flags for put
{0, DB_DUP|DB_DUPSORT, 0, 0, 0, 0}, //r_expect must change to EINVAL when/if we no longer accept 0 as flags for put
}; };
const int num_put = sizeof(put_tests) / sizeof(put_tests[0]); const int num_put = sizeof(put_tests) / sizeof(put_tests[0]);
CPUT_TEST cput_tests[] = {
{0, 0, {{TPUT, 0, EINVAL, 0, 1}, {TGET, DB_GET_BOTH, DB_NOTFOUND, 0, 1}, {NONE, }, }},
{0, DB_DUP|DB_DUPSORT, {{TPUT, 0, EINVAL, 0, 1}, {TGET, DB_GET_BOTH, DB_NOTFOUND, 0, 1}, {NONE, }, }},
{0, 0, {{TPUT, DB_KEYFIRST, 0, 0, 1}, {TGET, DB_GET_BOTH, 0, 0, 1}, {TPUT, DB_CURRENT, 0, 0, 2}, {TGET, DB_GET_BOTH, DB_NOTFOUND, 0, 1}}},
{0, DB_DUP|DB_DUPSORT, {{TPUT, DB_KEYFIRST, 0, 0, 1}, {TGET, DB_GET_BOTH, 0, 0, 1}, {TPUT, DB_CURRENT, EINVAL, 0, 2}, {TGET, DB_GET_BOTH, 0, 0, 1}}},
{0, 0, {{TPUT, DB_KEYLAST, 0, 0, 1}, {TGET, DB_GET_BOTH, 0, 0, 1}, {TPUT, DB_CURRENT, 0, 0, 2}, {TGET, DB_GET_BOTH, DB_NOTFOUND, 0, 1}}},
{0, DB_DUP|DB_DUPSORT, {{TPUT, DB_KEYLAST, 0, 0, 1}, {TGET, DB_GET_BOTH, 0, 0, 1}, {TPUT, DB_CURRENT, EINVAL, 0, 2}, {TGET, DB_GET_BOTH, 0, 0, 1}}},
{0, 0, {{TPUT, DB_CURRENT, EINVAL, 0, 1}, {TGET, DB_GET_BOTH, DB_NOTFOUND, 0, 1}, {NONE, }, }},
{0, DB_DUP|DB_DUPSORT, {{TPUT, DB_CURRENT, EINVAL, 0, 1}, {TGET, DB_GET_BOTH, DB_NOTFOUND, 0, 1}, {NONE, }, }},
{0, 0, {{TPUT, DB_NODUPDATA, EINVAL, 0, 1}, {TGET, DB_GET_BOTH, DB_NOTFOUND, 0, 1}, {NONE, }, }},
{0, DB_DUP|DB_DUPSORT, {{TPUT, DB_NODUPDATA, 0, 0, 1}, {TGET, DB_GET_BOTH, 0, 0, 1}, {TPUT, DB_NODUPDATA, 0, 0, 2}, {TGET, DB_GET_BOTH, 0, 0, 1}, }},
{0, DB_DUP|DB_DUPSORT, {{TPUT, DB_NODUPDATA, 0, 0, 1}, {TGET, DB_GET_BOTH, 0, 0, 1}, {TPUT, DB_NODUPDATA, 0, 0, 2}, {TGET, DB_GET_BOTH, 0, 0, 2}, }},
{0, DB_DUP|DB_DUPSORT, {{TPUT, DB_NODUPDATA, 0, 0, 1}, {TGET, DB_GET_BOTH, 0, 0, 1}, {TPUT, DB_NODUPDATA, DB_KEYEXIST, 0, 1}, {TGET, DB_GET_BOTH, 0, 0, 1}, }},
};
const int num_cput = sizeof(cput_tests) / sizeof(cput_tests[0]);
GET_TEST get_tests[] = { GET_TEST get_tests[] = {
{{0, 0, 0, 0, 0, 0}, DB_GET_BOTH, 0, 0, 0}, {{0, 0, 0, 0, 0, 0}, DB_GET_BOTH, 0, 0, 0},
{{0, 0, 0, 0, 0, 0}, DB_GET_BOTH, 0, 0, 0}, {{0, 0, 0, 0, 0, 0}, DB_GET_BOTH, 0, 0, 0},
...@@ -123,5 +194,18 @@ int main(int argc, const char *argv[]) { ...@@ -123,5 +194,18 @@ int main(int argc, const char *argv[]) {
close_dbs(); close_dbs();
} }
} }
for (i = 0; i < num_cput; i++) {
if (verbose) printf("cputTest [%d]\n", i);
#ifndef USE_TDB
if (!cput_tests[i].skip_bdb)
#endif
{
setup(cput_tests[i].db_flags);
cinsert_test(cput_tests[i].tests);
close_dbs();
}
}
return 0; 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