Commit 68753efb1effb53c8c0ea40c4edccbe42261c540
1 parent
2569446f
[FIX] Setting up a TopicLengthTests
Showing
4 changed files
with
81 additions
and
2 deletions
CMakeLists.txt
src/CMakeLists.txt
| ... | ... | @@ -13,8 +13,8 @@ include_directories( |
| 13 | 13 | ) |
| 14 | 14 | |
| 15 | 15 | set(SRC_LIST |
| 16 | - ${CMAKE_CURRENT_SOURCE_DIR}/log.cpp | |
| 17 | - ${CMAKE_CURRENT_SOURCE_DIR}/threadcontext.cpp | |
| 16 | + ${CMAKE_CURRENT_SOURCE_DIR}/log.cpp | |
| 17 | + ${CMAKE_CURRENT_SOURCE_DIR}/threadcontext.cpp | |
| 18 | 18 | ${CMAKE_CURRENT_SOURCE_DIR}/mqttpublisherbase.cpp |
| 19 | 19 | ${CMAKE_CURRENT_SOURCE_DIR}/mqttsubscriberbase.cpp |
| 20 | 20 | ${CMAKE_CURRENT_SOURCE_DIR}/clientpaho.cpp | ... | ... |
test/CMakeLists.txt
0 → 100644
| 1 | +#**************************************************************************** | |
| 2 | +#* Copyright (c) 2023 Open Systems Development B.V. | |
| 3 | +#***************************************************************************** | |
| 4 | +# | |
| 5 | +# Don't call this file directly from cmake. | |
| 6 | +# This file is included from the upper directory. | |
| 7 | +# | |
| 8 | +# Build rules for the MQTT Library | |
| 9 | + | |
| 10 | +add_executable(topictest | |
| 11 | + TopicLengthTest.cpp | |
| 12 | +) | |
| 13 | + | |
| 14 | +target_include_directories(topictest PRIVATE | |
| 15 | + ${CMAKE_CIRRENT_SOURECE_DIR} | |
| 16 | + ../include | |
| 17 | +) | |
| 18 | + | |
| 19 | +target_link_libraries(topictest PRIVATE | |
| 20 | + gmock_main | |
| 21 | + gmock | |
| 22 | + gtest | |
| 23 | + mqtt-cpp | |
| 24 | +) | |
| 25 | + | |
| 26 | +add_test(NAME topictest COMMAND topictest) | |
| 27 | + | |
| 28 | +set_tests_properties(topictest PROPERTIES | |
| 29 | + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | |
| 30 | +) | ... | ... |
test/TopicLengthTest.cpp
0 → 100644
| 1 | +/**************************************************************************** | |
| 2 | + * COpyright (c) 2023 Open Systems Development B.V. | |
| 3 | + ****************************************************************************/ | |
| 4 | + | |
| 5 | +#include <gmock/gmock.h> | |
| 6 | +#include <gtest/gtest.h> | |
| 7 | +#include <string> | |
| 8 | +#include <memory> | |
| 9 | + | |
| 10 | +#include "mqttclient.h" | |
| 11 | + | |
| 12 | +using namespace osdev::components::mqtt; | |
| 13 | +using namespace osdev::components::log; | |
| 14 | + | |
| 15 | +/**************************************************************************** | |
| 16 | + * H E L P E R C L A S S E S | |
| 17 | + ****************************************************************************/ | |
| 18 | +/// @brief class to generate a cumulative topic.. | |
| 19 | +class TopicTester | |
| 20 | +{ | |
| 21 | + public: | |
| 22 | + TopicTester(); | |
| 23 | + virtual ~TopicTester(); | |
| 24 | + | |
| 25 | + void RunTopicTester(int max_number_of_chars); | |
| 26 | + | |
| 27 | +}; | |
| 28 | + | |
| 29 | +class Publisher | |
| 30 | +{ | |
| 31 | + public: | |
| 32 | + Publisher(); | |
| 33 | + virtual ~Publisher() {} | |
| 34 | + | |
| 35 | + void connect(const std::string &hostname, | |
| 36 | + int portnumber = 1883, | |
| 37 | + const std::string &username = std::string(), | |
| 38 | + const std::string &password = std::string(), | |
| 39 | + const std::string &lwt_topic = std::string(), | |
| 40 | + const std::string &lwt_message = std::string() | |
| 41 | + ); | |
| 42 | + | |
| 43 | + void publish(const std::string &message_topic, const std::string &message_payload); | |
| 44 | + | |
| 45 | + private: | |
| 46 | + osdev::components::mqtt::MqttClient m_mqtt_client; | |
| 47 | +}; | ... | ... |