From e1818993931ec72d6742ec1f121ae19d3a1fd580 Mon Sep 17 00:00:00 2001 From: Nicolas Slusarenko Date: Wed, 21 Aug 2019 14:30:04 +0200 Subject: [PATCH 01/14] Migration completed of testing unit from GTest to Catch2. --- CMakeLists.txt | 31 +++----- include/dr_util/resource.hpp | 14 ++++ package.xml | 4 ++ test/CMakeLists.txt | 53 ++++++++++++++ test/bitwise.cpp | 91 ++++++++++++----------- test/button_filter.cpp | 63 ++++++++-------- test/environment.cpp | 23 +++--- test/expand.cpp | 39 +++++----- test/functional.cpp | 30 ++++---- test/geometry.cpp | 135 +++++++++++++++++++---------------- test/integer_sequence.cpp | 21 +++--- test/main.cpp | 2 + test/polynomial.cpp | 110 ++++++++++++++-------------- test/resource.cpp | 32 ++++----- test/timestamp.cpp | 65 ++++++++--------- test/tuple.cpp | 62 ++++++++-------- test/void_t.cpp | 29 +++----- 17 files changed, 423 insertions(+), 381 deletions(-) create mode 100644 include/dr_util/resource.hpp create mode 100644 test/CMakeLists.txt create mode 100644 test/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3462a59..ec13005 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,13 +7,16 @@ set(CMAKE_CXX_EXTENSIONS OFF) add_compile_options(-Wall -Wextra -Wpedantic -Werror) -find_package(catkin REQUIRED) +find_package(catkin REQUIRED COMPONENTS + dr_ros + roscpp + roslib +) + find_package(Boost REQUIRED COMPONENTS filesystem date_time) -include_directories( - "include/${PROJECT_NAME}" - SYSTEM "${Boost_INCLUDE_DIRS}" -) +include_directories("include/${PROJECT_NAME}") +include_directories(SYSTEM ${catkin_INCLUDE_DIRS}) catkin_package( LIBRARIES ${PROJECT_NAME} @@ -29,24 +32,10 @@ add_library(${PROJECT_NAME} src/polynomial.cpp ) -target_link_libraries(${PROJECT_NAME} PRIVATE ${catkin_LIBRARIES} ${Boost_LIBRARIES}) +target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES} ${Boost_LIBRARIES}) if (CATKIN_ENABLE_TESTING) - catkin_add_gtest(${PROJECT_NAME}_test_bitwise test/bitwise.cpp) - catkin_add_gtest(${PROJECT_NAME}_test_button_filter test/button_filter.cpp) - catkin_add_gtest(${PROJECT_NAME}_test_environment test/environment.cpp) - catkin_add_gtest(${PROJECT_NAME}_test_expand test/expand.cpp) - catkin_add_gtest(${PROJECT_NAME}_test_functional test/functional.cpp) - catkin_add_gtest(${PROJECT_NAME}_test_geometry test/geometry.cpp) - catkin_add_gtest(${PROJECT_NAME}_test_integer_sequence test/integer_sequence.cpp) - catkin_add_gtest(${PROJECT_NAME}_test_polynomial test/polynomial.cpp) - catkin_add_gtest(${PROJECT_NAME}_test_timestamp test/timestamp.cpp) - catkin_add_gtest(${PROJECT_NAME}_test_tuple test/tuple.cpp) - catkin_add_gtest(${PROJECT_NAME}_test_voidt_t test/void_t.cpp) - - target_link_libraries(${PROJECT_NAME}_test_environment ${PROJECT_NAME}) - target_link_libraries(${PROJECT_NAME}_test_expand ${PROJECT_NAME}) - target_link_libraries(${PROJECT_NAME}_test_polynomial ${PROJECT_NAME}) + add_subdirectory(test) endif() install( diff --git a/include/dr_util/resource.hpp b/include/dr_util/resource.hpp new file mode 100644 index 0000000..27b3347 --- /dev/null +++ b/include/dr_util/resource.hpp @@ -0,0 +1,14 @@ +#pragma once +#include + +namespace dr { + +/// Convert a ROS package URL or a regular file URL to a file path. +/** + * If the input does not contain an URI scheme it is treated as a relative file path and returned without modification. + * + * \throws if an unsupported URI scheme is encountered. + */ +std::string resolveResourceUrl(std::string const & url); + +} diff --git a/package.xml b/package.xml index 00a7988..aa85d24 100644 --- a/package.xml +++ b/package.xml @@ -10,4 +10,8 @@ catkin boost + dr_ros + roscpp + roslib + catch2 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..166df3b --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,53 @@ +find_package(Catch2 REQUIRED) +include_directories(${Catch2_INCLUDE_DIRS}) + +add_library(${PROJECT_NAME}_test_main EXCLUDE_FROM_ALL main.cpp) +target_link_libraries(${PROJECT_NAME}_test_main ${PROJECT_NAME}) + +define_property(GLOBAL PROPERTY CHECK_TARGET BRIEF_DOCS "." FULL_DOCS ".") +set_property(GLOBAL PROPERTY CHECK_TARGET "check") + +if (NOT TARGET tests) + add_custom_target(tests) +endif() + +function(declare_test name) + add_executable(${name} EXCLUDE_FROM_ALL ${ARGN}) + target_link_libraries(${name} PRIVATE ${PROJECT_NAME}_test_main) + add_custom_target(check_${name} COMMAND ${name}) + add_dependencies(tests ${name}) + + get_property(check_target GLOBAL PROPERTY CHECK_TARGET) + list(APPEND check_target COMMAND cmake -E cmake_echo_color --white --bold ${name} COMMAND ${name} DEPENDS ${name}) + set_property(GLOBAL PROPERTY CHECK_TARGET "${check_target}") + + add_test(NAME ${name} COMMAND ${name}) +endfunction() + +function(declare_tests prefix) + foreach(test ${ARGN}) + declare_test(${prefix}${test} ${test}.cpp) + endforeach() +endfunction() + +declare_tests(dr_util_ + "bitwise" + "button_filter" + "environment" + "expand" + "functional" + "geometry" + "integer_sequence" + "polynomial" + "resource" + "timestamp" + "tuple" + "void_t" +) + +get_property(check_target GLOBAL PROPERTY CHECK_TARGET) +add_custom_target(${check_target} USES_TERMINAL) + +if (TARGET run_tests) + add_dependencies(run_tests check) +endif() diff --git a/test/bitwise.cpp b/test/bitwise.cpp index e935d3e..93cf283 100644 --- a/test/bitwise.cpp +++ b/test/bitwise.cpp @@ -1,80 +1,79 @@ -#include "bitwise.hpp" - -#include +// Catch +#include -int main(int argc, char ** argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} +// This repository +#include "bitwise.hpp" namespace dr { -TEST(BitwiseTest, makeBitMask) { +TEST_CASE("BitwiseTest -- makeBitMask", "makeBitMask") { // least significant bit - EXPECT_EQ(0x1u, bitMask(0)); + REQUIRE( 0x1u == bitMask(0)); + // some middle bit - EXPECT_EQ(0x4000u, bitMask(14)); + REQUIRE( 0x4000u == bitMask(14)); + // most significant bit - EXPECT_EQ(0x80000000u, bitMask(31)); + REQUIRE(0x80000000u == bitMask(31)); } -TEST(BitwiseTest, testTestBit) { +TEST_CASE("BitwiseTest -- testTestBit", "testTestBit") { // least significant bit - EXPECT_TRUE(testBit(0x1, 0)); - EXPECT_FALSE(testBit(0x1, 14)); - EXPECT_FALSE(testBit(0x1, 31)); + REQUIRE(testBit(0x1, 0) == true); + REQUIRE(testBit(0x1, 14) == false); + REQUIRE(testBit(0x1, 31) == false); // some middle bit - EXPECT_FALSE(testBit(0x4000, 0)); - EXPECT_TRUE(testBit(0x4000, 14)); - EXPECT_FALSE(testBit(0x4000, 31)); + REQUIRE(testBit(0x4000, 0) == false); + REQUIRE(testBit(0x4000, 14) == true); + REQUIRE(testBit(0x4000, 31) == false); // most significant bit - EXPECT_FALSE(testBit(0x80000000, 0)); - EXPECT_FALSE(testBit(0x80000000, 14)); - EXPECT_TRUE(testBit(0x80000000, 31)); + REQUIRE(testBit(0x80000000, 0) == false); + REQUIRE(testBit(0x80000000, 14) == false); + REQUIRE(testBit(0x80000000, 31) == true); // no value - EXPECT_FALSE(testBit(0, 0)); - EXPECT_FALSE(testBit(0, 14)); - EXPECT_FALSE(testBit(0, 31)); + REQUIRE(testBit(0, 0) == false); + REQUIRE(testBit(0, 14) == false); + REQUIRE(testBit(0, 31) == false); // all bits set to true - EXPECT_TRUE(testBit(0xFFFFFFFF, 0)); - EXPECT_TRUE(testBit(0xFFFFFFFF, 14)); - EXPECT_TRUE(testBit(0xFFFFFFFF, 31)); + REQUIRE(testBit(0xFFFFFFFF, 0) == true); + REQUIRE(testBit(0xFFFFFFFF, 14) == true); + REQUIRE(testBit(0xFFFFFFFF, 31) == true); } -TEST(BitwiseTest, testTestRising) { +TEST_CASE("BitwiseTest -- testTestRising", "testTestRising") { // no change for all bits set to 1 - EXPECT_FALSE(testRising(0xFFFFFFFF, 0xFFFFFFFF, 0)); - EXPECT_FALSE(testRising(0xFFFFFFFF, 0xFFFFFFFF, 14)); - EXPECT_FALSE(testRising(0xFFFFFFFF, 0xFFFFFFFF, 31)); + REQUIRE(testRising(0xFFFFFFFF, 0xFFFFFFFF, 0) == false); + REQUIRE(testRising(0xFFFFFFFF, 0xFFFFFFFF, 14) == false); + REQUIRE(testRising(0xFFFFFFFF, 0xFFFFFFFF, 31) == false); // no change for all bits set to 0 - EXPECT_FALSE(testRising(0, 0, 0)); - EXPECT_FALSE(testRising(0, 0, 14)); - EXPECT_FALSE(testRising(0, 0, 31)); + REQUIRE(testRising(0, 0, 0) == false); + REQUIRE(testRising(0, 0, 14) == false); + REQUIRE(testRising(0, 0, 31) == false); // ignore falling value - EXPECT_TRUE(testRising(0xFFFFFFFF, 0, 0)); - EXPECT_TRUE(testRising(0xFFFFFFFF, 0, 14)); - EXPECT_TRUE(testRising(0xFFFFFFFF, 0, 31)); + REQUIRE(testRising(0xFFFFFFFF, 0, 0) == true); + REQUIRE(testRising(0xFFFFFFFF, 0, 14) == true); + REQUIRE(testRising(0xFFFFFFFF, 0, 31) == true); // test rising edge - EXPECT_FALSE(testRising(0, 0xFFFFFFFF, 0)); - EXPECT_FALSE(testRising(0, 0xFFFFFFFF, 14)); - EXPECT_FALSE(testRising(0, 0xFFFFFFFF, 31)); + REQUIRE(testRising(0, 0xFFFFFFFF, 0) == false); + REQUIRE(testRising(0, 0xFFFFFFFF, 14) == false); + REQUIRE(testRising(0, 0xFFFFFFFF, 31) == false); // test specific rising edge - EXPECT_TRUE(testRising(0x1, 0, 0)); - EXPECT_TRUE(testRising(0x4000, 0, 14)); - EXPECT_TRUE(testRising(0x80000000, 0, 31)); + REQUIRE(testRising(0x1, 0, 0) == true); + REQUIRE(testRising(0x4000, 0, 14) == true); + REQUIRE(testRising(0x80000000, 0, 31) == true); // test wrong rising edge - EXPECT_FALSE(testRising(0x2, 0, 0)); - EXPECT_FALSE(testRising(0x8000, 0, 14)); - EXPECT_FALSE(testRising(0x40000000, 0, 31)); + REQUIRE(testRising(0x2, 0, 0) == false); + REQUIRE(testRising(0x8000, 0, 14) == false); + REQUIRE(testRising(0x40000000, 0, 31) == false); } } diff --git a/test/button_filter.cpp b/test/button_filter.cpp index 2e02422..4b221b0 100644 --- a/test/button_filter.cpp +++ b/test/button_filter.cpp @@ -1,70 +1,67 @@ -#include "button_filter.hpp" - -#include +// Catch +#include -int main(int argc, char ** argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} +// This repository +#include "button_filter.hpp" namespace dr { -TEST(ButtonFilterTest, filterAlwaysHigh) { +TEST_CASE("ButtonFilterTest -- filterAlwaysHigh", "filterAlwaysHigh") { ButtonFilter bf(true, false); // pass through high signals always - EXPECT_FALSE(bf.filter(false)); - EXPECT_TRUE(bf.filter(true)); - EXPECT_TRUE(bf.filter(true)); + REQUIRE(bf.filter(false) == false); + REQUIRE(bf.filter(true) == true); + REQUIRE(bf.filter(true) == true); } -TEST(ButtonFilterTest, filterAlwaysLow) { +TEST_CASE("ButtonFilterTest -- filterAlwaysLow", "filterAlwaysLow") { ButtonFilter bf(false, true); // pass through low signals always - EXPECT_TRUE(bf.filter(false)); - EXPECT_TRUE(bf.filter(true)); - EXPECT_FALSE(bf.filter(true)); + REQUIRE(bf.filter(false) == true); + REQUIRE(bf.filter(true) == true); + REQUIRE(bf.filter(true) == false); } -TEST(ButtonFilterTest, filterAlwaysHighAndLow) { +TEST_CASE("ButtonFilterTest -- filterAlwaysHighAndLow", "filterAlwaysHighAndLow") { ButtonFilter bf(true, true); // pass through any signal - EXPECT_TRUE(bf.filter(false)); - EXPECT_TRUE(bf.filter(false)); - EXPECT_TRUE(bf.filter(true)); - EXPECT_TRUE(bf.filter(true)); + REQUIRE(bf.filter(false) == true); + REQUIRE(bf.filter(false) == true); + REQUIRE(bf.filter(true) == true); + REQUIRE(bf.filter(true) == true); } -TEST(ButtonFilterTest, filterRisingEdge) { +TEST_CASE("ButtonFilterTest -- filterRisingEdge", "filterRisingEdge") { ButtonFilter bf; // test rising edge - EXPECT_FALSE(bf.filter(false)); - EXPECT_TRUE(bf.filter(true)); + REQUIRE(bf.filter(false) == false); + REQUIRE(bf.filter(true) == true); } -TEST(ButtonFilterTest, filterFallingEdge) { +TEST_CASE("ButtonFilterTest -- filterFallingEdge", "filterFallingEdge") { ButtonFilter bf; // test falling edge - EXPECT_TRUE(bf.filter(true)); - EXPECT_TRUE(bf.filter(false)); + REQUIRE(bf.filter(true) == true); + REQUIRE(bf.filter(false) == true); } -TEST(ButtonFilterTest, filterMultiple) { +TEST_CASE("ButtonFilterTest -- filterMultiple", "filterMultiple") { ButtonFilter bf; // test multiple signals - EXPECT_TRUE(bf.filter(true)); - EXPECT_FALSE(bf.filter(true)); + REQUIRE(bf.filter(true) == true); + REQUIRE(bf.filter(true) == false); - EXPECT_TRUE(bf.filter(false)); - EXPECT_FALSE(bf.filter(false)); + REQUIRE(bf.filter(false) == true); + REQUIRE(bf.filter(false) == false); - EXPECT_TRUE(bf.filter(true)); - EXPECT_FALSE(bf.filter(true)); + REQUIRE(bf.filter(true) == true); + REQUIRE(bf.filter(true) == false); } } diff --git a/test/environment.cpp b/test/environment.cpp index c070bdb..c923ac9 100644 --- a/test/environment.cpp +++ b/test/environment.cpp @@ -1,22 +1,23 @@ -#include "environment.hpp" - +// C #include -#include -int main(int argc, char ** argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} +// Catch +#include + +// This repository +#include "environment.hpp" namespace dr { -TEST(Environment, getEnvironment) { +TEST_CASE("Environment -- getEnvironment", "getEnvironment") { ::clearenv(); - EXPECT_EQ(getEnvironment(), (std::map{})); + REQUIRE(getEnvironment() == (std::map{})); + ::setenv("FOO", "aap", true); - EXPECT_EQ(getEnvironment(), (std::map{{"FOO", "aap"}})); + REQUIRE(getEnvironment() == (std::map{{"FOO", "aap"}})); + ::setenv("BAR", "noot", true); - EXPECT_EQ(getEnvironment(), (std::map{{"FOO", "aap"}, {"BAR", "noot"}})); + REQUIRE(getEnvironment() == (std::map{{"FOO", "aap"}, {"BAR", "noot"}})); } } diff --git a/test/expand.cpp b/test/expand.cpp index d34cc61..20c102f 100644 --- a/test/expand.cpp +++ b/test/expand.cpp @@ -1,34 +1,31 @@ -#include "expand.hpp" - -#include +// Catch +#include -int main(int argc, char ** argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} +// This repository +#include "expand.hpp" namespace dr { -TEST(Expand, simple) { - EXPECT_EQ(expandVariables("$test", {{"test", "foo"}}), "foo"); - EXPECT_EQ(expandVariables("$test", {{"test", "bar"}}), "bar"); - EXPECT_EQ(expandVariables("${test}", {{"test", "foo"}}), "foo"); - EXPECT_EQ(expandVariables("${test}", {{"test", "bar"}}), "bar"); +TEST_CASE("Expand -- simple", "simple") { + REQUIRE(expandVariables("$test", {{"test", "foo"}}) == "foo"); + REQUIRE(expandVariables("$test", {{"test", "bar"}}) == "bar"); + REQUIRE(expandVariables("${test}", {{"test", "foo"}}) == "foo"); + REQUIRE(expandVariables("${test}", {{"test", "bar"}}) == "bar"); } -TEST(Expand, sentence) { - EXPECT_EQ(expandVariables("Hello $name, welcome to $place", {{"name", "Rick"}, {"place", "Earth"}}), "Hello Rick, welcome to Earth"); - EXPECT_EQ(expandVariables("Hello ${name}, welcome to ${place}", {{"name", "Rick"}, {"place", "Earth"}}), "Hello Rick, welcome to Earth"); +TEST_CASE("Expand -- sentence", "sentence") { + REQUIRE(expandVariables("Hello $name, welcome to $place", {{"name", "Rick"}, {"place", "Earth"}}) == "Hello Rick, welcome to Earth"); + REQUIRE(expandVariables("Hello ${name}, welcome to ${place}", {{"name", "Rick"}, {"place", "Earth"}}) == "Hello Rick, welcome to Earth"); } -TEST(Expand, nipple_brackets) { - EXPECT_EQ(expandVariables("test$testtest", {{"test", "wrong"}, {"testtest", "good"}}), "testgood"); - EXPECT_EQ(expandVariables("test${test}test", {{"test", "good"}, {"testtest", "wrong"}}), "testgoodtest"); +TEST_CASE("Expand -- nipple_brackets", "nipple_brackets") { + REQUIRE(expandVariables("test$testtest", {{"test", "wrong"}, {"testtest", "good"}}) == "testgood"); + REQUIRE(expandVariables("test${test}test", {{"test", "good"}, {"testtest", "wrong"}}) == "testgoodtest"); } -TEST(Expand, ignore_empty_key) { - EXPECT_EQ(expandVariables("$", {{"", "aap"}}), "$"); - EXPECT_EQ(expandVariables("${}", {{"", "aap"}}), "${}"); +TEST_CASE("Expand -- ignore_empty_key", "ignore_empty_key") { + REQUIRE(expandVariables("$", {{"", "aap"}}) == "$"); + REQUIRE(expandVariables("${}", {{"", "aap"}}) == "${}"); } } diff --git a/test/functional.cpp b/test/functional.cpp index 04d57ef..9a66624 100644 --- a/test/functional.cpp +++ b/test/functional.cpp @@ -1,30 +1,26 @@ +// C++ #include #include #include -#include +// Catch +#include +// This repository #include "functional.hpp" #include "tuple.hpp" -using namespace dr; - -int main(int argc, char * * argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - -TEST(FunctionalTest, callHardcoded) { - EXPECT_EQ(true, call([] () { return true; }, std::make_tuple())); - EXPECT_EQ(false, call([] () { return false; }, std::make_tuple())); +TEST_CASE("FunctionalTest -- callHardcoded", "callHardcoded") { + REQUIRE(true == dr::call([] () { return true; }, std::make_tuple())); + REQUIRE(false == dr::call([] () { return false; }, std::make_tuple())); } -TEST(FunctionalTest, callInput) { - EXPECT_EQ(true, call([] (bool input) { return input; }, std::make_tuple(true))); - EXPECT_EQ(false, call([] (bool input) { return input; }, std::make_tuple(false))); +TEST_CASE("FunctionalTest -- callInput", "callInput") { + REQUIRE(true == dr::call([] (bool input) { return input; }, std::make_tuple(true))); + REQUIRE(false == dr::call([] (bool input) { return input; }, std::make_tuple(false))); } -TEST(FunctionalTest, callSum) { - EXPECT_EQ( 3, call([] (int a, int b) { return a + b; }, std::make_tuple(1, 2))); - EXPECT_EQ(17, call([] (int a, int b) { return a + b; }, std::make_tuple(7, 10))); +TEST_CASE("FunctionalTest -- callSum", "callSum") { + REQUIRE( 3 == dr::call([] (int a, int b) { return a + b; }, std::make_tuple(1, 2))); + REQUIRE(17 == dr::call([] (int a, int b) { return a + b; }, std::make_tuple(7, 10))); } diff --git a/test/geometry.cpp b/test/geometry.cpp index 7aba2fd..641944b 100644 --- a/test/geometry.cpp +++ b/test/geometry.cpp @@ -1,109 +1,122 @@ -#include "geometry.hpp" +// Catch +#include -#include +// This repository +#include "geometry.hpp" -int main(int argc, char ** argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); +namespace { + void requireEqual(float const & a, float const & b) + { + REQUIRE_THAT(a, Catch::WithinULP(b, 0)); + } + + void requireNear(float const & a, float const & b, float const &tol){ + float diff = std::abs(a - b); + if (diff <= tol) { + SUCCEED(); + } else { + std::string msg = "first argument " + std::to_string(a) + + " differs from the second argument " + std::to_string(b) + + " in " + std::to_string(diff) + + " which is larger than the allowed tolerance " + std::to_string(tol); + FAIL(msg); + } + } } -namespace dr { - -TEST(GeometryTest, testPi) { +TEST_CASE("GeometryTest -- testPi", "testPi") { // test equality with C defined pi - EXPECT_DOUBLE_EQ(pi(), M_PI); + requireEqual(dr::pi(), M_PI); } -TEST(GeometryTest, testDegrees) { +TEST_CASE("GeometryTest -- testDegrees", "testDegrees") { // test normal use case - EXPECT_DOUBLE_EQ(degrees(0), 0); - EXPECT_DOUBLE_EQ(degrees(180), M_PI); - EXPECT_DOUBLE_EQ(degrees(360), 2 * M_PI); - EXPECT_NEAR(degrees(37), 0.645771823237901, 0.0000001); // 37 / 180 * pi + requireEqual(dr::degrees(0), 0); + requireEqual(dr::degrees(180), M_PI); + requireEqual(dr::degrees(360), 2 * M_PI); + requireNear(dr::degrees(37), 0.645771823237901, 0.0000001); // 37 / 180 * pi // test negativity - EXPECT_DOUBLE_EQ(degrees(-180), -M_PI); - EXPECT_DOUBLE_EQ(degrees(-360), -2 * M_PI); + requireEqual(dr::degrees(-180), -M_PI); + requireEqual(dr::degrees(-360), -2 * M_PI); } -TEST(GeometryTest, testToDegrees) { +TEST_CASE("GeometryTest -- testToDegrees", "testToDegrees") { // test normal use case - EXPECT_DOUBLE_EQ(to_degrees(0), 0); - EXPECT_DOUBLE_EQ(to_degrees(M_PI), 180); - EXPECT_DOUBLE_EQ(to_degrees(2 * M_PI), 360); - EXPECT_NEAR(to_degrees(0.645771823237901), 37, 0.0000001); // 37 / 180 * pi + requireEqual(dr::to_degrees(0), 0); + requireEqual(dr::to_degrees(M_PI), 180); + requireEqual(dr::to_degrees(2 * M_PI), 360); + requireNear(dr::to_degrees(0.645771823237901), 37, 0.0000001); // 37 / 180 * pi // test negativity - EXPECT_DOUBLE_EQ(to_degrees(-M_PI), -180); - EXPECT_DOUBLE_EQ(to_degrees(-2 * M_PI), -360); + requireEqual(dr::to_degrees(-M_PI), -180); + requireEqual(dr::to_degrees(-2 * M_PI), -360); } -TEST(GeometryTest, testSign) { +TEST_CASE("GeometryTest -- testSign", "testSign") { // normal use cases - EXPECT_EQ(sign(-1), -1); - EXPECT_EQ(sign(1), 1); - EXPECT_EQ(sign(0), 0); + REQUIRE(dr::sign(-1) == -1); + REQUIRE(dr::sign(1) == 1); + REQUIRE(dr::sign(0) == 0); // double use cases - EXPECT_DOUBLE_EQ(sign(M_PI), 1); - EXPECT_DOUBLE_EQ(sign(-M_PI), -1); - EXPECT_DOUBLE_EQ(sign(std::numeric_limits::quiet_NaN()), 0); + REQUIRE(dr::sign(M_PI) == 1); + REQUIRE(dr::sign(-M_PI) == -1); + REQUIRE(dr::sign(std::numeric_limits::quiet_NaN()) == 0); } -TEST(GeometryTest, testNormalizeAngle) { +TEST_CASE("GeometryTest -- testNormalizeAngle", "testNormalizeAngle") { // normal use - EXPECT_DOUBLE_EQ(normalizeAngle(3 * M_PI), M_PI); - EXPECT_DOUBLE_EQ(normalizeAngle(3.5 * M_PI), 1.5 * M_PI); + requireEqual(dr::normalizeAngle(3 * M_PI), M_PI); + requireEqual(dr::normalizeAngle(3.5 * M_PI), 1.5 * M_PI); // negativity - EXPECT_DOUBLE_EQ(normalizeAngle(-3 * M_PI), M_PI); - EXPECT_DOUBLE_EQ(normalizeAngle(-3.5 * M_PI), 0.5 * M_PI); + requireEqual(dr::normalizeAngle(-3 * M_PI), M_PI); + requireEqual(dr::normalizeAngle(-3.5 * M_PI), 0.5 * M_PI); } -TEST(GeometryTest, testAngleFrom) { +TEST_CASE("GeometryTest -- testAngleFrom", "testAngleFrom") { // same as normalizeAngle // normal use - EXPECT_DOUBLE_EQ(angleFrom(3 * M_PI, 0), M_PI); - EXPECT_DOUBLE_EQ(angleFrom(3.5 * M_PI, 0), 1.5 * M_PI); + requireEqual(dr::angleFrom(3 * M_PI, 0), M_PI); + requireEqual(dr::angleFrom(3.5 * M_PI, 0), 1.5 * M_PI); // negative angle - EXPECT_DOUBLE_EQ(angleFrom(-3 * M_PI, 0), M_PI); - EXPECT_DOUBLE_EQ(angleFrom(-3.5 * M_PI, 0), 0.5 * M_PI); + requireEqual(dr::angleFrom(-3 * M_PI, 0), M_PI); + requireEqual(dr::angleFrom(-3.5 * M_PI, 0), 0.5 * M_PI); // set different angle // normal use - EXPECT_DOUBLE_EQ(angleFrom(3 * M_PI, 5 * M_PI), 5 * M_PI); - EXPECT_DOUBLE_EQ(angleFrom(3.5 * M_PI, 5 * M_PI), 5.5 * M_PI); + requireEqual(dr::angleFrom(3 * M_PI, 5 * M_PI), 5 * M_PI); + requireEqual(dr::angleFrom(3.5 * M_PI, 5 * M_PI), 5.5 * M_PI); // negative from angle - EXPECT_DOUBLE_EQ(angleFrom(-3 * M_PI, -5 * M_PI), -5 * M_PI); - EXPECT_DOUBLE_EQ(angleFrom(-3.5 * M_PI, -5 * M_PI), -3.5 * M_PI); - -} + requireEqual(dr::angleFrom(-3 * M_PI, -5 * M_PI), -5 * M_PI); + requireEqual(dr::angleFrom(-3.5 * M_PI, -5 * M_PI), -3.5 * M_PI); -TEST(GeometryTest, testSquare) { - EXPECT_DOUBLE_EQ(square(2), 4); - EXPECT_DOUBLE_EQ(square(-2), 4); - EXPECT_NEAR(square(M_PI), 9.86960440108935861883, 0.000001); - EXPECT_NEAR(square(-M_PI), 9.86960440108935861883, 0.000001); } -TEST(GeometryTest, testSquareSum) { - EXPECT_DOUBLE_EQ(square_sum(2.0, 2.0), 8.0); - EXPECT_DOUBLE_EQ(square_sum(1.0, 2.0, 3.0, 4.0, 5.0), 55.0); - EXPECT_DOUBLE_EQ(square_sum(-1.0, -2.0, -3.0, -4.0, -5.0), 55.0); +TEST_CASE("GeometryTest -- testSquare", "testSquare") { + requireEqual(dr::square(2), 4); + requireEqual(dr::square(-2), 4); + requireNear(dr::square(M_PI), 9.86960440108935861883, 0.000001); + requireNear(dr::square(-M_PI), 9.86960440108935861883, 0.000001); } -TEST(GeometryTest, testLength) { - EXPECT_DOUBLE_EQ(length(1.0, 0.0, 0.0), 1.0); - EXPECT_NEAR(length(10.0, 10.0, 0.0), 14.1421356237309504880, 0.0000001); // sqrt(10*10 + 10*10) - EXPECT_DOUBLE_EQ(length(0.0, 0.0, 0.0), 0.0); +TEST_CASE("GeometryTest -- testSquareSum", "testSquareSum") { + requireEqual(dr::square_sum(2.0, 2.0), 8.0); + requireEqual(dr::square_sum(1.0, 2.0, 3.0, 4.0, 5.0), 55.0); + requireEqual(dr::square_sum(-1.0, -2.0, -3.0, -4.0, -5.0), 55.0); } -TEST(GeometryTest, testAngle) { - EXPECT_DOUBLE_EQ(angle(std::sqrt(2), 1.0, 1.0), M_PI_2); +TEST_CASE("GeometryTest -- testLength", "testLength") { + requireEqual(dr::length(1.0, 0.0, 0.0), 1.0); + requireNear(dr::length(10.0, 10.0, 0.0), 14.1421356237309504880, 0.0000001); // sqrt(10*10 + 10*10) + requireEqual(dr::length(0.0, 0.0, 0.0), 0.0); } +TEST_CASE("GeometryTest --testAngle", "testAngle") { + requireEqual(dr::angle(std::sqrt(2), 1.0, 1.0), M_PI_2); } diff --git a/test/integer_sequence.cpp b/test/integer_sequence.cpp index bd020bc..013cb3e 100644 --- a/test/integer_sequence.cpp +++ b/test/integer_sequence.cpp @@ -1,16 +1,14 @@ +// C++ #include #include #include -#include +// Catch2 +#include +// This repository #include "integer_sequence.hpp" -int main(int argc, char * * argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - namespace dr { template @@ -18,7 +16,7 @@ constexpr bool have_same_types(T1 const &, T2 const &) { return std::is_same{}; } -TEST(IntegerSequence, have_same_types) { +TEST_CASE("IntegerSequence -- have_same_types", "have_same_types") { bool b1; bool b2; bool const b3 = false; @@ -31,20 +29,21 @@ TEST(IntegerSequence, have_same_types) { static_assert(not have_same_types(b1, b4), ""); static_assert(not have_same_types(b1, bp), ""); static_assert(not have_same_types(b1, i), ""); + SUCCEED(); } -TEST(IntegerSequence, add_offset_int) { +TEST_CASE("IntegerSequence -- add_offset_int", "add_offset_int") { auto offset_sequence = offset_integer_sequence(std::make_integer_sequence{}); auto expected_sequence = std::integer_sequence{}; static_assert(have_same_types(offset_sequence, expected_sequence), ""); - ASSERT_TRUE(true); + SUCCEED(); } -TEST(IntegerSequence, add_offset_index) { +TEST_CASE("IntegerSequence -- add_offset_index", "add_offset_index") { auto offset_sequence = offset_index_sequence<8>(std::make_index_sequence<3>{}); auto expected_sequence = std::index_sequence<8, 9, 10>{}; static_assert(have_same_types(offset_sequence, expected_sequence), ""); - ASSERT_TRUE(true); + SUCCEED(); } } diff --git a/test/main.cpp b/test/main.cpp new file mode 100644 index 0000000..4ed06df --- /dev/null +++ b/test/main.cpp @@ -0,0 +1,2 @@ +#define CATCH_CONFIG_MAIN +#include diff --git a/test/polynomial.cpp b/test/polynomial.cpp index 967a186..e37dd30 100644 --- a/test/polynomial.cpp +++ b/test/polynomial.cpp @@ -1,82 +1,84 @@ -#include "polynomial.hpp" +// C++ +#include -#include +// Catch2 +#include -#include +// This repository +#include "polynomial.hpp" -int main(int argc, char ** argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); +namespace { + void requireEqual(float const & a, float const & b) + { + REQUIRE_THAT(a, Catch::WithinULP(b, 0)); + } } -namespace dr { - -TEST(PolynomialTest, emptyPolynomial) { - Polynomial p; - ASSERT_DOUBLE_EQ(0, p.y(0.0)); - ASSERT_DOUBLE_EQ(0, p.y(0.5)); - ASSERT_DOUBLE_EQ(0, p.y(1.0)); - ASSERT_DOUBLE_EQ(0, p.y(-0.5)); - ASSERT_DOUBLE_EQ(0, p.y(-1.0)); +TEST_CASE("PolynomialTest -- emptyPolynomial", "emptyPolynomial") { + dr::Polynomial p; + requireEqual(0, p.y(0.0)); + requireEqual(0, p.y(0.5)); + requireEqual(0, p.y(1.0)); + requireEqual(0, p.y(-0.5)); + requireEqual(0, p.y(-1.0)); } -TEST(PolynomialTest, constantPolynomial) { - Polynomial p; +TEST_CASE("PolynomialTest -- constantPolynomial", "constantPolynomial") { + dr::Polynomial p; p.terms.emplace_back(3.25, 0); - ASSERT_DOUBLE_EQ(3.25, p.y( 0.0)); - ASSERT_DOUBLE_EQ(3.25, p.y( 0.5)); - ASSERT_DOUBLE_EQ(3.25, p.y( 1.0)); - ASSERT_DOUBLE_EQ(3.25, p.y(-0.5)); - ASSERT_DOUBLE_EQ(3.25, p.y(-1.0)); + requireEqual(3.25, p.y( 0.0)); + requireEqual(3.25, p.y( 0.5)); + requireEqual(3.25, p.y( 1.0)); + requireEqual(3.25, p.y(-0.5)); + requireEqual(3.25, p.y(-1.0)); } -TEST(PolynomialTest, squareRoot) { - Polynomial p; +TEST_CASE("PolynomialTest -- squareRoot", "squareRoot") { + dr::Polynomial p; p.terms.emplace_back(1, 0.5); - ASSERT_DOUBLE_EQ( 0.000, p.y(0.0)); - ASSERT_DOUBLE_EQ( 1.000, p.y(1.0)); - ASSERT_DOUBLE_EQ( 2.000, p.y(4.0)); + requireEqual( 0.000, p.y(0.0)); + requireEqual( 1.000, p.y(1.0)); + requireEqual( 2.000, p.y(4.0)); - ASSERT_TRUE(std::isnan(p.y(-1.0))); - ASSERT_TRUE(std::isnan(p.y(-4.0))); + REQUIRE(std::isnan(p.y(-1.0)) == true); + REQUIRE(std::isnan(p.y(-4.0)) == true); } -TEST(PolynomialTest, firstOrder) { - Polynomial p; +TEST_CASE("PolynomialTest -- firstOrder", "firstOrder") { + dr::Polynomial p; p.terms.emplace_back(2, 1); - ASSERT_DOUBLE_EQ( 0, p.y(0.0)); - ASSERT_DOUBLE_EQ( 1, p.y(0.5)); - ASSERT_DOUBLE_EQ( 2, p.y(1.0)); - ASSERT_DOUBLE_EQ(-1, p.y(-0.5)); - ASSERT_DOUBLE_EQ(-2, p.y(-1.0)); + + requireEqual( 0, p.y(0.0)); + requireEqual( 1, p.y(0.5)); + requireEqual( 2, p.y(1.0)); + requireEqual(-1, p.y(-0.5)); + requireEqual(-2, p.y(-1.0)); } -TEST(PolynomialTest, thirdOrder) { - Polynomial p; +TEST_CASE("PolynomialTest -- thirdOrder", "thirdOrder") { + dr::Polynomial p; p.terms.emplace_back(2, 1); p.terms.emplace_back(1.5, 3); - ASSERT_DOUBLE_EQ( 0.0000, p.y(0.0)); - ASSERT_DOUBLE_EQ( 1.1875, p.y(0.5)); - ASSERT_DOUBLE_EQ( 3.5000, p.y(1.0)); - ASSERT_DOUBLE_EQ(-1.1875, p.y(-0.5)); - ASSERT_DOUBLE_EQ(-3.5000, p.y(-1.0)); + requireEqual( 0.0000, p.y(0.0)); + requireEqual( 1.1875, p.y(0.5)); + requireEqual( 3.5000, p.y(1.0)); + requireEqual(-1.1875, p.y(-0.5)); + requireEqual(-3.5000, p.y(-1.0)); } -TEST(PolynomialTest, fourthOrder) { - Polynomial p; +TEST_CASE("PolynomialTest -- fourthOrder", "fourthOrder") { + dr::Polynomial p; p.terms.emplace_back(1, 2); p.terms.emplace_back(2, 4); - ASSERT_DOUBLE_EQ( 0.000, p.y(0.0)); - ASSERT_DOUBLE_EQ( 0.375, p.y(0.5)); - ASSERT_DOUBLE_EQ( 3.000, p.y(1.0)); - ASSERT_DOUBLE_EQ(36.000, p.y(2.0)); - ASSERT_DOUBLE_EQ( 0.375, p.y(-0.5)); - ASSERT_DOUBLE_EQ( 3.000, p.y(-1.0)); - ASSERT_DOUBLE_EQ(36.000, p.y(-2.0)); -} - + requireEqual( 0.000, p.y(0.0)); + requireEqual( 0.375, p.y(0.5)); + requireEqual( 3.000, p.y(1.0)); + requireEqual(36.000, p.y(2.0)); + requireEqual( 0.375, p.y(-0.5)); + requireEqual( 3.000, p.y(-1.0)); + requireEqual(36.000, p.y(-2.0)); } diff --git a/test/resource.cpp b/test/resource.cpp index 7565401..24e5bfb 100644 --- a/test/resource.cpp +++ b/test/resource.cpp @@ -1,30 +1,24 @@ -#include "resource.hpp" +// Catch2 +#include +// ROS #include -#include - -int main(int argc, char ** argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - -namespace dr { - -TEST(ResourceTest, packageUrl) { - ASSERT_EQ(ros::package::getPath("dr_util") + "/test.file", rosUrlToPath("package://dr_util/test.file")); -} +// This repository +#include "resource.hpp" -TEST(ResourceTest, localFileUrl) { - ASSERT_EQ("/test.file", rosUrlToPath("file:///test.file")); +TEST_CASE("ResourceTest -- packageUrl", "packageUrl") { + REQUIRE(ros::package::getPath("dr_util") + "/test.file" == dr::resolveResourceUrl("package://dr_util/test.file")); } -TEST(ResourceTest, remoteFileUrl) { - ASSERT_ANY_THROW(rosUrlToPath("file://host/test.file")); +TEST_CASE("ResourceTest -- localFileUrl", "localFileUrl") { + REQUIRE("/test.file" == dr::resolveResourceUrl("file:///test.file")); } -TEST(ResourceTest, unsupportedScheme) { - ASSERT_ANY_THROW(rosUrlToPath("http://example.com/test.file")); +TEST_CASE("ResourceTest -- remoteFileUrl", "remoteFileUrl") { + REQUIRE_THROWS(dr::resolveResourceUrl("file://host/test.file")); } +TEST_CASE("ResourceTest -- unsupportedScheme", "unsupportedScheme") { + REQUIRE_THROWS(dr::resolveResourceUrl("http://example.com/test.file")); } diff --git a/test/timestamp.cpp b/test/timestamp.cpp index fa0ec92..9ac3b8f 100644 --- a/test/timestamp.cpp +++ b/test/timestamp.cpp @@ -1,43 +1,39 @@ -#include "../src/chrono_ptime.hpp" - -#include - +// C++ #include #include #include -int main(int argc, char ** argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} +// Catch +#include + +// This repository +#include "../src/chrono_ptime.hpp" namespace dr { -TEST(timestamp, system_clock_epoch) { +TEST_CASE("timestamp -- system_clock_epoch", "system_clock_epoch") { std::time_t epoch = std::chrono::system_clock::to_time_t(std::chrono::system_clock::time_point{}); std::tm * date = std::gmtime(&epoch); - ASSERT_EQ(date->tm_year, 70); - ASSERT_EQ(date->tm_mon, 0); - ASSERT_EQ(date->tm_mday, 1); - ASSERT_EQ(date->tm_hour, 0); - ASSERT_EQ(date->tm_min, 0); - ASSERT_EQ(date->tm_sec, 0); - ASSERT_EQ(date->tm_yday, 0); - ASSERT_EQ(date->tm_isdst, 0); + REQUIRE(date->tm_year == 70); + REQUIRE(date->tm_mon == 0); + REQUIRE(date->tm_mday == 1); + REQUIRE(date->tm_hour == 0); + REQUIRE(date->tm_min == 0); + REQUIRE(date->tm_sec == 0); + REQUIRE(date->tm_yday == 0); + REQUIRE(date->tm_isdst == 0); } -TEST(timestamp, chrono_ptime_epoch) { +TEST_CASE("timestamp -- chrono_ptime_epoch", "chrono_ptime_epoch") { boost::posix_time::ptime epoch = toPtime(std::chrono::system_clock::time_point{}); - ASSERT_EQ(epoch.date().year(), 1970); - ASSERT_EQ(epoch.date().month(), 1); - ASSERT_EQ(epoch.date().day(), 1); - ASSERT_EQ(epoch.date().day_of_year(), 1); - ASSERT_EQ(epoch.time_of_day(), boost::posix_time::seconds(0)); + REQUIRE(epoch.date().year() == 1970); + REQUIRE(epoch.date().month() == 1); + REQUIRE(epoch.date().day() == 1); + REQUIRE(epoch.date().day_of_year() == 1); + REQUIRE(epoch.time_of_day() == boost::posix_time::seconds(0)); } -TEST(timestamp, chrono_ptime_2017) { - setenv("TZ", "UTC", true); - ::tzset(); +TEST_CASE("timestamp -- chrono_ptime_2017", "chrono_ptime_2017") { std::tm tm; tm.tm_year = 117; @@ -50,15 +46,14 @@ TEST(timestamp, chrono_ptime_2017) { boost::posix_time::ptime time = toPtime(std::chrono::system_clock::from_time_t(std::mktime(&tm))); - ASSERT_EQ(time.date().year(), 2017); - ASSERT_EQ(time.date().month(), boost::gregorian::Mar); - ASSERT_EQ(time.date().day(), 30); - ASSERT_EQ(time.date().day_of_year(), 89); - ASSERT_EQ(time.date().day_of_week(), boost::gregorian::Thursday); - ASSERT_EQ(time.time_of_day().hours(), 13); - ASSERT_EQ(time.time_of_day().minutes(), 37); - ASSERT_EQ(time.time_of_day().seconds(), 42); + REQUIRE(time.date().year() == 2017); + REQUIRE(time.date().month() == boost::gregorian::Mar); + REQUIRE(time.date().day() == 30); + REQUIRE(time.date().day_of_year() == 89); + REQUIRE(time.date().day_of_week() == boost::gregorian::Thursday); + REQUIRE(time.time_of_day().hours() == 11); + REQUIRE(time.time_of_day().minutes() == 37); + REQUIRE(time.time_of_day().seconds() == 42); } - } diff --git a/test/tuple.cpp b/test/tuple.cpp index 6293f4a..13f9b85 100644 --- a/test/tuple.cpp +++ b/test/tuple.cpp @@ -1,54 +1,50 @@ +// C++ #include #include #include -#include +// Catch +#include +// This repository #include "tuple.hpp" -using namespace dr; - -int main(int argc, char * * argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - -TEST(TupleTest, sliceOne) { +TEST_CASE("TupleTest -- sliceOne", "sliceOne") { auto tuple = std::make_tuple(1, true, 3); - EXPECT_EQ(1u, std::tuple_size(tuple))>::value); - EXPECT_EQ(1u, std::tuple_size(tuple))>::value); - EXPECT_EQ(1u, std::tuple_size(tuple))>::value); - EXPECT_EQ(1, std::get<0>(tuple_slice<0, 1>(tuple))); - EXPECT_EQ(true, std::get<0>(tuple_slice<1, 1>(tuple))); - EXPECT_EQ(3, std::get<0>(tuple_slice<2, 1>(tuple))); + REQUIRE(1u == std::tuple_size(tuple))>::value); + REQUIRE(1u == std::tuple_size(tuple))>::value); + REQUIRE(1u == std::tuple_size(tuple))>::value); + REQUIRE(1 == std::get<0>(dr::tuple_slice<0, 1>(tuple))); + REQUIRE(true == std::get<0>(dr::tuple_slice<1, 1>(tuple))); + REQUIRE(3 == std::get<0>(dr::tuple_slice<2, 1>(tuple))); } -TEST(TupleTest, sliceTwo) { +TEST_CASE("TupleTest -- sliceTwo", "sliceTwo") { auto tuple = std::make_tuple(1, true, 3); - EXPECT_EQ(2u, std::tuple_size(tuple))>::value); - EXPECT_EQ(2u, std::tuple_size(tuple))>::value); - EXPECT_EQ(1, std::get<0>(tuple_slice<0, 2>(tuple))); - EXPECT_EQ(true, std::get<1>(tuple_slice<0, 2>(tuple))); - EXPECT_EQ(true, std::get<0>(tuple_slice<1, 2>(tuple))); - EXPECT_EQ(3, std::get<1>(tuple_slice<1, 2>(tuple))); + REQUIRE(2u == std::tuple_size(tuple))>::value); + REQUIRE(2u == std::tuple_size(tuple))>::value); + REQUIRE(1 == std::get<0>(dr::tuple_slice<0, 2>(tuple))); + REQUIRE(true == std::get<1>(dr::tuple_slice<0, 2>(tuple))); + REQUIRE(true == std::get<0>(dr::tuple_slice<1, 2>(tuple))); + REQUIRE(3 == std::get<1>(dr::tuple_slice<1, 2>(tuple))); } -TEST(TupleTest, sliceThree) { +TEST_CASE("TupleTest -- sliceThree", "sliceThree") { auto tuple = std::make_tuple(1, true, 3); - EXPECT_EQ(3u, std::tuple_size(tuple))>::value); - EXPECT_EQ(1, std::get<0>(tuple_slice<0, 3>(tuple))); - EXPECT_EQ(true, std::get<1>(tuple_slice<0, 3>(tuple))); - EXPECT_EQ(3, std::get<2>(tuple_slice<0, 3>(tuple))); + REQUIRE(3u == std::tuple_size(tuple))>::value); + REQUIRE(1 == std::get<0>(dr::tuple_slice<0, 3>(tuple))); + REQUIRE(true == std::get<1>(dr::tuple_slice<0, 3>(tuple))); + REQUIRE(3 == std::get<2>(dr::tuple_slice<0, 3>(tuple))); } -TEST(TupleTest, tail) { +TEST_CASE("TupleTest -- tail", "tail") { auto tuple = std::make_tuple(1, true, 3); - EXPECT_EQ(2u, std::tuple_size::value); - EXPECT_EQ(true, std::get<0>(tuple_tail(tuple))); - EXPECT_EQ(3, std::get<1>(tuple_tail(tuple))); + REQUIRE(2u == std::tuple_size::value); + REQUIRE(true == std::get<0>(dr::tuple_tail(tuple))); + REQUIRE(3 == std::get<1>(dr::tuple_tail(tuple))); } -TEST(TupleTest, tailEmpty) { +TEST_CASE("TupleTest -- tailEmpty", "tailEmpty") { auto tuple = std::make_tuple(1); - EXPECT_EQ(0u, std::tuple_size::value); + REQUIRE(0u == std::tuple_size::value); } diff --git a/test/void_t.cpp b/test/void_t.cpp index a5ce2d6..cf109a6 100644 --- a/test/void_t.cpp +++ b/test/void_t.cpp @@ -1,22 +1,13 @@ -#include "void_t.hpp" - -#include - -using namespace dr; - -int main(int argc, char * * argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - -namespace dr { +// Catch +#include -TEST(VoidT, type) { - static_assert(std::is_same>{}, ""); - static_assert(std::is_same>{}, ""); - static_assert(std::is_same>{}, ""); - static_assert(std::is_same>{}, ""); - ASSERT_TRUE(true); -} +// This repository +#include "void_t.hpp" +TEST_CASE("VoidT -- type", "type") { + static_assert(std::is_same>{}, ""); + static_assert(std::is_same>{}, ""); + static_assert(std::is_same>{}, ""); + static_assert(std::is_same>{}, ""); + SUCCEED(); } From 70773eeea8f90364a66204ddb644adb83648970a Mon Sep 17 00:00:00 2001 From: Nicolas Slusarenko Date: Mon, 26 Aug 2019 14:11:53 +0200 Subject: [PATCH 02/14] WIP Migration of testing unit from GTest to Catch2. --- package.xml | 2 +- test/resource.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/package.xml b/package.xml index aa85d24..5eda866 100644 --- a/package.xml +++ b/package.xml @@ -11,7 +11,7 @@ catkin boost dr_ros - roscpp + roscpp roslib catch2 diff --git a/test/resource.cpp b/test/resource.cpp index 24e5bfb..0d20191 100644 --- a/test/resource.cpp +++ b/test/resource.cpp @@ -7,8 +7,12 @@ // This repository #include "resource.hpp" +#include + TEST_CASE("ResourceTest -- packageUrl", "packageUrl") { - REQUIRE(ros::package::getPath("dr_util") + "/test.file" == dr::resolveResourceUrl("package://dr_util/test.file")); + std::cout << ros::package::getPath("dr_ros") << "\n"; + // REQUIRE(ros::package::getPath("dr_util") + "/test.file" == dr::resolveResourceUrl("package://dr_util/test.file")); + REQUIRE(ros::package::getPath("dr_ros") + "/test.file" == dr::resolveResourceUrl("package://dr_ros/test.file")); } TEST_CASE("ResourceTest -- localFileUrl", "localFileUrl") { From fc7102f834ba8a440aac230fcff4efb3159c35a5 Mon Sep 17 00:00:00 2001 From: Nicolas Slusarenko Date: Mon, 26 Aug 2019 14:16:12 +0200 Subject: [PATCH 03/14] WIP Migration of testing unit from GTest to Catch2. --- package.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/package.xml b/package.xml index 5eda866..3ca7e4c 100644 --- a/package.xml +++ b/package.xml @@ -11,6 +11,7 @@ catkin boost dr_ros + dr_util roscpp roslib catch2 From 21fa3d607eb29b57316ffaa1b41f551318673b7c Mon Sep 17 00:00:00 2001 From: Nicolas Slusarenko Date: Mon, 26 Aug 2019 14:16:42 +0200 Subject: [PATCH 04/14] WIP Migration of testing unit from GTest to Catch2. --- test/resource.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/resource.cpp b/test/resource.cpp index 0d20191..74caca6 100644 --- a/test/resource.cpp +++ b/test/resource.cpp @@ -11,8 +11,8 @@ TEST_CASE("ResourceTest -- packageUrl", "packageUrl") { std::cout << ros::package::getPath("dr_ros") << "\n"; - // REQUIRE(ros::package::getPath("dr_util") + "/test.file" == dr::resolveResourceUrl("package://dr_util/test.file")); - REQUIRE(ros::package::getPath("dr_ros") + "/test.file" == dr::resolveResourceUrl("package://dr_ros/test.file")); + CHECK(ros::package::getPath("dr_util") + "/test.file" == dr::resolveResourceUrl("package://dr_util/test.file")); + CHECK(ros::package::getPath("dr_ros") + "/test.file" == dr::resolveResourceUrl("package://dr_ros/test.file")); } TEST_CASE("ResourceTest -- localFileUrl", "localFileUrl") { From 2d8f47cf7f4e779316d9f45648da6754d0bb07aa Mon Sep 17 00:00:00 2001 From: Nicolas Slusarenko Date: Mon, 26 Aug 2019 14:21:52 +0200 Subject: [PATCH 05/14] WIP Migration of testing unit from GTest to Catch2. --- package.xml | 4 ++-- test/resource.cpp | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/package.xml b/package.xml index 3ca7e4c..39453e9 100644 --- a/package.xml +++ b/package.xml @@ -10,9 +10,9 @@ catkin boost - dr_ros - dr_util + dr_ros roscpp roslib catch2 + dr_util diff --git a/test/resource.cpp b/test/resource.cpp index 74caca6..1046fc3 100644 --- a/test/resource.cpp +++ b/test/resource.cpp @@ -10,9 +10,8 @@ #include TEST_CASE("ResourceTest -- packageUrl", "packageUrl") { - std::cout << ros::package::getPath("dr_ros") << "\n"; - CHECK(ros::package::getPath("dr_util") + "/test.file" == dr::resolveResourceUrl("package://dr_util/test.file")); - CHECK(ros::package::getPath("dr_ros") + "/test.file" == dr::resolveResourceUrl("package://dr_ros/test.file")); + std::cout << ros::package::getPath("dr_util") << "\n"; + REQUIRE(ros::package::getPath("dr_util") + "/test.file" == dr::resolveResourceUrl("package://dr_util/test.file")); } TEST_CASE("ResourceTest -- localFileUrl", "localFileUrl") { From b7dce48009c03d4a9a425831866f955c3d4abad3 Mon Sep 17 00:00:00 2001 From: Nicolas Slusarenko Date: Mon, 26 Aug 2019 14:23:15 +0200 Subject: [PATCH 06/14] WIP Migration of testing unit from GTest to Catch2. --- package.xml | 2 +- test/resource.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.xml b/package.xml index 39453e9..a917511 100644 --- a/package.xml +++ b/package.xml @@ -14,5 +14,5 @@ roscpp roslib catch2 - dr_util + dr_ros diff --git a/test/resource.cpp b/test/resource.cpp index 1046fc3..63f3df1 100644 --- a/test/resource.cpp +++ b/test/resource.cpp @@ -10,8 +10,8 @@ #include TEST_CASE("ResourceTest -- packageUrl", "packageUrl") { - std::cout << ros::package::getPath("dr_util") << "\n"; - REQUIRE(ros::package::getPath("dr_util") + "/test.file" == dr::resolveResourceUrl("package://dr_util/test.file")); + std::cout << ros::package::getPath("dr_ros") << "\n"; + REQUIRE(ros::package::getPath("dr_ros") + "/test.file" == dr::resolveResourceUrl("package://dr_ros/test.file")); } TEST_CASE("ResourceTest -- localFileUrl", "localFileUrl") { From 9614f88a11271fbaf8f3af3350cc3a3fb7ac9ffe Mon Sep 17 00:00:00 2001 From: Nicolas Slusarenko Date: Mon, 26 Aug 2019 14:32:02 +0200 Subject: [PATCH 07/14] WIP Migration of testing unit from GTest to Catch2. --- test/resource.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/resource.cpp b/test/resource.cpp index 63f3df1..07ddb24 100644 --- a/test/resource.cpp +++ b/test/resource.cpp @@ -10,8 +10,10 @@ #include TEST_CASE("ResourceTest -- packageUrl", "packageUrl") { - std::cout << ros::package::getPath("dr_ros") << "\n"; - REQUIRE(ros::package::getPath("dr_ros") + "/test.file" == dr::resolveResourceUrl("package://dr_ros/test.file")); + std::cout << "first:" << ros::package::getPath("dr_ros") << "\n"; + std::cout << "second:" << dr::resolveResourceUrl("package://dr_ros/test.file") << "\n"; + // REQUIRE(ros::package::getPath("dr_ros") + "/test.file" == dr::resolveResourceUrl("package://dr_ros/test.file")); + SUCCEED(); } TEST_CASE("ResourceTest -- localFileUrl", "localFileUrl") { From 09c415a62016f085b3ef990bf6cbfc42a005eac8 Mon Sep 17 00:00:00 2001 From: Nicolas Slusarenko Date: Tue, 29 Oct 2019 17:02:39 +0100 Subject: [PATCH 08/14] Use sections, remove commented lines and improved indentation. --- CMakeLists.txt | 3 +- test/bitwise.cpp | 145 +++++++++++++++++++------------------- test/button_filter.cpp | 95 +++++++++++++------------ test/environment.cpp | 8 +-- test/expand.cpp | 43 +++++------ test/functional.cpp | 39 +++++----- test/geometry.cpp | 116 ++++++++++++++++++++++++++++-- test/integer_sequence.cpp | 71 ++++++++++--------- test/polynomial.cpp | 126 +++++++++++++++++---------------- test/resource.cpp | 37 +++++----- test/timestamp.cpp | 100 +++++++++++++------------- test/tuple.cpp | 89 ++++++++++++----------- test/void_t.cpp | 8 +-- 13 files changed, 505 insertions(+), 375 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec13005..6255a3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,8 +9,7 @@ add_compile_options(-Wall -Wextra -Wpedantic -Werror) find_package(catkin REQUIRED COMPONENTS dr_ros - roscpp - roslib + roslib ) find_package(Boost REQUIRED COMPONENTS filesystem date_time) diff --git a/test/bitwise.cpp b/test/bitwise.cpp index 93cf283..19df66a 100644 --- a/test/bitwise.cpp +++ b/test/bitwise.cpp @@ -1,79 +1,82 @@ -// Catch -#include - // This repository #include "bitwise.hpp" -namespace dr { - -TEST_CASE("BitwiseTest -- makeBitMask", "makeBitMask") { - // least significant bit - REQUIRE( 0x1u == bitMask(0)); - - // some middle bit - REQUIRE( 0x4000u == bitMask(14)); - - // most significant bit - REQUIRE(0x80000000u == bitMask(31)); -} +// Catch +#include -TEST_CASE("BitwiseTest -- testTestBit", "testTestBit") { - // least significant bit - REQUIRE(testBit(0x1, 0) == true); - REQUIRE(testBit(0x1, 14) == false); - REQUIRE(testBit(0x1, 31) == false); - - // some middle bit - REQUIRE(testBit(0x4000, 0) == false); - REQUIRE(testBit(0x4000, 14) == true); - REQUIRE(testBit(0x4000, 31) == false); - - // most significant bit - REQUIRE(testBit(0x80000000, 0) == false); - REQUIRE(testBit(0x80000000, 14) == false); - REQUIRE(testBit(0x80000000, 31) == true); - - // no value - REQUIRE(testBit(0, 0) == false); - REQUIRE(testBit(0, 14) == false); - REQUIRE(testBit(0, 31) == false); - - // all bits set to true - REQUIRE(testBit(0xFFFFFFFF, 0) == true); - REQUIRE(testBit(0xFFFFFFFF, 14) == true); - REQUIRE(testBit(0xFFFFFFFF, 31) == true); -} +namespace dr { -TEST_CASE("BitwiseTest -- testTestRising", "testTestRising") { - // no change for all bits set to 1 - REQUIRE(testRising(0xFFFFFFFF, 0xFFFFFFFF, 0) == false); - REQUIRE(testRising(0xFFFFFFFF, 0xFFFFFFFF, 14) == false); - REQUIRE(testRising(0xFFFFFFFF, 0xFFFFFFFF, 31) == false); - - // no change for all bits set to 0 - REQUIRE(testRising(0, 0, 0) == false); - REQUIRE(testRising(0, 0, 14) == false); - REQUIRE(testRising(0, 0, 31) == false); - - // ignore falling value - REQUIRE(testRising(0xFFFFFFFF, 0, 0) == true); - REQUIRE(testRising(0xFFFFFFFF, 0, 14) == true); - REQUIRE(testRising(0xFFFFFFFF, 0, 31) == true); - - // test rising edge - REQUIRE(testRising(0, 0xFFFFFFFF, 0) == false); - REQUIRE(testRising(0, 0xFFFFFFFF, 14) == false); - REQUIRE(testRising(0, 0xFFFFFFFF, 31) == false); - - // test specific rising edge - REQUIRE(testRising(0x1, 0, 0) == true); - REQUIRE(testRising(0x4000, 0, 14) == true); - REQUIRE(testRising(0x80000000, 0, 31) == true); - - // test wrong rising edge - REQUIRE(testRising(0x2, 0, 0) == false); - REQUIRE(testRising(0x8000, 0, 14) == false); - REQUIRE(testRising(0x40000000, 0, 31) == false); +TEST_CASE("BitwiseTest") { + + SECTION("makeBitMask") { + // least significant bit + REQUIRE( 0x1u == bitMask(0)); + + // some middle bit + REQUIRE( 0x4000u == bitMask(14)); + + // most significant bit + REQUIRE(0x80000000u == bitMask(31)); + } + + SECTION("testTestBit") { + // least significant bit + REQUIRE(testBit(0x1, 0) == true); + REQUIRE(testBit(0x1, 14) == false); + REQUIRE(testBit(0x1, 31) == false); + + // some middle bit + REQUIRE(testBit(0x4000, 0) == false); + REQUIRE(testBit(0x4000, 14) == true); + REQUIRE(testBit(0x4000, 31) == false); + + // most significant bit + REQUIRE(testBit(0x80000000, 0) == false); + REQUIRE(testBit(0x80000000, 14) == false); + REQUIRE(testBit(0x80000000, 31) == true); + + // no value + REQUIRE(testBit(0, 0) == false); + REQUIRE(testBit(0, 14) == false); + REQUIRE(testBit(0, 31) == false); + + // all bits set to true + REQUIRE(testBit(0xFFFFFFFF, 0) == true); + REQUIRE(testBit(0xFFFFFFFF, 14) == true); + REQUIRE(testBit(0xFFFFFFFF, 31) == true); + } + + SECTION("testTestRising") { + // no change for all bits set to 1 + REQUIRE(testRising(0xFFFFFFFF, 0xFFFFFFFF, 0) == false); + REQUIRE(testRising(0xFFFFFFFF, 0xFFFFFFFF, 14) == false); + REQUIRE(testRising(0xFFFFFFFF, 0xFFFFFFFF, 31) == false); + + // no change for all bits set to 0 + REQUIRE(testRising(0, 0, 0) == false); + REQUIRE(testRising(0, 0, 14) == false); + REQUIRE(testRising(0, 0, 31) == false); + + // ignore falling value + REQUIRE(testRising(0xFFFFFFFF, 0, 0) == true); + REQUIRE(testRising(0xFFFFFFFF, 0, 14) == true); + REQUIRE(testRising(0xFFFFFFFF, 0, 31) == true); + + // test rising edge + REQUIRE(testRising(0, 0xFFFFFFFF, 0) == false); + REQUIRE(testRising(0, 0xFFFFFFFF, 14) == false); + REQUIRE(testRising(0, 0xFFFFFFFF, 31) == false); + + // test specific rising edge + REQUIRE(testRising(0x1, 0, 0) == true); + REQUIRE(testRising(0x4000, 0, 14) == true); + REQUIRE(testRising(0x80000000, 0, 31) == true); + + // test wrong rising edge + REQUIRE(testRising(0x2, 0, 0) == false); + REQUIRE(testRising(0x8000, 0, 14) == false); + REQUIRE(testRising(0x40000000, 0, 31) == false); + } } } diff --git a/test/button_filter.cpp b/test/button_filter.cpp index 4b221b0..238355e 100644 --- a/test/button_filter.cpp +++ b/test/button_filter.cpp @@ -1,67 +1,70 @@ -// Catch -#include - // This repository #include "button_filter.hpp" +// Catch +#include + namespace dr { -TEST_CASE("ButtonFilterTest -- filterAlwaysHigh", "filterAlwaysHigh") { - ButtonFilter bf(true, false); +TEST_CASE("ButtonFilterTest") { - // pass through high signals always - REQUIRE(bf.filter(false) == false); - REQUIRE(bf.filter(true) == true); - REQUIRE(bf.filter(true) == true); -} + SECTION("filterAlwaysHigh") { + ButtonFilter bf(true, false); -TEST_CASE("ButtonFilterTest -- filterAlwaysLow", "filterAlwaysLow") { - ButtonFilter bf(false, true); + // pass through high signals always + REQUIRE(bf.filter(false) == false); + REQUIRE(bf.filter(true) == true); + REQUIRE(bf.filter(true) == true); + } - // pass through low signals always - REQUIRE(bf.filter(false) == true); - REQUIRE(bf.filter(true) == true); - REQUIRE(bf.filter(true) == false); -} + SECTION("filterAlwaysLow") { + ButtonFilter bf(false, true); -TEST_CASE("ButtonFilterTest -- filterAlwaysHighAndLow", "filterAlwaysHighAndLow") { - ButtonFilter bf(true, true); + // pass through low signals always + REQUIRE(bf.filter(false) == true); + REQUIRE(bf.filter(true) == true); + REQUIRE(bf.filter(true) == false); + } - // pass through any signal - REQUIRE(bf.filter(false) == true); - REQUIRE(bf.filter(false) == true); - REQUIRE(bf.filter(true) == true); - REQUIRE(bf.filter(true) == true); -} + SECTION("filterAlwaysHighAndLow") { + ButtonFilter bf(true, true); -TEST_CASE("ButtonFilterTest -- filterRisingEdge", "filterRisingEdge") { - ButtonFilter bf; + // pass through any signal + REQUIRE(bf.filter(false) == true); + REQUIRE(bf.filter(false) == true); + REQUIRE(bf.filter(true) == true); + REQUIRE(bf.filter(true) == true); + } - // test rising edge - REQUIRE(bf.filter(false) == false); - REQUIRE(bf.filter(true) == true); -} + SECTION("filterRisingEdge") { + ButtonFilter bf; -TEST_CASE("ButtonFilterTest -- filterFallingEdge", "filterFallingEdge") { - ButtonFilter bf; + // test rising edge + REQUIRE(bf.filter(false) == false); + REQUIRE(bf.filter(true) == true); + } - // test falling edge - REQUIRE(bf.filter(true) == true); - REQUIRE(bf.filter(false) == true); -} + SECTION("filterFallingEdge") { + ButtonFilter bf; + + // test falling edge + REQUIRE(bf.filter(true) == true); + REQUIRE(bf.filter(false) == true); + } -TEST_CASE("ButtonFilterTest -- filterMultiple", "filterMultiple") { - ButtonFilter bf; + SECTION("filterMultiple") { + ButtonFilter bf; - // test multiple signals - REQUIRE(bf.filter(true) == true); - REQUIRE(bf.filter(true) == false); + // test multiple signals + REQUIRE(bf.filter(true) == true); + REQUIRE(bf.filter(true) == false); - REQUIRE(bf.filter(false) == true); - REQUIRE(bf.filter(false) == false); + REQUIRE(bf.filter(false) == true); + REQUIRE(bf.filter(false) == false); - REQUIRE(bf.filter(true) == true); - REQUIRE(bf.filter(true) == false); + REQUIRE(bf.filter(true) == true); + REQUIRE(bf.filter(true) == false); + } } } diff --git a/test/environment.cpp b/test/environment.cpp index c923ac9..aee359a 100644 --- a/test/environment.cpp +++ b/test/environment.cpp @@ -1,11 +1,11 @@ -// C -#include +// This repository +#include "environment.hpp" // Catch #include -// This repository -#include "environment.hpp" +// C +#include namespace dr { diff --git a/test/expand.cpp b/test/expand.cpp index 20c102f..74efe98 100644 --- a/test/expand.cpp +++ b/test/expand.cpp @@ -1,31 +1,34 @@ -// Catch -#include - // This repository #include "expand.hpp" +// Catch +#include + namespace dr { -TEST_CASE("Expand -- simple", "simple") { - REQUIRE(expandVariables("$test", {{"test", "foo"}}) == "foo"); - REQUIRE(expandVariables("$test", {{"test", "bar"}}) == "bar"); - REQUIRE(expandVariables("${test}", {{"test", "foo"}}) == "foo"); - REQUIRE(expandVariables("${test}", {{"test", "bar"}}) == "bar"); -} +TEST_CASE("Expand") { -TEST_CASE("Expand -- sentence", "sentence") { - REQUIRE(expandVariables("Hello $name, welcome to $place", {{"name", "Rick"}, {"place", "Earth"}}) == "Hello Rick, welcome to Earth"); - REQUIRE(expandVariables("Hello ${name}, welcome to ${place}", {{"name", "Rick"}, {"place", "Earth"}}) == "Hello Rick, welcome to Earth"); -} + SECTION("simple") { + REQUIRE(expandVariables("$test", {{"test", "foo"}}) == "foo"); + REQUIRE(expandVariables("$test", {{"test", "bar"}}) == "bar"); + REQUIRE(expandVariables("${test}", {{"test", "foo"}}) == "foo"); + REQUIRE(expandVariables("${test}", {{"test", "bar"}}) == "bar"); + } -TEST_CASE("Expand -- nipple_brackets", "nipple_brackets") { - REQUIRE(expandVariables("test$testtest", {{"test", "wrong"}, {"testtest", "good"}}) == "testgood"); - REQUIRE(expandVariables("test${test}test", {{"test", "good"}, {"testtest", "wrong"}}) == "testgoodtest"); -} + SECTION("sentence") { + REQUIRE(expandVariables("Hello $name, welcome to $place", {{"name", "Rick"}, {"place", "Earth"}}) == "Hello Rick, welcome to Earth"); + REQUIRE(expandVariables("Hello ${name}, welcome to ${place}", {{"name", "Rick"}, {"place", "Earth"}}) == "Hello Rick, welcome to Earth"); + } + + SECTION("nipple_brackets") { + REQUIRE(expandVariables("test$testtest", {{"test", "wrong"}, {"testtest", "good"}}) == "testgood"); + REQUIRE(expandVariables("test${test}test", {{"test", "good"}, {"testtest", "wrong"}}) == "testgoodtest"); + } -TEST_CASE("Expand -- ignore_empty_key", "ignore_empty_key") { - REQUIRE(expandVariables("$", {{"", "aap"}}) == "$"); - REQUIRE(expandVariables("${}", {{"", "aap"}}) == "${}"); + SECTION("ignore_empty_key") { + REQUIRE(expandVariables("$", {{"", "aap"}}) == "$"); + REQUIRE(expandVariables("${}", {{"", "aap"}}) == "${}"); + } } } diff --git a/test/functional.cpp b/test/functional.cpp index 9a66624..1a1533b 100644 --- a/test/functional.cpp +++ b/test/functional.cpp @@ -1,26 +1,31 @@ +// This repository +#include "functional.hpp" +#include "tuple.hpp" + +// Catch +#include + // C++ #include #include #include -// Catch -#include -// This repository -#include "functional.hpp" -#include "tuple.hpp" +TEST_CASE("FunctionalTest") { + + SECTION("callHardcoded") { + REQUIRE(true == dr::call([] () { return true; }, std::make_tuple())); + REQUIRE(false == dr::call([] () { return false; }, std::make_tuple())); + } -TEST_CASE("FunctionalTest -- callHardcoded", "callHardcoded") { - REQUIRE(true == dr::call([] () { return true; }, std::make_tuple())); - REQUIRE(false == dr::call([] () { return false; }, std::make_tuple())); -} + SECTION("callInput") { + REQUIRE(true == dr::call([] (bool input) { return input; }, std::make_tuple(true))); + REQUIRE(false == dr::call([] (bool input) { return input; }, std::make_tuple(false))); + } -TEST_CASE("FunctionalTest -- callInput", "callInput") { - REQUIRE(true == dr::call([] (bool input) { return input; }, std::make_tuple(true))); - REQUIRE(false == dr::call([] (bool input) { return input; }, std::make_tuple(false))); -} + SECTION("callSum") { + REQUIRE( 3 == dr::call([] (int a, int b) { return a + b; }, std::make_tuple(1, 2))); + REQUIRE(17 == dr::call([] (int a, int b) { return a + b; }, std::make_tuple(7, 10))); + } -TEST_CASE("FunctionalTest -- callSum", "callSum") { - REQUIRE( 3 == dr::call([] (int a, int b) { return a + b; }, std::make_tuple(1, 2))); - REQUIRE(17 == dr::call([] (int a, int b) { return a + b; }, std::make_tuple(7, 10))); -} +} \ No newline at end of file diff --git a/test/geometry.cpp b/test/geometry.cpp index 641944b..2fdccea 100644 --- a/test/geometry.cpp +++ b/test/geometry.cpp @@ -1,16 +1,15 @@ -// Catch -#include - // This repository #include "geometry.hpp" +// Catch +#include + namespace { - void requireEqual(float const & a, float const & b) - { + void requireEqual(float const & a, float const & b) { REQUIRE_THAT(a, Catch::WithinULP(b, 0)); } - void requireNear(float const & a, float const & b, float const &tol){ + void requireNear(float const & a, float const & b, float const &tol) { float diff = std::abs(a - b); if (diff <= tol) { SUCCEED(); @@ -24,6 +23,109 @@ namespace { } } + +TEST_CASE("GeometryTest") { + + SECTION("testPi") { + // test equality with C defined pi + requireEqual(dr::pi(), M_PI); + } + + SECTION("testDegrees") { + // test normal use case + requireEqual(dr::degrees(0), 0); + requireEqual(dr::degrees(180), M_PI); + requireEqual(dr::degrees(360), 2 * M_PI); + requireNear(dr::degrees(37), 0.645771823237901, 0.0000001); // 37 / 180 * pi + + // test negativity + requireEqual(dr::degrees(-180), -M_PI); + requireEqual(dr::degrees(-360), -2 * M_PI); + } + + SECTION("testToDegrees") { + // test normal use case + requireEqual(dr::to_degrees(0), 0); + requireEqual(dr::to_degrees(M_PI), 180); + requireEqual(dr::to_degrees(2 * M_PI), 360); + requireNear(dr::to_degrees(0.645771823237901), 37, 0.0000001); // 37 / 180 * pi + + // test negativity + requireEqual(dr::to_degrees(-M_PI), -180); + requireEqual(dr::to_degrees(-2 * M_PI), -360); + } + + SECTION("testSign") { + // normal use cases + REQUIRE(dr::sign(-1) == -1); + REQUIRE(dr::sign(1) == 1); + REQUIRE(dr::sign(0) == 0); + + // double use cases + REQUIRE(dr::sign(M_PI) == 1); + REQUIRE(dr::sign(-M_PI) == -1); + REQUIRE(dr::sign(std::numeric_limits::quiet_NaN()) == 0); + } + + SECTION("testNormalizeAngle") { + // normal use + requireEqual(dr::normalizeAngle(3 * M_PI), M_PI); + requireEqual(dr::normalizeAngle(3.5 * M_PI), 1.5 * M_PI); + + // negativity + requireEqual(dr::normalizeAngle(-3 * M_PI), M_PI); + requireEqual(dr::normalizeAngle(-3.5 * M_PI), 0.5 * M_PI); + } + + SECTION("testAngleFrom") { + // same as normalizeAngle + + // normal use + requireEqual(dr::angleFrom(3 * M_PI, 0), M_PI); + requireEqual(dr::angleFrom(3.5 * M_PI, 0), 1.5 * M_PI); + + // negative angle + requireEqual(dr::angleFrom(-3 * M_PI, 0), M_PI); + requireEqual(dr::angleFrom(-3.5 * M_PI, 0), 0.5 * M_PI); + + // set different angle + + // normal use + requireEqual(dr::angleFrom(3 * M_PI, 5 * M_PI), 5 * M_PI); + requireEqual(dr::angleFrom(3.5 * M_PI, 5 * M_PI), 5.5 * M_PI); + + // negative from angle + requireEqual(dr::angleFrom(-3 * M_PI, -5 * M_PI), -5 * M_PI); + requireEqual(dr::angleFrom(-3.5 * M_PI, -5 * M_PI), -3.5 * M_PI); + + } + + SECTION("testSquare") { + requireEqual(dr::square(2), 4); + requireEqual(dr::square(-2), 4); + requireNear(dr::square(M_PI), 9.86960440108935861883, 0.000001); + requireNear(dr::square(-M_PI), 9.86960440108935861883, 0.000001); + } + + SECTION("testSquareSum") { + requireEqual(dr::square_sum(2.0, 2.0), 8.0); + requireEqual(dr::square_sum(1.0, 2.0, 3.0, 4.0, 5.0), 55.0); + requireEqual(dr::square_sum(-1.0, -2.0, -3.0, -4.0, -5.0), 55.0); + } + + SECTION("testLength") { + requireEqual(dr::length(1.0, 0.0, 0.0), 1.0); + requireNear(dr::length(10.0, 10.0, 0.0), 14.1421356237309504880, 0.0000001); // sqrt(10*10 + 10*10) + requireEqual(dr::length(0.0, 0.0, 0.0), 0.0); + } + + SECTION("testAngle") { + requireEqual(dr::angle(std::sqrt(2), 1.0, 1.0), M_PI_2); + } +} + + +/* TEST_CASE("GeometryTest -- testPi", "testPi") { // test equality with C defined pi requireEqual(dr::pi(), M_PI); @@ -120,3 +222,5 @@ TEST_CASE("GeometryTest -- testLength", "testLength") { TEST_CASE("GeometryTest --testAngle", "testAngle") { requireEqual(dr::angle(std::sqrt(2), 1.0, 1.0), M_PI_2); } + +*/ diff --git a/test/integer_sequence.cpp b/test/integer_sequence.cpp index 013cb3e..ca3d705 100644 --- a/test/integer_sequence.cpp +++ b/test/integer_sequence.cpp @@ -1,13 +1,13 @@ -// C++ -#include -#include -#include +// This repository +#include "integer_sequence.hpp" // Catch2 #include -// This repository -#include "integer_sequence.hpp" +// C++ +#include +#include +#include namespace dr { @@ -16,34 +16,37 @@ constexpr bool have_same_types(T1 const &, T2 const &) { return std::is_same{}; } -TEST_CASE("IntegerSequence -- have_same_types", "have_same_types") { - bool b1; - bool b2; - bool const b3 = false; - bool volatile b4; - bool * bp; - int i; - - static_assert(have_same_types(b1, b2), ""); - static_assert(have_same_types(b1, b3), ""); - static_assert(not have_same_types(b1, b4), ""); - static_assert(not have_same_types(b1, bp), ""); - static_assert(not have_same_types(b1, i), ""); - SUCCEED(); -} - -TEST_CASE("IntegerSequence -- add_offset_int", "add_offset_int") { - auto offset_sequence = offset_integer_sequence(std::make_integer_sequence{}); - auto expected_sequence = std::integer_sequence{}; - static_assert(have_same_types(offset_sequence, expected_sequence), ""); - SUCCEED(); -} - -TEST_CASE("IntegerSequence -- add_offset_index", "add_offset_index") { - auto offset_sequence = offset_index_sequence<8>(std::make_index_sequence<3>{}); - auto expected_sequence = std::index_sequence<8, 9, 10>{}; - static_assert(have_same_types(offset_sequence, expected_sequence), ""); - SUCCEED(); +TEST_CASE("IntegerSequence") { + + SECTION("have_same_types") { + bool b1; + bool b2; + bool const b3 = false; + bool volatile b4; + bool * bp; + int i; + + static_assert(have_same_types(b1, b2), ""); + static_assert(have_same_types(b1, b3), ""); + static_assert(not have_same_types(b1, b4), ""); + static_assert(not have_same_types(b1, bp), ""); + static_assert(not have_same_types(b1, i), ""); + SUCCEED(); + } + + SECTION("add_offset_int") { + auto offset_sequence = offset_integer_sequence(std::make_integer_sequence{}); + auto expected_sequence = std::integer_sequence{}; + static_assert(have_same_types(offset_sequence, expected_sequence), ""); + SUCCEED(); + } + + SECTION("add_offset_index") { + auto offset_sequence = offset_index_sequence<8>(std::make_index_sequence<3>{}); + auto expected_sequence = std::index_sequence<8, 9, 10>{}; + static_assert(have_same_types(offset_sequence, expected_sequence), ""); + SUCCEED(); + } } } diff --git a/test/polynomial.cpp b/test/polynomial.cpp index e37dd30..cbb2ef5 100644 --- a/test/polynomial.cpp +++ b/test/polynomial.cpp @@ -1,84 +1,86 @@ -// C++ -#include +// This repository +#include "polynomial.hpp" // Catch2 #include -// This repository -#include "polynomial.hpp" +// C++ +#include namespace { - void requireEqual(float const & a, float const & b) - { + void requireEqual(float const & a, float const & b) { REQUIRE_THAT(a, Catch::WithinULP(b, 0)); } } -TEST_CASE("PolynomialTest -- emptyPolynomial", "emptyPolynomial") { - dr::Polynomial p; - requireEqual(0, p.y(0.0)); - requireEqual(0, p.y(0.5)); - requireEqual(0, p.y(1.0)); - requireEqual(0, p.y(-0.5)); - requireEqual(0, p.y(-1.0)); -} +TEST_CASE("PolynomialTest") { + + SECTION("emptyPolynomial") { + dr::Polynomial p; + requireEqual(0, p.y(0.0)); + requireEqual(0, p.y(0.5)); + requireEqual(0, p.y(1.0)); + requireEqual(0, p.y(-0.5)); + requireEqual(0, p.y(-1.0)); + } -TEST_CASE("PolynomialTest -- constantPolynomial", "constantPolynomial") { - dr::Polynomial p; - p.terms.emplace_back(3.25, 0); + SECTION("constantPolynomial") { + dr::Polynomial p; + p.terms.emplace_back(3.25, 0); - requireEqual(3.25, p.y( 0.0)); - requireEqual(3.25, p.y( 0.5)); - requireEqual(3.25, p.y( 1.0)); - requireEqual(3.25, p.y(-0.5)); - requireEqual(3.25, p.y(-1.0)); -} + requireEqual(3.25, p.y( 0.0)); + requireEqual(3.25, p.y( 0.5)); + requireEqual(3.25, p.y( 1.0)); + requireEqual(3.25, p.y(-0.5)); + requireEqual(3.25, p.y(-1.0)); + } -TEST_CASE("PolynomialTest -- squareRoot", "squareRoot") { - dr::Polynomial p; - p.terms.emplace_back(1, 0.5); + SECTION("squareRoot") { + dr::Polynomial p; + p.terms.emplace_back(1, 0.5); - requireEqual( 0.000, p.y(0.0)); - requireEqual( 1.000, p.y(1.0)); - requireEqual( 2.000, p.y(4.0)); + requireEqual( 0.000, p.y(0.0)); + requireEqual( 1.000, p.y(1.0)); + requireEqual( 2.000, p.y(4.0)); - REQUIRE(std::isnan(p.y(-1.0)) == true); - REQUIRE(std::isnan(p.y(-4.0)) == true); -} + REQUIRE(std::isnan(p.y(-1.0)) == true); + REQUIRE(std::isnan(p.y(-4.0)) == true); + } -TEST_CASE("PolynomialTest -- firstOrder", "firstOrder") { - dr::Polynomial p; - p.terms.emplace_back(2, 1); + SECTION("firstOrder") { + dr::Polynomial p; + p.terms.emplace_back(2, 1); - requireEqual( 0, p.y(0.0)); - requireEqual( 1, p.y(0.5)); - requireEqual( 2, p.y(1.0)); - requireEqual(-1, p.y(-0.5)); - requireEqual(-2, p.y(-1.0)); -} + requireEqual( 0, p.y(0.0)); + requireEqual( 1, p.y(0.5)); + requireEqual( 2, p.y(1.0)); + requireEqual(-1, p.y(-0.5)); + requireEqual(-2, p.y(-1.0)); + } -TEST_CASE("PolynomialTest -- thirdOrder", "thirdOrder") { - dr::Polynomial p; - p.terms.emplace_back(2, 1); - p.terms.emplace_back(1.5, 3); + SECTION("thirdOrder") { + dr::Polynomial p; + p.terms.emplace_back(2, 1); + p.terms.emplace_back(1.5, 3); - requireEqual( 0.0000, p.y(0.0)); - requireEqual( 1.1875, p.y(0.5)); - requireEqual( 3.5000, p.y(1.0)); - requireEqual(-1.1875, p.y(-0.5)); - requireEqual(-3.5000, p.y(-1.0)); -} + requireEqual( 0.0000, p.y(0.0)); + requireEqual( 1.1875, p.y(0.5)); + requireEqual( 3.5000, p.y(1.0)); + requireEqual(-1.1875, p.y(-0.5)); + requireEqual(-3.5000, p.y(-1.0)); + } -TEST_CASE("PolynomialTest -- fourthOrder", "fourthOrder") { - dr::Polynomial p; - p.terms.emplace_back(1, 2); - p.terms.emplace_back(2, 4); + SECTION("fourthOrder") { + dr::Polynomial p; + p.terms.emplace_back(1, 2); + p.terms.emplace_back(2, 4); - requireEqual( 0.000, p.y(0.0)); - requireEqual( 0.375, p.y(0.5)); - requireEqual( 3.000, p.y(1.0)); - requireEqual(36.000, p.y(2.0)); - requireEqual( 0.375, p.y(-0.5)); - requireEqual( 3.000, p.y(-1.0)); - requireEqual(36.000, p.y(-2.0)); + requireEqual( 0.000, p.y(0.0)); + requireEqual( 0.375, p.y(0.5)); + requireEqual( 3.000, p.y(1.0)); + requireEqual(36.000, p.y(2.0)); + requireEqual( 0.375, p.y(-0.5)); + requireEqual( 3.000, p.y(-1.0)); + requireEqual(36.000, p.y(-2.0)); + } } diff --git a/test/resource.cpp b/test/resource.cpp index 07ddb24..da1b0d2 100644 --- a/test/resource.cpp +++ b/test/resource.cpp @@ -1,29 +1,32 @@ +// This repository +#include "resource.hpp" + // Catch2 #include // ROS #include -// This repository -#include "resource.hpp" - +// C++ #include -TEST_CASE("ResourceTest -- packageUrl", "packageUrl") { - std::cout << "first:" << ros::package::getPath("dr_ros") << "\n"; - std::cout << "second:" << dr::resolveResourceUrl("package://dr_ros/test.file") << "\n"; - // REQUIRE(ros::package::getPath("dr_ros") + "/test.file" == dr::resolveResourceUrl("package://dr_ros/test.file")); - SUCCEED(); -} +TEST_CASE("ResourceTest") { + + SECTION("packageUrl") { + std::string first = ros::package::getPath("dr_ros") + "/test.file" ; + std::string second = dr::resolveResourceUrl("package://dr_ros/test.file"); + REQUIRE(first == second); + } -TEST_CASE("ResourceTest -- localFileUrl", "localFileUrl") { - REQUIRE("/test.file" == dr::resolveResourceUrl("file:///test.file")); -} + SECTION("localFileUrl") { + REQUIRE("/test.file" == dr::resolveResourceUrl("file:///test.file")); + } -TEST_CASE("ResourceTest -- remoteFileUrl", "remoteFileUrl") { - REQUIRE_THROWS(dr::resolveResourceUrl("file://host/test.file")); -} + SECTION("remoteFileUrl") { + REQUIRE_THROWS(dr::resolveResourceUrl("file://host/test.file")); + } -TEST_CASE("ResourceTest -- unsupportedScheme", "unsupportedScheme") { - REQUIRE_THROWS(dr::resolveResourceUrl("http://example.com/test.file")); + SECTION("unsupportedScheme") { + REQUIRE_THROWS(dr::resolveResourceUrl("http://example.com/test.file")); + } } diff --git a/test/timestamp.cpp b/test/timestamp.cpp index 9ac3b8f..d3d29e7 100644 --- a/test/timestamp.cpp +++ b/test/timestamp.cpp @@ -1,59 +1,61 @@ -// C++ -#include -#include -#include +// This repository +#include "../src/chrono_ptime.hpp" // Catch #include -// This repository -#include "../src/chrono_ptime.hpp" +// C++ +#include +#include +#include namespace dr { -TEST_CASE("timestamp -- system_clock_epoch", "system_clock_epoch") { - std::time_t epoch = std::chrono::system_clock::to_time_t(std::chrono::system_clock::time_point{}); - std::tm * date = std::gmtime(&epoch); - REQUIRE(date->tm_year == 70); - REQUIRE(date->tm_mon == 0); - REQUIRE(date->tm_mday == 1); - REQUIRE(date->tm_hour == 0); - REQUIRE(date->tm_min == 0); - REQUIRE(date->tm_sec == 0); - REQUIRE(date->tm_yday == 0); - REQUIRE(date->tm_isdst == 0); -} - -TEST_CASE("timestamp -- chrono_ptime_epoch", "chrono_ptime_epoch") { - boost::posix_time::ptime epoch = toPtime(std::chrono::system_clock::time_point{}); - REQUIRE(epoch.date().year() == 1970); - REQUIRE(epoch.date().month() == 1); - REQUIRE(epoch.date().day() == 1); - REQUIRE(epoch.date().day_of_year() == 1); - REQUIRE(epoch.time_of_day() == boost::posix_time::seconds(0)); -} - -TEST_CASE("timestamp -- chrono_ptime_2017", "chrono_ptime_2017") { - - std::tm tm; - tm.tm_year = 117; - tm.tm_mon = 2; - tm.tm_mday = 30; - tm.tm_wday = 4; - tm.tm_hour = 13; - tm.tm_min = 37; - tm.tm_sec = 42; - - boost::posix_time::ptime time = toPtime(std::chrono::system_clock::from_time_t(std::mktime(&tm))); - - REQUIRE(time.date().year() == 2017); - REQUIRE(time.date().month() == boost::gregorian::Mar); - REQUIRE(time.date().day() == 30); - REQUIRE(time.date().day_of_year() == 89); - REQUIRE(time.date().day_of_week() == boost::gregorian::Thursday); - REQUIRE(time.time_of_day().hours() == 11); - REQUIRE(time.time_of_day().minutes() == 37); - REQUIRE(time.time_of_day().seconds() == 42); +TEST_CASE("timestamp") { + + SECTION("system_clock_epoch") { + std::time_t epoch = std::chrono::system_clock::to_time_t(std::chrono::system_clock::time_point{}); + std::tm * date = std::gmtime(&epoch); + REQUIRE(date->tm_year == 70); + REQUIRE(date->tm_mon == 0); + REQUIRE(date->tm_mday == 1); + REQUIRE(date->tm_hour == 0); + REQUIRE(date->tm_min == 0); + REQUIRE(date->tm_sec == 0); + REQUIRE(date->tm_yday == 0); + REQUIRE(date->tm_isdst == 0); + } + + SECTION("chrono_ptime_epoch") { + boost::posix_time::ptime epoch = toPtime(std::chrono::system_clock::time_point{}); + REQUIRE(epoch.date().year() == 1970); + REQUIRE(epoch.date().month() == 1); + REQUIRE(epoch.date().day() == 1); + REQUIRE(epoch.date().day_of_year() == 1); + REQUIRE(epoch.time_of_day() == boost::posix_time::seconds(0)); + } + + SECTION("chrono_ptime_2017") { + std::tm tm; + tm.tm_year = 117; + tm.tm_mon = 2; + tm.tm_mday = 30; + tm.tm_wday = 4; + tm.tm_hour = 13; + tm.tm_min = 37; + tm.tm_sec = 42; + + boost::posix_time::ptime time = toPtime(std::chrono::system_clock::from_time_t(std::mktime(&tm))); + + REQUIRE(time.date().year() == 2017); + REQUIRE(time.date().month() == boost::gregorian::Mar); + REQUIRE(time.date().day() == 30); + REQUIRE(time.date().day_of_year() == 89); + REQUIRE(time.date().day_of_week() == boost::gregorian::Thursday); + REQUIRE(time.time_of_day().hours() == 11); + REQUIRE(time.time_of_day().minutes() == 37); + REQUIRE(time.time_of_day().seconds() == 42); + } } } diff --git a/test/tuple.cpp b/test/tuple.cpp index 13f9b85..0cfb0c6 100644 --- a/test/tuple.cpp +++ b/test/tuple.cpp @@ -1,50 +1,53 @@ +// This repository +#include "tuple.hpp" + +// Catch +#include + // C++ #include #include #include -// Catch -#include +TEST_CASE("TupleTest") { -// This repository -#include "tuple.hpp" + SECTION("sliceOne") { + auto tuple = std::make_tuple(1, true, 3); + REQUIRE(1u == std::tuple_size(tuple))>::value); + REQUIRE(1u == std::tuple_size(tuple))>::value); + REQUIRE(1u == std::tuple_size(tuple))>::value); + REQUIRE(1 == std::get<0>(dr::tuple_slice<0, 1>(tuple))); + REQUIRE(true == std::get<0>(dr::tuple_slice<1, 1>(tuple))); + REQUIRE(3 == std::get<0>(dr::tuple_slice<2, 1>(tuple))); + } + + SECTION("sliceTwo") { + auto tuple = std::make_tuple(1, true, 3); + REQUIRE(2u == std::tuple_size(tuple))>::value); + REQUIRE(2u == std::tuple_size(tuple))>::value); + REQUIRE(1 == std::get<0>(dr::tuple_slice<0, 2>(tuple))); + REQUIRE(true == std::get<1>(dr::tuple_slice<0, 2>(tuple))); + REQUIRE(true == std::get<0>(dr::tuple_slice<1, 2>(tuple))); + REQUIRE(3 == std::get<1>(dr::tuple_slice<1, 2>(tuple))); + } + + SECTION("sliceThree") { + auto tuple = std::make_tuple(1, true, 3); + REQUIRE(3u == std::tuple_size(tuple))>::value); + REQUIRE(1 == std::get<0>(dr::tuple_slice<0, 3>(tuple))); + REQUIRE(true == std::get<1>(dr::tuple_slice<0, 3>(tuple))); + REQUIRE(3 == std::get<2>(dr::tuple_slice<0, 3>(tuple))); + } + + SECTION("tail") { + auto tuple = std::make_tuple(1, true, 3); + REQUIRE(2u == std::tuple_size::value); + REQUIRE(true == std::get<0>(dr::tuple_tail(tuple))); + REQUIRE(3 == std::get<1>(dr::tuple_tail(tuple))); + } -TEST_CASE("TupleTest -- sliceOne", "sliceOne") { - auto tuple = std::make_tuple(1, true, 3); - REQUIRE(1u == std::tuple_size(tuple))>::value); - REQUIRE(1u == std::tuple_size(tuple))>::value); - REQUIRE(1u == std::tuple_size(tuple))>::value); - REQUIRE(1 == std::get<0>(dr::tuple_slice<0, 1>(tuple))); - REQUIRE(true == std::get<0>(dr::tuple_slice<1, 1>(tuple))); - REQUIRE(3 == std::get<0>(dr::tuple_slice<2, 1>(tuple))); -} - -TEST_CASE("TupleTest -- sliceTwo", "sliceTwo") { - auto tuple = std::make_tuple(1, true, 3); - REQUIRE(2u == std::tuple_size(tuple))>::value); - REQUIRE(2u == std::tuple_size(tuple))>::value); - REQUIRE(1 == std::get<0>(dr::tuple_slice<0, 2>(tuple))); - REQUIRE(true == std::get<1>(dr::tuple_slice<0, 2>(tuple))); - REQUIRE(true == std::get<0>(dr::tuple_slice<1, 2>(tuple))); - REQUIRE(3 == std::get<1>(dr::tuple_slice<1, 2>(tuple))); -} - -TEST_CASE("TupleTest -- sliceThree", "sliceThree") { - auto tuple = std::make_tuple(1, true, 3); - REQUIRE(3u == std::tuple_size(tuple))>::value); - REQUIRE(1 == std::get<0>(dr::tuple_slice<0, 3>(tuple))); - REQUIRE(true == std::get<1>(dr::tuple_slice<0, 3>(tuple))); - REQUIRE(3 == std::get<2>(dr::tuple_slice<0, 3>(tuple))); -} - -TEST_CASE("TupleTest -- tail", "tail") { - auto tuple = std::make_tuple(1, true, 3); - REQUIRE(2u == std::tuple_size::value); - REQUIRE(true == std::get<0>(dr::tuple_tail(tuple))); - REQUIRE(3 == std::get<1>(dr::tuple_tail(tuple))); -} - -TEST_CASE("TupleTest -- tailEmpty", "tailEmpty") { - auto tuple = std::make_tuple(1); - REQUIRE(0u == std::tuple_size::value); -} + SECTION("tailEmpty") { + auto tuple = std::make_tuple(1); + REQUIRE(0u == std::tuple_size::value); + } +} \ No newline at end of file diff --git a/test/void_t.cpp b/test/void_t.cpp index cf109a6..36fe88f 100644 --- a/test/void_t.cpp +++ b/test/void_t.cpp @@ -1,10 +1,10 @@ -// Catch -#include - // This repository #include "void_t.hpp" -TEST_CASE("VoidT -- type", "type") { +// Catch +#include + +TEST_CASE("VoidT", "type") { static_assert(std::is_same>{}, ""); static_assert(std::is_same>{}, ""); static_assert(std::is_same>{}, ""); From b0dcf41154650db9241d5db239b20853e8e0badc Mon Sep 17 00:00:00 2001 From: Nicolas Slusarenko Date: Tue, 29 Oct 2019 17:26:08 +0100 Subject: [PATCH 09/14] WIP just to verify buildbot. --- package.xml | 3 +++ test/resource.cpp | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/package.xml b/package.xml index a917511..54ece77 100644 --- a/package.xml +++ b/package.xml @@ -13,6 +13,9 @@ dr_ros roscpp roslib + + dr_log + catch2 dr_ros diff --git a/test/resource.cpp b/test/resource.cpp index da1b0d2..2b93290 100644 --- a/test/resource.cpp +++ b/test/resource.cpp @@ -13,8 +13,15 @@ TEST_CASE("ResourceTest") { SECTION("packageUrl") { - std::string first = ros::package::getPath("dr_ros") + "/test.file" ; - std::string second = dr::resolveResourceUrl("package://dr_ros/test.file"); + // std::string first = ros::package::getPath("dr_ros") + "/test.file" ; + std::string first = ros::package::getPath("dr_log") + "/test.file" ; + // std::string second = dr::resolveResourceUrl("package://dr_ros/test.file"); + std::string second = dr::resolveResourceUrl("package://dr_log/test.file"); + // std::string second = dr::resolveResourceUrl("package://boost/test.file"); + + std::cout << "first:" << first << "\n"; + std::cout << "second:" << second << "\n"; + REQUIRE(first == second); } From 8e123951e8ebba04b19b0488790fd08a6b1d95d0 Mon Sep 17 00:00:00 2001 From: Nicolas Slusarenko Date: Tue, 29 Oct 2019 17:37:28 +0100 Subject: [PATCH 10/14] Another verification in buildbot. --- package.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/package.xml b/package.xml index 54ece77..a23998c 100644 --- a/package.xml +++ b/package.xml @@ -18,4 +18,5 @@ catch2 dr_ros + dr_log From d00eda4fd524b0aff1217eabea8de3e0cf914110 Mon Sep 17 00:00:00 2001 From: Nicolas Slusarenko Date: Tue, 29 Oct 2019 17:55:56 +0100 Subject: [PATCH 11/14] Yet another verification in buildbot. --- CMakeLists.txt | 2 +- test/resource.cpp | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6255a3b..e376b5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ add_compile_options(-Wall -Wextra -Wpedantic -Werror) find_package(catkin REQUIRED COMPONENTS dr_ros - roslib + roslib ) find_package(Boost REQUIRED COMPONENTS filesystem date_time) diff --git a/test/resource.cpp b/test/resource.cpp index 2b93290..35a4f21 100644 --- a/test/resource.cpp +++ b/test/resource.cpp @@ -9,6 +9,7 @@ // C++ #include +#include TEST_CASE("ResourceTest") { @@ -16,7 +17,14 @@ TEST_CASE("ResourceTest") { // std::string first = ros::package::getPath("dr_ros") + "/test.file" ; std::string first = ros::package::getPath("dr_log") + "/test.file" ; // std::string second = dr::resolveResourceUrl("package://dr_ros/test.file"); - std::string second = dr::resolveResourceUrl("package://dr_log/test.file"); + + std::string second; + + try { + second = dr::resolveResourceUrl("package://dr_log/test.file"); + } catch (std::exception & e){ + std::cout << "exception:" << e.what() << "\n"; + } // std::string second = dr::resolveResourceUrl("package://boost/test.file"); std::cout << "first:" << first << "\n"; From e57ecffc630c50bf91a1ea28d2cf86355988b186 Mon Sep 17 00:00:00 2001 From: Nicolas Slusarenko Date: Tue, 29 Oct 2019 17:59:57 +0100 Subject: [PATCH 12/14] More verification in buildbot. --- test/resource.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/resource.cpp b/test/resource.cpp index 35a4f21..5b4e7fe 100644 --- a/test/resource.cpp +++ b/test/resource.cpp @@ -21,7 +21,8 @@ TEST_CASE("ResourceTest") { std::string second; try { - second = dr::resolveResourceUrl("package://dr_log/test.file"); + // second = dr::resolveResourceUrl("package://dr_log/test.file"); + second = dr::resolveResourceUrl("anything://dr_log/test.file"); } catch (std::exception & e){ std::cout << "exception:" << e.what() << "\n"; } From 6c79b68e2a166c01264b4f3e95721b1ed6935de2 Mon Sep 17 00:00:00 2001 From: Nicolas Slusarenko Date: Tue, 19 Nov 2019 10:17:59 +0100 Subject: [PATCH 13/14] WIP an experiment in BuildBot. --- test/resource.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/resource.cpp b/test/resource.cpp index 5b4e7fe..9302b8c 100644 --- a/test/resource.cpp +++ b/test/resource.cpp @@ -11,9 +11,30 @@ #include #include +namespace { + + std::string exec(const char * cmd) { + std::array buffer; + std::string result; + std::unique_ptr pipe(popen(cmd, "r"), pclose); + if (!pipe) { + throw std::runtime_error("popen() failed!"); + } + while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { + result += buffer.data(); + } + return result; + } +} + + TEST_CASE("ResourceTest") { SECTION("packageUrl") { + + std::cout << "find result:" << exec("find / -name rospack") << "\n"; + std::cout << "value of PATH:" << exec("echo $PATH") << "\n"; + // std::string first = ros::package::getPath("dr_ros") + "/test.file" ; std::string first = ros::package::getPath("dr_log") + "/test.file" ; // std::string second = dr::resolveResourceUrl("package://dr_ros/test.file"); From 303d8491f86b177bc2c22d61c330e19b9f90f0e2 Mon Sep 17 00:00:00 2001 From: Nicolas Slusarenko Date: Fri, 22 Nov 2019 12:00:19 +0100 Subject: [PATCH 14/14] Commented the failure in testing-unit. --- test/resource.cpp | 55 +++++++++++------------------------------------ 1 file changed, 12 insertions(+), 43 deletions(-) diff --git a/test/resource.cpp b/test/resource.cpp index 9302b8c..02cb292 100644 --- a/test/resource.cpp +++ b/test/resource.cpp @@ -7,52 +7,21 @@ // ROS #include -// C++ -#include -#include - -namespace { - - std::string exec(const char * cmd) { - std::array buffer; - std::string result; - std::unique_ptr pipe(popen(cmd, "r"), pclose); - if (!pipe) { - throw std::runtime_error("popen() failed!"); - } - while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { - result += buffer.data(); - } - return result; - } -} - - TEST_CASE("ResourceTest") { SECTION("packageUrl") { - - std::cout << "find result:" << exec("find / -name rospack") << "\n"; - std::cout << "value of PATH:" << exec("echo $PATH") << "\n"; - - // std::string first = ros::package::getPath("dr_ros") + "/test.file" ; - std::string first = ros::package::getPath("dr_log") + "/test.file" ; - // std::string second = dr::resolveResourceUrl("package://dr_ros/test.file"); - - std::string second; - - try { - // second = dr::resolveResourceUrl("package://dr_log/test.file"); - second = dr::resolveResourceUrl("anything://dr_log/test.file"); - } catch (std::exception & e){ - std::cout << "exception:" << e.what() << "\n"; - } - // std::string second = dr::resolveResourceUrl("package://boost/test.file"); - - std::cout << "first:" << first << "\n"; - std::cout << "second:" << second << "\n"; - - REQUIRE(first == second); + /** + * TODO: This test fails in BuildBot because it can not resolve the location + * of the "package://some_package". At the end of a chain of calls, + * 'ROSPack::run(..)' excecutes "rospack find some_package". + * + * More about this method. + * http://docs.ros.org/indigo/api/rospack/html/rospack__backcompat_8cpp_source.html * + * + * This method succeeds if rospack is installed and located in the PATH. + * In BuildBot test-container rospack is installed, but its location is not in the PATH. + **/ + REQUIRE(ros::package::getPath("dr_util") + "/test.file" == dr::resolveResourceUrl("package://dr_util/test.file")); } SECTION("localFileUrl") {