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

« back to all changes in this revision

Viewing changes to libdb/test/scr015/TestSimpleAccess.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
 
 * 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.
15
 
 */
16
 
 
17
 
#include <db_cxx.h>
18
 
#include <iostream.h>
19
 
 
20
 
int main(int argc, char *argv[])
21
 
{
22
 
        try {
23
 
                Db *db = new Db(NULL, 0);
24
 
                db->open(NULL, "my.db", NULL, DB_BTREE, DB_CREATE, 0644);
25
 
 
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);
33
 
 
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);
40
 
 
41
 
                int ret;
42
 
 
43
 
                if ((ret = db->get(NULL, goodkeydbt, resultdbt, 0)) != 0) {
44
 
                        cout << "get: " << DbEnv::strerror(ret) << "\n";
45
 
                }
46
 
                else {
47
 
                        char *result = (char *)resultdbt->get_data();
48
 
                        cout << "got data: " << result << "\n";
49
 
                }
50
 
 
51
 
                if ((ret = db->get(NULL, badkeydbt, resultdbt, 0)) != 0) {
52
 
                        // We expect this...
53
 
                        cout << "get using bad key: "
54
 
                             << DbEnv::strerror(ret) << "\n";
55
 
                }
56
 
                else {
57
 
                        char *result = (char *)resultdbt->get_data();
58
 
                        cout << "*** got data using bad key!!: "
59
 
                             << result << "\n";
60
 
                }
61
 
                cout << "finished test\n";
62
 
        }
63
 
        catch (DbException &dbe) {
64
 
                cerr << "Db Exception: " << dbe.what();
65
 
        }
66
 
        return 0;
67
 
}