diff --git a/test/TopicLengthTest.cpp b/test/TopicLengthTest.cpp index 462145a..980a0ab 100644 --- a/test/TopicLengthTest.cpp +++ b/test/TopicLengthTest.cpp @@ -15,33 +15,74 @@ 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 +class Publisher { - public: - TopicTester(); - virtual ~TopicTester(); +public: + Publisher() : m_mqtt_client("TopicTester"){} + 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() + ) + { + m_mqtt_client.connect(hostname, portnumber, + osdev::components::mqtt::Credentials(username, password), + osdev::components::mqtt::mqtt_LWT(lwt_topic, lwt_message), + true, + osdev::components::log::LogSettings + { + osdev::components::log::LogLevel::Debug, + osdev::components::log::LogMask::None + }); + } - void RunTopicTester(int max_number_of_chars); + void publish(const std::string &message_topic, const std::string &message_payload) + { + osdev::components::mqtt::MqttMessage message(message_topic, true, false, message_payload); + osdev::components::mqtt::Token t_result = m_mqtt_client.publish(message, 0); + } +private: + osdev::components::mqtt::MqttClient m_mqtt_client; }; -class Publisher +/// @brief class to generate a cumulative topic.. +class TopicTester { public: - Publisher(); - virtual ~Publisher() {} + TopicTester(std::shared_ptr publisher) : m_publisher(publisher){} + virtual ~TopicTester(){} - 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 RunTopicTester(int max_number_of_chars) + { + for(int nCount = 1; nCount < max_number_of_chars; nCount++) + { + std::string subtopic(nCount, 'a'); + std::string topic = std::string("topics/" + subtopic); + std::string message(std::to_string(topic.size())); - void publish(const std::string &message_topic, const std::string &message_payload); + m_publisher->publish(topic, message); + } + } private: - osdev::components::mqtt::MqttClient m_mqtt_client; + std::shared_ptr m_publisher; }; + +/***************************************************************************** + * T H E A C T U A L T E S T S + *****************************************************************************/ +/// TopicTester +TEST(topictest, TopicLengthTest) +{ + std::shared_ptr pPublisher = std::make_shared(); + pPublisher->connect("127.0.0.1", 1883); + + TopicTester oTester(pPublisher); + + oTester.RunTopicTester(101); +}