diff options
| -rw-r--r-- | project2/sql/unittests/testCore.cpp | 7 | ||||
| -rw-r--r-- | project2/sql/unittests/testCore.h | 7 | ||||
| -rw-r--r-- | project2/sql/unittests/testpq.cpp | 44 | 
3 files changed, 52 insertions, 6 deletions
diff --git a/project2/sql/unittests/testCore.cpp b/project2/sql/unittests/testCore.cpp index 8af0e43..911eccb 100644 --- a/project2/sql/unittests/testCore.cpp +++ b/project2/sql/unittests/testCore.cpp @@ -2,7 +2,12 @@  #include <testOptionsSource.h>  #include <definedDirs.h> -TestCore::TestCore() +TestCore::TestCore() : +	testInt(43), +	testDouble(3.14), +	testString("Some C String"), +	testDateTime(boost::posix_time::from_time_t(time(NULL))), +	testInterval(boost::posix_time::time_duration(1, 2, 3))  {  	TestOptionsSource::LoadTestOptions({  			{ "common.datasourceRoot", (RootDir / "datasources").string() }, diff --git a/project2/sql/unittests/testCore.h b/project2/sql/unittests/testCore.h index e39e9c6..b807922 100644 --- a/project2/sql/unittests/testCore.h +++ b/project2/sql/unittests/testCore.h @@ -2,10 +2,17 @@  #define PROJECT2_SQL_UNITTEST_CORE  #include <commonObjects.h> +#include <variableType.h>  class TestCore : public CommonObjects {  	public:  		TestCore(); + +		int testInt; +		double testDouble; +		std::string testString; +		boost::posix_time::ptime testDateTime; +		boost::posix_time::time_duration testInterval;  };  #endif diff --git a/project2/sql/unittests/testpq.cpp b/project2/sql/unittests/testpq.cpp index 434a184..9218612 100644 --- a/project2/sql/unittests/testpq.cpp +++ b/project2/sql/unittests/testpq.cpp @@ -4,8 +4,11 @@  #include <mockDatasource.h>  #include <definedDirs.h>  #include <modifycommand.h> +#include <selectcommand.h> +#include <column.h>  #include <sql-modPQ.h>  #include "testCore.h" +#include <sqlHandleAsVariableType.h>  class StandardMockDatabase : public MockPqDatabase {  	public: @@ -44,17 +47,48 @@ BOOST_AUTO_TEST_CASE( bindAndSend )  	auto rw = ds->getWritable();  	auto mod = rw->newModifyCommand("INSERT INTO test VALUES(?, ?, ?, ?, ?, ?)"); -	mod->bindParamI(0, 12); -	mod->bindParamF(1, 3.14); -	mod->bindParamS(2, "C String"); -	mod->bindParamT(3, boost::posix_time::from_time_t(time(NULL))); +	mod->bindParamI(0, testInt); +	mod->bindParamF(1, testDouble); +	mod->bindParamS(2, testString); +	mod->bindParamT(3, testDateTime); +	mod->bindParamT(5, testInterval);  	mod->bindNull(4); -	mod->bindNull(5);  	mod->execute();  	delete mod;  	ds->commit();  	ds->close();  } +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>("pqmock"); +	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, testDateTime); +		assertColumnValueHelper(*select, 5, testInterval); +		rows += 1; +	} +	delete select; +	BOOST_REQUIRE_EQUAL(1, rows); +	ds->close(); +} +  BOOST_AUTO_TEST_SUITE_END();  | 
