From ea8f6068b9a49214225ffdc74fd0bfa9d06dd197 Mon Sep 17 00:00:00 2001 From: ralfulrich <ralf.ulrich@kit.edu> Date: Thu, 6 Jun 2019 13:42:43 +0200 Subject: [PATCH] added main testing object --- Framework/Testing/CMakeList.txt | 52 ++++++++++++++++++++++++ Framework/Testing/CMakeLists.txt | 52 ++++++++++++++++++++++++ Framework/Testing/TestMain.cc | 13 ++++++ Processes/Testing/ContinousProcessTest.h | 41 +++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 Framework/Testing/CMakeList.txt create mode 100644 Framework/Testing/CMakeLists.txt create mode 100644 Framework/Testing/TestMain.cc create mode 100644 Processes/Testing/ContinousProcessTest.h diff --git a/Framework/Testing/CMakeList.txt b/Framework/Testing/CMakeList.txt new file mode 100644 index 000000000..0c616e186 --- /dev/null +++ b/Framework/Testing/CMakeList.txt @@ -0,0 +1,52 @@ +set ( + TESTING_SOURCES + TestMain.cc + ) + +set ( + TESTING_HEADERS + ) + +set ( + TESTING_NAMESPACE + corsika/testing + ) + +add_library (CORSIKAtesting STATIC ${TESTING_SOURCES}) +CORSIKA_COPY_HEADERS_TO_NAMESPACE (CORSIKAtesting ${TESTING_NAMESPACE} ${TESTING_HEADERS}) + +set_target_properties ( + CORSIKAtesting + PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER "${TESTING_HEADERS}" + ) + +# target dependencies on other libraries (also the header onlys) +target_link_libraries ( + CORSIKAtesting + CORSIKAthirdparty + ) + +# target_include_directories ( +# CORSIKAtesting +# SYSTEM +# PUBLIC ${CATCH2_INCLUDE_DIR} +# INTERFACE ${CATCH2_INCLUDE_DIR} +# ) + +target_include_directories ( + CORSIKAtesting + INTERFACE + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include> + $<INSTALL_INTERFACE:include/include> + ) + +install ( + TARGETS CORSIKAtesting + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + PUBLIC_HEADER DESTINATION include/${TESTING_NAMESPACE} + ) + diff --git a/Framework/Testing/CMakeLists.txt b/Framework/Testing/CMakeLists.txt new file mode 100644 index 000000000..0c616e186 --- /dev/null +++ b/Framework/Testing/CMakeLists.txt @@ -0,0 +1,52 @@ +set ( + TESTING_SOURCES + TestMain.cc + ) + +set ( + TESTING_HEADERS + ) + +set ( + TESTING_NAMESPACE + corsika/testing + ) + +add_library (CORSIKAtesting STATIC ${TESTING_SOURCES}) +CORSIKA_COPY_HEADERS_TO_NAMESPACE (CORSIKAtesting ${TESTING_NAMESPACE} ${TESTING_HEADERS}) + +set_target_properties ( + CORSIKAtesting + PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER "${TESTING_HEADERS}" + ) + +# target dependencies on other libraries (also the header onlys) +target_link_libraries ( + CORSIKAtesting + CORSIKAthirdparty + ) + +# target_include_directories ( +# CORSIKAtesting +# SYSTEM +# PUBLIC ${CATCH2_INCLUDE_DIR} +# INTERFACE ${CATCH2_INCLUDE_DIR} +# ) + +target_include_directories ( + CORSIKAtesting + INTERFACE + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include> + $<INSTALL_INTERFACE:include/include> + ) + +install ( + TARGETS CORSIKAtesting + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + PUBLIC_HEADER DESTINATION include/${TESTING_NAMESPACE} + ) + diff --git a/Framework/Testing/TestMain.cc b/Framework/Testing/TestMain.cc new file mode 100644 index 000000000..da6f2c3f1 --- /dev/null +++ b/Framework/Testing/TestMain.cc @@ -0,0 +1,13 @@ +/* + * (c) Copyright 2019 CORSIKA Project, corsika-project@lists.kit.edu + * + * See file AUTHORS for a list of contributors. + * + * This software is distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3). See file LICENSE for a full version of + * the license. + */ + +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one + // cpp file +#include <catch2/catch.hpp> diff --git a/Processes/Testing/ContinousProcessTest.h b/Processes/Testing/ContinousProcessTest.h new file mode 100644 index 000000000..d4da97557 --- /dev/null +++ b/Processes/Testing/ContinousProcessTest.h @@ -0,0 +1,41 @@ +/* + * (c) Copyright 2019 CORSIKA Project, corsika-project@lists.kit.edu + * + * See file AUTHORS for a list of contributors. + * + * This software is distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3). See file LICENSE for a full version of + * the license. + */ + +#pragma once + +TEMPLATE_TEST_CASE("vectors can be sized and resized", "[vector][template]", int, + std::string, (std::tuple<int, float>)) { + + std::vector<TestType> v(5); + + REQUIRE(v.size() == 5); + REQUIRE(v.capacity() >= 5); + + SECTION("resizing bigger changes size and capacity") { + v.resize(10); + + REQUIRE(v.size() == 10); + REQUIRE(v.capacity() >= 10); + } + SECTION("resizing smaller changes size but not capacity") { + v.resize(0); + + REQUIRE(v.size() == 0); + REQUIRE(v.capacity() >= 5); + + SECTION("We can use the 'swap trick' to reset the capacity") { + std::vector<TestType> empty; + empty.swap(v); + + REQUIRE(v.capacity() == 0); + } + } + SECTION("reserving smaller does not change size or capacity") { v.reserve(0); } +} -- GitLab