Tidying up the tests

This commit is contained in:
Aleksandar Fabijanic
2007-05-23 01:06:46 +00:00
parent 2fe37eab6f
commit 418bb651c1
16 changed files with 248 additions and 107 deletions

View File

@@ -799,12 +799,12 @@ void ODBCDB2Test::recreateVectorsTable()
}
bool ODBCDB2Test::checkODBCSetup(const std::string& dbName)
bool ODBCDB2Test::canConnect(const std::string& driver, const std::string& dsn)
{
Utility::DriverMap::iterator itDrv = _drivers.begin();
for (; itDrv != _drivers.end(); ++itDrv)
{
if (((itDrv->first).find(dbName) != std::string::npos))
if (((itDrv->first).find(driver) != std::string::npos))
{
std::cout << "Driver found: " << itDrv->first
<< " (" << itDrv->second << ')' << std::endl;
@@ -814,11 +814,32 @@ bool ODBCDB2Test::checkODBCSetup(const std::string& dbName)
if (_drivers.end() == itDrv)
{
std::cout << dbName << " driver NOT found, tests not available." << std::endl;
std::cout << driver << " driver NOT found, tests not available." << std::endl;
return false;
}
_dbConnString = "DSN=PocoDataDB2Test;Uid=db2admin;Pwd=db2admin;";
Utility::DSNMap dataSources;
Utility::dataSources(dataSources);
Utility::DSNMap::iterator itDSN = dataSources.begin();
for (; itDSN != dataSources.end(); ++itDSN)
{
if (itDSN->first == dsn && itDSN->second == driver)
{
std::cout << "DSN found: " << itDSN->first
<< " (" << itDSN->second << ')' << std::endl;
format(_dbConnString, "DSN=%s", dsn);
return true;
}
}
// DSN not found, try connect without it
format(_dbConnString, "Driver=%s;"
"Database=POCOTEST;"
"Hostname=localhost;"
"Port=50000;"
"Protocol=TCPIP;"
"Uid=db2admin;"
"Pwd=db2admin;", driver);
return true;
}
@@ -836,10 +857,10 @@ void ODBCDB2Test::tearDown()
}
bool ODBCDB2Test::init(const std::string& dbName)
bool ODBCDB2Test::init(const std::string& driver, const std::string& dsn)
{
Utility::drivers(_drivers);
if (!checkODBCSetup()) return false;
if (!canConnect(driver, dsn)) return false;
ODBC::Connector::registerConnector();
try
@@ -852,9 +873,9 @@ bool ODBCDB2Test::init(const std::string& dbName)
}
if (_pSession && _pSession->isConnected())
std::cout << "*** Connected to " << dbName << " test database." << std::endl;
std::cout << "*** Connected to [" << driver << "] test database." << std::endl;
_pExecutor = new SQLExecutor(dbName + " SQL Executor", _pSession);
_pExecutor = new SQLExecutor(driver + " SQL Executor", _pSession);
return true;
}
@@ -862,7 +883,7 @@ bool ODBCDB2Test::init(const std::string& dbName)
CppUnit::Test* ODBCDB2Test::suite()
{
if (init())
if (init("IBM DB2 ODBC DRIVER - DB2COPY1", "PocoDataDB2Test"))
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCDB2Test");