AWS IoT Device SDK C: MQTT
MQTT 3.1.1 client library
Return to main page ↑
iot_tests_mqtt_subscription.c File Reference

Tests for the functions in iot_mqtt_subscription.c. More...

#include "iot_config.h"
#include <stdio.h>
#include <string.h>
#include "iot_init.h"
#include "platform/iot_threads.h"
#include "platform/iot_clock.h"
#include "private/iot_mqtt_internal.h"
#include "unity_fixture.h"
#include "iot_test_access_mqtt.h"

Macros

#define AWS_IOT_MQTT_SERVER   true
 Determine which MQTT server mode to test (AWS IoT or Mosquitto).
 
#define LIST_ITEM_COUNT   ( 10 )
 Number of subscriptions.
 
#define TEST_TOPIC_FILTER_FORMAT   ( "/test%lu" )
 Format of each topic filter.
 
#define TEST_TOPIC_FILTER_LENGTH   ( sizeof( TEST_TOPIC_FILTER_FORMAT ) + 1 )
 Maximum length of each topic filter.
 
#define SUBSCRIPTION_CALLBACK_FUNCTION
 A non-NULL function pointer to use for subscription callback. This "function" should cause a crash if actually called. More...
 
#define TOPIC_FILTER_MATCH_MAX_LENGTH   ( 32 )
 All test topic filters in the tests TEST_MQTT_Unit_Subscription_TopicFilterMatchTrue_ and TEST_MQTT_Unit_Subscription_TopicFilterMatchFalse_ should be shorter than this length.
 
#define TEST_TOPIC_MATCH(topicNameString, topicFilterString, exactMatch, expectedResult)
 Macro to check a single topic name against a topic filter. More...
 

Functions

static void _populateList (void)
 Places dummy subscriptions in the subscription list of _pMqttConnection.
 
static void _removalCallback (void *pArgument, IotMqttCallbackParam_t *pPublish)
 A subscription callback function that unlinks its subscription.
 
static void _publishCallback (void *pArgument, IotMqttCallbackParam_t *pPublish)
 A subscription callback function that only reports whether it was invoked.
 
 TEST_GROUP (MQTT_Unit_Subscription)
 Test group for MQTT subscription tests.
 
 TEST_SETUP (MQTT_Unit_Subscription)
 Test setup for MQTT subscription tests.
 
 TEST_TEAR_DOWN (MQTT_Unit_Subscription)
 Test tear down for MQTT subscription tests.
 
 TEST_GROUP_RUNNER (MQTT_Unit_Subscription)
 Test group runner for MQTT subscription tests.
 
void TEST_MQTT_Unit_Subscription_ListInsertRemove_ (void)
 Tests simple insertion and removal of elements from the subscription list.
 
void TEST_MQTT_Unit_Subscription_ListFindByTopicFilter_ (void)
 Tests searching the subscription list using a topic filter.
 
void TEST_MQTT_Unit_Subscription_ListFindByPacket_ (void)
 Tests searching the subscription list using a packet identifier.
 
void TEST_MQTT_Unit_Subscription_SubscriptionRemoveByPacket_ (void)
 Tests removing subscriptions by packet identifier.
 
void TEST_MQTT_Unit_Subscription_SubscriptionRemoveByTopicFilter_ (void)
 Tests removing subscriptions by a topic filter.
 
void TEST_MQTT_Unit_Subscription_SubscriptionAddDuplicate_ (void)
 Tests adding duplicate subscriptions.
 
void TEST_MQTT_Unit_Subscription_SubscriptionAddMallocFail_ (void)
 Tests adding subscriptions when memory allocation fails at various points.
 
void TEST_MQTT_Unit_Subscription_ProcessPublish_ (void)
 Tests invoking subscription callbacks with PUBLISH messages.
 
void TEST_MQTT_Unit_Subscription_ProcessPublishMultiple_ (void)
 Tests that all matching subscription callbacks are invoked for a PUBLISH.
 
void TEST_MQTT_Unit_Subscription_SubscriptionUnsubscribe_ (void)
 Tests that the unsubscribed flag is respected for subscriptions.
 
void TEST_MQTT_Unit_Subscription_TopicFilterMatchTrue_ (void)
 Tests result of matching topic filters and topic names.
 
void TEST_MQTT_Unit_Subscription_TopicFilterMatchFalse_ (void)
 Tests result of matching topic filters and topic names that don't match.
 

Variables

static bool _connectionCreated = false
 Tracks whether the global MQTT connection has been created.
 
static _mqttConnection_t_pMqttConnection = IOT_MQTT_CONNECTION_INITIALIZER
 The MQTT connection shared by all tests.
 

Detailed Description

Tests for the functions in iot_mqtt_subscription.c.

Macro Definition Documentation

◆ SUBSCRIPTION_CALLBACK_FUNCTION

#define SUBSCRIPTION_CALLBACK_FUNCTION
Value:
( ( void ( * )( void *, \
IotMqttCallbackParam_t * ) ) 0x1 )

A non-NULL function pointer to use for subscription callback. This "function" should cause a crash if actually called.

◆ TEST_TOPIC_MATCH

#define TEST_TOPIC_MATCH (   topicNameString,
  topicFilterString,
  exactMatch,
  expectedResult 
)
Value:
{ \
_topicMatchParams_t _topicMatchParams = { 0 }; \
_topicMatchParams.pTopicName = topicNameString; \
_topicMatchParams.topicNameLength = ( uint16_t ) strlen( _topicMatchParams.pTopicName ); \
_topicMatchParams.exactMatchOnly = exactMatch; \
\
pTopicFilter->topicFilterLength = ( uint16_t ) snprintf( pTopicFilter->pTopicFilter, \
topicFilterString ); \
\
TEST_ASSERT_EQUAL_INT( expectedResult, \
IotTestMqtt_topicMatch( &( pTopicFilter->link ), &_topicMatchParams ) ); \
}
bool IotTestMqtt_topicMatch(const IotLink_t *pSubscriptionLink, void *pMatch)
Test access function for _topicMatch.
Definition: iot_test_access_mqtt_subscription.c:40
#define TOPIC_FILTER_MATCH_MAX_LENGTH
All test topic filters in the tests TEST_MQTT_Unit_Subscription_TopicFilterMatchTrue_ and TEST_MQTT_U...
Definition: iot_tests_mqtt_subscription.c:93

Macro to check a single topic name against a topic filter.

Parameters
[in]topicNameStringThe topic name to check.
[in]topicFilterStringThe topic filter to check.
[in]exactMatchWhether an exact match is required. If this is false, wildcard matching is allowed.
[in]expectedResultWhether the topic name and filter are expected to match.
Note
This macro may only be used when a _mqttSubscription_t pointer named pTopicFilter is in scope.