Skip to content

Commit 16d314f

Browse files
committed
try to fix travis
1 parent 45260a2 commit 16d314f

File tree

3 files changed

+65
-53
lines changed

3 files changed

+65
-53
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ addons:
66
apt:
77
sources:
88
- ubuntu-toolchain-r-test
9+
- george-edison55-precise-backports
910
packages:
1011
- gcc-5
1112
- g++-5
1213
- libsqlite3-dev
1314
- libsqlcipher-dev
14-
- libboost-all-dev
15+
- cmake-data
16+
- cmake
1517

1618
before_install:
1719
- export CXX="g++-5" CC="gcc-5"
1820

19-
script: ./configure && make test && make clean && make LDFLAGS="-lsqlcipher -DENABLE_SQLCIPHER_TESTS" test
21+
script: mkdir build && cd ./build && cmake -DENABLE_SQLCIPHER_TESTS=ON .. && make && ./tests

CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
cmake_minimum_required(VERSION 3.10)
1+
cmake_minimum_required(VERSION 3.0)
2+
OPTION(ENABLE_SQLCIPHER_TESTS "enable sqlchipher test")
23

34
# Creates the file compile_commands.json in the build directory.
45
SET( CMAKE_EXPORT_COMPILE_COMMANDS ON )
@@ -11,6 +12,7 @@ include("cmake/DownloadProject.CMake")
1112
project(SqliteModernCpp)
1213

1314
find_package(sqlite3 REQUIRED)
15+
1416
download_project(
1517
PROJ catch
1618
GIT_REPOSITORY [email protected]:catchorg/Catch2.git
@@ -22,6 +24,13 @@ set(CATCH_INCLUDE_DIR ${CMAKE_BINARY_DIR}/catch-src/single_include/)
2224
set(TEST_SOURCE_DIR ${CMAKE_SOURCE_DIR}/tests)
2325
file(GLOB TEST_SOURCES ${TEST_SOURCE_DIR}/*.cc)
2426

27+
message(STATUS ${ENABLE_SQLCIPHER_TESTS})
28+
IF(NOT ENABLE_SQLCIPHER_TESTS)
29+
list(REMOVE_ITEM TEST_SOURCES ${TEST_SOURCE_DIR}/sqlcipher.cc)
30+
ENDIF(NOT ENABLE_SQLCIPHER_TESTS)
31+
message(STATUS ${TEST_SOURCES})
32+
message(STATUS ${TEST_SOURCE_DIR}/sqlcipher.cc)
33+
2534
enable_testing()
2635

2736
add_library (sqlite_modern_cpp INTERFACE)
@@ -33,6 +42,9 @@ target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
3342
add_executable(tests ${TEST_SOURCES})
3443
target_include_directories(tests INTERFACE ${SQLITE3_INCLUDE_DIRS})
3544
target_link_libraries(tests Catch sqlite_modern_cpp sqlite3)
45+
IF(ENABLE_SQLCIPHER_TESTS)
46+
set_target_properties(tests PROPERTIES COMPILE_FLAGS '-lsqlcipher')
47+
ENDIF(ENABLE_SQLCIPHER_TESTS)
3648

3749
ParseAndAddCatchTests(tests)
3850

tests/sqlcipher.cc

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,54 @@
33
#include <cstdlib>
44
#include <catch.hpp>
55

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;
109

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+
}
1251
{
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";
5755
}
58-
#endif
56+
}

0 commit comments

Comments
 (0)