|
3 | 3 | #include <cstdlib>
|
4 | 4 | #include <catch.hpp>
|
5 | 5 |
|
6 |
| -#ifdef ENABLE_SQLCIPHER_TESTS |
7 |
| - #include <sqlite_modern_cpp/sqlcipher.h> |
8 |
| - using namespace sqlite; |
9 |
| - using namespace std; |
| 6 | +#include <sqlite_modern_cpp/sqlcipher.h> |
| 7 | +using namespace sqlite; |
| 8 | +using namespace std; |
10 | 9 |
|
11 |
| - struct TmpFile |
| 10 | +struct TmpFile |
| 11 | +{ |
| 12 | + string fname; |
| 13 | + |
| 14 | + TmpFile(): fname("./sqlcipher.db") { } |
| 15 | + ~TmpFile() { remove(fname.c_str()); } |
| 16 | +}; |
| 17 | + |
| 18 | +TEST_CASE("sqlcipher works", "[sqlcipher]") { |
| 19 | + TmpFile file; |
| 20 | + sqlcipher_config config; |
| 21 | + { |
| 22 | + config.key = "DebugKey"; |
| 23 | + sqlcipher_database db(file.fname, config); |
| 24 | + |
| 25 | + db << "CREATE TABLE foo (a integer, b string);"; |
| 26 | + db << "INSERT INTO foo VALUES (?, ?)" << 1 << "hello"; |
| 27 | + db << "INSERT INTO foo VALUES (?, ?)" << 2 << "world"; |
| 28 | + |
| 29 | + string str; |
| 30 | + db << "SELECT b from FOO where a=?;" << 2 >> str; |
| 31 | + |
| 32 | + REQUIRE(str == "world"); |
| 33 | + } |
| 34 | + |
| 35 | + bool failed = false; |
| 36 | + try { |
| 37 | + config.key = "DebugKey2"; |
| 38 | + sqlcipher_database db(file.fname, config); |
| 39 | + db << "INSERT INTO foo VALUES (?, ?)" << 3 << "fail"; |
| 40 | + } catch(errors::notadb) { |
| 41 | + failed = true; |
| 42 | + // Expected, wrong key |
| 43 | + } |
| 44 | + REQUIRE(failed == true); |
| 45 | + |
| 46 | + { |
| 47 | + config.key = "DebugKey"; |
| 48 | + sqlcipher_database db(file.fname, config); |
| 49 | + db.rekey("DebugKey2"); |
| 50 | + } |
12 | 51 | {
|
13 |
| - string fname; |
14 |
| - |
15 |
| - TmpFile(): fname("./sqlcipher.db") { } |
16 |
| - ~TmpFile() { remove(fname.c_str()); } |
17 |
| - }; |
18 |
| - |
19 |
| - TEST_CASE("sqlcipher works", "[sqlcipher]") { |
20 |
| - TmpFile file; |
21 |
| - sqlcipher_config config; |
22 |
| - { |
23 |
| - config.key = "DebugKey"; |
24 |
| - sqlcipher_database db(file.fname, config); |
25 |
| - |
26 |
| - db << "CREATE TABLE foo (a integer, b string);"; |
27 |
| - db << "INSERT INTO foo VALUES (?, ?)" << 1 << "hello"; |
28 |
| - db << "INSERT INTO foo VALUES (?, ?)" << 2 << "world"; |
29 |
| - |
30 |
| - string str; |
31 |
| - db << "SELECT b from FOO where a=?;" << 2 >> str; |
32 |
| - |
33 |
| - REQUIRE(str == "world"); |
34 |
| - } |
35 |
| - |
36 |
| - bool failed = false; |
37 |
| - try { |
38 |
| - config.key = "DebugKey2"; |
39 |
| - sqlcipher_database db(file.fname, config); |
40 |
| - db << "INSERT INTO foo VALUES (?, ?)" << 3 << "fail"; |
41 |
| - } catch(errors::notadb) { |
42 |
| - failed = true; |
43 |
| - // Expected, wrong key |
44 |
| - } |
45 |
| - REQUIRE(failed == true); |
46 |
| - |
47 |
| - { |
48 |
| - config.key = "DebugKey"; |
49 |
| - sqlcipher_database db(file.fname, config); |
50 |
| - db.rekey("DebugKey2"); |
51 |
| - } |
52 |
| - { |
53 |
| - config.key = "DebugKey2"; |
54 |
| - sqlcipher_database db(file.fname, config); |
55 |
| - db << "INSERT INTO foo VALUES (?, ?)" << 3 << "fail"; |
56 |
| - } |
| 52 | + config.key = "DebugKey2"; |
| 53 | + sqlcipher_database db(file.fname, config); |
| 54 | + db << "INSERT INTO foo VALUES (?, ?)" << 3 << "fail"; |
57 | 55 | }
|
58 |
| -#endif |
| 56 | +} |
0 commit comments