diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-01-02 20:39:15 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-01-02 20:39:15 +0100 |
commit | b1c99b0c3b0a8d65f237f507ad238ce441233b3f (patch) | |
tree | f493704fac3177d0b2a37e1e189117fe6dc705ce /tests | |
parent | 992a1b3d2653ed527c2a301f80140bc35d84e832 (diff) |
Fix dependency, added test for CompiledSQL
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-compiledsql.cpp | 34 |
1 files changed, 22 insertions, 12 deletions
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( -<config> - <datapath>.</datapath> - <maxage>2592000</maxage> -</config> -)CONFIG"); std::error_code ec; fs::remove(testDbFilename, ec); - - m_config = std::make_shared<Config>(testConfigFilename); } void TearDown() override { std::error_code ec; fs::remove(testDbFilename, ec); - fs::remove(testConfigFilename, ec); } - std::shared_ptr<Config> 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<std::string>(0), "abc"); + stmt3.init("SELECT id FROM documents WHERE id = ?"); + stmt3.bind(1, "def"); + ASSERT_FALSE(stmt3.execute()); + + EXPECT_TRUE(fs::exists(testDbFilename)); } |