summaryrefslogtreecommitdiff
path: root/libmysqlpp/unittests
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-12-31 04:04:31 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2017-05-04 20:44:40 +0100
commitdb1e2f066393af3e58814417de5bbe7ea08a145d (patch)
tree9d01e48d8ef7d63fbcca6aced2461b3f1e234dfd /libmysqlpp/unittests
parentBeginnings of embbeded MySQL (diff)
downloadlibdbpp-mysql-db1e2f066393af3e58814417de5bbe7ea08a145d.tar.bz2
libdbpp-mysql-db1e2f066393af3e58814417de5bbe7ea08a145d.tar.xz
libdbpp-mysql-db1e2f066393af3e58814417de5bbe7ea08a145d.zip
Basics working, could do with a tidy up around mocking
Diffstat (limited to 'libmysqlpp/unittests')
-rw-r--r--libmysqlpp/unittests/Jamfile.jam2
-rw-r--r--libmysqlpp/unittests/test.impl.h (renamed from libmysqlpp/unittests/testMain.cpp)77
-rw-r--r--libmysqlpp/unittests/testmysql.cpp45
-rw-r--r--libmysqlpp/unittests/testmysqle.cpp18
4 files changed, 70 insertions, 72 deletions
diff --git a/libmysqlpp/unittests/Jamfile.jam b/libmysqlpp/unittests/Jamfile.jam
index c7bf637..d4014ea 100644
--- a/libmysqlpp/unittests/Jamfile.jam
+++ b/libmysqlpp/unittests/Jamfile.jam
@@ -24,7 +24,7 @@ run
run
testmysqle.cpp
- : : :
+ : --log_level=all : :
<define>ROOT=\"$(me)\"
<define>BOOST_TEST_DYN_LINK
<library>..//dbpp-mysql-embedded
diff --git a/libmysqlpp/unittests/testMain.cpp b/libmysqlpp/unittests/test.impl.h
index 0811d5c..13ae738 100644
--- a/libmysqlpp/unittests/testMain.cpp
+++ b/libmysqlpp/unittests/test.impl.h
@@ -1,17 +1,19 @@
+#include <boost/test/unit_test.hpp>
#include <modifycommand.h>
#include <selectcommand.h>
+#include <connection.h>
+#include <mockDatabase.h>
#include <column.h>
#include <testCore.h>
#include <fstream>
#include <boost/date_time/posix_time/posix_time.hpp>
-
-BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
+#include <definedDirs.h>
BOOST_FIXTURE_TEST_SUITE( Core, DB::TestCore );
BOOST_AUTO_TEST_CASE( transactions )
{
- auto ro = DB::MockDatabase::openConnectionTo("mysqlmock");
+ auto ro = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("mysqlmock"));
BOOST_REQUIRE_EQUAL(false, ro->inTx());
ro->beginTx();
@@ -23,15 +25,13 @@ BOOST_AUTO_TEST_CASE( transactions )
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("mysqlmock");
+ auto rw = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("mysqlmock"));
- auto mod = rw->newModifyCommand("INSERT INTO test VALUES(?, ?, ?, ?, ?, ?)");
+ auto mod = rw->modify("INSERT INTO test VALUES(?, ?, ?, ?, ?, ?)");
mod->bindParamI(0, testInt);
mod->bindParamF(1, testDouble);
mod->bindParamS(2, testString);
@@ -39,15 +39,13 @@ BOOST_AUTO_TEST_CASE( bindAndSend )
mod->bindParamT(4, testDateTime);
mod->bindParamT(5, testInterval);
mod->execute();
- delete mod;
- delete rw;
}
BOOST_AUTO_TEST_CASE( bindAndSelect )
{
- auto ro = DB::MockDatabase::openConnectionTo("mysqlmock");
+ auto ro = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("mysqlmock"));
- auto select = ro->newSelectCommand("SELECT * FROM test WHERE id = ?");
+ auto select = ro->select("SELECT * FROM test WHERE id = ?");
select->bindParamI(0, testInt);
select->execute();
int rows = 0;
@@ -60,16 +58,14 @@ BOOST_AUTO_TEST_CASE( bindAndSelect )
assertColumnValueHelper(*select, 5, testInterval);
rows += 1;
}
- delete select;
BOOST_REQUIRE_EQUAL(1, rows);
- delete ro;
}
BOOST_AUTO_TEST_CASE( bindAndSelectOther )
{
- auto ro = DB::MockDatabase::openConnectionTo("mysqlmock");
+ auto ro = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("mysqlmock"));
- auto select = ro->newSelectCommand("SELECT * FROM test WHERE id != ?");
+ auto select = ro->select("SELECT * FROM test WHERE id != ?");
select->bindParamI(0, testInt);
select->execute();
int rows = 0;
@@ -82,54 +78,13 @@ BOOST_AUTO_TEST_CASE( bindAndSelectOther )
assertColumnValueHelper(*select, 5, boost::posix_time::time_duration(38, 13, 12));
rows += 1;
}
- delete select;
BOOST_REQUIRE_EQUAL(1, rows);
- delete ro;
-}
-
-BOOST_AUTO_TEST_CASE( bulkload )
-{
- auto ro = DB::MockDatabase::openConnectionTo("mysqlmock");
-
- auto count = ro->newSelectCommand("SELECT COUNT(*) FROM bulktest");
- // Test empty
- ro->beginBulkUpload("bulktest", "");
- ro->endBulkUpload(NULL);
- assertScalarValueHelper(*count, 0);
- // Test sample file
- ro->beginBulkUpload("bulktest", "");
- std::ifstream in((rootDir / "bulk.sample").string());
- if (!in.good()) throw std::runtime_error("Couldn't open bulk.sample");
- char buf[BUFSIZ];
- for (std::streamsize r; (r = in.readsome(buf, sizeof(buf))) > 0; ) {
- ro->bulkUploadData(buf, r);
- }
- ro->endBulkUpload(NULL);
- assertScalarValueHelper(*count, 800);
-
- delete count;
- delete ro;
-}
-
-BOOST_AUTO_TEST_CASE( bigIterate )
-{
- auto ro = DB::MockDatabase::openConnectionTo("mysqlmock");
-
- auto count = ro->newSelectCommand("SELECT * FROM bulktest");
- unsigned int rows = 0;
- while (count->fetch()) {
- rows += 1;
- }
- BOOST_REQUIRE_EQUAL(800, rows);
-
- delete count;
- delete ro;
}
BOOST_AUTO_TEST_CASE( insertId )
{
- auto ro = DB::MockDatabase::openConnectionTo("mysqlmock");
- auto ins = ro->newModifyCommand("INSERT INTO inserts(num) VALUES(?)");
+ auto ro = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("mysqlmock"));
+ auto ins = ro->modify("INSERT INTO inserts(num) VALUES(?)");
ins->bindParamI(0, 4);
ins->execute();
BOOST_REQUIRE_EQUAL(1, ro->insertId());
@@ -139,18 +94,14 @@ BOOST_AUTO_TEST_CASE( insertId )
ins->bindParamI(0, -4);
ins->execute();
BOOST_REQUIRE_EQUAL(3, ro->insertId());
- delete ins;
- delete ro;
}
BOOST_AUTO_TEST_CASE( errors )
{
- auto ro = DB::MockDatabase::openConnectionTo("mysqlmock");
+ auto ro = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("mysqlmock"));
BOOST_REQUIRE_THROW(ro->execute("nonsense"), DB::Error);
- delete ro;
BOOST_REQUIRE_THROW(DB::ConnectionFactory::createNew("mysql", "server=nohost"), DB::ConnectionError);
}
BOOST_AUTO_TEST_SUITE_END();
-
diff --git a/libmysqlpp/unittests/testmysql.cpp b/libmysqlpp/unittests/testmysql.cpp
index d363716..fd29485 100644
--- a/libmysqlpp/unittests/testmysql.cpp
+++ b/libmysqlpp/unittests/testmysql.cpp
@@ -1,6 +1,3 @@
-#define BOOST_TEST_MODULE TestMySQL
-#include <boost/test/unit_test.hpp>
-
#include <my-mock.h>
#include <definedDirs.h>
@@ -12,5 +9,45 @@ class StandardMockDatabase : public MySQL::Mock {
}
};
-#include "testMain.cpp"
+#define BOOST_TEST_MODULE TestMySQL
+
+#include "test.impl.h"
+BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
+
+BOOST_FIXTURE_TEST_SUITE( Core, DB::TestCore );
+
+BOOST_AUTO_TEST_CASE( bulkload )
+{
+ auto ro = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("mysqlmock"));
+
+ auto count = ro->select("SELECT COUNT(*) FROM bulktest");
+ // Test empty
+ ro->beginBulkUpload("bulktest", "");
+ ro->endBulkUpload(NULL);
+ assertScalarValueHelper(*count, 0);
+ // Test sample file
+ ro->beginBulkUpload("bulktest", "");
+ std::ifstream in((rootDir / "bulk.sample").string());
+ if (!in.good()) throw std::runtime_error("Couldn't open bulk.sample");
+ char buf[BUFSIZ];
+ for (std::streamsize r; (r = in.readsome(buf, sizeof(buf))) > 0; ) {
+ ro->bulkUploadData(buf, r);
+ }
+ ro->endBulkUpload(NULL);
+ assertScalarValueHelper(*count, 800);
+}
+
+BOOST_AUTO_TEST_CASE( bigIterate )
+{
+ auto ro = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("mysqlmock"));
+
+ auto count = ro->select("SELECT * FROM bulktest");
+ unsigned int rows = 0;
+ while (count->fetch()) {
+ rows += 1;
+ }
+ BOOST_REQUIRE_EQUAL(800, rows);
+}
+
+BOOST_AUTO_TEST_SUITE_END();
diff --git a/libmysqlpp/unittests/testmysqle.cpp b/libmysqlpp/unittests/testmysqle.cpp
index 0d1defb..659433b 100644
--- a/libmysqlpp/unittests/testmysqle.cpp
+++ b/libmysqlpp/unittests/testmysqle.cpp
@@ -1,6 +1,3 @@
-#define BOOST_TEST_MODULE TestEmbeddedMySQL
-#include <boost/test/unit_test.hpp>
-
#include <embeddedmy-mock.h>
#include <definedDirs.h>
@@ -12,5 +9,18 @@ class StandardMockDatabase : public MySQL::Embedded::Mock {
}
};
-#include "testMain.cpp"
+#define BOOST_TEST_MODULE TestEmbeddedMySQL
+
+#include "test.impl.h"
+BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
+
+BOOST_FIXTURE_TEST_SUITE( Core, DB::TestCore );
+
+BOOST_AUTO_TEST_CASE( bulkload )
+{
+ auto ro = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("mysqlmock"));
+ BOOST_REQUIRE_THROW(ro->beginBulkUpload("any", nullptr), DB::BulkUploadNotSupported);
+}
+
+BOOST_AUTO_TEST_SUITE_END();