2007-12-17 22:00:54 +00:00
|
|
|
#include <db_cxx.h>
|
2007-12-20 19:00:35 +00:00
|
|
|
#include <errno.h>
|
2007-12-21 11:07:29 +00:00
|
|
|
#include <assert.h>
|
2013-04-16 23:59:21 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/stat.h>
|
2007-12-17 22:00:54 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
2007-12-20 19:00:35 +00:00
|
|
|
|
|
|
|
void test_dbt(void) {
|
2007-12-20 18:34:33 +00:00
|
|
|
u_int32_t size = 3;
|
|
|
|
u_int32_t flags = 5;
|
|
|
|
u_int32_t ulen = 7;
|
|
|
|
void* data = &size;
|
2007-12-17 22:00:54 +00:00
|
|
|
Dbt dbt;
|
2007-12-20 18:34:33 +00:00
|
|
|
|
|
|
|
dbt.set_size(size);
|
|
|
|
dbt.set_flags(flags);
|
|
|
|
dbt.set_data(data);
|
|
|
|
dbt.set_ulen(ulen);
|
|
|
|
assert(dbt.get_size() == size);
|
|
|
|
assert(dbt.get_flags() == flags);
|
|
|
|
assert(dbt.get_data() == data);
|
|
|
|
assert(dbt.get_ulen() == ulen);
|
2007-12-20 19:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int cmp(DB *db, const DBT *dbt1, const DBT *dbt2) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_db(void) {
|
2007-12-21 05:57:33 +00:00
|
|
|
DbEnv env(DB_CXX_NO_EXCEPTIONS);
|
2013-04-16 23:59:21 -04:00
|
|
|
{ int r = env.set_redzone(0); assert(r==0); }
|
|
|
|
int r = env.open("test1.dir", DB_CREATE|DB_PRIVATE, 0666);
|
2013-04-16 23:57:53 -04:00
|
|
|
assert(r==0);
|
2007-12-21 05:57:33 +00:00
|
|
|
Db db(&env, 0);
|
|
|
|
|
2007-12-20 19:00:35 +00:00
|
|
|
r = db.set_bt_compare(cmp); assert(r == 0);
|
|
|
|
r = db.remove("DoesNotExist.db", NULL, 0); assert(r == ENOENT);
|
2007-12-21 19:59:31 +00:00
|
|
|
// The db is closed
|
|
|
|
r = env.close(0); assert(r== 0);
|
2007-12-20 19:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2013-04-16 23:59:21 -04:00
|
|
|
system("rm -rf test1.dir");
|
|
|
|
mkdir("test1.dir", 0777);
|
2007-12-20 19:00:35 +00:00
|
|
|
test_dbt();
|
|
|
|
test_db();
|
2007-12-17 22:00:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|