2
* See the file LICENSE for redistribution information.
4
* Copyright (c) 2000-2002
5
* Sleepycat Software. All rights reserved.
11
* Do some regression tests for constructors.
12
* Run normally (without arguments) it is a simple regression test.
13
* Run with a numeric argument, it repeats the regression a number
14
* of times, to try to determine if there are memory leaks.
20
int main(int argc, char *argv[])
23
Db *db = new Db(NULL, 0);
24
db->open(NULL, "my.db", NULL, DB_BTREE, DB_CREATE, 0644);
26
// populate our massive database.
27
// all our strings include null for convenience.
28
// Note we have to cast for idiomatic
29
// usage, since newer gcc requires it.
30
Dbt *keydbt = new Dbt((char *)"key", 4);
31
Dbt *datadbt = new Dbt((char *)"data", 5);
32
db->put(NULL, keydbt, datadbt, 0);
34
// Now, retrieve. We could use keydbt over again,
35
// but that wouldn't be typical in an application.
36
Dbt *goodkeydbt = new Dbt((char *)"key", 4);
37
Dbt *badkeydbt = new Dbt((char *)"badkey", 7);
38
Dbt *resultdbt = new Dbt();
39
resultdbt->set_flags(DB_DBT_MALLOC);
43
if ((ret = db->get(NULL, goodkeydbt, resultdbt, 0)) != 0) {
44
cout << "get: " << DbEnv::strerror(ret) << "\n";
47
char *result = (char *)resultdbt->get_data();
48
cout << "got data: " << result << "\n";
51
if ((ret = db->get(NULL, badkeydbt, resultdbt, 0)) != 0) {
53
cout << "get using bad key: "
54
<< DbEnv::strerror(ret) << "\n";
57
char *result = (char *)resultdbt->get_data();
58
cout << "*** got data using bad key!!: "
61
cout << "finished test\n";
63
catch (DbException &dbe) {
64
cerr << "Db Exception: " << dbe.what();