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)
TARGETS = $(patsubst %.cpp,%,$(SRCS))
# OPTFLAGS = -O0
# GCOV_FLAGS = -fprofile-arcs -ftest-coverage
CPPFLAGS = -I../ -I../../include
......@@ -23,32 +24,68 @@ $(DBCXX):
clean:
rm -rf $(TARGETS) *.gcno *.gcda *.gcov *.db
check: $(TARGETS) \
check_db_create_1 check_db_create_2 check_db_create_3 check_db_create_4 check_permissions
$(VGRIND) ./test1
$(VGRIND) ./test1e
rm -f foo.db
$(VGRIND) ./db_create -s main foo.db
rm -f foo.db
$(VGRIND) ./db_create -D -S -s main foo.db
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
check_test1: test1
$(VGRIND) ./$<
check_test_errpfx: test_errpfx
$(VGRIND) ./$< > errpfxactual.out
(echo "Prefix: Hello Name!";echo -n ": Success") > errpfxexpect.out
diff errpfxactual.out errpfxexpect.out
check_test_db_assoc3: test_db_assoc3
$(VGRIND) ./test_db_assoc3
$(VGRIND) ./test_db_assoc3 --more
check_test_cursor_count: test_cursor_count
$(VGRIND) ./test_cursor_count
$(VGRIND) ./test_fd
check_test_error_stream: 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
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_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:
$(VGRIND) ./db_create; let exitcode=$$?; if [ $$exitcode -ne 0 ] ; then exit 0; else exit 1; fi
check_db_create_2:
......@@ -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
check_permissions:
rm -f test.db
./db_create test.db 1 1
chmod -w test.db
./db_create test.db 2 2; let exitcode=$$?; if [ $$exitcode -ne 0 ] ; then exit 0; else exit 1; fi
rm -f permissions.tdb
./db_create permissions.tdb 1 1
chmod -w permissions.tdb
./db_create permissions.tdb 2 2; let exitcode=$$?; if [ $$exitcode -ne 0 ] ; then exit 0; else exit 1; fi
......@@ -4,6 +4,9 @@
#include <unistd.h>
#include <stdlib.h>
#define FNAME __FILE__ ".tdb"
#define FNAME2 __FILE__ "2.tdb"
#ifndef DB_DELETE_ANY
#define DB_DELETE_ANY 0
#endif
......@@ -89,32 +92,32 @@ void test_db_exceptions (void) {
assert(dbdb!=0);
assert(dbdb==db.get_const_DB());
assert(&db==Db::get_const_Db(dbdb));
unlink("foo.db");
TC(db.open(0, "foo.db", 0, DB_BTREE, DB_CREATE, 0777), 0);
TC(db.open(0, "foo.db", 0, DB_BTREE, DB_CREATE, 0777), EINVAL); // it was already open
unlink(FNAME);
TC(db.open(0, FNAME, 0, DB_BTREE, DB_CREATE, 0777), 0);
TC(db.open(0, FNAME, 0, DB_BTREE, DB_CREATE, 0777), EINVAL); // it was already open
{
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);
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);
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);
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);
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);
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;
......@@ -149,8 +152,8 @@ void test_dbc_exceptions () {
DbEnv env(0);
TC(env.open(".", DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE , 0777), 0);
Db db(&env, 0);
unlink("foo.db");
TC(db.open(0, "foo.db", 0, DB_BTREE, DB_CREATE, 0777), 0);
unlink(FNAME);
TC(db.open(0, FNAME, 0, DB_BTREE, DB_CREATE, 0777), 0);
for (int k = 1; k<4; k++) {
Dbt key(&k, sizeof k);
Dbt val(&k, sizeof k);
......
......@@ -40,22 +40,9 @@ void test_db(void) {
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()
{
test_dbt();
test_db();
test_db_env();
return 0;
}
......@@ -6,23 +6,6 @@
#include <iostream>
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) {
return 0;
}
......@@ -65,7 +48,6 @@ void test_db_env(void) {
int main()
{
test_dbt();
test_db();
test_db_env();
return 0;
......
......@@ -7,6 +7,8 @@
int verbose;
#define FNAME __FILE__ ".tdb"
#ifndef DB_YESOVERWRITE
#define BDB 1
#define DB_YESOVERWRITE 0
......@@ -333,8 +335,8 @@ int main(int argc, char *argv[]) {
Db db(0, DB_CXX_NO_EXCEPTIONS);
r = db.set_flags(DB_DUP + DB_DUPSORT); assert(r == 0);
unlink("test.db");
r = db.open(0, "test.db", 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0);
unlink(FNAME);
r = db.open(0, FNAME, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0);
load(&db, 10);
test_cursor_count_flags(&db);
......
......@@ -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
Dbt nc_key,nc_data;
#define DIR "dir.test.db.accoc3"
#define DIR "dir.test.db.assoc3"
void create_databases (void) {
int r;
......
......@@ -7,10 +7,12 @@ void test_new_delete() {
delete db;
}
#define FNAME __FILE__ ".tdb"
void test_new_open_delete() {
unlink("test.db");
unlink(FNAME);
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);
delete db;
}
......
......@@ -6,6 +6,8 @@
int verbose;
#define FNAME __FILE__ ".tdb"
int test_error_stream(const char *dbfile) {
int r;
......@@ -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 @@
int verbose;
#define FNAME __FILE__ ".tdb"
int test_fd(const char *dbfile) {
int r;
int fd;
......@@ -38,6 +40,6 @@ int main(int argc, char *argv[]) {
verbose += 1;
}
return test_fd("test.db");
return test_fd(FNAME);
}
......@@ -4,6 +4,8 @@
#include <unistd.h>
#include <stdlib.h>
#define FNAME __FILE__ ".tdb"
#define TC(expr, expect) ({ \
try { \
expr; \
......@@ -22,8 +24,8 @@ void test_no_env () {
#else
Db db(0, 0);
#endif
unlink("foo.db");
TC(db.open(0, "foo.db", 0, DB_BTREE, DB_CREATE, 0777), 0);
unlink(FNAME);
TC(db.open(0, FNAME, 0, DB_BTREE, DB_CREATE, 0777), 0);
}
int main(int argc, char *argv[]) {
......
......@@ -14,7 +14,7 @@
#include <sys/types.h>
#include <unistd.h>
#define DIR "dir_test_reverse_compare_fun"
#define DIR __FILE__ ".dir"
int verbose;
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