Skip to content

Commit

Permalink
Bring ODBC tests up to speed
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzmbrzl committed Feb 17, 2024
1 parent b548333 commit b3be869
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 189 deletions.
109 changes: 60 additions & 49 deletions tests/odbc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,69 +1,80 @@
###############################################################################
#
# This file is part of CMake configuration for SOCI library
#
# Copyright (C) 2010-2013 Mateusz Loskot <mateusz@loskot.net>
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
###############################################################################

if (WIN32)
# MDBTools driver seems unreliable
soci_backend_test(
NAME access
BACKEND ODBC
DEPENDS ODBC
SOURCE test-odbc-access.cpp ${SOCI_TESTS_COMMON}
CONNSTR "FILEDSN=${CMAKE_CURRENT_SOURCE_DIR}/test-access.dsn")
else()
message(STATUS "MS Access test disabled on non-Windows platform")
endif()

set(MSSQL_VER $ENV{MSSQL_VER})
if (NOT MSSQL_VER)
# Use the same value that was used before by default.
set(MSSQL_VER "2014")
endif()
configure_file("test-mssql.dsn.in" "test-mssql.dsn" @ONLY)
configure_file("test-mssql.dsn.in" "${CMAKE_CURRENT_BINARY_DIR}/test-mssql.dsn" @ONLY)


if (WIN32)
add_library(odbc_ms_access_tests OBJECT odbc_ms_access_tests.cpp)
target_link_libraries(odbc_ms_access_tests PUBLIC soci_common_tests soci_odbc_interface)

soci_make_tests(
OBJECT_LIB odbc_ms_access_tests
CONNECTION_STRING "FILEDSN=${CMAKE_CURRENT_BINARY_DIR}/test-access.dsn"
SHARED_NAME "soci_odbc_ms_access_test"
STATIC_NAME "soci_odbc_ms_access_test_static"
SOCI_DEP_ALIAS "ODBC"
)
endif()

soci_backend_test(
NAME mssql
BACKEND ODBC
DEPENDS ODBC
SOURCE test-odbc-mssql.cpp ${SOCI_TESTS_COMMON}
CONNSTR "FILEDSN=${CMAKE_CURRENT_BINARY_DIR}/test-mssql.dsn")

soci_backend_test(
NAME mysql
BACKEND ODBC
DEPENDS ODBC
SOURCE test-odbc-mysql.cpp ${SOCI_TESTS_COMMON}
CONNSTR "FILEDSN=${CMAKE_CURRENT_SOURCE_DIR}/test-mysql.dsn")
add_library(odbc_mssql_tests OBJECT odbc_mssql_tests.cpp)
target_link_libraries(odbc_mssql_tests PUBLIC soci_common_tests soci_odbc_interface)

soci_make_tests(
OBJECT_LIB odbc_mssql_tests
CONNECTION_STRING "FILEDSN=${CMAKE_CURRENT_BINARY_DIR}/test-access.dsn"
SHARED_NAME "soci_odbc_mssql_test"
STATIC_NAME "soci_odbc_mssql_test_static"
SOCI_DEP_ALIAS "ODBC"
)


add_library(odbc_mysql_tests OBJECT odbc_mysql_tests.cpp)
target_link_libraries(odbc_mysql_tests PUBLIC soci_common_tests soci_odbc_interface)
target_include_directories(odbc_mysql_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../")

soci_make_tests(
OBJECT_LIB odbc_mysql_tests
CONNECTION_STRING "FILEDSN=${CMAKE_CURRENT_SOURCE_DIR}/test-mysql.dsn"
SHARED_NAME "soci_odbc_mysql_test"
STATIC_NAME "soci_odbc_mysql_test_static"
SOCI_DEP_ALIAS "ODBC"
)


if(WIN32)
set(TEST_PGSQL_DSN "test-postgresql-win64.dsn")
else()
set(TEST_PGSQL_DSN "test-postgresql.dsn")
endif()
soci_backend_test(
NAME postgresql
BACKEND ODBC
DEPENDS ODBC
SOURCE test-odbc-postgresql.cpp ${SOCI_TESTS_COMMON}
CONNSTR "FILEDSN=${CMAKE_CURRENT_SOURCE_DIR}/${TEST_PGSQL_DSN}")

add_library(odbc_postgresql_tests OBJECT odbc_postgresql_tests.cpp)
target_link_libraries(odbc_postgresql_tests PUBLIC soci_common_tests soci_odbc_interface)

soci_make_tests(
OBJECT_LIB odbc_postgresql_tests
CONNECTION_STRING "FILEDSN=${CMAKE_CURRENT_SOURCE_DIR}/${TEST_PGSQL_DSN}"
SHARED_NAME "soci_odbc_postgresql_test"
STATIC_NAME "soci_odbc_postgresql_test_static"
SOCI_DEP_ALIAS "ODBC"
)

# TODO: DB2 backend is tested by Travis CI on dedicated VM, separate from ODBC,
# in order to test DB2 with ODBC, it would be best to install DB2 driver only.
# if (NOT $ENV{TRAVIS})
option(WITH_ODBC_TEST_DB2 "Build ODBC DB2 test" OFF)
if (WITH_ODBC_TEST_DB2)
soci_backend_test(
NAME db2
BACKEND ODBC
SOURCE test-odbc-db2.cpp
CONNSTR "FILEDSN=${CMAKE_CURRENT_SOURCE_DIR}/test-db2.dsn")
else()
message(STATUS "ODBC DB2 test disabled.")
add_library(odbc_db2_tests OBJECT odbc_db2_tests.cpp)
target_link_libraries(odbc_db2_tests PUBLIC soci_common_tests soci_odbc_interface)

soci_make_tests(
OBJECT_LIB odbc_db2_tests
CONNECTION_STRING "FILEDSN=${CMAKE_CURRENT_SOURCE_DIR}/test-db2.dsn"
SHARED_NAME "soci_odbc_db2_test"
STATIC_NAME "soci_odbc_db2_test_static"
SOCI_DEP_ALIAS "ODBC"
)
endif()
49 changes: 19 additions & 30 deletions tests/odbc/test-odbc-db2.cpp → tests/odbc/odbc_db2_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
// http://www.boost.org/LICENSE_1_0.txt)
//

#include <catch.hpp>

#include "common-tests.h"

#include "soci/soci.h"
#include "soci/odbc/soci-odbc.h"
#include "common-tests.h"

#include <iostream>
#include <string>
#include <ctime>
Expand Down Expand Up @@ -251,37 +255,22 @@ TEST_CASE("ODBC/DB2 vector unsigned long long", "[odbc][db2][vector][unsigned][l
std::cout << "test odbc_db2_unsigned_long_long_vector passed" << std::endl;
}

int main(int argc, char** argv)
{
#ifdef _MSC_VER
// Redirect errors, unrecoverable problems, and assert() failures to STDERR,
// instead of debug message window.
// This hack is required to run assert()-driven tests by Buildbot.
// NOTE: Comment this 2 lines for debugging with Visual C++ debugger to catch assertions inside.
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
#endif //_MSC_VER

if (argc >= 2)
{
connectString = argv[1];

// Replace the connect string with the process name to ensure that
// CATCH uses the correct name in its messages.
argv[1] = argv[0];
namespace soci
{
namespace tests
{

argc--;
argv++;
}
else
{
std::cerr << std::endl <<
"usage: test-odbc-db2 \"DSN=<db>;Uid=<user>;Pwd=<password>\"" <<
std::endl << std::endl;
return EXIT_FAILURE;
}
std::unique_ptr<test_context_base> instantiate_test_context(const soci::backend_factory &backend, const std::string &connection_string)
{
connectString = connection_string;
return std::make_unique<test_context>(backend, connection_string);
}

test_context tc(backEnd, connectString);
const backend_factory &create_backend_factory()
{
return backEnd;
}

return Catch::Session().run(argc, argv);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
// http://www.boost.org/LICENSE_1_0.txt)
//

#include <catch.hpp>

#include "common-tests.h"

#include "soci/soci.h"
#include "soci/odbc/soci-odbc.h"
#include "common-tests.h"

#include <iostream>
#include <string>
#include <ctime>
Expand Down Expand Up @@ -114,35 +118,22 @@ class test_context : public test_context_base
}
};

int main(int argc, char** argv)
{

#ifdef _MSC_VER
// Redirect errors, unrecoverable problems, and assert() failures to STDERR,
// instead of debug message window.
// This hack is required to run assert()-driven tests by Buildbot.
// NOTE: Comment this 2 lines for debugging with Visual C++ debugger to catch assertions inside.
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
#endif //_MSC_VER

if (argc >= 2 && argv[1][0] != '-')
{
connectString = argv[1];

// Replace the connect string with the process name to ensure that
// CATCH uses the correct name in its messages.
argv[1] = argv[0];
namespace soci
{
namespace tests
{

argc--;
argv++;
}
else
{
connectString = "FILEDSN=./test-access.dsn";
}
std::unique_ptr<test_context_base> instantiate_test_context(const soci::backend_factory &backend, const std::string &connection_string)
{
connectString = connection_string;
return std::make_unique<test_context>(backend, connection_string);
}

test_context tc(backEnd, connectString);
const backend_factory &create_backend_factory()
{
return backEnd;
}

return Catch::Session().run(argc, argv);
}
}
46 changes: 19 additions & 27 deletions tests/odbc/test-odbc-mssql.cpp → tests/odbc/odbc_mssql_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
// http://www.boost.org/LICENSE_1_0.txt)
//

#include <catch.hpp>

#include "common-tests.h"

#include "soci/soci.h"
#include "soci/odbc/soci-odbc.h"
#include "common-tests.h"

#include <iostream>
#include <string>
#include <ctime>
Expand Down Expand Up @@ -216,34 +220,22 @@ class test_context : public test_context_base
}
};

int main(int argc, char** argv)
{
#ifdef _MSC_VER
// Redirect errors, unrecoverable problems, and assert() failures to STDERR,
// instead of debug message window.
// This hack is required to run assert()-driven tests by Buildbot.
// NOTE: Comment this 2 lines for debugging with Visual C++ debugger to catch assertions inside.
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
#endif //_MSC_VER

if (argc >= 2 && argv[1][0] != '-')
{
connectString = argv[1];

// Replace the connect string with the process name to ensure that
// CATCH uses the correct name in its messages.
argv[1] = argv[0];
namespace soci
{
namespace tests
{

argc--;
argv++;
}
else
{
connectString = "FILEDSN=./test-mssql.dsn";
}
std::unique_ptr<test_context_base> instantiate_test_context(const soci::backend_factory &backend, const std::string &connection_string)
{
connectString = connection_string;
return std::make_unique<test_context>(backend, connection_string);
}

test_context tc(backEnd, connectString);
const backend_factory &create_backend_factory()
{
return backEnd;
}

return Catch::Session().run(argc, argv);
}
}
46 changes: 19 additions & 27 deletions tests/odbc/test-odbc-mysql.cpp → tests/odbc/odbc_mysql_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
// http://www.boost.org/LICENSE_1_0.txt)
//

#include <catch.hpp>

#include "mysql/mysql_tests.h"

#include "soci/soci.h"
#include "soci/odbc/soci-odbc.h"
#include "mysql/test-mysql.h"

#include <iostream>
#include <string>
#include <ctime>
Expand All @@ -33,34 +37,22 @@ class test_context_odbc : public test_context
}
};

int main(int argc, char** argv)
{
#ifdef _MSC_VER
// Redirect errors, unrecoverable problems, and assert() failures to STDERR,
// instead of debug message window.
// This hack is required to run assert()-driven tests by Buildbot.
// NOTE: Comment this 2 lines for debugging with Visual C++ debugger to catch assertions inside.
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
#endif //_MSC_VER

if (argc >= 2 && argv[1][0] != '-')
{
connectString = argv[1];

// Replace the connect string with the process name to ensure that
// CATCH uses the correct name in its messages.
argv[1] = argv[0];
namespace soci
{
namespace tests
{

argc--;
argv++;
}
else
{
connectString = "FILEDSN=./test-mysql.dsn";
}
std::unique_ptr<test_context_base> instantiate_test_context(const soci::backend_factory &backend, const std::string &connection_string)
{
connectString = connection_string;
return std::make_unique<test_context>(backend, connection_string);
}

test_context_odbc tc(backEnd, connectString);
const backend_factory &create_backend_factory()
{
return backEnd;
}

return Catch::Session().run(argc, argv);
}
}
Loading

0 comments on commit b3be869

Please sign in to comment.