generated from wessel/boilerplate
chore(Tilmann): Rename to tilmann standard
This commit is contained in:
@@ -23,22 +23,22 @@ find_package(rclcpp_action REQUIRED)
|
||||
find_package(std_msgs REQUIRED)
|
||||
find_package(sensor_msgs REQUIRED)
|
||||
|
||||
add_executable(imu_database_writer
|
||||
src/imu_database_writer/Main.cpp
|
||||
add_executable(g2_2025_imu_database_writer_node
|
||||
src/g2_2025_imu_database_writer_node/Main.cpp
|
||||
src/database/DatabaseManager.cpp
|
||||
src/config/ConfigManager.cpp
|
||||
src/imu_database_writer/nodes/IMUDatabaseWriter.cpp
|
||||
src/g2_2025_imu_database_writer_node/nodes/IMUDatabaseWriter.cpp
|
||||
)
|
||||
target_include_directories(imu_database_writer PRIVATE
|
||||
target_include_directories(g2_2025_imu_database_writer_node PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/imu_database_writer
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/g2_2025_imu_database_writer_node
|
||||
)
|
||||
ament_target_dependencies(imu_database_writer rclcpp sensor_msgs)
|
||||
target_link_libraries(imu_database_writer pqxx pq tomlplusplus::tomlplusplus)
|
||||
ament_target_dependencies(g2_2025_imu_database_writer_node rclcpp sensor_msgs)
|
||||
target_link_libraries(g2_2025_imu_database_writer_node pqxx pq tomlplusplus::tomlplusplus)
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
imu_database_writer
|
||||
g2_2025_imu_database_writer_node
|
||||
DESTINATION lib/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
@@ -63,13 +63,13 @@ if(BUILD_TESTING)
|
||||
# Add gtest for IMUDatabaseWriter node
|
||||
ament_add_gtest(${PROJECT_NAME}_test_imu_database_writer
|
||||
test/IMUDatabaseWriter.test.cpp
|
||||
src/imu_database_writer/nodes/IMUDatabaseWriter.cpp
|
||||
src/g2_2025_imu_database_writer_node/nodes/IMUDatabaseWriter.cpp
|
||||
src/database/DatabaseManager.cpp
|
||||
src/config/ConfigManager.cpp
|
||||
)
|
||||
target_include_directories(${PROJECT_NAME}_test_imu_database_writer PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/imu_database_writer
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/g2_2025_imu_database_writer_node
|
||||
)
|
||||
ament_target_dependencies(${PROJECT_NAME}_test_imu_database_writer
|
||||
rclcpp
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace assignments::two::imu_database_writer {
|
||||
|
||||
IMUDatabaseWriter::IMUDatabaseWriter(std::unique_ptr<DatabaseManager> db_manager)
|
||||
: Node("imu_database_writer")
|
||||
: Node("g2_2025_imu_database_writer_node")
|
||||
{
|
||||
// allow injection of mock database manager for tests
|
||||
if (db_manager) {
|
||||
@@ -3,43 +3,13 @@
|
||||
#include <rclcpp/rclcpp.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "imu_database_writer/nodes/IMUDatabaseWriter.hpp"
|
||||
#include "database/DatabaseManager.hpp"
|
||||
#include "g2_2025_imu_database_writer_node/nodes/IMUDatabaseWriter.hpp"
|
||||
#include "mocks/MockDatabaseManager.hpp"
|
||||
#include "sensor_msgs/msg/imu.hpp"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using namespace assignments::two::imu_database_writer;
|
||||
|
||||
namespace assignments::two {
|
||||
|
||||
class MockDatabaseManager : public DatabaseManager {
|
||||
public:
|
||||
explicit MockDatabaseManager(rclcpp::Logger logger = rclcpp::get_logger("mock_db"))
|
||||
: DatabaseManager(logger) {
|
||||
}
|
||||
|
||||
// Match the current DatabaseManager::store_imu_data signature (no timestamp)
|
||||
bool store_imu_data(
|
||||
double linear_accel_x, double linear_accel_y, double linear_accel_z,
|
||||
double angular_vel_x, double angular_vel_y, double angular_vel_z
|
||||
) override {
|
||||
called_ = true;
|
||||
last_la_x_ = linear_accel_x;
|
||||
last_la_y_ = linear_accel_y;
|
||||
last_la_z_ = linear_accel_z;
|
||||
last_av_x_ = angular_vel_x;
|
||||
last_av_y_ = angular_vel_y;
|
||||
last_av_z_ = angular_vel_z;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool called_ = false;
|
||||
double last_la_x_ = 0.0, last_la_y_ = 0.0, last_la_z_ = 0.0;
|
||||
double last_av_x_ = 0.0, last_av_y_ = 0.0, last_av_z_ = 0.0;
|
||||
};
|
||||
|
||||
} // namespace assignments::two
|
||||
|
||||
class IMUDatabaseWriterTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
@@ -97,8 +67,3 @@ TEST_F(IMUDatabaseWriterTest, ReceivesAndForwardsIMU) {
|
||||
|
||||
EXPECT_TRUE(mock_db_ptr_->called_);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
@@ -4,12 +4,6 @@
|
||||
|
||||
namespace assignments::two {
|
||||
|
||||
struct MockStoredResult {
|
||||
int exam_count;
|
||||
int final_grade;
|
||||
bool is_retake;
|
||||
};
|
||||
|
||||
class MockDatabaseManager : public DatabaseManager {
|
||||
public:
|
||||
explicit MockDatabaseManager(
|
||||
@@ -27,11 +21,23 @@ public:
|
||||
connection_status_ = status;
|
||||
}
|
||||
|
||||
void clear_failed_students() {
|
||||
failed_students_.clear();
|
||||
bool store_imu_data(
|
||||
double linear_accel_x, double linear_accel_y, double linear_accel_z,
|
||||
double angular_vel_x, double angular_vel_y, double angular_vel_z
|
||||
) override {
|
||||
called_ = true;
|
||||
last_la_x_ = linear_accel_x;
|
||||
last_la_y_ = linear_accel_y;
|
||||
last_la_z_ = linear_accel_z;
|
||||
last_av_x_ = angular_vel_x;
|
||||
last_av_y_ = angular_vel_y;
|
||||
last_av_z_ = angular_vel_z;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<MockStoredResult> stored_results;
|
||||
bool called_ = false;
|
||||
double last_la_x_ = 0.0, last_la_y_ = 0.0, last_la_z_ = 0.0;
|
||||
double last_av_x_ = 0.0, last_av_y_ = 0.0, last_av_z_ = 0.0;
|
||||
|
||||
private:
|
||||
bool connection_status_ = true;
|
||||
|
||||
Reference in New Issue
Block a user