mirror of
https://github.com/jhasse/poly2tri.git
synced 2025-08-03 13:55:39 +02:00
Add CMake files for the unit tests
- Building unit tests is optional, disabled by default to prevent the library clients from pulling the dependency on boost - Add the unit tests to the Github Actions. - Use boost::filesystem to manipulate paths for better portability
This commit is contained in:
32
unittest/CMakeLists.txt
Normal file
32
unittest/CMakeLists.txt
Normal file
@@ -0,0 +1,32 @@
|
||||
# Dependencies
|
||||
if (WIN32)
|
||||
set(Boost_USE_STATIC_LIBS ON)
|
||||
endif()
|
||||
find_package(Boost 1.69 REQUIRED COMPONENTS
|
||||
filesystem
|
||||
unit_test_framework
|
||||
)
|
||||
|
||||
# Build Unit Tests
|
||||
add_executable(test_poly2tri
|
||||
main.cpp
|
||||
TriangleTest.cpp
|
||||
)
|
||||
|
||||
target_include_directories(test_poly2tri
|
||||
PRIVATE
|
||||
${Boost_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_compile_definitions(test_poly2tri
|
||||
PRIVATE
|
||||
P2T_BASE_DIR="${PROJECT_SOURCE_DIR}"
|
||||
)
|
||||
|
||||
target_link_libraries(test_poly2tri
|
||||
PRIVATE
|
||||
poly2tri
|
||||
${Boost_LIBRARIES}
|
||||
)
|
||||
|
||||
add_test(NAME poly2tri COMMAND test_poly2tri)
|
@@ -1,3 +1,6 @@
|
||||
#ifndef WIN32
|
||||
#define BOOST_TEST_DYN_LINK
|
||||
#endif
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <poly2tri/common/shapes.h>
|
||||
|
||||
|
@@ -1,5 +1,9 @@
|
||||
#ifndef WIN32
|
||||
#define BOOST_TEST_DYN_LINK
|
||||
#endif
|
||||
#define BOOST_TEST_MODULE Poly2triTest
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <poly2tri/poly2tri.h>
|
||||
#include <fstream>
|
||||
@@ -64,9 +68,13 @@ BOOST_AUTO_TEST_CASE(TestbedFilesTest)
|
||||
// Load pointset from file
|
||||
// Parse and tokenize data file
|
||||
std::string line;
|
||||
const std::string src(__FILE__); // ../unittest/main.cpp
|
||||
auto folder = src.substr(0, src.find_last_of('/')) + "/../testbed/data/";
|
||||
std::ifstream myfile(folder + filename);
|
||||
#ifndef P2T_BASE_DIR
|
||||
const auto basedir = boost::filesystem::path(__FILE__).remove_filename().parent_path();
|
||||
#else
|
||||
const auto basedir = boost::filesystem::path(P2T_BASE_DIR);
|
||||
#endif
|
||||
const auto datafile = basedir / boost::filesystem::path("testbed/data") / boost::filesystem::path(filename);
|
||||
std::ifstream myfile(datafile.string());
|
||||
BOOST_REQUIRE(myfile.is_open());
|
||||
while (!myfile.eof()) {
|
||||
getline(myfile, line);
|
||||
|
Reference in New Issue
Block a user