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

@@ -1,25 +1,26 @@
# #
# Makefile # Makefile
# #
# $Id: //poco/Main/Data/ODBC/testsuite/Makefile#1 $ # $Id: //poco/Main/Data/ODBC/testsuite/Makefile#1 $
# #
# Makefile for Poco SQLite testsuite # Makefile for Poco SQLite testsuite
# #
include $(POCO_BASE)/build/rules/global include $(POCO_BASE)/build/rules/global
ifeq ($(OSNAME),Darwin) ifeq ($(OSNAME),Darwin)
SYSLIBS += -liodbc -liodbcinst SYSLIBS += -liodbc -liodbcinst
else else
SYSLIBS += -lodbc -lodbcinst SYSLIBS += -lodbc -lodbcinst
endif endif
objects = ODBCTestSuite Driver \ objects = ODBCTestSuite Driver \
ODBCDB2Test ODBCMySQLTest ODBCOracleTest \ ODBCDB2Test ODBCMySQLTest ODBCOracleTest \
ODBCPostgreSQLTest ODBCSQLiteTest SQLExecutor ODBCPostgreSQLTest ODBCSQLiteTest ODBCSQLServerTest \
SQLExecutor
target = testrunner
target_version = 1 target = testrunner
target_libs = PocoODBC PocoData PocoFoundation CppUnit target_version = 1
target_libs = PocoODBC PocoData PocoFoundation CppUnit
include $(POCO_BASE)/build/rules/exec
include $(POCO_BASE)/build/rules/exec

View File

@@ -139,12 +139,12 @@ void ODBCAccessTest::recreatePersonTable()
} }
bool ODBCAccessTest::checkODBCSetup(const std::string& dbName) bool ODBCAccessTest::canConnect(const std::string& driver, const std::string& dsn)
{ {
Utility::DriverMap::iterator itDrv = _drivers.begin(); Utility::DriverMap::iterator itDrv = _drivers.begin();
for (; itDrv != _drivers.end(); ++itDrv) 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 std::cout << "Driver found: " << itDrv->first
<< " (" << itDrv->second << ')' << std::endl; << " (" << itDrv->second << ')' << std::endl;
@@ -154,11 +154,26 @@ bool ODBCAccessTest::checkODBCSetup(const std::string& dbName)
if (_drivers.end() == itDrv) 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; return false;
} }
_dbConnString = "DRIVER=Microsoft Access Driver (*.mdb);" 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;"
"UID=admin;" "UID=admin;"
"UserCommitSync=Yes;" "UserCommitSync=Yes;"
"Threads=3;" "Threads=3;"
@@ -168,8 +183,7 @@ bool ODBCAccessTest::checkODBCSetup(const std::string& dbName)
"MaxBufferSize=2048;" "MaxBufferSize=2048;"
"FIL=MS Access;" "FIL=MS Access;"
"DriverId=25;" "DriverId=25;"
"DefaultDir=C:\\;" "DBQ=test.mdb;", driver);
"DBQ=C:\\test.mdb;";
return true; return true;
} }
@@ -186,10 +200,10 @@ void ODBCAccessTest::tearDown()
} }
bool ODBCAccessTest::init(const std::string& dbName) bool ODBCAccessTest::init(const std::string& driver, const std::string& dsn)
{ {
Utility::drivers(_drivers); Utility::drivers(_drivers);
if (!checkODBCSetup()) return false; if (!canConnect(driver, dsn)) return false;
ODBC::Connector::registerConnector(); ODBC::Connector::registerConnector();
try try
@@ -202,7 +216,7 @@ bool ODBCAccessTest::init(const std::string& dbName)
} }
//N.B. Access driver does not suport check for connection. //N.B. Access driver does not suport check for connection.
std::cout << "*** Connected to " << dbName << std::endl; std::cout << "*** Connected to [" << driver << "] test database." << std::endl;
return true; return true;
} }
@@ -210,7 +224,7 @@ bool ODBCAccessTest::init(const std::string& dbName)
CppUnit::Test* ODBCAccessTest::suite() CppUnit::Test* ODBCAccessTest::suite()
{ {
if (init()) if (init("Microsoft Access Driver (*.mdb)", "PocoDataAccessTest"))
{ {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCAccessTest"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCAccessTest");

View File

@@ -67,8 +67,8 @@ private:
void dropTable(const std::string& tableName); void dropTable(const std::string& tableName);
void recreatePersonTable(); void recreatePersonTable();
static bool init(const std::string& dbName = "Microsoft Access Driver"); static bool init(const std::string& driver, const std::string& dsn);
static bool checkODBCSetup(const std::string& dbName = "Microsoft Access Driver"); static bool canConnect(const std::string& driver, const std::string& dsn);
static Poco::Data::ODBC::Utility::DriverMap _drivers; static Poco::Data::ODBC::Utility::DriverMap _drivers;
static std::string _dbConnString; static std::string _dbConnString;

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(); Utility::DriverMap::iterator itDrv = _drivers.begin();
for (; itDrv != _drivers.end(); ++itDrv) 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 std::cout << "Driver found: " << itDrv->first
<< " (" << itDrv->second << ')' << std::endl; << " (" << itDrv->second << ')' << std::endl;
@@ -814,11 +814,32 @@ bool ODBCDB2Test::checkODBCSetup(const std::string& dbName)
if (_drivers.end() == itDrv) 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; 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; 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); Utility::drivers(_drivers);
if (!checkODBCSetup()) return false; if (!canConnect(driver, dsn)) return false;
ODBC::Connector::registerConnector(); ODBC::Connector::registerConnector();
try try
@@ -852,9 +873,9 @@ bool ODBCDB2Test::init(const std::string& dbName)
} }
if (_pSession && _pSession->isConnected()) 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; return true;
} }
@@ -862,7 +883,7 @@ bool ODBCDB2Test::init(const std::string& dbName)
CppUnit::Test* ODBCDB2Test::suite() CppUnit::Test* ODBCDB2Test::suite()
{ {
if (init()) if (init("IBM DB2 ODBC DRIVER - DB2COPY1", "PocoDataDB2Test"))
{ {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCDB2Test"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCDB2Test");

View File

@@ -120,8 +120,8 @@ private:
void recreateTuplesTable(); void recreateTuplesTable();
void recreateVectorsTable(); void recreateVectorsTable();
static bool init(const std::string& dbName = "IBM DB2"); static bool init(const std::string& driver, const std::string& dsn);
static bool checkODBCSetup(const std::string& dbName = "IBM DB2"); static bool canConnect(const std::string& driver, const std::string& dsn);
static Poco::Data::ODBC::Utility::DriverMap _drivers; static Poco::Data::ODBC::Utility::DriverMap _drivers;
static std::string _dbConnString; static std::string _dbConnString;

View File

@@ -788,12 +788,12 @@ void ODBCMySQLTest::recreateVectorsTable()
} }
bool ODBCMySQLTest::checkODBCSetup(const std::string& dbName) bool ODBCMySQLTest::canConnect(const std::string& driver, const std::string& dsn)
{ {
Utility::DriverMap::iterator itDrv = _drivers.begin(); Utility::DriverMap::iterator itDrv = _drivers.begin();
for (; itDrv != _drivers.end(); ++itDrv) 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 std::cout << "Driver found: " << itDrv->first
<< " (" << itDrv->second << ')' << std::endl; << " (" << itDrv->second << ')' << std::endl;
@@ -803,15 +803,30 @@ bool ODBCMySQLTest::checkODBCSetup(const std::string& dbName)
if (_drivers.end() == itDrv) 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; return false;
} }
_dbConnString = "DRIVER=MySQL ODBC 3.51 Driver;" 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=test;" "DATABASE=test;"
"SERVER=localhost;" "SERVER=localhost;"
"UID=root;" "UID=root;"
"PWD=mysql;"; "PWD=mysql;", driver);
return true; return true;
} }
@@ -829,10 +844,10 @@ void ODBCMySQLTest::tearDown()
} }
bool ODBCMySQLTest::init(const std::string& dbName) bool ODBCMySQLTest::init(const std::string& driver, const std::string& dsn)
{ {
Utility::drivers(_drivers); Utility::drivers(_drivers);
if (!checkODBCSetup()) return false; if (!canConnect(driver, dsn)) return false;
ODBC::Connector::registerConnector(); ODBC::Connector::registerConnector();
try try
@@ -845,9 +860,9 @@ bool ODBCMySQLTest::init(const std::string& dbName)
} }
if (_pSession && _pSession->isConnected()) 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; return true;
} }
@@ -855,7 +870,7 @@ bool ODBCMySQLTest::init(const std::string& dbName)
CppUnit::Test* ODBCMySQLTest::suite() CppUnit::Test* ODBCMySQLTest::suite()
{ {
if (init()) if (init("MySQL ODBC 3.51 Driver", "PocoDataMySQLTest"))
{ {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCMySQLTest"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCMySQLTest");

View File

@@ -122,8 +122,8 @@ private:
void recreateTuplesTable(); void recreateTuplesTable();
void recreateVectorsTable(); void recreateVectorsTable();
static bool checkODBCSetup(const std::string& dbName = "MySQL"); static bool init(const std::string& driver, const std::string& dsn);
static bool init(const std::string& dbName = "MySQL"); static bool canConnect(const std::string& driver, const std::string& dsn);
static Poco::Data::ODBC::Utility::DriverMap _drivers; static Poco::Data::ODBC::Utility::DriverMap _drivers;
static std::string _dbConnString; static std::string _dbConnString;

View File

@@ -796,12 +796,12 @@ void ODBCOracleTest::recreateVectorsTable()
} }
bool ODBCOracleTest::checkODBCSetup(const std::string& dbName) bool ODBCOracleTest::canConnect(const std::string& driver, const std::string& dsn)
{ {
Utility::DriverMap::iterator itDrv = _drivers.begin(); Utility::DriverMap::iterator itDrv = _drivers.begin();
for (; itDrv != _drivers.end(); ++itDrv) 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 std::cout << "Driver found: " << itDrv->first
<< " (" << itDrv->second << ')' << std::endl; << " (" << itDrv->second << ')' << std::endl;
@@ -811,11 +811,54 @@ bool ODBCOracleTest::checkODBCSetup(const std::string& dbName)
if (_drivers.end() == itDrv) 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; return false;
} }
_dbConnString = "DSN=PocoDataOracleTest;Uid=Scott;Pwd=Tiger;"; 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};"
"UID=Scott;"
"PWD=Tiger;"
"TLO=O;"
"FBS=60000;"
"FWC=F;"
"CSR=F;"
"MDI=Me;"
"MTS=T;"
"DPM=F;"
"NUM=NLS;"
"BAM=IfAllSuccessful;"
"BTD=F;"
"RST=T;"
"LOB=T;"
"FDL=10;"
"FRC=10;"
"QTO=T;"
"FEN=T;"
"XSM=Default;"
"EXC=F;"
"APA=T;"
"DBA=W;"
"DBQ=XE;"
"SERVER="
"(DESCRIPTION="
" (ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))"
" (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XE))"
");", driver);
return true; return true;
} }
@@ -833,10 +876,10 @@ void ODBCOracleTest::tearDown()
} }
bool ODBCOracleTest::init(const std::string& dbName) bool ODBCOracleTest::init(const std::string& driver, const std::string& dsn)
{ {
Utility::drivers(_drivers); Utility::drivers(_drivers);
if (!checkODBCSetup()) return false; if (!canConnect(driver, dsn)) return false;
ODBC::Connector::registerConnector(); ODBC::Connector::registerConnector();
try try
@@ -849,9 +892,9 @@ bool ODBCOracleTest::init(const std::string& dbName)
} }
if (_pSession && _pSession->isConnected()) 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; return true;
} }
@@ -859,7 +902,7 @@ bool ODBCOracleTest::init(const std::string& dbName)
CppUnit::Test* ODBCOracleTest::suite() CppUnit::Test* ODBCOracleTest::suite()
{ {
if (init()) if (init("Oracle in XE", "PocoDataOracleTest"))
{ {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCOracleTest"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCOracleTest");

View File

@@ -121,8 +121,8 @@ private:
void recreateTuplesTable(); void recreateTuplesTable();
void recreateVectorsTable(); void recreateVectorsTable();
static bool checkODBCSetup(const std::string& dbName = "Oracle"); static bool init(const std::string& driver, const std::string& dsn);
static bool init(const std::string& dbName = "Oracle"); static bool canConnect(const std::string& driver, const std::string& dsn);
static Poco::Data::ODBC::Utility::DriverMap _drivers; static Poco::Data::ODBC::Utility::DriverMap _drivers;
static std::string _dbConnString; static std::string _dbConnString;

View File

@@ -782,12 +782,12 @@ void ODBCPostgreSQLTest::recreateVectorsTable()
} }
bool ODBCPostgreSQLTest::checkODBCSetup(const std::string& dbName) bool ODBCPostgreSQLTest::canConnect(const std::string& driver, const std::string& dsn)
{ {
Utility::DriverMap::iterator itDrv = _drivers.begin(); Utility::DriverMap::iterator itDrv = _drivers.begin();
for (; itDrv != _drivers.end(); ++itDrv) 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 std::cout << "Driver found: " << itDrv->first
<< " (" << itDrv->second << ')' << std::endl; << " (" << itDrv->second << ')' << std::endl;
@@ -797,11 +797,26 @@ bool ODBCPostgreSQLTest::checkODBCSetup(const std::string& dbName)
if (_drivers.end() == itDrv) 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; return false;
} }
_dbConnString = "DRIVER=PostgreSQL ANSI;" 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=postgres;" "DATABASE=postgres;"
"SERVER=localhost;" "SERVER=localhost;"
"PORT=5432;" "PORT=5432;"
@@ -836,7 +851,7 @@ bool ODBCPostgreSQLTest::checkODBCSetup(const std::string& dbName)
"RowVersioning=0;" "RowVersioning=0;"
"ShowOidColumn=0;" "ShowOidColumn=0;"
"FakeOidIndex=0;" "FakeOidIndex=0;"
"ReadOnly=0;"; "ReadOnly=0;", driver);
return true; return true;
} }
@@ -854,10 +869,10 @@ void ODBCPostgreSQLTest::tearDown()
} }
bool ODBCPostgreSQLTest::init(const std::string& dbName) bool ODBCPostgreSQLTest::init(const std::string& driver, const std::string& dsn)
{ {
Utility::drivers(_drivers); Utility::drivers(_drivers);
if (!checkODBCSetup()) return false; if (!canConnect(driver, dsn)) return false;
ODBC::Connector::registerConnector(); ODBC::Connector::registerConnector();
try try
@@ -870,9 +885,9 @@ bool ODBCPostgreSQLTest::init(const std::string& dbName)
} }
if (_pSession && _pSession->isConnected()) 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; return true;
} }
@@ -880,7 +895,7 @@ bool ODBCPostgreSQLTest::init(const std::string& dbName)
CppUnit::Test* ODBCPostgreSQLTest::suite() CppUnit::Test* ODBCPostgreSQLTest::suite()
{ {
if (init()) if (init("PostgreSQL ANSI", "PocoDataPostgreSQLTest"))
{ {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCPostgreSQLTest"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCPostgreSQLTest");

View File

@@ -122,8 +122,8 @@ private:
void recreateTuplesTable(); void recreateTuplesTable();
void recreateVectorsTable(); void recreateVectorsTable();
static bool init(const std::string& dbName = "PostgreSQL"); static bool init(const std::string& driver, const std::string& dsn);
static bool checkODBCSetup(const std::string& dbName = "PostgreSQL"); static bool canConnect(const std::string& driver, const std::string& dsn);
static Poco::Data::ODBC::Utility::DriverMap _drivers; static Poco::Data::ODBC::Utility::DriverMap _drivers;
static std::string _dbConnString; static std::string _dbConnString;

View File

@@ -809,12 +809,12 @@ void ODBCSQLServerTest::recreateVectorsTable()
} }
bool ODBCSQLServerTest::checkODBCSetup(const std::string& dbName) bool ODBCSQLServerTest::canConnect(const std::string& driver, const std::string& dsn)
{ {
Utility::DriverMap::iterator itDrv = _drivers.begin(); Utility::DriverMap::iterator itDrv = _drivers.begin();
for (; itDrv != _drivers.end(); ++itDrv) 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 std::cout << "Driver found: " << itDrv->first
<< " (" << itDrv->second << ')' << std::endl; << " (" << itDrv->second << ')' << std::endl;
@@ -824,15 +824,30 @@ bool ODBCSQLServerTest::checkODBCSetup(const std::string& dbName)
if (_drivers.end() == itDrv) 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; return false;
} }
_dbConnString = "DRIVER=SQL Server;" 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;"
"UID=test;" "UID=test;"
"PWD=test;" "PWD=test;"
"DATABASE=test;" "DATABASE=test;"
"SERVER=(local);"; "SERVER=(local);", driver);
return true; return true;
} }
@@ -850,10 +865,10 @@ void ODBCSQLServerTest::tearDown()
} }
bool ODBCSQLServerTest::init(const std::string& dbName) bool ODBCSQLServerTest::init(const std::string& driver, const std::string& dsn)
{ {
Utility::drivers(_drivers); Utility::drivers(_drivers);
if (!checkODBCSetup()) return false; if (!canConnect(driver, dsn)) return false;
ODBC::Connector::registerConnector(); ODBC::Connector::registerConnector();
try try
@@ -866,9 +881,9 @@ bool ODBCSQLServerTest::init(const std::string& dbName)
} }
if (_pSession && _pSession->isConnected()) 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; return true;
} }
@@ -876,7 +891,7 @@ bool ODBCSQLServerTest::init(const std::string& dbName)
CppUnit::Test* ODBCSQLServerTest::suite() CppUnit::Test* ODBCSQLServerTest::suite()
{ {
if (init()) if (init("SQL Server", "PocoDataSQLServerTest"))
{ {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCSQLServerTest"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCSQLServerTest");

View File

@@ -124,8 +124,8 @@ private:
void recreateVectorTable(); void recreateVectorTable();
void recreateVectorsTable(); void recreateVectorsTable();
static bool checkODBCSetup(const std::string& dbName = "SQL Server"); static bool init(const std::string& driver, const std::string& dsn);
static bool init(const std::string& dbName = "SQL Server"); static bool canConnect(const std::string& driver, const std::string& dsn);
static Poco::Data::ODBC::Utility::DriverMap _drivers; static Poco::Data::ODBC::Utility::DriverMap _drivers;
static std::string _dbConnString; static std::string _dbConnString;

View File

@@ -778,12 +778,12 @@ void ODBCSQLiteTest::recreateVectorsTable()
} }
bool ODBCSQLiteTest::checkODBCSetup(const std::string& dbName) bool ODBCSQLiteTest::canConnect(const std::string& driver, const std::string& dsn)
{ {
Utility::DriverMap::iterator itDrv = _drivers.begin(); Utility::DriverMap::iterator itDrv = _drivers.begin();
for (; itDrv != _drivers.end(); ++itDrv) 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 std::cout << "Driver found: " << itDrv->first
<< " (" << itDrv->second << ')' << std::endl; << " (" << itDrv->second << ')' << std::endl;
@@ -793,11 +793,26 @@ bool ODBCSQLiteTest::checkODBCSetup(const std::string& dbName)
if (_drivers.end() == itDrv) 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; return false;
} }
_dbConnString = "Driver=SQLite3 ODBC Driver;Database=dummy.db;"; 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=dummy.db;", driver);
return true; return true;
} }
@@ -815,10 +830,10 @@ void ODBCSQLiteTest::tearDown()
} }
bool ODBCSQLiteTest::init(const std::string& dbName) bool ODBCSQLiteTest::init(const std::string& driver, const std::string& dsn)
{ {
Utility::drivers(_drivers); Utility::drivers(_drivers);
if (!checkODBCSetup()) return false; if (!canConnect(driver, dsn)) return false;
ODBC::Connector::registerConnector(); ODBC::Connector::registerConnector();
try try
@@ -831,9 +846,9 @@ bool ODBCSQLiteTest::init(const std::string& dbName)
} }
if (_pSession && _pSession->isConnected()) 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; return true;
} }
@@ -841,7 +856,7 @@ bool ODBCSQLiteTest::init(const std::string& dbName)
CppUnit::Test* ODBCSQLiteTest::suite() CppUnit::Test* ODBCSQLiteTest::suite()
{ {
if (init()) if (init("SQLite3 ODBC Driver", "PocoDataSQLiteTest"))
{ {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCSQLiteTest"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCSQLiteTest");

View File

@@ -120,8 +120,8 @@ private:
void recreateTuplesTable(); void recreateTuplesTable();
void recreateVectorsTable(); void recreateVectorsTable();
static bool checkODBCSetup(const std::string& dbName = "SQLite3"); static bool init(const std::string& driver, const std::string& dsn);
static bool init(const std::string& dbName = "SQLite3"); static bool canConnect(const std::string& driver, const std::string& dsn);
static Poco::Data::ODBC::Utility::DriverMap _drivers; static Poco::Data::ODBC::Utility::DriverMap _drivers;
static std::string _dbConnString; static std::string _dbConnString;

View File

@@ -67,8 +67,10 @@ CppUnit::Test* ODBCTestSuite::suite()
addTest(pSuite, ODBCDB2Test::suite()); addTest(pSuite, ODBCDB2Test::suite());
addTest(pSuite, ODBCMySQLTest::suite()); addTest(pSuite, ODBCMySQLTest::suite());
addTest(pSuite, ODBCSQLiteTest::suite()); addTest(pSuite, ODBCSQLiteTest::suite());
addTest(pSuite, ODBCAccessTest::suite());
addTest(pSuite, ODBCSQLServerTest::suite()); addTest(pSuite, ODBCSQLServerTest::suite());
#if defined(POCO_OS_FAMILY_WINDOWS)
addTest(pSuite, ODBCAccessTest::suite());
#endif
return pSuite; return pSuite;
} }