diff --git a/Data/MySQL/testsuite/src/MySQLTest.cpp b/Data/MySQL/testsuite/src/MySQLTest.cpp index 1ab1f59a6..a61f0377a 100644 --- a/Data/MySQL/testsuite/src/MySQLTest.cpp +++ b/Data/MySQL/testsuite/src/MySQLTest.cpp @@ -13,6 +13,7 @@ #include "MySQLTest.h" #include "CppUnit/TestCaller.h" #include "CppUnit/TestSuite.h" +#include "Poco/Environment.h" #include "Poco/String.h" #include "Poco/Format.h" #include "Poco/Tuple.h" @@ -33,6 +34,7 @@ using Poco::Data::MySQL::ConnectionException; using Poco::Data::MySQL::Utility; using Poco::Data::MySQL::StatementException; using Poco::format; +using Poco::Environment; using Poco::NotFoundException; using Poco::Int32; using Poco::Nullable; @@ -44,21 +46,37 @@ Poco::SharedPtr MySQLTest::_pExecutor = 0; // // Parameters for barebone-test -#define MYSQL_USER "root" -#define MYSQL_PWD "poco" -#define MYSQL_HOST "localhost" -#define MYSQL_PORT 3306 -#define MYSQL_DB "pocotestdb" + +std::string MySQLTest::getHost() +{ + return "localhost"; +} +std::string MySQLTest::getPort() +{ + return "3306"; +} +std::string MySQLTest::getUser() +{ + return "root"; +} +std::string MySQLTest::getPass() +{ + if (Environment::has("APPVEYOR")) + return "Password12!"; + else + return "poco"; +} +std::string MySQLTest::getBase() +{ + return "pocotestdb"; +} + +std::string MySQLTest::_dbConnString; + + // // Connection string -std::string MySQLTest::_dbConnString = "host=" MYSQL_HOST - ";user=" MYSQL_USER - ";password=" MYSQL_PWD - ";db=" MYSQL_DB - ";compress=true" - ";auto-reconnect=true" - ";secure-auth=true"; MySQLTest::MySQLTest(const std::string& name): @@ -84,17 +102,18 @@ void MySQLTest::dbInfo(Session& session) void MySQLTest::connectNoDB() { - std::string dbConnString = "host=" MYSQL_HOST - ";user=" MYSQL_USER - ";password=" MYSQL_PWD - ";compress=true;auto-reconnect=true"; + std::string dbConnString; + dbConnString = "host=" + getHost(); + dbConnString += ";user=" + getUser(); + dbConnString += ";password=" + getPass(); + dbConnString += ";compress=true;auto-reconnect=true"; try { Session session(MySQL::Connector::KEY, dbConnString); std::cout << "Connected to [" << "MySQL" << "] without database." << std::endl; dbInfo(session); - session << "CREATE DATABASE IF NOT EXISTS " MYSQL_DB ";", now; + session << "CREATE DATABASE IF NOT EXISTS " + getBase() + ";", now; std::cout << "Disconnecting ..." << std::endl; session.close(); std::cout << "Disconnected." << std::endl; @@ -117,7 +136,7 @@ void MySQLTest::testBareboneMySQL() "Fourth INTEGER," "Fifth FLOAT)"; - _pExecutor->bareboneMySQLTest(MYSQL_HOST, MYSQL_USER, MYSQL_PWD, MYSQL_DB, MYSQL_PORT, tableCreateString.c_str()); + _pExecutor->bareboneMySQLTest(getHost(), getUser(), getPass(), getBase(), getPort(), tableCreateString.c_str()); } @@ -837,6 +856,14 @@ CppUnit::Test* MySQLTest::suite() { MySQL::Connector::registerConnector(); + _dbConnString = "host=" + getHost(); + _dbConnString += ";user=" + getUser(); + _dbConnString += ";password=" + getPass(); + _dbConnString += ";db=" + getBase(); + _dbConnString += ";compress=true"; + _dbConnString += ";auto-reconnect=true"; + _dbConnString += ";secure-auth=true"; + try { _pSession = new Session(MySQL::Connector::KEY, _dbConnString); diff --git a/Data/MySQL/testsuite/src/MySQLTest.h b/Data/MySQL/testsuite/src/MySQLTest.h index d3eea4a65..af3f3a6a3 100644 --- a/Data/MySQL/testsuite/src/MySQLTest.h +++ b/Data/MySQL/testsuite/src/MySQLTest.h @@ -128,6 +128,11 @@ private: static void dbInfo(Poco::Data::Session& session); + static std::string getHost(); + static std::string getPort(); + static std::string getUser(); + static std::string getPass(); + static std::string getBase(); static std::string _dbConnString; static Poco::SharedPtr _pSession; static Poco::SharedPtr _pExecutor; diff --git a/Data/MySQL/testsuite/src/SQLExecutor.cpp b/Data/MySQL/testsuite/src/SQLExecutor.cpp index 00cfb351f..f2814d1bb 100644 --- a/Data/MySQL/testsuite/src/SQLExecutor.cpp +++ b/Data/MySQL/testsuite/src/SQLExecutor.cpp @@ -27,10 +27,6 @@ #include "Poco/Data/MySQL/Connector.h" #include "Poco/Data/MySQL/MySQLException.h" -#ifdef _WIN32 -#include -#endif - #include #include #include @@ -155,13 +151,13 @@ SQLExecutor::~SQLExecutor() } -void SQLExecutor::bareboneMySQLTest(const char* host, const char* user, const char* pwd, const char* db, int port, const char* tableCreateString) +void SQLExecutor::bareboneMySQLTest(const std::string& host, const std::string& user, const std::string& pwd, const std::string& db, const std::string& port, const char* tableCreateString) { int rc; MYSQL* hsession = mysql_init(0); assert (hsession != 0); - MYSQL* tmp = mysql_real_connect(hsession, host, user, pwd, db, port, 0, 0); + MYSQL* tmp = mysql_real_connect(hsession, host.c_str(), user.c_str(), pwd.c_str(), db.c_str(), stoi(port), 0, 0); assert(tmp == hsession); MYSQL_STMT* hstmt = mysql_stmt_init(hsession); diff --git a/Data/MySQL/testsuite/src/SQLExecutor.h b/Data/MySQL/testsuite/src/SQLExecutor.h index e39baf81c..9a19eb2e3 100644 --- a/Data/MySQL/testsuite/src/SQLExecutor.h +++ b/Data/MySQL/testsuite/src/SQLExecutor.h @@ -38,7 +38,7 @@ public: SQLExecutor(const std::string& name, Poco::Data::Session* _pSession); ~SQLExecutor(); - void bareboneMySQLTest(const char* host, const char* user, const char* pwd, const char* db, int port, const char* tableCreateString); + void bareboneMySQLTest(const std::string& host, const std::string& user, const std::string& pwd, const std::string& db, const std::string& port, const char* tableCreateString); /// This function uses "bare bone" MySQL API calls (i.e. calls are not /// "wrapped" in PocoData framework structures). /// The purpose of the function is to verify that driver behaves diff --git a/appveyor.yml b/appveyor.yml index da63465f8..0d4393a12 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -330,10 +330,16 @@ build_script: } before_test: +# ------------------------------------------------------------------------------------------- +# MySQL + - ps: | + $env:MYSQL_PWD="Password12!" + $cmd = 'mysql -e "create database pocotestdb;" --user=root'; + iex "& $cmd" + # ------------------------------------------------------------------------------------------- # PostgreSQL - set PATH=C:\Program Files\PostgreSQL\9.4\bin\;%PATH% -# ------------------------------------------------------------------------------------------- - ps: | $line='-------------------------------------------------------------------------------------'; @@ -352,6 +358,7 @@ before_test: after_test: + test_script: - ps: | $runs=0;$fails=0;$failedTests='';$status=0;$tab="`t"; @@ -364,12 +371,12 @@ test_script: if ($env:platform -eq "Win32") { $env:PATH = "$env:POCO_BASE\bin;" + $env:PATH;$suffix = ''; - $excluded = @('Data', 'Data/MySQL', 'Data/ODBC','Data/PostgreSQL', 'Redis', 'PDF') + $excluded = @('Data', 'Data/ODBC','Data/PostgreSQL', 'Redis', 'PDF') } if ($env:platform -eq "x64") { $env:PATH = "$env:POCO_BASE\bin64;" + $env:PATH;$suffix = 64; - $excluded = @('Data', 'Data/MySQL', 'Data/ODBC','Redis', 'PDF') + $excluded = @('Data', 'Data/ODBC','Redis', 'PDF') } Write-Host -ForegroundColor Yellow '>>> current directory is ' $(get-location).Path;