~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/test/scr015/TestLogc.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*-
2
 
 * See the file LICENSE for redistribution information.
3
 
 *
4
 
 * Copyright (c) 2000-2002
5
 
 *      Sleepycat Software.  All rights reserved.
6
 
 *
7
 
 * $Id$
8
 
 */
9
 
 
10
 
/*
11
 
 * A basic regression test for the Logc class.
12
 
 */
13
 
 
14
 
#include <db_cxx.h>
15
 
#include <iostream.h>
16
 
 
17
 
static void show_dbt(ostream &os, Dbt *dbt)
18
 
{
19
 
        int i;
20
 
        int size = dbt->get_size();
21
 
        unsigned char *data = (unsigned char *)dbt->get_data();
22
 
 
23
 
        os << "size: " << size << " data: ";
24
 
        for (i=0; i<size && i<10; i++) {
25
 
                os << (int)data[i] << " ";
26
 
        }
27
 
        if (i<size)
28
 
                os << "...";
29
 
}
30
 
 
31
 
int main(int argc, char *argv[])
32
 
{
33
 
        try {
34
 
                DbEnv *env = new DbEnv(0);
35
 
                env->open(".", DB_CREATE | DB_INIT_LOG | DB_INIT_MPOOL, 0);
36
 
 
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);
46
 
                db1->close(0);
47
 
 
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);
56
 
                db2->close(0);
57
 
 
58
 
                // Now get a log cursor and walk through.
59
 
                DbLogc *logc;
60
 
 
61
 
                env->log_cursor(&logc, 0);
62
 
                int ret = 0;
63
 
                DbLsn lsn;
64
 
                Dbt *dbt = new Dbt();
65
 
                u_int32_t flags = DB_FIRST;
66
 
 
67
 
                int count = 0;
68
 
                while ((ret = logc->get(&lsn, dbt, flags)) == 0) {
69
 
 
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
74
 
                        // 'enough'.
75
 
                        //
76
 
                        //     cout << "logc.get: " << count;
77
 
                        //     show_dbt(cout, dbt);
78
 
                        //      cout << "\n";
79
 
                        //
80
 
                        count++;
81
 
                        flags = DB_NEXT;
82
 
                }
83
 
                if (ret != DB_NOTFOUND) {
84
 
                        cerr << "*** FAIL: logc.get returned: "
85
 
                             << DbEnv::strerror(ret) << "\n";
86
 
                }
87
 
                logc->close(0);
88
 
 
89
 
                // There has to be at *least* four log records,
90
 
                // since we did four separate database operations.
91
 
                //
92
 
                if (count < 4)
93
 
                        cerr << "*** FAIL: not enough log records\n";
94
 
 
95
 
                cout << "TestLogc done.\n";
96
 
        }
97
 
        catch (DbException &dbe) {
98
 
                cerr << "*** FAIL: " << dbe.what() <<"\n";
99
 
        }
100
 
        return 0;
101
 
}