diff --git a/CMakeLists.txt b/CMakeLists.txt index 34291a3..f0b6f39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,5 +13,7 @@ add_subdirectory(examples/pub) add_subdirectory(examples/sub) add_subdirectory(examples/subunsub) +add_subdirectory(test) + include(packaging) package_component() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8235e56..fb7017e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,8 +13,8 @@ include_directories( ) set(SRC_LIST - ${CMAKE_CURRENT_SOURCE_DIR}/log.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/threadcontext.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/log.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/threadcontext.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mqttpublisherbase.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mqttsubscriberbase.cpp ${CMAKE_CURRENT_SOURCE_DIR}/clientpaho.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..1471cf8 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,30 @@ +#**************************************************************************** +#* Copyright (c) 2023 Open Systems Development B.V. +#***************************************************************************** +# +# Don't call this file directly from cmake. +# This file is included from the upper directory. +# +# Build rules for the MQTT Library + +add_executable(topictest + TopicLengthTest.cpp +) + +target_include_directories(topictest PRIVATE + ${CMAKE_CIRRENT_SOURECE_DIR} + ../include +) + +target_link_libraries(topictest PRIVATE + gmock_main + gmock + gtest + mqtt-cpp +) + +add_test(NAME topictest COMMAND topictest) + +set_tests_properties(topictest PROPERTIES + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" +) diff --git a/test/TopicLengthTest.cpp b/test/TopicLengthTest.cpp new file mode 100644 index 0000000..462145a --- /dev/null +++ b/test/TopicLengthTest.cpp @@ -0,0 +1,47 @@ +/**************************************************************************** + * COpyright (c) 2023 Open Systems Development B.V. + ****************************************************************************/ + +#include +#include +#include +#include + +#include "mqttclient.h" + +using namespace osdev::components::mqtt; +using namespace osdev::components::log; + +/**************************************************************************** + * H E L P E R C L A S S E S + ****************************************************************************/ +/// @brief class to generate a cumulative topic.. +class TopicTester +{ + public: + TopicTester(); + virtual ~TopicTester(); + + void RunTopicTester(int max_number_of_chars); + +}; + +class Publisher +{ + public: + Publisher(); + virtual ~Publisher() {} + + void connect(const std::string &hostname, + int portnumber = 1883, + const std::string &username = std::string(), + const std::string &password = std::string(), + const std::string &lwt_topic = std::string(), + const std::string &lwt_message = std::string() + ); + + void publish(const std::string &message_topic, const std::string &message_payload); + + private: + osdev::components::mqtt::MqttClient m_mqtt_client; +};