Commit dfc95d64 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Make the test_error more comprehensive. Addresses #445.

git-svn-id: file:///svn/tokudb@2407 c7de825b-a66e-492c-adef-691d508d4ae1
parent c1931e7b
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <stdio.h> #include <stdio.h>
#include "test.h" #include "test.h"
const char *expect_errpfx=0; char const* expect_errpfx;
int n_handle_error=0; int n_handle_error=0;
void handle_error (const DB_ENV *dbenv, const char *errpfx, const char *msg) { void handle_error (const DB_ENV *dbenv, const char *errpfx, const char *msg) {
...@@ -35,33 +35,47 @@ int main (int argc, const char *argv[]) { ...@@ -35,33 +35,47 @@ int main (int argc, const char *argv[]) {
r = env->close(env, 0); assert(r==0); r = env->close(env, 0); assert(r==0);
} }
int do_errfile, do_errcall; int do_errfile, do_errcall,do_errpfx;
for (do_errfile=0; do_errfile<2; do_errfile++) { for (do_errpfx=0; do_errpfx<2; do_errpfx++) {
for (do_errcall=0; do_errcall<2; do_errcall++) { for (do_errfile=0; do_errfile<2; do_errfile++) {
DB_ENV *env; for (do_errcall=0; do_errcall<2; do_errcall++) {
char buf[10000]=""; DB_ENV *env;
FILE *write_here = fmemopen(buf, sizeof(buf), "w"); char buf[10000]="";
n_handle_error=0; FILE *write_here = fmemopen(buf, sizeof(buf), "w");
r = db_env_create(&env, 0); assert(r==0); n_handle_error=0;
env->set_errfile(env,0); // Turn off those annoying errors r = db_env_create(&env, 0); assert(r==0);
if (do_errfile) if (do_errpfx) {
env->set_errfile(env, write_here); expect_errpfx="whoopi";
if (do_errcall) env->set_errpfx(env, expect_errpfx);
env->set_errcall(env, handle_error); } else {
r = env->open(env, DIR, -1, 0644); expect_errpfx=0;
assert(r==EINVAL); }
r = env->close(env, 0); assert(r==0); env->set_errfile(env,0); // Turn off those annoying errors
fclose(write_here); if (do_errfile)
if (do_errfile) { env->set_errfile(env, write_here);
assert(buf[0]!=0); if (do_errcall)
assert(buf[0]!=':'); env->set_errcall(env, handle_error);
} else { r = env->open(env, DIR, -1, 0644);
assert(buf[0]==0); assert(r==EINVAL);
} r = env->close(env, 0); assert(r==0);
if (do_errcall) { fclose(write_here);
assert(n_handle_error==1); if (do_errfile) {
} else { printf("buf=%s(end of buf)\n", buf);
assert(n_handle_error==0); if (do_errpfx) {
assert(strncmp(buf,"whoopi:",6)==0);
} else {
assert(buf[0]!=0);
assert(buf[0]!=':');
}
assert(buf[strlen(buf)-1]=='\n');
} else {
assert(buf[0]==0);
}
if (do_errcall) {
assert(n_handle_error==1);
} else {
assert(n_handle_error==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