From ed4ceef8289026a10f5355584e2f4101cfc2defa Mon Sep 17 00:00:00 2001 From: ShotaAk Date: Fri, 5 Jan 2024 13:40:04 +0900 Subject: [PATCH] Implement read_data tests --- rt_manipulators_lib/test/test_hardware.cpp | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/rt_manipulators_lib/test/test_hardware.cpp b/rt_manipulators_lib/test/test_hardware.cpp index 61bf9da..e70f921 100644 --- a/rt_manipulators_lib/test/test_hardware.cpp +++ b/rt_manipulators_lib/test/test_hardware.cpp @@ -120,7 +120,24 @@ TEST(HardwareTest, write_data) { } TEST(HardwareTest, read_data) { + const uint8_t TEST_BYTE_DATA = 0x12; + const uint16_t TEST_WORD_DATA = 0x1234; + const uint32_t TEST_DOUBLE_WORD_DATA = 0x12345678; auto mock = create_comm_mock(); + + When(Method(mock, read_byte_data)).AlwaysDo([](uint8_t id, uint16_t addr, uint8_t& result) { + result = TEST_BYTE_DATA; + return true; + }); + When(Method(mock, read_word_data)).AlwaysDo([](uint8_t id, uint16_t addr, uint16_t& result) { + result = TEST_WORD_DATA; + return true; + }); + When(Method(mock, read_double_word_data)).AlwaysDo([](uint8_t id, uint16_t addr, uint32_t& result) { + result = TEST_DOUBLE_WORD_DATA; + return true; + }); + rt_manipulators_cpp::Hardware hardware( std::unique_ptr(&mock.get())); @@ -138,15 +155,18 @@ TEST(HardwareTest, read_data) { Verify(Method(mock, read_double_word_data)).Never(); // Identify joint via joint name - EXPECT_FALSE(hardware.read_data("joint1", 0x00, byte_data)); + EXPECT_TRUE(hardware.read_data("joint1", 0x00, byte_data)); Verify(Method(mock, read_byte_data)).Once(); + EXPECT_EQ(byte_data, TEST_BYTE_DATA); // Identify joint via joint id - EXPECT_FALSE(hardware.read_data(2, 0x00, word_data)); + EXPECT_TRUE(hardware.read_data(2, 0x00, word_data)); Verify(Method(mock, read_word_data)).Once(); + EXPECT_EQ(word_data, TEST_WORD_DATA); - EXPECT_FALSE(hardware.read_data("joint3", 0x00, double_word_data)); + EXPECT_TRUE(hardware.read_data("joint3", 0x00, double_word_data)); Verify(Method(mock, read_double_word_data)).Once(); + EXPECT_EQ(double_word_data, TEST_DOUBLE_WORD_DATA); // Return false when data type is not matched double invalid_type_data = 0.0;