Commit 2686065f authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Fix up error handling and add tests. Fixes #246.

git-svn-id: file:///svn/tokudb@1535 c7de825b-a66e-492c-adef-691d508d4ae1
parent 121b1eb8
......@@ -120,11 +120,13 @@ NO_VGRIND = \
db_dbt_mem_behavior \
db_assoc3 \
db_curs2 \
db_delete \
db_env_open_nocreate \
db_env_open_open_close \
db_open_notexist_reopen \
db_remove_subdb \
log4 \
log5 \
# Comment to terminate list so the previous line can end with a slash
$(patsubst %,test_%.bdbrun,$(NO_VGRIND)): VGRIND=
......
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <db.h>
#ifndef DB_YESOVERWRITE
#define DB_YESOVERWRITE 0
......
// I want fmemopen
#define _GNU_SOURCE
#include "test.h"
#include <assert.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdio.h>
const char *expect_errpfx=0;
int n_handle_error=0;
void handle_error (const DB_ENV *dbenv, const char *errpfx, const char *msg) {
assert(errpfx==expect_errpfx);
n_handle_error++;
}
int main (int argc, const char *argv[]) {
parse_args(argc, argv);
system("rm -rf " DIR);
int r=mkdir(DIR, 0777); assert(r==0);
{
DB_ENV *env;
r = db_env_create(&env, 0); assert(r==0);
r = env->open(env, DIR, -1, 0644);
assert(r==EINVAL && n_handle_error==0);
r = env->close(env, 0); assert(r==0);
}
int do_errfile, do_errcall;
for (do_errfile=0; do_errfile<2; do_errfile++) {
for (do_errcall=0; do_errcall<2; do_errcall++) {
DB_ENV *env;
char buf[10000]="";
FILE *write_here = fmemopen(buf, sizeof(buf), "w");
n_handle_error=0;
r = db_env_create(&env, 0); assert(r==0);
if (do_errfile)
env->set_errfile(env, write_here);
if (do_errcall)
env->set_errcall(env, handle_error);
r = env->open(env, DIR, -1, 0644);
assert(r==EINVAL);
r = env->close(env, 0); assert(r==0);
fclose(write_here);
if (do_errfile) {
assert(buf[0]!=0);
assert(buf[0]!=':');
} else {
assert(buf[0]==0);
}
if (do_errcall) {
assert(n_handle_error==1);
} else {
assert(n_handle_error==0);
}
}
}
return 0;
}
This diff is collapsed.
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