summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test-compiledsql.cpp34
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));
}