diff options
Diffstat (limited to 'project2/sql/unittests/testmysql.cpp')
-rw-r--r-- | project2/sql/unittests/testmysql.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/project2/sql/unittests/testmysql.cpp b/project2/sql/unittests/testmysql.cpp index 6cbc440..546199c 100644 --- a/project2/sql/unittests/testmysql.cpp +++ b/project2/sql/unittests/testmysql.cpp @@ -9,6 +9,7 @@ #include <sql-modMySQL.h> #include "testCore.h" #include <sqlHandleAsVariableType.h> +#include <fstream> class StandardMockDatabase : public MockMySQLDatabase { public: @@ -61,6 +62,17 @@ BOOST_AUTO_TEST_CASE( bindAndSend ) template<typename T> void +assertColumnValueHelper(DB::SelectCommand & sel, const T & t) +{ + while (sel.fetch()) { + HandleAsVariableType h; + sel[0].apply(h); + BOOST_REQUIRE_EQUAL(t, h.variable.as<T>()); + } +} + +template<typename T> +void assertColumnValueHelper(DB::SelectCommand & sel, unsigned int col, const T & t) { HandleAsVariableType h; @@ -114,5 +126,46 @@ BOOST_AUTO_TEST_CASE( bindAndSelectOther ) ds->close(); } +BOOST_AUTO_TEST_CASE( bulkload ) +{ + RdbmsDataSource * ds = CommonObjects::dataSource<RdbmsDataSource>("mysqlmock"); + auto ro = ds->getReadonly(); + + auto count = ro->newSelectCommand("SELECT COUNT(*) FROM bulktest"); + // Test empty + ro->beginBulkUpload("bulktest", ""); + ro->endBulkUpload(NULL); + assertColumnValueHelper(*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); + assertColumnValueHelper(*count, 800); + + delete count; + ds->close(); +} + +BOOST_AUTO_TEST_CASE( bigIterate ) +{ + RdbmsDataSource * ds = CommonObjects::dataSource<RdbmsDataSource>("mysqlmock"); + auto ro = ds->getReadonly(); + + auto count = ro->newSelectCommand("SELECT * FROM bulktest"); + unsigned int rows = 0; + while (count->fetch()) { + rows += 1; + } + BOOST_REQUIRE_EQUAL(800, rows); + + delete count; + ds->close(); +} + BOOST_AUTO_TEST_SUITE_END(); |