From f567b2ef1afd95d35cb6717c218782b5fa59cdc3 Mon Sep 17 00:00:00 2001 From: ralfulrich <ralf.ulrich@kit.edu> Date: Thu, 9 Aug 2018 09:55:38 +0200 Subject: [PATCH] first unit testing examples --- CMakeLists.txt | 2 +- Framework/Geometry/CMakeLists.txt | 9 ++++++++- Framework/Geometry/testGeometry.cc | 26 ++++++++++++++++++++++++++ Framework/Units/CMakeLists.txt | 5 +++++ Framework/Units/testUnits.cc | 12 ++++++++++++ 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 Framework/Geometry/testGeometry.cc create mode 100644 Framework/Units/testUnits.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index b88229e0..2539e281 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ set (CMAKE_INSTALL_MESSAGE LAZY) # --std=c++14 set (CMAKE_CXX_STANDARD 14) - +enable_testing () #add_custom_target (corsika_pre_build) #add_custom_command (TARGET corsika_pre_build PRE_BUILD COMMAND "${PROJECT_SOURCE_DIR}/pre_compile.py") diff --git a/Framework/Geometry/CMakeLists.txt b/Framework/Geometry/CMakeLists.txt index c7ca4aa9..a1f8a8bb 100644 --- a/Framework/Geometry/CMakeLists.txt +++ b/Framework/Geometry/CMakeLists.txt @@ -17,8 +17,15 @@ target_include_directories (CORSIKAgeometry INTERFACE ${EIGEN3_INCLUDE_DIR}) target_include_directories (CORSIKAgeometry INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/Framework> $<INSTALL_INTERFACE:include/Framework> ) - + install (TARGETS CORSIKAgeometry LIBRARY DESTINATION lib ARCHIVE DESTINATION lib PUBLIC_HEADER DESTINATION include/Geometry) + + +# code testing +add_executable (testGeometry testGeometry.cc) +target_link_libraries (testGeometry CORSIKAgeometry CORSIKAunits CORSIKAthirdparty) # for catch2 +add_test (NAME testGeometry COMMAND testGeometry -o report.xml -r junit) + diff --git a/Framework/Geometry/testGeometry.cc b/Framework/Geometry/testGeometry.cc new file mode 100644 index 00000000..d5a34b78 --- /dev/null +++ b/Framework/Geometry/testGeometry.cc @@ -0,0 +1,26 @@ +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file +#include <ThirdParty/catch2/catch.hpp> + +#include <Units/PhysicalUnits.h> + +using namespace phys::units; +using namespace phys::units::io; +using namespace phys::units::literals; + +TEST_CASE( "PhysicalUnits", "[Units]" ) +{ + SECTION( "sectionOne" ) + { + REQUIRE( 1_m/1_m == 1 ); + } + + SECTION( "sectionTwo" ) + { + REQUIRE_FALSE( 1_m/1_m == 2 ); + } + + SECTION( "sectionThree" ) + { + REQUIRE( 1_s/1_s == 2 ); + } +} diff --git a/Framework/Units/CMakeLists.txt b/Framework/Units/CMakeLists.txt index 4a8245af..d7d3af7e 100644 --- a/Framework/Units/CMakeLists.txt +++ b/Framework/Units/CMakeLists.txt @@ -11,3 +11,8 @@ target_include_directories (CORSIKAunits install (FILES PhysicalUnits.h DESTINATION include/Units) +# code testing +add_executable (testUnits testUnits.cc) +target_link_libraries (testUnits CORSIKAunits CORSIKAthirdparty) # for catch2 +add_test(NAME testUnits COMMAND testUnits) + diff --git a/Framework/Units/testUnits.cc b/Framework/Units/testUnits.cc new file mode 100644 index 00000000..eeae88d0 --- /dev/null +++ b/Framework/Units/testUnits.cc @@ -0,0 +1,12 @@ +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file +#include <ThirdParty/catch2/catch.hpp> + +#include <Units/PhysicalUnits.h> + +using namespace phys::units; +using namespace phys::units::io; +using namespace phys::units::literals; + +TEST_CASE( "PhysicalUnits", "[Units]" ) { + REQUIRE( 1_m/1_m == 1 ); +} -- GitLab