mariadb/cxx/tests/test_error_stream.cpp
Bradley C. Kuszmaul 8c8162ede4 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
2013-04-16 23:58:57 -04:00

54 lines
1.3 KiB
C++

#include <iostream>
#include <fcntl.h>
#include <assert.h>
#include <errno.h>
#include <db_cxx.h>
#include <memory.h>
int verbose;
#define DIR __FILE__ ".dir"
#define FNAME "test.tdb"
int test_error_stream(void) {
int 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(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(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);
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();
}