Commit 875d146a authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Fix #809.

git-svn-id: file:///svn/tokudb@3901 c7de825b-a66e-492c-adef-691d508d4ae1
parent 564e3c09
SRCS = $(wildcard *.cpp) SRCS = $(wildcard *.cpp)
TARGETS = $(patsubst %.cpp,%,$(SRCS)) TARGETS = $(patsubst %.cpp,%,$(SRCS))
# OPTFLAGS = -O0 # OPTFLAGS = -O0
# GCOV_FLAGS = -fprofile-arcs -ftest-coverage # GCOV_FLAGS = -fprofile-arcs -ftest-coverage
CPPFLAGS = -I../ -I../../include CPPFLAGS = -I../ -I../../include
...@@ -23,32 +24,68 @@ $(DBCXX): ...@@ -23,32 +24,68 @@ $(DBCXX):
clean: clean:
rm -rf $(TARGETS) *.gcno *.gcda *.gcov *.db rm -rf $(TARGETS) *.gcno *.gcda *.gcov *.db
check: $(TARGETS) \ check_test1: test1
check_db_create_1 check_db_create_2 check_db_create_3 check_db_create_4 check_permissions $(VGRIND) ./$<
$(VGRIND) ./test1 check_test_errpfx: test_errpfx
$(VGRIND) ./test1e $(VGRIND) ./$< > errpfxactual.out
rm -f foo.db (echo "Prefix: Hello Name!";echo -n ": Success") > errpfxexpect.out
$(VGRIND) ./db_create -s main foo.db diff errpfxactual.out errpfxexpect.out
rm -f foo.db
$(VGRIND) ./db_create -D -S -s main foo.db check_test_db_assoc3: test_db_assoc3
rm -f foo.db
$(VGRIND) ./db_create foo.db a b c d
$(VGRIND) ./db_dump foo.db > foo.out
(echo " 61";echo " 62";echo " 63";echo " 64")>foo.expectout
diff foo.out foo.expectout
$(VGRIND) ./db_dump_e foo.db > foo.out
diff foo.out foo.expectout
$(VGRIND) ./exceptions
$(VGRIND) ./test_no_env
$(VGRIND) ./test_db_assoc3 $(VGRIND) ./test_db_assoc3
$(VGRIND) ./test_db_assoc3 --more $(VGRIND) ./test_db_assoc3 --more
check_test_cursor_count: test_cursor_count
$(VGRIND) ./test_cursor_count $(VGRIND) ./test_cursor_count
$(VGRIND) ./test_fd
check_test_error_stream: test_error_stream
$(VGRIND) ./test_error_stream $(VGRIND) ./test_error_stream
check_test1e: test1e
$(VGRIND) ./test1e > test1eactual.out
(echo "Prefix: Hello Name!";echo -n ": Success") > test1expect.out
diff test1eactual.out test1expect.out
check_create_dump_diff: db_create db_dump db_dump_e
rm -f cdd.tdb
$(VGRIND) ./db_create cdd.tdb a b c d
$(VGRIND) ./db_dump cdd.tdb > cdd.out
(echo " 61";echo " 62";echo " 63";echo " 64")>cddexpect.out
diff cdd.out cddexpect.out
$(VGRIND) ./db_dump_e cdd.tdb > cdd.out
diff cdd.out cddexpect.out
check_test_reverse_compare_fun: test_reverse_compare_fun
$(VGRIND) ./test_reverse_compare_fun $(VGRIND) ./test_reverse_compare_fun
check: $(TARGETS) \
check_create_dump_diff \
check_test1 \
check_test_errpfx \
check_test_db_assoc3 \
check_test_cursor_count \
check_test_error_stream \
check_test_reverse_compare_fun \
check_test1e \
check_db_create \
check_db_create_DSM \
check_db_create_1 check_db_create_2 check_db_create_3 check_db_create_4 \
check_permissions \
check_a_bunch
check_a_bunch:
$(VGRIND) ./exceptions
$(VGRIND) ./test_no_env
$(VGRIND) ./test_fd
$(VGRIND) ./test_db_delete $(VGRIND) ./test_db_delete
$(VGRIND) ./test_get_not_found $(VGRIND) ./test_get_not_found
check_db_create: db_create
rm -f $@.tdb; $(VGRIND) ./db_create -s main $@.tdb
check_db_create_DSM: db_create
rm -f $@.tdb
$(VGRIND) ./db_create -D -S -s main $@.tdb
check_db_create_1: check_db_create_1:
$(VGRIND) ./db_create; let exitcode=$$?; if [ $$exitcode -ne 0 ] ; then exit 0; else exit 1; fi $(VGRIND) ./db_create; let exitcode=$$?; if [ $$exitcode -ne 0 ] ; then exit 0; else exit 1; fi
check_db_create_2: check_db_create_2:
...@@ -59,7 +96,7 @@ check_db_create_4: ...@@ -59,7 +96,7 @@ check_db_create_4:
$(VGRIND) ./db_create -s; let exitcode=$$?; if [ $$exitcode -ne 0 ] ; then exit 0; else exit 1; fi $(VGRIND) ./db_create -s; let exitcode=$$?; if [ $$exitcode -ne 0 ] ; then exit 0; else exit 1; fi
check_permissions: check_permissions:
rm -f test.db rm -f permissions.tdb
./db_create test.db 1 1 ./db_create permissions.tdb 1 1
chmod -w test.db chmod -w permissions.tdb
./db_create test.db 2 2; let exitcode=$$?; if [ $$exitcode -ne 0 ] ; then exit 0; else exit 1; fi ./db_create permissions.tdb 2 2; let exitcode=$$?; if [ $$exitcode -ne 0 ] ; then exit 0; else exit 1; fi
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#define FNAME __FILE__ ".tdb"
#define FNAME2 __FILE__ "2.tdb"
#ifndef DB_DELETE_ANY #ifndef DB_DELETE_ANY
#define DB_DELETE_ANY 0 #define DB_DELETE_ANY 0
#endif #endif
...@@ -89,32 +92,32 @@ void test_db_exceptions (void) { ...@@ -89,32 +92,32 @@ void test_db_exceptions (void) {
assert(dbdb!=0); assert(dbdb!=0);
assert(dbdb==db.get_const_DB()); assert(dbdb==db.get_const_DB());
assert(&db==Db::get_const_Db(dbdb)); assert(&db==Db::get_const_Db(dbdb));
unlink("foo.db"); unlink(FNAME);
TC(db.open(0, "foo.db", 0, DB_BTREE, DB_CREATE, 0777), 0); TC(db.open(0, FNAME, 0, DB_BTREE, DB_CREATE, 0777), 0);
TC(db.open(0, "foo.db", 0, DB_BTREE, DB_CREATE, 0777), EINVAL); // it was already open TC(db.open(0, FNAME, 0, DB_BTREE, DB_CREATE, 0777), EINVAL); // it was already open
{ {
Db db2(&env, 0); Db db2(&env, 0);
TC(db2.open(0, "foo2.db", 0, DB_BTREE, 0, 0777), ENOENT); // it doesn't exist TC(db2.open(0, FNAME2, 0, DB_BTREE, 0, 0777), ENOENT); // it doesn't exist
} }
{ {
Db db2(&env, 0); Db db2(&env, 0);
TC(db2.open(0, "foo.db", 0, DB_BTREE, 0, 0777), 0); // it does exist TC(db2.open(0, FNAME, 0, DB_BTREE, 0, 0777), 0); // it does exist
} }
{ {
Db db2(&env, 0); Db db2(&env, 0);
TC(db2.open(0, "foo.db", 0, DB_BTREE, -1, 0777), EINVAL); // bad flags TC(db2.open(0, FNAME, 0, DB_BTREE, -1, 0777), EINVAL); // bad flags
} }
{ {
Db db2(&env, 0); Db db2(&env, 0);
TC(db2.open(0, "foo.db", 0, (DBTYPE)-1, 0, 0777), EINVAL); // bad type TC(db2.open(0, FNAME, 0, (DBTYPE)-1, 0, 0777), EINVAL); // bad type
} }
{ {
Db db2(&env, 0); Db db2(&env, 0);
TC(db2.open(0, "foo.db", "sub.db", DB_BTREE, DB_CREATE, 0777), EINVAL); // sub DB cannot exist TC(db2.open(0, FNAME, "sub.db", DB_BTREE, DB_CREATE, 0777), EINVAL); // sub DB cannot exist
} }
{ {
Db db2(&env, 0); Db db2(&env, 0);
TC(db2.open(0, "foo.db", "sub.db", DB_BTREE, 0, 0777), EINVAL); // sub DB cannot exist withou DB_CREATE TC(db2.open(0, FNAME, "sub.db", DB_BTREE, 0, 0777), EINVAL); // sub DB cannot exist withou DB_CREATE
} }
{ {
Dbc *curs; Dbc *curs;
...@@ -149,8 +152,8 @@ void test_dbc_exceptions () { ...@@ -149,8 +152,8 @@ void test_dbc_exceptions () {
DbEnv env(0); DbEnv env(0);
TC(env.open(".", DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE , 0777), 0); TC(env.open(".", DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE , 0777), 0);
Db db(&env, 0); Db db(&env, 0);
unlink("foo.db"); unlink(FNAME);
TC(db.open(0, "foo.db", 0, DB_BTREE, DB_CREATE, 0777), 0); TC(db.open(0, FNAME, 0, DB_BTREE, DB_CREATE, 0777), 0);
for (int k = 1; k<4; k++) { for (int k = 1; k<4; k++) {
Dbt key(&k, sizeof k); Dbt key(&k, sizeof k);
Dbt val(&k, sizeof k); Dbt val(&k, sizeof k);
......
...@@ -40,22 +40,9 @@ void test_db(void) { ...@@ -40,22 +40,9 @@ void test_db(void) {
r = env.close(0); assert(r== 0); r = env.close(0); assert(r== 0);
} }
void test_db_env(void) {
DbEnv dbenv(DB_CXX_NO_EXCEPTIONS);
int r;
r = dbenv.set_data_dir("."); assert(r == 0);
r = dbenv.set_data_dir(".."); assert(r == 0);
r = dbenv.set_data_dir(NULL); assert(r == EINVAL);
dbenv.set_errpfx("Prefix");
dbenv.set_errfile(stdout);
dbenv.err(0, "Hello %s!\n", "Name");
}
int main() int main()
{ {
test_dbt(); test_dbt();
test_db(); test_db();
test_db_env();
return 0; return 0;
} }
...@@ -6,23 +6,6 @@ ...@@ -6,23 +6,6 @@
#include <iostream> #include <iostream>
using namespace std; using namespace std;
void test_dbt(void) {
u_int32_t size = 3;
u_int32_t flags = 5;
u_int32_t ulen = 7;
void* data = &size;
Dbt dbt;
dbt.set_size(size);
dbt.set_flags(flags);
dbt.set_data(data);
dbt.set_ulen(ulen);
assert(dbt.get_size() == size);
assert(dbt.get_flags() == flags);
assert(dbt.get_data() == data);
assert(dbt.get_ulen() == ulen);
}
int cmp(DB *db, const DBT *dbt1, const DBT *dbt2) { int cmp(DB *db, const DBT *dbt1, const DBT *dbt2) {
return 0; return 0;
} }
...@@ -65,7 +48,6 @@ void test_db_env(void) { ...@@ -65,7 +48,6 @@ void test_db_env(void) {
int main() int main()
{ {
test_dbt();
test_db(); test_db();
test_db_env(); test_db_env();
return 0; return 0;
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
int verbose; int verbose;
#define FNAME __FILE__ ".tdb"
#ifndef DB_YESOVERWRITE #ifndef DB_YESOVERWRITE
#define BDB 1 #define BDB 1
#define DB_YESOVERWRITE 0 #define DB_YESOVERWRITE 0
...@@ -333,8 +335,8 @@ int main(int argc, char *argv[]) { ...@@ -333,8 +335,8 @@ int main(int argc, char *argv[]) {
Db db(0, DB_CXX_NO_EXCEPTIONS); Db db(0, DB_CXX_NO_EXCEPTIONS);
r = db.set_flags(DB_DUP + DB_DUPSORT); assert(r == 0); r = db.set_flags(DB_DUP + DB_DUPSORT); assert(r == 0);
unlink("test.db"); unlink(FNAME);
r = db.open(0, "test.db", 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0); r = db.open(0, FNAME, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0);
load(&db, 10); load(&db, 10);
test_cursor_count_flags(&db); test_cursor_count_flags(&db);
......
...@@ -197,7 +197,7 @@ int calc_n_items=0; // The number of items we expect the cursor to acount ...@@ -197,7 +197,7 @@ int calc_n_items=0; // The number of items we expect the cursor to acount
int count_all_items=0; // The total number of items int count_all_items=0; // The total number of items
Dbt nc_key,nc_data; Dbt nc_key,nc_data;
#define DIR "dir.test.db.accoc3" #define DIR "dir.test.db.assoc3"
void create_databases (void) { void create_databases (void) {
int r; int r;
......
...@@ -7,10 +7,12 @@ void test_new_delete() { ...@@ -7,10 +7,12 @@ void test_new_delete() {
delete db; delete db;
} }
#define FNAME __FILE__ ".tdb"
void test_new_open_delete() { void test_new_open_delete() {
unlink("test.db"); unlink(FNAME);
Db *db = new Db(0, 0); assert(db != 0); Db *db = new Db(0, 0); assert(db != 0);
int r = db->open(0, "test.db", 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0); int r = db->open(0, FNAME, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0);
r = db->close(0); assert(r == 0); r = db->close(0); assert(r == 0);
delete db; delete db;
} }
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
int verbose; int verbose;
#define FNAME __FILE__ ".tdb"
int test_error_stream(const char *dbfile) { int test_error_stream(const char *dbfile) {
int r; int r;
...@@ -46,5 +48,5 @@ int main(int argc, char *argv[]) { ...@@ -46,5 +48,5 @@ int main(int argc, char *argv[]) {
} }
} }
return test_error_stream("test.db"); return test_error_stream(FNAME);
} }
#include <db_cxx.h>
#include <errno.h>
#include <assert.h>
#include <iostream>
using namespace std;
void test_db_env(void) {
DbEnv dbenv(DB_CXX_NO_EXCEPTIONS);
int r;
r = dbenv.set_data_dir("."); assert(r == 0);
r = dbenv.set_data_dir(".."); assert(r == 0);
r = dbenv.set_data_dir(NULL); assert(r == EINVAL);
dbenv.set_errpfx("Prefix");
dbenv.set_errfile(stdout);
dbenv.err(0, "Hello %s!\n", "Name");
}
int main()
{
test_db_env();
return 0;
}
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
int verbose; int verbose;
#define FNAME __FILE__ ".tdb"
int test_fd(const char *dbfile) { int test_fd(const char *dbfile) {
int r; int r;
int fd; int fd;
...@@ -38,6 +40,6 @@ int main(int argc, char *argv[]) { ...@@ -38,6 +40,6 @@ int main(int argc, char *argv[]) {
verbose += 1; verbose += 1;
} }
return test_fd("test.db"); return test_fd(FNAME);
} }
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#define FNAME __FILE__ ".tdb"
#define TC(expr, expect) ({ \ #define TC(expr, expect) ({ \
try { \ try { \
expr; \ expr; \
...@@ -22,8 +24,8 @@ void test_no_env () { ...@@ -22,8 +24,8 @@ void test_no_env () {
#else #else
Db db(0, 0); Db db(0, 0);
#endif #endif
unlink("foo.db"); unlink(FNAME);
TC(db.open(0, "foo.db", 0, DB_BTREE, DB_CREATE, 0777), 0); TC(db.open(0, FNAME, 0, DB_BTREE, DB_CREATE, 0777), 0);
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#define DIR "dir_test_reverse_compare_fun" #define DIR __FILE__ ".dir"
int verbose; int verbose;
int keycompare (const void *key1, unsigned int key1len, const void *key2, unsigned int key2len) { int keycompare (const void *key1, unsigned int key1len, const void *key2, unsigned int key2len) {
......
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