Debian Codegraph @

debian/tests/build

raw
1 #!/bin/sh
2 # autopkgtest check: Builds a small application against leveldb, checking
3 # if it compiles, links and runs successfully.
4 # Author: Alessio Treglia <[email protected]>
5
6 set -e
7
8 WORKDIR=$(mktemp -d)
9 trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
10 cd $WORKDIR
11
12 if [ -n "$DEB_HOST_MULTIARCH" ]; then
13 CROSS_COMPILE="$DEB_HOST_GNU_TYPE-"
14 fi
15
16 cat <<EOF > build_test.cpp
17 #include <iostream>
18 #include <sstream>
19 #include <string>
20 #include <cassert>
21
22 #include "leveldb/db.h"
23
24 using namespace std;
25
26 int main(int argc, char **argv)
27 {
28 leveldb::DB *db;
29 leveldb::Options opts;
30 leveldb::ReadOptions r_opts;
31 leveldb::WriteOptions w_opts;
32 std::string value;
33
34 opts.create_if_missing = true;
35 // Create a new db
36 leveldb::Status s = leveldb::DB::Open(opts,
37 "./build_test_db",
38 &db);
39 assert (s.ok() == true);
40 // Check if the db is empty
41 s = db->Get(r_opts, "test_key1", &value);
42 assert (s.IsNotFound() == true);
43 // Add such new key to the db
44 s = db->Put(w_opts, "test_key1", "test_value1");
45 assert (s.ok() == true);
46 // Get the new key
47 s = db->Get(r_opts, "test_key1", &value);
48 assert (s.ok() == true);
49 // Check the return value
50 assert (value.compare("test_value1") == 0);
51 // Delete the key
52 s = db->Delete(w_opts, "test_key1");
53 assert (s.ok() == true);
54 // Check if the deletion's gone well
55 s = db->Get(r_opts, "test_key1", &value);
56 assert (s.IsNotFound() == true);
57
58 // Close the db
59 delete db;
60
61 return 0;
62 }
63 EOF
64
65 ${CROSS_COMPILE}g++ -o build_test build_test.cpp -pthread -lleveldb -lsnappy
66 echo "build: OK"
67 [ -x build_test ]
68 ./build_test
69 echo "run: OK"