diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 06ef789..cdb1402 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -40,6 +40,4 @@ jobs: - run: make dep_install PKG=intrometry_pjmsg_topic - run: make intrometry BUILD_PROFILE=scan_build - run: make intrometry - - run: make test PKG=intrometry_frontend - - run: make test PKG=intrometry_pjmsg_mcap - - run: make test PKG=intrometry_pjmsg_topic + - run: make test PKG=intrometry_tests diff --git a/README.md b/README.md index 7866461..af7fa10 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ target_link_libraries(my_library intrometry::) ### C++ ``` -#include /.h> +#include /all.h> ``` diff --git a/frontend/include/intrometry/combo.h b/frontend/include/intrometry/combo.h index 0a8bf34..820c983 100644 --- a/frontend/include/intrometry/combo.h +++ b/frontend/include/intrometry/combo.h @@ -28,7 +28,7 @@ namespace intrometry class ComboSink { public: - std::shared_ptr sink_; + std::shared_ptr sink_; std::tuple data_; public: diff --git a/frontend/include/intrometry/sink.h b/frontend/include/intrometry/sink.h index 7882916..5187d09 100644 --- a/frontend/include/intrometry/sink.h +++ b/frontend/include/intrometry/sink.h @@ -22,10 +22,10 @@ namespace intrometry * * @ingroup API */ - class SinkBase + class Sink { public: - virtual ~SinkBase() = default; + virtual ~Sink() = default; /** * Initialize sink. @@ -88,7 +88,7 @@ namespace intrometry template - class SinkPIMPLBase : public SinkBase + class SinkPIMPLBase : public Sink { public: using Parameters = t_Parameters; diff --git a/pjmsg_mcap/CMakeLists.txt b/pjmsg_mcap/CMakeLists.txt index fe4074b..82dc83e 100644 --- a/pjmsg_mcap/CMakeLists.txt +++ b/pjmsg_mcap/CMakeLists.txt @@ -74,12 +74,6 @@ install(DIRECTORY include/intrometry ) -if(NOT DEFINED BUILD_TESTING OR BUILD_TESTING) - enable_testing() - add_subdirectory(test) -endif() - - # --- # cmake package stuff export(EXPORT ${PROJECT_NAME} @@ -106,7 +100,8 @@ file( "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" "include(\"\${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}Targets.cmake\")\n" "include(CMakeFindDependencyMacro)\n" - "find_dependency(ariles2_namevalue2_ws)" + "find_dependency(ariles2_namevalue2_ws)\n" + "find_dependency(intrometry_frontend)" ) install( diff --git a/pjmsg_mcap/include/intrometry/pjmsg_mcap/pjmsg_mcap.h b/pjmsg_mcap/include/intrometry/pjmsg_mcap/all.h similarity index 86% rename from pjmsg_mcap/include/intrometry/pjmsg_mcap/pjmsg_mcap.h rename to pjmsg_mcap/include/intrometry/pjmsg_mcap/all.h index e7fbf1c..98912c5 100644 --- a/pjmsg_mcap/include/intrometry/pjmsg_mcap/pjmsg_mcap.h +++ b/pjmsg_mcap/include/intrometry/pjmsg_mcap/all.h @@ -8,4 +8,4 @@ #pragma once #include -#include "sink.h" +#include diff --git a/pjmsg_mcap/package.xml b/pjmsg_mcap/package.xml index ac89147..11e5c65 100644 --- a/pjmsg_mcap/package.xml +++ b/pjmsg_mcap/package.xml @@ -17,6 +17,4 @@ ariles2_namevalue2_ws thread_supervisor ariles2_namevalue2_ws - - gtest diff --git a/pjmsg_mcap/src/intrometry.cpp b/pjmsg_mcap/src/intrometry.cpp index 0b3bf7a..e5c3b73 100644 --- a/pjmsg_mcap/src/intrometry.cpp +++ b/pjmsg_mcap/src/intrometry.cpp @@ -324,7 +324,10 @@ namespace intrometry::pjmsg_mcap::sink const std::string topic_prefix = intrometry::backend::str_concat("/intrometry/", node_id.empty() ? random_id : node_id); - std::filesystem::create_directories(directory); + if (not directory.empty()) + { + std::filesystem::create_directories(directory); + } const std::filesystem::path filename = directory / intrometry::backend::str_concat( node_id, @@ -334,7 +337,6 @@ namespace intrometry::pjmsg_mcap::sink intrometry::backend::getDateString(), ".mcap"); - mcap_writer_.initialize(filename, topic_prefix); thread_supervisor_.add( diff --git a/pjmsg_mcap/test/CMakeLists.txt b/pjmsg_mcap/test/CMakeLists.txt deleted file mode 100644 index d25fa86..0000000 --- a/pjmsg_mcap/test/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -find_package(GTest REQUIRED) - -foreach(TEST_NAME combo intrometry) - add_executable(test_${TEST_NAME} ${TEST_NAME}.cpp) - target_link_libraries(test_${TEST_NAME} ${PROJECT_NAME} - GTest::GTest - thread_supervisor::thread_supervisor - ) - add_test(test_${TEST_NAME} test_${TEST_NAME}) -endforeach() diff --git a/pjmsg_topic/CMakeLists.txt b/pjmsg_topic/CMakeLists.txt index d8f9ae9..9282dc4 100644 --- a/pjmsg_topic/CMakeLists.txt +++ b/pjmsg_topic/CMakeLists.txt @@ -68,11 +68,6 @@ install(DIRECTORY include/intrometry ) -if(BUILD_TESTING) - add_subdirectory(test) -endif() - - # --- # cmake package stuff export(EXPORT ${PROJECT_NAME} diff --git a/pjmsg_topic/include/intrometry/pjmsg_topic/pjmsg_topic.h b/pjmsg_topic/include/intrometry/pjmsg_topic/all.h similarity index 85% rename from pjmsg_topic/include/intrometry/pjmsg_topic/pjmsg_topic.h rename to pjmsg_topic/include/intrometry/pjmsg_topic/all.h index e7fbf1c..adf659e 100644 --- a/pjmsg_topic/include/intrometry/pjmsg_topic/pjmsg_topic.h +++ b/pjmsg_topic/include/intrometry/pjmsg_topic/all.h @@ -8,4 +8,4 @@ #pragma once #include -#include "sink.h" +#include diff --git a/pjmsg_topic/package.xml b/pjmsg_topic/package.xml index a06cf9d..098f30e 100644 --- a/pjmsg_topic/package.xml +++ b/pjmsg_topic/package.xml @@ -21,6 +21,4 @@ thread_supervisor plotjuggler_msgs ariles2_namevalue2_ws - - gtest diff --git a/pjmsg_topic/test/CMakeLists.txt b/pjmsg_topic/test/CMakeLists.txt deleted file mode 100644 index 9e81518..0000000 --- a/pjmsg_topic/test/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -find_package(GTest REQUIRED) - -foreach(TEST_NAME combo intrometry) - add_executable(test_${TEST_NAME} ${TEST_NAME}.cpp) - target_link_libraries(test_${TEST_NAME} ${PROJECT_NAME} - rclcpp::rclcpp - GTest::GTest - thread_supervisor::thread_supervisor - plotjuggler_msgs::plotjuggler_msgs__rosidl_typesupport_cpp - ) - add_test(test_${TEST_NAME} test_${TEST_NAME}) -endforeach() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..4210688 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.8) +project(intrometry_tests VERSION 1.0.0 LANGUAGES CXX) + +if(CCWS_CXX_FLAGS) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CCWS_CXX_FLAGS}") + set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CCWS_LINKER_FLAGS}") +else() + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + set(CMAKE_VERBOSE_MAKEFILE ON) + + if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + endif() + + if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic -Werror) + endif() +endif() + +if(NOT DEFINED BUILD_TESTING OR BUILD_TESTING) + enable_testing() + add_subdirectory(test) +endif() diff --git a/tests/package.xml b/tests/package.xml new file mode 100644 index 0000000..0e911be --- /dev/null +++ b/tests/package.xml @@ -0,0 +1,19 @@ + + + intrometry_tests + 1.0.0 + Intrometry tests + Alexander Sherikov + Alexander Sherikov + Apache 2.0 + + + cmake + + + thread_supervisor + intrometry_pjmsg_mcap + intrometry_pjmsg_topic + + gtest + diff --git a/tests/test/CMakeLists.txt b/tests/test/CMakeLists.txt new file mode 100644 index 0000000..15d8c51 --- /dev/null +++ b/tests/test/CMakeLists.txt @@ -0,0 +1,42 @@ +find_package(GTest REQUIRED) +find_package(thread_supervisor REQUIRED) + +set(TEST_BACKEND pjmsg_mcap) +foreach(TEST_NAME combo intrometry) + find_package(intrometry_${TEST_BACKEND} REQUIRED) + + add_executable(test_${TEST_BACKEND}_${TEST_NAME} ${TEST_BACKEND}_${TEST_NAME}.cpp) + target_link_libraries(test_${TEST_BACKEND}_${TEST_NAME} + intrometry::${TEST_BACKEND} + GTest::GTest + ) + add_test(test_${TEST_BACKEND}_${TEST_NAME} test_${TEST_BACKEND}_${TEST_NAME}) +endforeach() + +set(TEST_BACKEND pjmsg_topic) +foreach(TEST_NAME combo intrometry) + find_package(rclcpp REQUIRED) + find_package(plotjuggler_msgs REQUIRED) + find_package(intrometry_${TEST_BACKEND} REQUIRED) + + add_executable(test_${TEST_BACKEND}_${TEST_NAME} ${TEST_BACKEND}_${TEST_NAME}.cpp) + target_link_libraries(test_${TEST_BACKEND}_${TEST_NAME} + intrometry::${TEST_BACKEND} + GTest::GTest + thread_supervisor::thread_supervisor + rclcpp::rclcpp + plotjuggler_msgs::plotjuggler_msgs__rosidl_typesupport_cpp + ) + add_test(test_${TEST_BACKEND}_${TEST_NAME} test_${TEST_BACKEND}_${TEST_NAME}) +endforeach() + + +foreach(TEST_NAME sink_base) + add_executable(test_${TEST_NAME} ${TEST_NAME}.cpp) + target_link_libraries(test_${TEST_NAME} + intrometry::pjmsg_topic + intrometry::pjmsg_mcap + GTest::GTest + ) + add_test(test_${TEST_NAME} test_${TEST_NAME}) +endforeach() diff --git a/pjmsg_mcap/test/common.h b/tests/test/common.h similarity index 96% rename from pjmsg_mcap/test/common.h rename to tests/test/common.h index 0af90f2..d2b3244 100644 --- a/pjmsg_mcap/test/common.h +++ b/tests/test/common.h @@ -6,8 +6,8 @@ @brief */ +#pragma once -#include "intrometry/pjmsg_mcap/pjmsg_mcap.h" #include #include diff --git a/pjmsg_mcap/test/combo.cpp b/tests/test/pjmsg_mcap_combo.cpp similarity index 88% rename from pjmsg_mcap/test/combo.cpp rename to tests/test/pjmsg_mcap_combo.cpp index aa2e8e4..fd87e6e 100644 --- a/pjmsg_mcap/test/combo.cpp +++ b/tests/test/pjmsg_mcap_combo.cpp @@ -6,25 +6,25 @@ @brief */ -#include "common.h" +#include "pjmsg_mcap_common.h" namespace { - class ComboSinkFixture : public ::testing::Test + class PjmsgMcapComboSinkFixture : public ::testing::Test { public: intrometry::ComboSink intrometry_sink_; public: - ComboSinkFixture() + PjmsgMcapComboSinkFixture() { intrometry_sink_.initialize( intrometry::Source::Parameters(/*persistent_structure=*/true), "ComboSinkFixture"); } }; - class MultiSinkFixture : public ::testing::Test + class PjmsgMcapMultiSinkFixture : public ::testing::Test { public: using MultiPub = intrometry::ComboSink; @@ -33,7 +33,7 @@ namespace } // namespace -TEST_F(ComboSinkFixture, Simple) +TEST_F(PjmsgMcapComboSinkFixture, Simple) { for (intrometry_sink_.get().size_ = 0; intrometry_sink_.get().size_ < 5; @@ -46,7 +46,7 @@ TEST_F(ComboSinkFixture, Simple) ASSERT_TRUE(true); } -TEST_F(MultiSinkFixture, Multi) +TEST_F(PjmsgMcapMultiSinkFixture, Multi) { MultiPubVec pub_vector; diff --git a/tests/test/pjmsg_mcap_common.h b/tests/test/pjmsg_mcap_common.h new file mode 100644 index 0000000..f962f92 --- /dev/null +++ b/tests/test/pjmsg_mcap_common.h @@ -0,0 +1,13 @@ +/** + @file + @author Alexander Sherikov + @copyright 2024 Alexander Sherikov. Licensed under the Apache License, + Version 2.0. (see LICENSE or http://www.apache.org/licenses/LICENSE-2.0) + @brief +*/ + +#pragma once + +#include +#include "common.h" + diff --git a/pjmsg_mcap/test/intrometry.cpp b/tests/test/pjmsg_mcap_intrometry.cpp similarity index 85% rename from pjmsg_mcap/test/intrometry.cpp rename to tests/test/pjmsg_mcap_intrometry.cpp index 35b7c5c..c1ccacc 100644 --- a/pjmsg_mcap/test/intrometry.cpp +++ b/tests/test/pjmsg_mcap_intrometry.cpp @@ -6,18 +6,18 @@ @brief */ -#include "common.h" +#include "pjmsg_mcap_common.h" namespace { - class IntrometryFixture : public ::testing::Test + class PjmsgMcapIntrometryFixture : public ::testing::Test { public: intrometry::pjmsg_mcap::Sink intrometry_sink_; public: - IntrometryFixture() : intrometry_sink_("IntrometryFixture") + PjmsgMcapIntrometryFixture() : intrometry_sink_("IntrometryFixture") { intrometry_sink_.initialize(); } @@ -25,7 +25,7 @@ namespace } // namespace -TEST_F(IntrometryFixture, ArilesDynamic) +TEST_F(PjmsgMcapIntrometryFixture, ArilesDynamic) { intrometry_tests::ArilesDebug debug; intrometry_sink_.assign(debug); @@ -42,7 +42,7 @@ TEST_F(IntrometryFixture, ArilesDynamic) } -TEST_F(IntrometryFixture, ArilesPersistent) +TEST_F(PjmsgMcapIntrometryFixture, ArilesPersistent) { intrometry_tests::ArilesDebug debug{}; intrometry_sink_.assign(debug, intrometry::Source::Parameters(/*persistent_structure=*/true)); @@ -60,7 +60,7 @@ TEST_F(IntrometryFixture, ArilesPersistent) } -TEST_F(IntrometryFixture, MultipleSources) +TEST_F(PjmsgMcapIntrometryFixture, MultipleSources) { const intrometry_tests::ArilesDebug debug0{}; const intrometry_tests::ArilesDebug1 debug1{}; diff --git a/pjmsg_topic/test/combo.cpp b/tests/test/pjmsg_topic_combo.cpp similarity index 88% rename from pjmsg_topic/test/combo.cpp rename to tests/test/pjmsg_topic_combo.cpp index 7f7a0ff..2327914 100644 --- a/pjmsg_topic/test/combo.cpp +++ b/tests/test/pjmsg_topic_combo.cpp @@ -6,18 +6,18 @@ @brief */ -#include "common.h" +#include "pjmsg_topic_common.h" namespace { - class ComboSinkFixture : public ::testing::Test, public intrometry_tests::SubscriberNode + class PjmsgTopicComboSinkFixture : public ::testing::Test, public intrometry_tests::SubscriberNode { public: intrometry::ComboSink intrometry_sink_; public: - ComboSinkFixture() + PjmsgTopicComboSinkFixture() { intrometry_tests::SubscriberNode::initialize("combosinkfixture"); intrometry_sink_.initialize( @@ -25,7 +25,7 @@ namespace } }; - class MultiSinkFixture : public ::testing::Test + class PjmsgTopicMultiSinkFixture : public ::testing::Test { public: using MultiPub = intrometry::ComboSink; @@ -34,7 +34,7 @@ namespace } // namespace -TEST_F(ComboSinkFixture, Simple) +TEST_F(PjmsgTopicComboSinkFixture, Simple) { for (intrometry_sink_.get().size_ = 0; intrometry_sink_.get().size_ < 5; @@ -47,7 +47,7 @@ TEST_F(ComboSinkFixture, Simple) ASSERT_TRUE(checkReceived()); } -TEST_F(MultiSinkFixture, Multi) +TEST_F(PjmsgTopicMultiSinkFixture, Multi) { MultiPubVec pub_vector; std::array sub_vector; diff --git a/pjmsg_topic/test/common.h b/tests/test/pjmsg_topic_common.h similarity index 77% rename from pjmsg_topic/test/common.h rename to tests/test/pjmsg_topic_common.h index 639aa36..b870fde 100644 --- a/pjmsg_topic/test/common.h +++ b/tests/test/pjmsg_topic_common.h @@ -6,22 +6,15 @@ @brief */ +#pragma once -#include "intrometry/intrometry.h" -#include "intrometry/pjmsg_topic/sink.h" - -#include -#include - -#include +#include +#include "common.h" #include #include #include -#include -#include - namespace intrometry_tests { @@ -32,28 +25,6 @@ namespace intrometry_tests using ValuesSubscriptionPtr = rclcpp::Subscription::SharedPtr; - class ArilesDebug : public ariles2::DefaultBase - { -#define ARILES2_DEFAULT_ID "ArilesDebug" -#define ARILES2_ENTRIES(v) \ - ARILES2_TYPED_ENTRY_(v, duration, double) \ - ARILES2_TYPED_ENTRY_(v, size, std::size_t) \ - ARILES2_TYPED_ENTRY_(v, vec, std::vector) -#include ARILES2_INITIALIZE - public: - virtual ~ArilesDebug() = default; - }; - - class ArilesDebug1 : public ArilesDebug - { -#define ARILES2_DEFAULT_ID "ArilesDebug1" -#define ARILES2_ENTRIES(v) ARILES2_PARENT(v, ArilesDebug) -#include ARILES2_INITIALIZE - public: - virtual ~ArilesDebug1() = default; - }; - - template class Subscription { diff --git a/pjmsg_topic/test/intrometry.cpp b/tests/test/pjmsg_topic_intrometry.cpp similarity index 83% rename from pjmsg_topic/test/intrometry.cpp rename to tests/test/pjmsg_topic_intrometry.cpp index eb8f280..7f0b065 100644 --- a/pjmsg_topic/test/intrometry.cpp +++ b/tests/test/pjmsg_topic_intrometry.cpp @@ -6,18 +6,18 @@ @brief */ -#include "common.h" +#include "pjmsg_topic_common.h" namespace { - class IntrometryFixture : public ::testing::Test, public intrometry_tests::SubscriberNode + class PjmsgTopicIntrometryFixture : public ::testing::Test, public intrometry_tests::SubscriberNode { public: intrometry::pjmsg_topic::Sink intrometry_sink_; public: - IntrometryFixture() : intrometry_sink_("IntrometryFixture") + PjmsgTopicIntrometryFixture() : intrometry_sink_("IntrometryFixture") { intrometry_tests::SubscriberNode::initialize("intrometryfixture"); intrometry_sink_.initialize(); @@ -26,7 +26,7 @@ namespace } // namespace -TEST_F(IntrometryFixture, ArilesDynamic) +TEST_F(PjmsgTopicIntrometryFixture, ArilesDynamic) { intrometry_tests::ArilesDebug debug; intrometry_sink_.assign(debug); @@ -43,7 +43,7 @@ TEST_F(IntrometryFixture, ArilesDynamic) } -TEST_F(IntrometryFixture, ArilesPersistent) +TEST_F(PjmsgTopicIntrometryFixture, ArilesPersistent) { intrometry_tests::ArilesDebug debug{}; intrometry_sink_.assign(debug, intrometry::Source::Parameters(/*persistent_structure=*/true)); @@ -60,7 +60,7 @@ TEST_F(IntrometryFixture, ArilesPersistent) } -TEST_F(IntrometryFixture, MultipleSources) +TEST_F(PjmsgTopicIntrometryFixture, MultipleSources) { const intrometry_tests::ArilesDebug debug0{}; const intrometry_tests::ArilesDebug1 debug1{}; diff --git a/tests/test/sink_base.cpp b/tests/test/sink_base.cpp new file mode 100644 index 0000000..90cc7ba --- /dev/null +++ b/tests/test/sink_base.cpp @@ -0,0 +1,69 @@ +/** + @file + @author Alexander Sherikov + @copyright 2024 Alexander Sherikov. Licensed under the Apache License, + Version 2.0. (see LICENSE or http://www.apache.org/licenses/LICENSE-2.0) + @brief +*/ + +#include +#include +#include "common.h" + + +namespace +{ + class SinkBase : public ::testing::Test + { + public: + std::shared_ptr sink_mcap_; + std::shared_ptr sink_topic_; + std::shared_ptr sink_; + + public: + SinkBase() + { + sink_mcap_ = std::make_shared("SinkBase"); + sink_topic_ = std::make_shared("SinkBase"); + + sink_mcap_->initialize(); + sink_topic_->initialize(); + } + + void useSink() + { + intrometry_tests::ArilesDebug debug; + sink_->assign(debug); + + for (debug.size_ = 0; debug.size_ < 5; ++debug.size_) + { + sink_->write(debug); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + } + + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + sink_->retract(debug); + } + }; +} // namespace + + +TEST_F(SinkBase, MCAP) +{ + sink_ = sink_mcap_; + useSink(); + ASSERT_TRUE(true); +} + +TEST_F(SinkBase, Topic) +{ + sink_ = sink_topic_; + useSink(); + ASSERT_TRUE(true); +} + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}