2013-04-17 00:00:36 -04:00
|
|
|
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
// vim: expandtab:ts=8:sw=4:softtabstop=4:
|
2007-12-21 11:07:29 +00:00
|
|
|
#include <db_cxx.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
2013-04-16 23:57:38 -04:00
|
|
|
#include <stdlib.h>
|
2013-04-16 23:59:21 -04:00
|
|
|
#include <sys/stat.h>
|
2007-12-21 11:07:29 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int cmp(DB *db, const DBT *dbt1, const DBT *dbt2) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-16 23:59:21 -04:00
|
|
|
#define DIR "test1e.dir"
|
|
|
|
|
2007-12-21 11:07:29 +00:00
|
|
|
void test_db(void) {
|
2013-04-16 23:59:21 -04:00
|
|
|
system("rm -rf " DIR);
|
|
|
|
mkdir(DIR, 0777);
|
2007-12-21 11:07:29 +00:00
|
|
|
DbEnv env(0);
|
2013-04-16 23:59:24 -04:00
|
|
|
{ int r = env.set_redzone(0); assert(r==0); }
|
|
|
|
{ int r = env.set_default_bt_compare(cmp); assert(r == 0); }
|
2013-04-16 23:59:21 -04:00
|
|
|
env.open(DIR, DB_CREATE|DB_PRIVATE, 0666);
|
2007-12-21 11:07:29 +00:00
|
|
|
Db db(&env, 0);
|
|
|
|
|
|
|
|
try {
|
2013-04-16 23:59:59 -04:00
|
|
|
db.remove("DoesNotExist.db", NULL, 0);
|
2007-12-21 11:07:29 +00:00
|
|
|
abort(); // must not make it here.
|
|
|
|
} catch (DbException e) {
|
|
|
|
assert(e.get_errno() == ENOENT);
|
|
|
|
}
|
|
|
|
// The db is closed.
|
|
|
|
env.close(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_db_env(void) {
|
|
|
|
DbEnv dbenv(0);
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = dbenv.set_data_dir("."); assert(r == 0);
|
|
|
|
try {
|
|
|
|
r = dbenv.set_data_dir(NULL);
|
|
|
|
abort();
|
|
|
|
} catch (DbException e) {
|
|
|
|
assert(e.get_errno() == EINVAL);
|
|
|
|
}
|
|
|
|
dbenv.set_errpfx("Prefix");
|
|
|
|
dbenv.set_errfile(stdout);
|
|
|
|
dbenv.err(0, "Hello %s!\n", "Name");
|
|
|
|
dbenv.close(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
test_db();
|
|
|
|
test_db_env();
|
|
|
|
return 0;
|
|
|
|
}
|