diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-12-31 04:04:31 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-05-04 20:44:40 +0100 |
commit | db1e2f066393af3e58814417de5bbe7ea08a145d (patch) | |
tree | 9d01e48d8ef7d63fbcca6aced2461b3f1e234dfd /libmysqlpp/unittests/testmysql.cpp | |
parent | Beginnings of embbeded MySQL (diff) | |
download | libdbpp-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/testmysql.cpp')
-rw-r--r-- | libmysqlpp/unittests/testmysql.cpp | 45 |
1 files changed, 41 insertions, 4 deletions
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(); |