summaryrefslogtreecommitdiff
path: root/libmysqlpp/unittests
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2018-04-15 15:10:58 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2018-04-15 15:10:58 +0100
commit2d7c7d4f13c21d7c5b259c8724d3add1f506dd12 (patch)
tree98e50ec84dc594abd72c6981a3fc115c9fc3fb41 /libmysqlpp/unittests
parentStandalone split (diff)
downloadlibdbpp-mysql-1.2.0.tar.bz2
libdbpp-mysql-1.2.0.tar.xz
libdbpp-mysql-1.2.0.zip
Upgrade everything to C++17
Diffstat (limited to 'libmysqlpp/unittests')
-rw-r--r--libmysqlpp/unittests/Jamfile.jam1
-rw-r--r--libmysqlpp/unittests/testmysql.cpp33
2 files changed, 9 insertions, 25 deletions
diff --git a/libmysqlpp/unittests/Jamfile.jam b/libmysqlpp/unittests/Jamfile.jam
index 167939a..89f3182 100644
--- a/libmysqlpp/unittests/Jamfile.jam
+++ b/libmysqlpp/unittests/Jamfile.jam
@@ -14,6 +14,7 @@ run
<define>BOOST_TEST_DYN_LINK
<library>..//dbpp-mysql
<library>dbpptestcore
+ <library>..//adhocutil
<library>boost_utf
<library>boost_system
<library>boost_filesystem
diff --git a/libmysqlpp/unittests/testmysql.cpp b/libmysqlpp/unittests/testmysql.cpp
index 00c15aa..b2e8175 100644
--- a/libmysqlpp/unittests/testmysql.cpp
+++ b/libmysqlpp/unittests/testmysql.cpp
@@ -12,9 +12,9 @@
#include <fstream>
#include <boost/date_time/posix_time/posix_time.hpp>
-class StandardMockDatabase : public MySQL::Mock {
+class StandardMockDatabase : public DB::PluginMock<MySQL::Mock> {
public:
- StandardMockDatabase() : MySQL::Mock("mysqlmock", {
+ StandardMockDatabase() : DB::PluginMock<MySQL::Mock>("options=p2testmysql", "mysqlmock", {
rootDir / "mysqlschema.sql" })
{
}
@@ -38,15 +38,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 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);
@@ -54,15 +52,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 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;
@@ -75,16 +71,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 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;
@@ -97,16 +91,14 @@ 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");
+ auto count = ro->select("SELECT COUNT(*) FROM bulktest");
// Test empty
ro->beginBulkUpload("bulktest", "");
ro->endBulkUpload(NULL);
@@ -121,30 +113,24 @@ BOOST_AUTO_TEST_CASE( bulkload )
}
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");
+ auto count = ro->select("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 ins = ro->modify("INSERT INTO inserts(num) VALUES(?)");
ins->bindParamI(0, 4);
ins->execute();
BOOST_REQUIRE_EQUAL(1, ro->insertId());
@@ -154,15 +140,12 @@ 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");
BOOST_REQUIRE_THROW(ro->execute("nonsense"), DB::Error);
- delete ro;
BOOST_REQUIRE_THROW(DB::ConnectionFactory::createNew("mysql", "server=nohost"), DB::ConnectionError);
}