summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--project2/sql/unittests/pqschema.sql4
-rw-r--r--project2/sql/unittests/testpq.cpp53
2 files changed, 57 insertions, 0 deletions
diff --git a/project2/sql/unittests/pqschema.sql b/project2/sql/unittests/pqschema.sql
index b0581ab..2c7e94a 100644
--- a/project2/sql/unittests/pqschema.sql
+++ b/project2/sql/unittests/pqschema.sql
@@ -31,3 +31,7 @@ AS $tag$
WHERE string != 'complex '' string;';
$tag$;
+CREATE TABLE bulktest(
+ id int,
+ string text);
+
diff --git a/project2/sql/unittests/testpq.cpp b/project2/sql/unittests/testpq.cpp
index 0890bee..da38a34 100644
--- a/project2/sql/unittests/testpq.cpp
+++ b/project2/sql/unittests/testpq.cpp
@@ -9,6 +9,7 @@
#include <sql-modPQ.h>
#include "testCore.h"
#include <sqlHandleAsVariableType.h>
+#include <fstream>
class StandardMockDatabase : public MockPqDatabase {
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;
@@ -130,5 +142,46 @@ BOOST_AUTO_TEST_CASE( testP2MockScriptDir )
ds->close();
}
+BOOST_AUTO_TEST_CASE( bulkload )
+{
+ RdbmsDataSource * ds = CommonObjects::dataSource<RdbmsDataSource>("pqmock");
+ 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>("pqmock");
+ 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();