diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c3fa1f..b697f02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,8 @@ message(STATUS "Relase flags ${CMAKE_CXX_FLAGS_RELEASE}") message(STATUS "Linker flags ${CMAKE_EXE_LINKER_FLAGS}") +enable_testing() + add_subdirectory(src) add_subdirectory(test) add_subdirectory(backends) diff --git a/backends/postgres/CMakeLists.txt b/backends/postgres/CMakeLists.txt index 82932e3..5b428c0 100644 --- a/backends/postgres/CMakeLists.txt +++ b/backends/postgres/CMakeLists.txt @@ -18,6 +18,8 @@ set(SOURCES set(LIBRARY_TARGET matador-postgres) +add_subdirectory(test) + add_library(${LIBRARY_TARGET} MODULE ${SOURCES} ${HEADER}) set_target_properties(${LIBRARY_TARGET} diff --git a/backends/postgres/test/CMakeLists.txt b/backends/postgres/test/CMakeLists.txt new file mode 100644 index 0000000..31414ef --- /dev/null +++ b/backends/postgres/test/CMakeLists.txt @@ -0,0 +1,34 @@ +Include(FetchContent) + +FetchContent_Declare( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.4.0 # or a later release +) + +FetchContent_MakeAvailable(Catch2) + +SET(POSTGRES_CONNECTION_STRING "postgresql://test:test123@127.0.0.1/matador_test" CACHE STRING "postgresql connection string") + +CONFIGURE_FILE(Connection.hpp.in ${PROJECT_BINARY_DIR}/backends/postgres/test/connection.hpp @ONLY IMMEDIATE) + +MESSAGE(STATUS "postgresql connection string: ${POSTGRES_CONNECTION_STRING}") +MESSAGE(STATUS "current binary dir: ${CMAKE_CURRENT_BINARY_DIR}") + +set(TEST_SOURCES ../../tests/QueryTest.cpp) + +set(LIBRARY_TEST_TARGET postgres_tests) + +add_executable(${LIBRARY_TEST_TARGET} ${TEST_SOURCES}) + +target_link_libraries(${LIBRARY_TEST_TARGET} PRIVATE + Catch2::Catch2WithMain + matador + ${CMAKE_DL_LIBS} + ${PostgreSQL_LIBRARY}) + +target_include_directories(${LIBRARY_TEST_TARGET} + PUBLIC $/include + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + +add_test(NAME matador_postgres_tests COMMAND ${LIBRARY_TEST_TARGET}) diff --git a/backends/postgres/test/Connection.hpp.in b/backends/postgres/test/Connection.hpp.in new file mode 100644 index 0000000..7e491c8 --- /dev/null +++ b/backends/postgres/test/Connection.hpp.in @@ -0,0 +1,10 @@ +#ifndef POSTGRES_CONNECTION_HPP +#define POSTGRES_CONNECTION_HPP + +#define MATADOR_DB_TYPE "Postgres" + +namespace matador::test::connection { + const char* const dns = "@POSTGRES_CONNECTION_STRING@"; +} + +#endif /*POSTGRES_CONNECTION_HPP*/ \ No newline at end of file diff --git a/backends/tests/QueryTest.cpp b/backends/tests/QueryTest.cpp new file mode 100644 index 0000000..251bb14 --- /dev/null +++ b/backends/tests/QueryTest.cpp @@ -0,0 +1,7 @@ +#include "catch2/catch_test_macros.hpp" + +#include + +TEST_CASE(MATADOR_DB_TYPE " - Query test", "[query]") { + REQUIRE(std::string(matador::test::connection::dns) == "hallo welt"); +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9844638..a4a625f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -41,4 +41,6 @@ target_link_libraries(tests PRIVATE ${CMAKE_DL_LIBS} ${SQLite3_LIBRARIES} ${PostgreSQL_LIBRARY}) -target_include_directories(tests PUBLIC $/include) \ No newline at end of file +target_include_directories(tests PUBLIC $/include) + +add_test(NAME matador_tests COMMAND tests) diff --git a/test/Databases.hpp b/test/Databases.hpp index 0b3de2d..20d51e8 100644 --- a/test/Databases.hpp +++ b/test/Databases.hpp @@ -3,8 +3,8 @@ struct Postgres { - constexpr static const char *dns{"postgres://test:test123@127.0.0.1:15432/test"}; -// constexpr static const char *dns{"postgres://test:test123@127.0.0.1:5432/matador_test"}; +// constexpr static const char *dns{"postgres://test:test123@127.0.0.1:15432/test"}; + constexpr static const char *dns{"postgres://test:test123@127.0.0.1:5432/matador_test"}; }; struct Sqlite @@ -14,8 +14,8 @@ struct Sqlite struct MySql { - constexpr static const char *dns{"mysql://test:test123!@127.0.0.1:3306/testdb"}; -// constexpr static const char *dns{"mysql://test:test123!@127.0.0.1:3306/matador_test"}; +// constexpr static const char *dns{"mysql://test:test123!@127.0.0.1:3306/testdb"}; + constexpr static const char *dns{"mysql://test:test123!@127.0.0.1:3306/matador_test"}; }; #endif //QUERY_DATABASES_HPP