diff --git a/CMakeLists.txt b/CMakeLists.txt index 724966e..9d796c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,5 +8,6 @@ include(projectheader) project_header(modbus-cpp) add_subdirectory(src) -add_subdirectory(tools) +add_subdirectory(tests) +# add_subdirectory(tools) diff --git a/src/modbusbase.h b/src/modbusbase.h index 378cf82..9b517c4 100644 --- a/src/modbusbase.h +++ b/src/modbusbase.h @@ -57,8 +57,8 @@ namespace modbus { class ModbusBase { public: - ModbusBase(); - virtual ~ModbusBase(); + ModbusBase() {} + virtual ~ModbusBase() {} // Pure virtuals. Override when inherited. virtual bool Connect() = 0; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..c51b292 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,28 @@ +# **************************************************************** +# Copyright (c)2022 Peter M. Groen +# This file is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. +# **************************************************************** +add_executable(modbustest + connectionconfigtest.cpp +) + +target_include_directories(modbustest PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_BINARY_DIR} +) + +target_link_libraries(modbustest PRIVATE + gmock_main + gmock + gtest + modbus-cpp +) + +add_test(NAME modbustest COMMAND modbustest) + +set_tests_properties(modbustest PROPERTIES + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" +) diff --git a/tests/connectionconfigtest.cpp b/tests/connectionconfigtest.cpp new file mode 100644 index 0000000..1c96be9 --- /dev/null +++ b/tests/connectionconfigtest.cpp @@ -0,0 +1,27 @@ +/**************************************************************** + * Copyright (c)2022 Peter M. Groen + * This file is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + ****************************************************************/ + +#include +#include + +#include "connectionconfig.h" + +using namespace osdev::components::modbus; + +TEST(ConnectionConfigTest, SerialPortConfig) +{ + ConnectionConfig oConfig; + oConfig.setBaudRate( B9600 ); + oConfig.setConnectionType( ConnectionConfig::E_CONNECTIONTYPE::SERIAL ); + oConfig.setDataBits( 8 ); + oConfig.setStopBits( 1 ); + oConfig.setFrameTimeout( 10 ); + oConfig.setParity( ConnectionConfig::E_PARITY::NONE ); + oConfig.setPortName( "/dev/ttyUSB0" ); + + // Test all parameters + +}