Commit 40c6b751f30e507324daa02de78b0e9bbe1c2504
1 parent
e4139b67
Implement RTU Unittest
Showing
4 changed files
with
59 additions
and
3 deletions
CMakeLists.txt
src/modbusbase.h
| @@ -57,8 +57,8 @@ namespace modbus { | @@ -57,8 +57,8 @@ namespace modbus { | ||
| 57 | class ModbusBase | 57 | class ModbusBase |
| 58 | { | 58 | { |
| 59 | public: | 59 | public: |
| 60 | - ModbusBase(); | ||
| 61 | - virtual ~ModbusBase(); | 60 | + ModbusBase() {} |
| 61 | + virtual ~ModbusBase() {} | ||
| 62 | 62 | ||
| 63 | // Pure virtuals. Override when inherited. | 63 | // Pure virtuals. Override when inherited. |
| 64 | virtual bool Connect() = 0; | 64 | virtual bool Connect() = 0; |
tests/CMakeLists.txt
0 → 100644
| 1 | +# **************************************************************** | ||
| 2 | +# Copyright (c)2022 Peter M. Groen | ||
| 3 | +# This file is licensed under the MIT license found in the | ||
| 4 | +# LICENSE file in the root directory of this source tree. | ||
| 5 | +# **************************************************************** | ||
| 6 | +add_executable(modbustest | ||
| 7 | + connectionconfigtest.cpp | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +target_include_directories(modbustest PRIVATE | ||
| 11 | + ${CMAKE_CURRENT_SOURCE_DIR} | ||
| 12 | + ${CMAKE_SOURCE_DIR}/include | ||
| 13 | + ${CMAKE_SOURCE_DIR}/src | ||
| 14 | + ${CMAKE_BINARY_DIR} | ||
| 15 | +) | ||
| 16 | + | ||
| 17 | +target_link_libraries(modbustest PRIVATE | ||
| 18 | + gmock_main | ||
| 19 | + gmock | ||
| 20 | + gtest | ||
| 21 | + modbus-cpp | ||
| 22 | +) | ||
| 23 | + | ||
| 24 | +add_test(NAME modbustest COMMAND modbustest) | ||
| 25 | + | ||
| 26 | +set_tests_properties(modbustest PROPERTIES | ||
| 27 | + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
| 28 | +) |
tests/connectionconfigtest.cpp
0 → 100644
| 1 | +/**************************************************************** | ||
| 2 | + * Copyright (c)2022 Peter M. Groen | ||
| 3 | + * This file is licensed under the MIT license found in the | ||
| 4 | + * LICENSE file in the root directory of this source tree. | ||
| 5 | + ****************************************************************/ | ||
| 6 | + | ||
| 7 | +#include <gmock/gmock.h> | ||
| 8 | +#include <gtest/gtest.h> | ||
| 9 | + | ||
| 10 | +#include "connectionconfig.h" | ||
| 11 | + | ||
| 12 | +using namespace osdev::components::modbus; | ||
| 13 | + | ||
| 14 | +TEST(ConnectionConfigTest, SerialPortConfig) | ||
| 15 | +{ | ||
| 16 | + ConnectionConfig oConfig; | ||
| 17 | + oConfig.setBaudRate( B9600 ); | ||
| 18 | + oConfig.setConnectionType( ConnectionConfig::E_CONNECTIONTYPE::SERIAL ); | ||
| 19 | + oConfig.setDataBits( 8 ); | ||
| 20 | + oConfig.setStopBits( 1 ); | ||
| 21 | + oConfig.setFrameTimeout( 10 ); | ||
| 22 | + oConfig.setParity( ConnectionConfig::E_PARITY::NONE ); | ||
| 23 | + oConfig.setPortName( "/dev/ttyUSB0" ); | ||
| 24 | + | ||
| 25 | + // Test all parameters | ||
| 26 | + | ||
| 27 | +} |