Commit 18defacb authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul Committed by Yoni Fogel

things don't really work without an environment. Refs #2285, [t:2285]

git-svn-id: file:///svn/toku/tokudb@16842 c7de825b-a66e-492c-adef-691d508d4ae1
parent 6088dfa4
......@@ -121,15 +121,17 @@ check: $(TARGETS) \
check_db_create_1 check_db_create_2 check_db_create_3 check_db_create_4 \
check_permissions \
check_exceptions \
check_a_bunch
check_test_db_delete \
check_a_get_not_found \
# line intentionally left blank
check_a_bunch:
$(VGRIND) ./test_no_env $(SUMMARIZE_CMD)
$(VGRIND) ./test_fd $(SUMMARIZE_CMD)
$(VGRIND) ./test_db_delete $(SUMMARIZE_CMD)
check_test_get_not_found: test_get_not_found
$(VGRIND) ./test_get_not_found $(SUMMARIZE_CMD)
check_exceptions:
check_test_db_delete: test_db_delete
$(VGRIND) ./test_db_delete $(SUMMARIZE_CMD)
check_exceptions: exceptions
$(VGRIND) ./exceptions $(SUMMARIZE_CMD)
check_db_create: db_create
......
#include <stdio.h>
#include <assert.h>
#include <db_cxx.h>
#include <stdlib.h>
#include <memory.h>
#define DIR __FILE__ ".dir"
#define FNAME "test.tdb"
void test_new_delete() {
Db *db = new Db(0, 0); assert(db != 0);
delete db;
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
{ int r = env.open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0); }
Db *db = new Db(&env, 0); assert(db != 0);
delete db;
}
#define FNAME __FILE__ ".tdb"
void test_new_open_delete() {
unlink(FNAME);
Db *db = new Db(0, 0); assert(db != 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;
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(0);
{ int r = env.open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0); }
Db *db = new Db(&env, 0); assert(db != 0);
{ int r = db->open(NULL, FNAME, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0); }
{ int r = db->close(0); assert(r == 0); }
delete db;
}
int main() {
test_new_delete();
test_new_open_delete();
return 0;
test_new_delete();
test_new_open_delete();
return 0;
}
......@@ -3,28 +3,30 @@
#include <assert.h>
#include <errno.h>
#include <db_cxx.h>
#include <memory.h>
int verbose;
#define FNAME __FILE__ ".tdb"
#define DIR __FILE__ ".dir"
#define FNAME "test.tdb"
int test_error_stream(const char *dbfile) {
int test_error_stream(void) {
int r;
r = unlink(dbfile);
r = creat(dbfile, 0777); assert(r >= 0); close(r);
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
DbEnv env(DB_CXX_NO_EXCEPTIONS);
env.set_errpfx("my_env_error_stream");
env.set_error_stream(&std::cerr);
r = env.open(".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
r = env.open(".", DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == EINVAL);
r = env.open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
r = env.open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == EINVAL);
Db db(&env, 0);
db.set_errpfx("my_db_error_stream");
db.set_error_stream(&std::cerr);
r = db.open(0, dbfile, 0, DB_BTREE, DB_CREATE, 0777); assert(r != 0);
r = db.open(NULL, FNAME, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0);
r = db.close(0); assert(r == 0);
r = db.close(0); assert(r == EINVAL);
r = env.close(0); assert(r == 0);
......@@ -48,5 +50,5 @@ int main(int argc, char *argv[]) {
}
}
return test_error_stream(FNAME);
return test_error_stream();
}
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <assert.h>
#include <db_cxx.h>
int verbose;
#define FNAME __FILE__ ".tdb"
int test_fd(const char *dbfile) {
int r;
int fd;
Db db(0, DB_CXX_NO_EXCEPTIONS);
r = db.fd(&fd); assert(r == EINVAL);
unlink(dbfile);
if (verbose) { printf("opening %s\n", dbfile); fflush(stdout); }
r = db.open(0, dbfile, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0);
r = db.fd(&fd); assert(r == 0); assert(fd >= 0);
if (verbose) { printf("fd=%d\n", fd); fflush(stdout); }
if (verbose) { printf("closing\n"); fflush(stdout); }
r = db.close(0); assert(r == 0);
if (verbose) { printf("closed\n"); fflush(stdout); }
return 0;
}
int usage() {
printf("test_fd [-v] [--verbose]\n");
return 1;
}
int main(int argc, char *argv[]) {
for (int i=1; i<argc; i++) {
char *arg = argv[i];
if (0 == strcmp(arg, "-h") || 0 == strcmp(arg, "--help"))
return usage();
if (0 == strcmp(arg, "-v") || 0 == strcmp(arg, "--verbose"))
verbose += 1;
}
return test_fd(FNAME);
}
#include <assert.h>
#include <db_cxx.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#define FNAME __FILE__ ".tdb"
#define TC(expr, expect) \
try { \
expr; \
assert(expect==0); \
} catch (DbException e) { \
if (e.get_errno()!=expect) fprintf(stderr, "err=%d %s\n", e.get_errno(), db_strerror(e.get_errno())); \
assert(e.get_errno()==expect); \
}
void test_no_env () {
#if 0
DbEnv env(0);
TC(env.open(".", DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE , 0777), 0);
Db db(&env, 0);
#else
Db db(0, 0);
#endif
unlink(FNAME);
TC(db.open(0, FNAME, 0, DB_BTREE, DB_CREATE, 0777), 0);
}
int main(int argc, char *argv[]) {
test_no_env();
system("rm -f *.tokulog");
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