mirror of
https://github.com/MariaDB/server.git
synced 2025-02-02 03:51:50 +01:00
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
This commit is contained in:
parent
bb06a5a944
commit
8c8162ede4
5 changed files with 40 additions and 105 deletions
|
@ -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
|
||||
|
|
|
@ -1,19 +1,29 @@
|
|||
#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);
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
#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);
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
#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;
|
||||
}
|
Loading…
Add table
Reference in a new issue