Skip to content

Commit

Permalink
Create separate package for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asherikov committed Jan 13, 2025
1 parent aac33c8 commit 1c34de1
Show file tree
Hide file tree
Showing 24 changed files with 209 additions and 107 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ target_link_libraries(my_library intrometry::<BACKEND>)
### C++

```
#include <intrometry/<BACKEND>/<BACKEND>.h>
#include <intrometry/<BACKEND>/all.h>
```


Expand Down
2 changes: 1 addition & 1 deletion frontend/include/intrometry/combo.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace intrometry
class ComboSink
{
public:
std::shared_ptr<SinkBase> sink_;
std::shared_ptr<Sink> sink_;
std::tuple<t_Ariles...> data_;

public:
Expand Down
6 changes: 3 additions & 3 deletions frontend/include/intrometry/sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ namespace intrometry
*
* @ingroup API
*/
class SinkBase
class Sink
{
public:
virtual ~SinkBase() = default;
virtual ~Sink() = default;

/**
* Initialize sink.
Expand Down Expand Up @@ -88,7 +88,7 @@ namespace intrometry


template <class t_Parameters, class t_Implementation>
class SinkPIMPLBase : public SinkBase
class SinkPIMPLBase : public Sink
{
public:
using Parameters = t_Parameters;
Expand Down
9 changes: 2 additions & 7 deletions pjmsg_mcap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
#pragma once

#include <intrometry/intrometry.h>
#include "sink.h"
#include <intrometry/pjmsg_mcap/sink.h>
2 changes: 0 additions & 2 deletions pjmsg_mcap/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@
<build_depend>ariles2_namevalue2_ws</build_depend>
<exec_depend>thread_supervisor</exec_depend>
<exec_depend>ariles2_namevalue2_ws</exec_depend>

<test_depend>gtest</test_depend>
</package>
6 changes: 4 additions & 2 deletions pjmsg_mcap/src/intrometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -334,7 +337,6 @@ namespace intrometry::pjmsg_mcap::sink
intrometry::backend::getDateString(),
".mcap");


mcap_writer_.initialize(filename, topic_prefix);

thread_supervisor_.add(
Expand Down
10 changes: 0 additions & 10 deletions pjmsg_mcap/test/CMakeLists.txt

This file was deleted.

5 changes: 0 additions & 5 deletions pjmsg_topic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ install(DIRECTORY include/intrometry
)


if(BUILD_TESTING)
add_subdirectory(test)
endif()


# ---
# cmake package stuff
export(EXPORT ${PROJECT_NAME}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
#pragma once

#include <intrometry/intrometry.h>
#include "sink.h"
#include <intrometry/pjmsg_topic/sink.h>
2 changes: 0 additions & 2 deletions pjmsg_topic/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@
<exec_depend>thread_supervisor</exec_depend>
<exec_depend>plotjuggler_msgs</exec_depend>
<exec_depend>ariles2_namevalue2_ws</exec_depend>

<test_depend>gtest</test_depend>
</package>
12 changes: 0 additions & 12 deletions pjmsg_topic/test/CMakeLists.txt

This file was deleted.

24 changes: 24 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
19 changes: 19 additions & 0 deletions tests/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<package format="2">
<name>intrometry_tests</name>
<version>1.0.0</version>
<description>Intrometry tests</description>
<maintainer email="[email protected]">Alexander Sherikov</maintainer>
<author email="[email protected]">Alexander Sherikov</author>
<license>Apache 2.0</license>

<export>
<build_type>cmake</build_type>
</export>

<depend>thread_supervisor</depend>
<depend>intrometry_pjmsg_mcap</depend>
<depend>intrometry_pjmsg_topic</depend>

<test_depend>gtest</test_depend>
</package>
42 changes: 42 additions & 0 deletions tests/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion pjmsg_mcap/test/common.h → tests/test/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
@brief
*/

#pragma once

#include "intrometry/pjmsg_mcap/pjmsg_mcap.h"

#include <chrono>
#include <thread>
Expand Down
12 changes: 6 additions & 6 deletions pjmsg_mcap/test/combo.cpp → tests/test/pjmsg_mcap_combo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_tests::ArilesDebug> intrometry_sink_;

public:
ComboSinkFixture()
PjmsgMcapComboSinkFixture()
{
intrometry_sink_.initialize<intrometry::pjmsg_mcap::Sink>(
intrometry::Source::Parameters(/*persistent_structure=*/true), "ComboSinkFixture");
}
};

class MultiSinkFixture : public ::testing::Test
class PjmsgMcapMultiSinkFixture : public ::testing::Test
{
public:
using MultiPub = intrometry::ComboSink<intrometry_tests::ArilesDebug, intrometry_tests::ArilesDebug1>;
Expand All @@ -33,7 +33,7 @@ namespace
} // namespace


TEST_F(ComboSinkFixture, Simple)
TEST_F(PjmsgMcapComboSinkFixture, Simple)
{
for (intrometry_sink_.get<intrometry_tests::ArilesDebug>().size_ = 0;
intrometry_sink_.get<intrometry_tests::ArilesDebug>().size_ < 5;
Expand All @@ -46,7 +46,7 @@ TEST_F(ComboSinkFixture, Simple)
ASSERT_TRUE(true);
}

TEST_F(MultiSinkFixture, Multi)
TEST_F(PjmsgMcapMultiSinkFixture, Multi)
{
MultiPubVec pub_vector;

Expand Down
13 changes: 13 additions & 0 deletions tests/test/pjmsg_mcap_common.h
Original file line number Diff line number Diff line change
@@ -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 <intrometry/pjmsg_mcap/all.h>
#include "common.h"

Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
@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();
}
};
} // namespace


TEST_F(IntrometryFixture, ArilesDynamic)
TEST_F(PjmsgMcapIntrometryFixture, ArilesDynamic)
{
intrometry_tests::ArilesDebug debug;
intrometry_sink_.assign(debug);
Expand All @@ -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));
Expand All @@ -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{};
Expand Down
Loading

0 comments on commit 1c34de1

Please sign in to comment.