From b1c99b0c3b0a8d65f237f507ad238ce441233b3f Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Mon, 2 Jan 2023 20:39:15 +0100 Subject: Fix dependency, added test for CompiledSQL --- compiledsql.h | 2 ++ debian/control | 2 +- tests/test-compiledsql.cpp | 34 ++++++++++++++++++++++------------ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/compiledsql.h b/compiledsql.h index 923be83..7510408 100644 --- a/compiledsql.h +++ b/compiledsql.h @@ -13,6 +13,7 @@ public: void init(const std::string& stmt); + // index 1-based as in SQLite template void bind(int index, T value) { @@ -21,6 +22,7 @@ public: bool execute(); + // index 0-based as in SQLite template T getColumn(const int index) { diff --git a/debian/control b/debian/control index aecfa97..6b0db0e 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: whiteboard Section: web Priority: optional Maintainer: Roland Reichwein -Build-Depends: debhelper (>= 12), libboost-all-dev | libboost1.71-all-dev, clang | g++-9, llvm | g++-9, lld | g++-9, uglifyjs, python3-pkg-resources, htmlmin, cleancss, libfcgi-dev, libqrcodegencpp-dev, libmagick++-dev, pkg-config, libfmt-dev, libsqlitecpp-dev, googletest, gcovr, webserver, libreichwein-dev +Build-Depends: debhelper (>= 12), libboost-all-dev | libboost1.71-all-dev, clang | g++-9, llvm | g++-9, lld | g++-9, uglifyjs, python3-pkg-resources, htmlmin, cleancss, libfcgi-dev, libqrcodegencpp-dev, libgraphicsmagick++-dev, pkg-config, libfmt-dev, libsqlitecpp-dev, googletest, gcovr, webserver, libreichwein-dev Standards-Version: 4.5.0 Homepage: http://www.reichwein.it/whiteboard/ diff --git a/tests/test-compiledsql.cpp b/tests/test-compiledsql.cpp index 4fe29e0..00a8221 100644 --- a/tests/test-compiledsql.cpp +++ b/tests/test-compiledsql.cpp @@ -14,7 +14,6 @@ namespace fs = std::filesystem; namespace { - const std::string testConfigFilename{"./test.conf"}; const std::string testDbFilename{"./whiteboard.db3"}; } @@ -29,29 +28,40 @@ protected: void SetUp() override { - File::setFile(testConfigFilename, R"CONFIG( - - . - 2592000 - -)CONFIG"); std::error_code ec; fs::remove(testDbFilename, ec); - - m_config = std::make_shared(testConfigFilename); } void TearDown() override { std::error_code ec; fs::remove(testDbFilename, ec); - fs::remove(testConfigFilename, ec); } - std::shared_ptr m_config; }; -TEST_F(CompiledSQLTest, connection) +TEST_F(CompiledSQLTest, create) { + SQLite::Database db{testDbFilename, SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE}; + + CompiledSQL stmt1{db}; + stmt1.init("CREATE TABLE documents (id VARCHAR(16) PRIMARY KEY)"); + stmt1.execute(); + + CompiledSQL stmt2{db}; + stmt2.init("INSERT INTO documents (id) values (?)"); + stmt2.bind(1, "abc"); + ASSERT_TRUE(stmt2.execute()); + + CompiledSQL stmt3{db}; + stmt3.init("SELECT id FROM documents WHERE id = ?"); + stmt3.bind(1, "abc"); + ASSERT_TRUE(stmt3.execute()); + EXPECT_EQ(stmt3.getColumn(0), "abc"); + stmt3.init("SELECT id FROM documents WHERE id = ?"); + stmt3.bind(1, "def"); + ASSERT_FALSE(stmt3.execute()); + + EXPECT_TRUE(fs::exists(testDbFilename)); } -- cgit v1.2.3