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 --- tests/test-compiledsql.cpp | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'tests/test-compiledsql.cpp') 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