From 955a96e1ea9caa15f191a4490e539a2696021b8a Mon Sep 17 00:00:00 2001
From: Dan Goodliffe <dan@randomdan.homeip.net>
Date: Thu, 24 Sep 2015 03:03:25 +0100
Subject: MySQL mocking and tests from Project2

---
 project2/sql/sql-modMySQL.cpp          |  30 ------
 project2/sql/sql-modMySQL.h            |  17 ----
 project2/sql/unittests/mysqlschema.sql |  14 ---
 project2/sql/unittests/testmysql.cpp   | 171 ---------------------------------
 4 files changed, 232 deletions(-)
 delete mode 100644 project2/sql/sql-modMySQL.cpp
 delete mode 100644 project2/sql/sql-modMySQL.h
 delete mode 100644 project2/sql/unittests/mysqlschema.sql
 delete mode 100644 project2/sql/unittests/testmysql.cpp

diff --git a/project2/sql/sql-modMySQL.cpp b/project2/sql/sql-modMySQL.cpp
deleted file mode 100644
index 728c9e1..0000000
--- a/project2/sql/sql-modMySQL.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-#include "connectionLoader.h"
-#include "../libmysqlpp/connection.h"
-#include "sql-modMySQL.h"
-#include <buffer.h>
-#include <scripts.h>
-#include <logger.h>
-#include <fstream>
-
-typedef MySQL::Connection MySQLConnection;
-DECLARE_GENERIC_LOADER("mysql", ConnectionLoader, MySQLConnection)
-
-MockMySQLDatabase::MockMySQLDatabase(const std::string & name, const std::vector<boost::filesystem::path> & ss) :
-	MockServerDatabase("options=p2testmysql", name, "mysql")
-{
-	CreateNewDatabase();
-	PlaySchemaScripts(ss);
-}
-
-DB::Connection *
-MockMySQLDatabase::openConnection() const
-{
-	return InstanceMap<ConnectionLoader, std::string>::Get<std::invalid_argument>("mysql")->create(
-			stringbf("options=p2testmysql;database=%s", testDbName));
-}
-
-MockMySQLDatabase::~MockMySQLDatabase()
-{
-	DropDatabase();
-}
-
diff --git a/project2/sql/sql-modMySQL.h b/project2/sql/sql-modMySQL.h
deleted file mode 100644
index b303e71..0000000
--- a/project2/sql/sql-modMySQL.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef MOCKMYSQLDATASOURCE_H
-#define MOCKMYSQLDATASOURCE_H
-
-#include "mockDatabase.h"
-#include <boost/filesystem/path.hpp>
-
-class MockMySQLDatabase : public MockServerDatabase {
-	public:
-		MockMySQLDatabase(const std::string & name, const std::vector<boost::filesystem::path> & ss);
-		~MockMySQLDatabase();
-
-	private:
-		DB::Connection * openConnection() const override;
-};
-
-#endif
-
diff --git a/project2/sql/unittests/mysqlschema.sql b/project2/sql/unittests/mysqlschema.sql
deleted file mode 100644
index 58724c8..0000000
--- a/project2/sql/unittests/mysqlschema.sql
+++ /dev/null
@@ -1,14 +0,0 @@
-CREATE TABLE test(
-		id int,
-		fl numeric(5,2),
-		string varchar(30),
-		boolean bool,
-		dt timestamp,
-		ts time);
-
-INSERT INTO test VALUES(4, 123.45, 'some text', true, '2015-04-27 23:06:03', '38:13:12');
-
-CREATE TABLE bulktest(
-		intcol int,
-		stringcol varchar(3000));
-
diff --git a/project2/sql/unittests/testmysql.cpp b/project2/sql/unittests/testmysql.cpp
deleted file mode 100644
index 546199c..0000000
--- a/project2/sql/unittests/testmysql.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-#define BOOST_TEST_MODULE TestMySQL
-#include <boost/test/unit_test.hpp>
-
-#include <mockDatasource.h>
-#include <definedDirs.h>
-#include <modifycommand.h>
-#include <selectcommand.h>
-#include <column.h>
-#include <sql-modMySQL.h>
-#include "testCore.h"
-#include <sqlHandleAsVariableType.h>
-#include <fstream>
-
-class StandardMockDatabase : public MockMySQLDatabase {
-	public:
-		StandardMockDatabase() : MockMySQLDatabase("mysqlmock", {
-				RootDir / "mysqlschema.sql" })
-		{
-		}
-};
-
-BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
-
-BOOST_FIXTURE_TEST_SUITE( Core, TestCore );
-
-BOOST_AUTO_TEST_CASE( transactions )
-{
-	RdbmsDataSource * ds = CommonObjects::dataSource<RdbmsDataSource>("mysqlmock");
-	auto ro = ds->getReadonly();
-
-	BOOST_REQUIRE_EQUAL(false, ro->inTx());
-	ro->beginTx();
-	BOOST_REQUIRE_EQUAL(true, ro->inTx());
-	ro->rollbackTx();
-	BOOST_REQUIRE_EQUAL(false, ro->inTx());
-
-	ro->beginTx();
-	BOOST_REQUIRE_EQUAL(true, ro->inTx());
-	ro->commitTx();
-	BOOST_REQUIRE_EQUAL(false, ro->inTx());
-
-	ds->close();
-}
-
-BOOST_AUTO_TEST_CASE( bindAndSend )
-{
-	RdbmsDataSource * ds = CommonObjects::dataSource<RdbmsDataSource>("mysqlmock");
-	auto rw = ds->getWritable();
-
-	auto mod = rw->newModifyCommand("INSERT INTO test VALUES(?, ?, ?, ?, ?, ?)");
-	mod->bindParamI(0, testInt);
-	mod->bindParamF(1, testDouble);
-	mod->bindParamS(2, testString);
-	mod->bindParamB(3, testBool);
-	mod->bindParamT(4, testDateTime);
-	mod->bindParamT(5, testInterval);
-	mod->execute();
-	delete mod;
-	ds->commit();
-	ds->close();
-}
-
-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;
-	sel[col].apply(h);
-	BOOST_REQUIRE_EQUAL(t, h.variable.as<T>());
-}
-
-BOOST_AUTO_TEST_CASE( bindAndSelect )
-{
-	RdbmsDataSource * ds = CommonObjects::dataSource<RdbmsDataSource>("mysqlmock");
-	auto ro = ds->getReadonly();
-
-	auto select = ro->newSelectCommand("SELECT * FROM test WHERE id = ?");
-	select->bindParamI(0, testInt);
-	select->execute();
-	int rows = 0;
-	while (select->fetch()) {
-		assertColumnValueHelper(*select, 0, testInt);
-		assertColumnValueHelper(*select, 1, testDouble);
-		assertColumnValueHelper(*select, 2, testString);
-		assertColumnValueHelper(*select, 3, testBool);
-		assertColumnValueHelper(*select, 4, testDateTime);
-		assertColumnValueHelper(*select, 5, testInterval);
-		rows += 1;
-	}
-	delete select;
-	BOOST_REQUIRE_EQUAL(1, rows);
-	ds->close();
-}
-
-BOOST_AUTO_TEST_CASE( bindAndSelectOther )
-{
-	RdbmsDataSource * ds = CommonObjects::dataSource<RdbmsDataSource>("mysqlmock");
-	auto ro = ds->getReadonly();
-
-	auto select = ro->newSelectCommand("SELECT * FROM test WHERE id != ?");
-	select->bindParamI(0, testInt);
-	select->execute();
-	int rows = 0;
-	while (select->fetch()) {
-		assertColumnValueHelper(*select, 0, 4);
-		assertColumnValueHelper(*select, 1, 123.45);
-		assertColumnValueHelper(*select, 2, std::string("some text"));
-		assertColumnValueHelper(*select, 3, true);
-		assertColumnValueHelper(*select, 4, boost::posix_time::ptime_from_tm({ 3, 6, 23, 27, 3, 115, 0, 0, 0, 0, 0}));
-		assertColumnValueHelper(*select, 5, boost::posix_time::time_duration(38, 13, 12));
-		rows += 1;
-	}
-	delete select;
-	BOOST_REQUIRE_EQUAL(1, rows);
-	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();
-
-- 
cgit v1.2.3