From c9fa963e71258c5adfb71cf1996cd1bcb33df0bb Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 26 Feb 2023 08:54:17 +0100 Subject: Start with copy of whiteboard --- tests/test-compiledsql.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/test-compiledsql.cpp (limited to 'tests/test-compiledsql.cpp') diff --git a/tests/test-compiledsql.cpp b/tests/test-compiledsql.cpp new file mode 100644 index 0000000..d14220c --- /dev/null +++ b/tests/test-compiledsql.cpp @@ -0,0 +1,77 @@ +#include + +#include +#include +#include +#include + +#include "libreichwein/file.h" + +#include "config.h" +#include "storage.h" +#include "whiteboard.h" + +namespace fs = std::filesystem; + +namespace { + const std::string testDbFilename{"./whiteboard.db3"}; +} + +class CompiledSQLTest: public ::testing::Test +{ +protected: + CompiledSQLTest(){ + } + + ~CompiledSQLTest() override{ + } + + void SetUp() override + { + std::error_code ec; + fs::remove(testDbFilename, ec); + } + + void TearDown() override + { + std::error_code ec; + fs::remove(testDbFilename, ec); + } + +}; + +TEST_F(CompiledSQLTest, create) +{ + SQLite::Database db{testDbFilename, SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE}; + + { + CompiledSQL stmt1{db, "CREATE TABLE documents (id VARCHAR(16) PRIMARY KEY)"}; + CompiledSQL::Guard g{stmt1}; + stmt1.execute(); + } + + { + CompiledSQL stmt2{db, "INSERT INTO documents (id) values (?)"}; + CompiledSQL::Guard g{stmt2}; + stmt2.bind(1, "abc"); + ASSERT_TRUE(stmt2.execute()); + } + + { + CompiledSQL stmt3{db, "SELECT id FROM documents WHERE id = ?"}; + CompiledSQL::Guard g{stmt3}; + stmt3.bind(1, "abc"); + ASSERT_TRUE(stmt3.execute()); + EXPECT_EQ(stmt3.getColumn(0), "abc"); + } + + { + CompiledSQL stmt4{db, "SELECT id FROM documents WHERE id = ?"}; + CompiledSQL::Guard g{stmt4}; + stmt4.bind(1, "def"); + ASSERT_FALSE(stmt4.execute()); + } + + EXPECT_TRUE(fs::exists(testDbFilename)); +} + -- cgit v1.2.3