-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
273 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include "UnitTestBmBase.h" | ||
#include "UnitTestPropsHandler.h" | ||
#include "UnitTestProtocolDefs.h" | ||
|
||
#include <cxxtest/TestSuite.h> | ||
|
||
class UnitTestBmPublish : public CxxTest::TestSuite, public UnitTestBmBase | ||
{ | ||
public: | ||
void test1(); | ||
|
||
private: | ||
virtual void setUp() override | ||
{ | ||
unitTestSetUp(); | ||
} | ||
|
||
virtual void tearDown() override | ||
{ | ||
unitTestTearDown(); | ||
} | ||
}; | ||
|
||
void UnitTestBmPublish::test1() | ||
{ | ||
// Qos0 publish with properties | ||
auto* client = unitTestAllocAndInitClient(); | ||
unitTestPerformPubTopicAliasConnect(client, __FUNCTION__, 10); | ||
TS_ASSERT(unitTestIsConnected(client)); | ||
|
||
const std::string Topic("some/topic"); | ||
auto ec = unitTestPubTopicAliasAlloc(client, Topic.c_str(), 1U); | ||
TS_ASSERT_EQUALS(ec, CC_Mqtt5ErrorCode_NotSupported); | ||
|
||
auto* publish = unitTestPublishPrepare(client, nullptr); | ||
TS_ASSERT_DIFFERS(publish, nullptr); | ||
|
||
const UnitTestData Data = { 0x1, 0x2, 0x3, 0x4, 0x5}; | ||
const CC_Mqtt5QoS Qos = CC_Mqtt5QoS_AtMostOnceDelivery; | ||
const bool Retain = true; | ||
|
||
auto config = CC_Mqtt5PublishBasicConfig(); | ||
unitTestPublishInitConfigBasic(&config); | ||
|
||
config.m_topic = Topic.c_str(); | ||
config.m_data = &Data[0]; | ||
config.m_dataLen = static_cast<decltype(config.m_dataLen)>(Data.size()); | ||
config.m_qos = Qos; | ||
TS_ASSERT_EQUALS(config.m_topicAliasPref, CC_Mqtt5TopicAliasPreference_UseAliasIfAvailable); | ||
config.m_retain = Retain; | ||
|
||
ec = unitTestPublishConfigBasic(publish, &config); | ||
TS_ASSERT_EQUALS(ec, CC_Mqtt5ErrorCode_Success); | ||
|
||
const std::string PubUserPropKey1 = "Key1"; | ||
const std::string PubUserPropVal1 = "Val1"; | ||
auto userProp1 = CC_Mqtt5UserProp(); | ||
userProp1.m_key = PubUserPropKey1.c_str(); | ||
userProp1.m_value = PubUserPropVal1.c_str(); | ||
ec = unitTestPublishAddUserProp(publish, &userProp1); | ||
TS_ASSERT_EQUALS(ec, CC_Mqtt5ErrorCode_NotSupported); | ||
|
||
const std::string ContentType("ContentType"); | ||
const std::string ResponseTopic("ResponseTopic"); | ||
const UnitTestData CorrelationData = {0x11, 0x22, 0x33, 0x44}; | ||
const unsigned MsgExpiry = 10; | ||
const CC_Mqtt5PayloadFormat Format = CC_Mqtt5PayloadFormat_Utf8; | ||
|
||
auto extra = CC_Mqtt5PublishExtraConfig(); | ||
unitTestPublishInitConfigExtra(&extra); | ||
extra.m_contentType = ContentType.c_str(); | ||
extra.m_responseTopic = ResponseTopic.c_str(); | ||
extra.m_correlationData = &CorrelationData[0]; | ||
extra.m_correlationDataLen = static_cast<decltype(extra.m_correlationDataLen)>(CorrelationData.size()); | ||
extra.m_messageExpiryInterval = MsgExpiry; | ||
extra.m_format = Format; | ||
ec = unitTestPublishConfigExtra(publish, &extra); | ||
TS_ASSERT_EQUALS(ec, CC_Mqtt5ErrorCode_Success); | ||
|
||
ec = unitTestSendPublish(publish); | ||
TS_ASSERT_EQUALS(ec, CC_Mqtt5ErrorCode_Success); | ||
|
||
TS_ASSERT(unitTestIsPublishComplete()); | ||
auto& pubackInfo = unitTestPublishResponseInfo(); | ||
TS_ASSERT_EQUALS(pubackInfo.m_status, CC_Mqtt5AsyncOpStatus_Complete); | ||
unitTestPopPublishResponseInfo(); | ||
|
||
auto sentMsg = unitTestGetSentMessage(); | ||
TS_ASSERT(sentMsg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
#include "UnitTestBmBase.h" | ||
#include "UnitTestPropsHandler.h" | ||
#include "UnitTestProtocolDefs.h" | ||
|
||
#include <cxxtest/TestSuite.h> | ||
|
||
class UnitTestBmReceive : public CxxTest::TestSuite, public UnitTestBmBase | ||
{ | ||
public: | ||
void test1(); | ||
void test2(); | ||
void test3(); | ||
|
||
private: | ||
virtual void setUp() override | ||
{ | ||
unitTestSetUp(); | ||
} | ||
|
||
virtual void tearDown() override | ||
{ | ||
unitTestTearDown(); | ||
} | ||
}; | ||
|
||
void UnitTestBmReceive::test1() | ||
{ | ||
// Simple receive of Qos0 | ||
auto* client = unitTestAllocAndInitClient(); | ||
unitTestPerformBasicConnect(client, __FUNCTION__); | ||
TS_ASSERT(unitTestIsConnected(client)); | ||
|
||
unitTestPerformBasicSubscribe(client, "#"); | ||
unitTestTick(1000); | ||
|
||
const std::string Topic = "some/topic"; | ||
const UnitTestData Data = {'h', 'e', 'l', 'l', 'o'}; | ||
|
||
UnitTestPublishMsg publishMsg; | ||
publishMsg.field_topic().value() = Topic; | ||
publishMsg.field_payload().value() = Data; | ||
publishMsg.doRefresh(); | ||
unitTestReceiveMessage(publishMsg); | ||
|
||
TS_ASSERT(unitTestHasMessageRecieved()); | ||
auto& msgInfo = unitTestReceivedMessageInfo(); | ||
TS_ASSERT_EQUALS(msgInfo.m_topic, Topic); | ||
TS_ASSERT_EQUALS(msgInfo.m_data, Data); | ||
TS_ASSERT(msgInfo.m_subIds.empty()); | ||
TS_ASSERT_EQUALS(msgInfo.m_qos, CC_Mqtt5QoS_AtMostOnceDelivery); | ||
unitTestPopReceivedMessageInfo(); | ||
} | ||
|
||
void UnitTestBmReceive::test2() | ||
{ | ||
// Testing ignore of the user properties | ||
auto* client = unitTestAllocAndInitClient(); | ||
unitTestPerformBasicConnect(client, __FUNCTION__); | ||
TS_ASSERT(unitTestIsConnected(client)); | ||
|
||
unitTestPerformBasicSubscribe(client, "#"); | ||
unitTestTick(1000); | ||
|
||
const std::string Topic = "some/topic"; | ||
const UnitTestData Data = {'h', 'e', 'l', 'l', 'o'}; | ||
const std::string UserPropKey1("Key1"); | ||
const std::string UserPropVal1("Val1"); | ||
|
||
UnitTestPublishMsg publishMsg; | ||
publishMsg.field_topic().value() = Topic; | ||
publishMsg.field_payload().value() = Data; | ||
|
||
auto& propsVec = publishMsg.field_properties().value(); | ||
do { | ||
propsVec.resize(propsVec.size() + 1U); | ||
auto& field = propsVec.back().initField_userProperty(); | ||
field.field_value().field_first().setValue(UserPropKey1); | ||
field.field_value().field_second().setValue(UserPropVal1); | ||
} while (false); | ||
|
||
publishMsg.doRefresh(); | ||
unitTestReceiveMessage(publishMsg); | ||
|
||
TS_ASSERT(unitTestHasMessageRecieved()); | ||
auto& msgInfo = unitTestReceivedMessageInfo(); | ||
TS_ASSERT_EQUALS(msgInfo.m_topic, Topic); | ||
TS_ASSERT_EQUALS(msgInfo.m_data, Data); | ||
TS_ASSERT(msgInfo.m_userProps.empty()); | ||
TS_ASSERT(msgInfo.m_subIds.empty()); | ||
TS_ASSERT_EQUALS(msgInfo.m_qos, CC_Mqtt5QoS_AtMostOnceDelivery); | ||
unitTestPopReceivedMessageInfo(); | ||
} | ||
|
||
void UnitTestBmReceive::test3() | ||
{ | ||
// Testing ignore of the too many properties | ||
auto* client = unitTestAllocAndInitClient(); | ||
unitTestPerformBasicConnect(client, __FUNCTION__); | ||
TS_ASSERT(unitTestIsConnected(client)); | ||
|
||
unitTestPerformBasicSubscribe(client, "#"); | ||
unitTestTick(1000); | ||
|
||
const std::string Topic = "some/topic"; | ||
const UnitTestData Data = {'h', 'e', 'l', 'l', 'o'}; | ||
const unsigned MessageExpiryInterval = 10; | ||
const std::string ResponseTopic = "ResponseTopic"; | ||
const UnitTestData CorrelationData = {0x21, 0x32, 0x43, 0x54}; | ||
const CC_Mqtt5PayloadFormat Format = CC_Mqtt5PayloadFormat_Utf8; | ||
const bool Retain = true; | ||
const std::string ContentType("ContentType"); | ||
const std::string UserPropKey1("Key1"); | ||
const std::string UserPropVal1("Val1"); | ||
const unsigned SubId = 1; | ||
|
||
UnitTestPublishMsg publishMsg; | ||
publishMsg.transportField_flags().field_retain().setBitValue_bit(Retain); | ||
publishMsg.field_topic().value() = Topic; | ||
publishMsg.field_payload().value() = Data; | ||
|
||
auto& propsVec = publishMsg.field_properties().value(); | ||
do { | ||
propsVec.resize(propsVec.size() + 1U); | ||
auto& field = propsVec.back().initField_payloadFormatIndicator(); | ||
field.field_value().setValue(Format); | ||
} while (false); | ||
|
||
do { | ||
propsVec.resize(propsVec.size() + 1U); | ||
auto& field = propsVec.back().initField_messageExpiryInterval(); | ||
field.field_value().setValue(MessageExpiryInterval); | ||
} while (false); | ||
|
||
do { | ||
propsVec.resize(propsVec.size() + 1U); | ||
auto& field = propsVec.back().initField_responseTopic(); | ||
field.field_value().setValue(ResponseTopic); | ||
} while (false); | ||
|
||
do { | ||
propsVec.resize(propsVec.size() + 1U); | ||
auto& field = propsVec.back().initField_correlationData(); | ||
field.field_value().setValue(CorrelationData); | ||
} while (false); | ||
|
||
do { | ||
propsVec.resize(propsVec.size() + 1U); | ||
auto& field = propsVec.back().initField_contentType(); | ||
field.field_value().setValue(ContentType); | ||
} while (false); | ||
|
||
do { | ||
propsVec.resize(propsVec.size() + 1U); | ||
auto& field = propsVec.back().initField_subscriptionId(); | ||
field.field_value().setValue(SubId); | ||
} while (false); | ||
|
||
do { | ||
propsVec.resize(propsVec.size() + 1U); | ||
auto& field = propsVec.back().initField_userProperty(); | ||
field.field_value().field_first().setValue(UserPropKey1); | ||
field.field_value().field_second().setValue(UserPropVal1); | ||
} while (false); | ||
|
||
publishMsg.doRefresh(); | ||
unitTestReceiveMessage(publishMsg); | ||
|
||
TS_ASSERT(unitTestHasMessageRecieved()); | ||
auto& msgInfo = unitTestReceivedMessageInfo(); | ||
TS_ASSERT_EQUALS(msgInfo.m_topic, Topic); | ||
TS_ASSERT_EQUALS(msgInfo.m_data, Data); | ||
TS_ASSERT_EQUALS(msgInfo.m_format, Format); | ||
TS_ASSERT_EQUALS(msgInfo.m_messageExpiryInterval, MessageExpiryInterval); | ||
TS_ASSERT_EQUALS(msgInfo.m_responseTopic, ResponseTopic); | ||
TS_ASSERT_EQUALS(msgInfo.m_correlationData, CorrelationData); | ||
TS_ASSERT(msgInfo.m_userProps.empty()); // expected to be ignored | ||
TS_ASSERT(msgInfo.m_subIds.empty()); // expected to be ignored | ||
TS_ASSERT_EQUALS(msgInfo.m_qos, CC_Mqtt5QoS_AtMostOnceDelivery); | ||
TS_ASSERT_EQUALS(msgInfo.m_retained, Retain); | ||
unitTestPopReceivedMessageInfo(); | ||
} |