Skip to content

Commit

Permalink
make tests build under mingw
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasDebrunner committed Apr 2, 2024
1 parent 30cebbb commit 92e0480
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmake/toolchain-mingw64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# the name of the target operating system
set(CMAKE_SYSTEM_NAME Windows)

# which compilers to use for C and C++
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc-posix)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++-posix)

# here we specify the root directory of the target environment
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)

# adjust the default behaviour of the FIND_ commands:
# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# for libraries and headers in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
6 changes: 6 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ target_compile_options(tests PRIVATE -O0 -g --coverage -Wall -Wextra -pedantic)
target_link_options(tests PRIVATE --coverage)
target_include_directories(tests PRIVATE ../include)
target_link_libraries(tests PRIVATE Threads::Threads)

if(WIN32)
message(STATUS "Building for Windows")
add_compile_definitions(WINVER=0x0601 _WIN32_WINNT=0x0601) # require at least Windows 7
target_link_libraries(tests PRIVATE wsock32 ws2_32)
endif()
16 changes: 16 additions & 0 deletions tests/MessageSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using namespace mav;

#ifndef _NO_STD_FILESYSTEM
std::string dump_minimal_xml() {
// write temporary file
auto temp_path = std::filesystem::temp_directory_path();
Expand All @@ -18,12 +19,20 @@ std::string dump_minimal_xml() {
out.close();
return xml_file.u8string();
}
#endif

TEST_CASE("Message set creation") {

#ifndef _NO_STD_FILESYSTEM
// test loading from file for systems with std::filesystem
auto file_name = dump_minimal_xml();
MessageSet message_set{file_name};
std::remove(file_name.c_str());
#else
// just load from the string for systems without filesystem
MessageSet message_set;
message_set.addFromXMLString(minimal_xml);
#endif

CHECK_EQ(message_set.size(), 2);

Expand Down Expand Up @@ -65,9 +74,16 @@ TEST_CASE("Message set creation") {
}

TEST_CASE("Create messages from set") {
#ifndef _NO_STD_FILESYSTEM
// test loading from file for systems with std::filesystem
auto file_name = dump_minimal_xml();
MessageSet message_set{file_name};
std::remove(file_name.c_str());
#else
// just load from the string for systems without filesystem
MessageSet message_set;
message_set.addFromXMLString(minimal_xml);
#endif

REQUIRE(message_set.contains("HEARTBEAT"));
SUBCASE("Can create message from name") {
Expand Down
1 change: 1 addition & 0 deletions tests/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
// Created by thomas on 01.02.23.
//
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <windows.h>
#include "doctest.h"

0 comments on commit 92e0480

Please sign in to comment.