Commit 684f5eb8543d5318dcda878dfa183664fc26cbf5

Authored by Wiebe Cazemier
1 parent f5c83951

Add simple test for user properties

Showing 1 changed file with 48 additions and 0 deletions
FlashMQTests/tst_maintests.cpp
... ... @@ -135,6 +135,8 @@ private slots:
135 135  
136 136 void testQosDowngradeOnOfflineClients();
137 137  
  138 + void testUserProperties();
  139 +
138 140 };
139 141  
140 142 MainTests::MainTests()
... ... @@ -1812,6 +1814,52 @@ void MainTests::testQosDowngradeOnOfflineClients()
1812 1814 MYCASTCOMPARE(12, testCount);
1813 1815 }
1814 1816  
  1817 +void MainTests::testUserProperties()
  1818 +{
  1819 + FlashMQTestClient sender;
  1820 + sender.start();
  1821 + sender.connectClient(ProtocolVersion::Mqtt5);
  1822 +
  1823 + FlashMQTestClient receiver5;
  1824 + receiver5.start();
  1825 + receiver5.connectClient(ProtocolVersion::Mqtt5);
  1826 + receiver5.subscribe("#", 1);
  1827 +
  1828 + FlashMQTestClient receiver3;
  1829 + receiver3.start();
  1830 + receiver3.connectClient(ProtocolVersion::Mqtt311);
  1831 + receiver3.subscribe("#", 1);
  1832 +
  1833 + Publish pub("I'm/going/to/leave/a/message", "boo", 1);
  1834 + pub.constructPropertyBuilder();
  1835 + pub.propertyBuilder->writeUserProperty("mykey", "myval");
  1836 + pub.propertyBuilder->writeUserProperty("mykeyhaha", "myvalhaha");
  1837 + sender.publish(pub);
  1838 +
  1839 + receiver5.waitForMessageCount(1);
  1840 + receiver3.waitForMessageCount(1);
  1841 +
  1842 + MqttPacket &pack5 = receiver5.receivedPublishes.front();
  1843 +
  1844 + const std::vector<std::pair<std::string, std::string>> *properties5 = pack5.getUserProperties();
  1845 +
  1846 + QVERIFY(properties5);
  1847 + MYCASTCOMPARE(properties5->size(), 2);
  1848 +
  1849 + const std::pair<std::string, std::string> &firstPair = properties5->operator[](0);
  1850 + const std::pair<std::string, std::string> &secondPair = properties5->operator[](1);
  1851 +
  1852 + QCOMPARE(firstPair.first, "mykey");
  1853 + QCOMPARE(firstPair.second, "myval");
  1854 +
  1855 + QCOMPARE(secondPair.first, "mykeyhaha");
  1856 + QCOMPARE(secondPair.second, "myvalhaha");
  1857 +
  1858 + MqttPacket &pack3 = receiver3.receivedPublishes.front();
  1859 + const std::vector<std::pair<std::string, std::string>> *properties3 = pack3.getUserProperties();
  1860 + QVERIFY(properties3 == nullptr);
  1861 +}
  1862 +
1815 1863 int main(int argc, char *argv[])
1816 1864 {
1817 1865 QCoreApplication app(argc, argv);
... ...