summaryrefslogtreecommitdiff
path: root/libsqlitepp/unittests/testsqlite.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-09-24 03:05:12 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2015-09-24 03:06:07 +0100
commit35382065da97e8e98c3883caebc0b8f51aa33e90 (patch)
tree5b53d246def27e0f588ab0d02a91532e0c913908 /libsqlitepp/unittests/testsqlite.cpp
parentConnector compatibility fix (diff)
downloadlibdbpp-sqlite-35382065da97e8e98c3883caebc0b8f51aa33e90.tar.bz2
libdbpp-sqlite-35382065da97e8e98c3883caebc0b8f51aa33e90.tar.xz
libdbpp-sqlite-35382065da97e8e98c3883caebc0b8f51aa33e90.zip
SQLite mocking and tests from Project2
Diffstat (limited to 'libsqlitepp/unittests/testsqlite.cpp')
-rw-r--r--libsqlitepp/unittests/testsqlite.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/libsqlitepp/unittests/testsqlite.cpp b/libsqlitepp/unittests/testsqlite.cpp
new file mode 100644
index 0000000..a4b7880
--- /dev/null
+++ b/libsqlitepp/unittests/testsqlite.cpp
@@ -0,0 +1,76 @@
+#define BOOST_TEST_MODULE TestSQLite
+#include <boost/test/unit_test.hpp>
+
+#include <definedDirs.h>
+#include <modifycommand.h>
+#include <selectcommand.h>
+#include <column.h>
+#include <mock.h>
+#include "testCore.h"
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+class StandardMockDatabase : public SQLite::Mock {
+ public:
+ StandardMockDatabase() : SQLite::Mock("sqlitemock", {
+ rootDir / "sqliteschema.sql" })
+ {
+ }
+};
+
+BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
+
+BOOST_FIXTURE_TEST_SUITE( Core, DB::TestCore );
+
+BOOST_AUTO_TEST_CASE( transactions )
+{
+ auto ro = DB::MockDatabase::openConnectionTo("sqlitemock");
+
+ BOOST_REQUIRE_EQUAL(false, ro->inTx());
+ ro->beginTx();
+ BOOST_REQUIRE_EQUAL(true, ro->inTx());
+ ro->rollbackTx();
+ BOOST_REQUIRE_EQUAL(false, ro->inTx());
+
+ ro->beginTx();
+ BOOST_REQUIRE_EQUAL(true, ro->inTx());
+ ro->commitTx();
+ BOOST_REQUIRE_EQUAL(false, ro->inTx());
+
+ delete ro;
+}
+
+BOOST_AUTO_TEST_CASE( bindAndSend )
+{
+ auto rw = DB::MockDatabase::openConnectionTo("sqlitemock");
+
+ auto mod = rw->newModifyCommand("INSERT INTO test VALUES(?, ?, ?)");
+ mod->bindParamI(0, testInt);
+ mod->bindParamF(1, testDouble);
+ mod->bindParamS(2, testString);
+ mod->execute();
+ delete mod;
+ rw->commitTx();
+ delete rw;
+}
+
+BOOST_AUTO_TEST_CASE( bindAndSelect )
+{
+ auto ro = DB::MockDatabase::openConnectionTo("sqlitemock");
+
+ auto select = ro->newSelectCommand("SELECT * FROM test WHERE id = ?");
+ select->bindParamI(0, testInt);
+ select->execute();
+ int rows = 0;
+ while (select->fetch()) {
+ assertColumnValueHelper(*select, 0, testInt);
+ assertColumnValueHelper(*select, 1, testDouble);
+ assertColumnValueHelper(*select, 2, testString);
+ rows += 1;
+ }
+ delete select;
+ BOOST_REQUIRE_EQUAL(1, rows);
+ delete ro;
+}
+
+BOOST_AUTO_TEST_SUITE_END();
+