2
* See the file LICENSE for redistribution information.
4
* Copyright (c) 2000-2002
5
* Sleepycat Software. All rights reserved.
11
* A basic regression test for the Logc class.
17
static void show_dbt(ostream &os, Dbt *dbt)
20
int size = dbt->get_size();
21
unsigned char *data = (unsigned char *)dbt->get_data();
23
os << "size: " << size << " data: ";
24
for (i=0; i<size && i<10; i++) {
25
os << (int)data[i] << " ";
31
int main(int argc, char *argv[])
34
DbEnv *env = new DbEnv(0);
35
env->open(".", DB_CREATE | DB_INIT_LOG | DB_INIT_MPOOL, 0);
37
// Do some database activity to get something into the log.
38
Db *db1 = new Db(env, 0);
39
db1->open(NULL, "first.db", NULL, DB_BTREE, DB_CREATE, 0);
40
Dbt *key = new Dbt((char *)"a", 1);
41
Dbt *data = new Dbt((char *)"b", 1);
42
db1->put(NULL, key, data, 0);
43
key->set_data((char *)"c");
44
data->set_data((char *)"d");
45
db1->put(NULL, key, data, 0);
48
Db *db2 = new Db(env, 0);
49
db2->open(NULL, "second.db", NULL, DB_BTREE, DB_CREATE, 0);
50
key->set_data((char *)"w");
51
data->set_data((char *)"x");
52
db2->put(NULL, key, data, 0);
53
key->set_data((char *)"y");
54
data->set_data((char *)"z");
55
db2->put(NULL, key, data, 0);
58
// Now get a log cursor and walk through.
61
env->log_cursor(&logc, 0);
65
u_int32_t flags = DB_FIRST;
68
while ((ret = logc->get(&lsn, dbt, flags)) == 0) {
70
// We ignore the contents of the log record,
71
// it's not portable. Even the exact count
72
// is may change when the underlying implementation
73
// changes, we'll just make sure at the end we saw
76
// cout << "logc.get: " << count;
77
// show_dbt(cout, dbt);
83
if (ret != DB_NOTFOUND) {
84
cerr << "*** FAIL: logc.get returned: "
85
<< DbEnv::strerror(ret) << "\n";
89
// There has to be at *least* four log records,
90
// since we did four separate database operations.
93
cerr << "*** FAIL: not enough log records\n";
95
cout << "TestLogc done.\n";
97
catch (DbException &dbe) {
98
cerr << "*** FAIL: " << dbe.what() <<"\n";