Commit 315a9bf4 authored by Rich Prohaska's avatar Rich Prohaska

test DbEnv::set_error_stream. addresses #255

git-svn-id: file:///svn/tokudb@1612 c7de825b-a66e-492c-adef-691d508d4ae1
parent 7157eee2
#include <stdarg.h>
#include <assert.h>
#include <errno.h>
#include <db_cxx.h>
#include <stdarg.h>
DbEnv::DbEnv (u_int32_t flags)
: do_no_exceptions((flags&DB_CXX_NO_EXCEPTIONS)!=0),
......@@ -34,7 +35,9 @@ DbEnv::~DbEnv(void)
}
int DbEnv::close(u_int32_t flags) {
int ret = the_env->close(the_env, flags);
int ret = EINVAL;
if (the_env)
ret = the_env->close(the_env, flags);
the_env = 0; /* get rid of the env ref, so we don't touch it (even if we failed, or when the destructor is called) */
return maybe_throw_error(ret);
}
......@@ -128,8 +131,10 @@ void DbEnv::set_errcall(void (*db_errcall_fcn)(const DbEnv *, const char *, cons
extern "C" void toku_db_env_error_stream_c(const DB_ENV *dbenv_c, const char *errpfx, const char *msg) {
DbEnv *dbenv = (DbEnv *) dbenv_c->api1_internal;
if (dbenv->_error_stream)
*dbenv->_error_stream << errpfx << ":" << msg << "\n";
if (dbenv->_error_stream) {
if (errpfx) *(dbenv->_error_stream) << errpfx;
if (msg) *(dbenv->_error_stream) << ":" << msg << "\n";
}
}
void DbEnv::set_error_stream(std::ostream *new_error_stream) {
......
#include <iostream>
#include <fcntl.h>
#include <assert.h>
#include <errno.h>
#include <db_cxx.h>
int verbose;
int test_error_stream(const char *dbfile) {
int r;
r = unlink(dbfile);
r = creat(dbfile, 0777); assert(r >= 0); close(r);
DbEnv env(DB_CXX_NO_EXCEPTIONS);
env.set_errpfx("my_test_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);
Db db(&env, 0);
r = db.open(0, dbfile, 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);
r = env.close(0); assert(r == EINVAL);
return 0;
}
int usage() {
printf("test_error_stream [-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; continue;
}
}
return test_error_stream("test.db");
}
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