Skip to content

Commit 720ab0b

Browse files
committed
FIX UT on windows (sql.properties file not found)
Add tests_config.h.in to allow CMAKE parameter tests (Server, User, Pass and DB) and also define sql.properties path.
1 parent 12528e6 commit 720ab0b

File tree

5 files changed

+75
-25
lines changed

5 files changed

+75
-25
lines changed

test/CJUnitTestsPort/BaseTestFixture.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
33
44
The MySQL Connector/C++ is licensed under the terms of the GPLv2
55
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -29,27 +29,23 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2929

3030
#include "BaseTestFixture.h"
3131
#include "../common/stringutils.h"
32+
#include "tests_config.h"
3233

3334
namespace testsuite
3435
{
35-
static const String defaultHost= _T("127.0.0.1");
36-
static const String defaultPort= _T("3306");
37-
static const String defaultDb= _T("test");
38-
static const String defaultLogin= _T("root");
39-
static const String defaultPasswd= _T("root");
36+
37+
static const String defaultHost= _T(TEST_DEFAULT_HOST);
38+
static const String defaultDb= _T(TEST_DEFAULT_DB);
39+
static const String defaultLogin= _T(TEST_DEFAULT_LOGIN);
40+
static const String defaultPasswd= _T(TEST_DEFAULT_PASSWD);
4041

4142
int TestFixtureCommon::instanceCount=1;
4243

4344
Properties TestFixtureCommon::sqlProps;
4445

45-
static const char * possiblePropertiesLocations[]={".."
46-
, "test/CJUnitTestsPort"
47-
, NULL //last should be NULL
48-
};
49-
50-
int TestFixtureCommon::propsLoaded=resources::LoadProperties("sql.properties"
46+
int TestFixtureCommon::propsLoaded=resources::LoadProperties(SQL_PROPERTIES_FILE
5147
, sqlProps
52-
, possiblePropertiesLocations);
48+
, NULL);
5349

5450
Driver * TestFixtureCommon::driver=NULL;
5551

@@ -739,7 +735,7 @@ void BaseTestFixture::setUp()
739735
} else
740736
{*/
741737
String tmp( "Connected to " );
742-
DatabaseMetaData meta(this->conn->getMetaData());
738+
DatabaseMetaData meta(this->conn->getMetaData());
743739
tmp.append( meta->getDatabaseProductName() );
744740
tmp.append( " / " );
745741
tmp.append( meta->getDatabaseProductVersion() );

test/CJUnitTestsPort/ccpptests.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
33
44
The MySQL Connector/C++ is licensed under the terms of the GPLv2
55
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2929
#include "../framework/test_tapOutputter.h"
3030
#include "../framework/test_filter.h"
3131
#include <stdlib.h>
32+
#include "tests_config.h"
3233

3334
int main(int argc, char** argv)
3435
{
@@ -40,10 +41,10 @@ int main(int argc, char** argv)
4041

4142
Properties defaultStringValues;
4243

43-
defaultStringValues.insert( Properties::value_type( "dbUrl" , "tcp://127.0.0.1:3306" ) );
44-
defaultStringValues.insert( Properties::value_type( "dbUser" , "root" ) );
45-
defaultStringValues.insert( Properties::value_type( "dbPasswd", "root" ) );
46-
defaultStringValues.insert( Properties::value_type( "dbSchema", "test" ) );
44+
defaultStringValues.insert( Properties::value_type( "dbUrl" , TEST_DEFAULT_HOST ) );
45+
defaultStringValues.insert( Properties::value_type( "dbUser" , TEST_DEFAULT_LOGIN ) );
46+
defaultStringValues.insert( Properties::value_type( "dbPasswd", TEST_DEFAULT_PASSWD) );
47+
defaultStringValues.insert( Properties::value_type( "dbSchema", TEST_DEFAULT_DB ) );
4748
defaultStringValues.insert( Properties::value_type( "filter" , "" ) );
4849

4950
std::map<String, bool> defaultBoolValues;

test/CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
33
#
44
# The MySQL Connector/C++ is licensed under the terms of the GPLv2
55
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -22,6 +22,22 @@
2222
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323
#
2424

25+
26+
#Use Options to configure default test server params
27+
28+
SET(TEST_DEFAULT_HOST "tcp://localhost:3306" CACHE STRING "Defines Unit Tests default server" )
29+
SET(TEST_DEFAULT_DB "test" CACHE STRING "Defines Unit Tests default Database" )
30+
SET(TEST_DEFAULT_LOGIN "root" CACHE STRING "Defines Unit Tests default login user" )
31+
SET(TEST_DEFAULT_PASSWD "root" CACHE STRING "Defines Unit Tests default login user password" )
32+
33+
# sql.properties file for CJUnitTestsPort tests
34+
set(SQL_PROPERTIES_FILE "${CMAKE_CURRENT_SOURCE_DIR}/CJUnitTestsPort/sql.properties")
35+
36+
configure_file(tests_config.h.in
37+
${CMAKE_BINARY_DIR}/tests_config.h)
38+
39+
INCLUDE_DIRECTORIES("${CMAKE_BINARY_DIR}")
40+
2541
IF(WIN32)
2642
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
2743
LINK_DIRECTORIES(${MYSQL_DIR}/lib/debug)

test/tests_config.h.in

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3+
4+
The MySQL Connector/C++ is licensed under the terms of the GPLv2
5+
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
6+
MySQL Connectors. There are special exceptions to the terms and
7+
conditions of the GPLv2 as it is applied to this software, see the
8+
FLOSS License Exception
9+
<http://www.mysql.com/about/legal/licensing/foss-exception.html>.
10+
11+
This program is free software; you can redistribute it and/or modify
12+
it under the terms of the GNU General Public License as published
13+
by the Free Software Foundation; version 2 of the License.
14+
15+
This program is distributed in the hope that it will be useful, but
16+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17+
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18+
for more details.
19+
20+
You should have received a copy of the GNU General Public License along
21+
with this program; if not, write to the Free Software Foundation, Inc.,
22+
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23+
*/
24+
25+
#ifndef _TESTS_CONFIG_IN_
26+
#define _TESTS_CONFIG_IN_
27+
28+
#define TEST_DEFAULT_HOST "${TEST_DEFAULT_HOST}"
29+
#define TEST_DEFAULT_DB "${TEST_DEFAULT_DB}"
30+
#define TEST_DEFAULT_LOGIN "${TEST_DEFAULT_LOGIN}"
31+
#define TEST_DEFAULT_PASSWD "${TEST_DEFAULT_PASSWD}"
32+
33+
#define SQL_PROPERTIES_FILE "${SQL_PROPERTIES_FILE}"
34+
35+
36+
#endif //_TESTS_CONFIG_IN_

test/unit/main.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
33
44
The MySQL Connector/C++ is licensed under the terms of the GPLv2
55
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2828
#include "../framework/start_options.h"
2929
#include "../framework/test_tapOutputter.h"
3030
#include "../framework/test_filter.h"
31+
#include "tests_config.h"
3132
#include <stdlib.h>
3233

3334
int main(int argc, char** argv)
@@ -40,10 +41,10 @@ int main(int argc, char** argv)
4041

4142
Properties defaultStringValues;
4243

43-
defaultStringValues.insert(Properties::value_type("dbUrl", "tcp://127.0.0.1:3306"));
44-
defaultStringValues.insert(Properties::value_type("dbUser", "root"));
45-
defaultStringValues.insert(Properties::value_type("dbPasswd", "root"));
46-
defaultStringValues.insert(Properties::value_type("dbSchema", "test"));
44+
defaultStringValues.insert(Properties::value_type("dbUrl" ,TEST_DEFAULT_HOST ));
45+
defaultStringValues.insert(Properties::value_type("dbUser" ,TEST_DEFAULT_LOGIN ));
46+
defaultStringValues.insert(Properties::value_type("dbPasswd",TEST_DEFAULT_PASSWD));
47+
defaultStringValues.insert(Properties::value_type("dbSchema",TEST_DEFAULT_DB ));
4748

4849
std::map<String, bool> defaultBoolValues;
4950

0 commit comments

Comments
 (0)