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-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);
|
|
|
|
env.open(NULL, DB_PRIVATE, 0666);
|
|
|
|
Db db(&env, 0);
|
|
|
|
|
2007-12-20 19:00:35 +00:00
|
|
|
int r;
|
|
|
|
|
|
|
|
r = db.set_bt_compare(cmp); assert(r == 0);
|
|
|
|
r = db.remove("DoesNotExist.db", NULL, 0); assert(r == ENOENT);
|
|
|
|
}
|
|
|
|
|
2007-12-20 19:43:42 +00:00
|
|
|
void test_db_env(void) {
|
2007-12-21 05:57:33 +00:00
|
|
|
DbEnv dbenv(DB_CXX_NO_EXCEPTIONS);
|
2007-12-20 19:43:42 +00:00
|
|
|
int r;
|
|
|
|
|
|
|
|
r = dbenv.set_data_dir("."); assert(r == 0);
|
|
|
|
r = dbenv.set_data_dir(".."); assert(r == 0);
|
|
|
|
r = dbenv.set_data_dir(NULL); assert(r == EINVAL);
|
|
|
|
dbenv.set_errpfx("Prefix");
|
2007-12-21 05:57:33 +00:00
|
|
|
dbenv.set_errfile(stdout);
|
|
|
|
dbenv.err(0, "Hello %s!\n", "Name");
|
2007-12-20 19:43:42 +00:00
|
|
|
}
|
|
|
|
|
2007-12-20 19:00:35 +00:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
test_dbt();
|
|
|
|
test_db();
|
2007-12-20 19:43:42 +00:00
|
|
|
test_db_env();
|
2007-12-17 22:00:54 +00:00
|
|
|
cout << "Hello World!" << endl; cout << "Welcome to C++ Programming" << endl;
|
|
|
|
return 0;
|
|
|
|
}
|