Commit 37906d07abdb8b04f686f7aae5d98caf863aa58e

Authored by Peter M. Groen
1 parent 68753efb

Added Topic Length Test

Showing 1 changed file with 59 additions and 18 deletions
test/TopicLengthTest.cpp
... ... @@ -15,33 +15,74 @@ using namespace osdev::components::log;
15 15 /****************************************************************************
16 16 * H E L P E R C L A S S E S
17 17 ****************************************************************************/
18   -/// @brief class to generate a cumulative topic..
19   -class TopicTester
  18 +class Publisher
20 19 {
21   - public:
22   - TopicTester();
23   - virtual ~TopicTester();
  20 +public:
  21 + Publisher() : m_mqtt_client("TopicTester"){}
  22 + virtual ~Publisher() {}
  23 +
  24 + void connect(const std::string &hostname,
  25 + int portnumber = 1883,
  26 + const std::string &username = std::string(),
  27 + const std::string &password = std::string(),
  28 + const std::string &lwt_topic = std::string(),
  29 + const std::string &lwt_message = std::string()
  30 + )
  31 + {
  32 + m_mqtt_client.connect(hostname, portnumber,
  33 + osdev::components::mqtt::Credentials(username, password),
  34 + osdev::components::mqtt::mqtt_LWT(lwt_topic, lwt_message),
  35 + true,
  36 + osdev::components::log::LogSettings
  37 + {
  38 + osdev::components::log::LogLevel::Debug,
  39 + osdev::components::log::LogMask::None
  40 + });
  41 + }
24 42  
25   - void RunTopicTester(int max_number_of_chars);
  43 + void publish(const std::string &message_topic, const std::string &message_payload)
  44 + {
  45 + osdev::components::mqtt::MqttMessage message(message_topic, true, false, message_payload);
  46 + osdev::components::mqtt::Token t_result = m_mqtt_client.publish(message, 0);
  47 + }
26 48  
  49 +private:
  50 + osdev::components::mqtt::MqttClient m_mqtt_client;
27 51 };
28 52  
29   -class Publisher
  53 +/// @brief class to generate a cumulative topic..
  54 +class TopicTester
30 55 {
31 56 public:
32   - Publisher();
33   - virtual ~Publisher() {}
  57 + TopicTester(std::shared_ptr<Publisher> publisher) : m_publisher(publisher){}
  58 + virtual ~TopicTester(){}
34 59  
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   - );
  60 + void RunTopicTester(int max_number_of_chars)
  61 + {
  62 + for(int nCount = 1; nCount < max_number_of_chars; nCount++)
  63 + {
  64 + std::string subtopic(nCount, 'a');
  65 + std::string topic = std::string("topics/" + subtopic);
  66 + std::string message(std::to_string(topic.size()));
42 67  
43   - void publish(const std::string &message_topic, const std::string &message_payload);
  68 + m_publisher->publish(topic, message);
  69 + }
  70 + }
44 71  
45 72 private:
46   - osdev::components::mqtt::MqttClient m_mqtt_client;
  73 + std::shared_ptr<Publisher> m_publisher;
47 74 };
  75 +
  76 +/*****************************************************************************
  77 + * T H E A C T U A L T E S T S
  78 + *****************************************************************************/
  79 +/// TopicTester
  80 +TEST(topictest, TopicLengthTest)
  81 +{
  82 + std::shared_ptr<Publisher> pPublisher = std::make_shared<Publisher>();
  83 + pPublisher->connect("127.0.0.1", 1883);
  84 +
  85 + TopicTester oTester(pPublisher);
  86 +
  87 + oTester.RunTopicTester(101);
  88 +}
... ...