Skip to main content

C++ reference

roboticks_cpp is a header-only ament_cmake INTERFACE library. It ships:
  • The ROBOTICKS_CONFIRMS macro.
  • A thread-safe ConfirmsRegistry.
  • gtest-compatible rclcpp assertion helpers.
  • An optional gtest_main target that wires the registry dump into the standard gtest exit.

CMake

The package exports two targets via ament_cmake:

ROBOTICKS_CONFIRMS

The macro expands to a ConfirmsRegistry::instance().add(...) call. It must appear inside a gtest test body. Place it as the first statement so the registry record is created before any assertion can short-circuit:
For typed tests or value-parameterised tests, the token mirrors gtest’s full name:
The registry stores (token, [req_ids...], file, line) — file and line are captured via __FILE__ and __LINE__.

ConfirmsRegistry

Methods

Thread safety

All mutating methods are guarded by an internal std::mutex. instance() is safe under C++11 magic statics. Read methods (size, dump) take a shared view under the same lock — concurrent dumps and adds serialise but don’t deadlock.

JSON dump shape

Consumed by the JUnit stitcher.

Assertion helpers

Templated free functions in roboticks_cpp:::
Failure modes use gtest’s FAIL() macro so they appear in the standard gtest summary and stop the current test. Timeouts surface as FAIL() << "timed out waiting for ...";.

Example

Stitching into JUnit

ament_cmake_gtest writes per-test JUnit XML at test_results/<package>/<test>.gtest.xml. The Python-side stitcher merges confirms.json from the registry dump:
The stitcher matches by SuiteName.TestName (gtest format) ↔ SuiteName_TestName (registry token). When you use colcon test --event-handlers roboticks+, this happens automatically.
v0.1 is registry-only. The C++ side records confirms IDs; the stitcher merges them into JUnit. Phase 11 will ship a native JUnit reporter so the macro writes properties directly — wire shape unchanged.

Manual registry dump

If you bring your own main():

Linking with colcon test

The roboticks+ event handler ships in roboticks_cpp and:
  1. Locates the JUnit XML colcon wrote.
  2. Locates the confirms.json the test binary dumped.
  3. Stitches and writes a side-by-side *.junit.xml for upload.
The handler is silent on success and logs a warning if it can’t find either file.

Headers

Next

Writing tests in C++

Tutorial with full examples.

Wire contract

The schema the stitcher targets.

Pytest plugin

The Python-side equivalent.

Coverage

gcov/lcov wiring inside colcon.