Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coremqtt-agent: Add unit tests for subscription_manager.c #90

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion applications/helpers/logging/mocks/inc/logging_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ DECLARE_FAKE_VOID_FUNC_VARARG( SdkLogError,
DECLARE_FAKE_VOID_FUNC_VARARG( SdkLogWarn,
const char *,
... );
#define LogWarn( message ) ( SdkLogError message )
#define LogWarn( message ) ( SdkLogWarn message )
DECLARE_FAKE_VOID_FUNC_VARARG( SdkLogInfo,
const char *,
... );
Expand Down
8 changes: 8 additions & 0 deletions components/aws_iot/coremqtt/library_mocks/inc/core_mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,12 @@ DECLARE_FAKE_VALUE_FUNC( MQTTStatus_t,
uint32_t,
bool * );

DECLARE_FAKE_VALUE_FUNC( MQTTStatus_t,
MQTT_MatchTopic,
const char *,
const uint16_t,
const char *,
const uint16_t,
bool * );

#endif /* CORE_MQTT_H */
8 changes: 8 additions & 0 deletions components/aws_iot/coremqtt/library_mocks/src/core_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ DEFINE_FAKE_VALUE_FUNC( MQTTStatus_t,
const MQTTPublishInfo_t *,
uint32_t,
bool * );

DEFINE_FAKE_VALUE_FUNC( MQTTStatus_t,
MQTT_MatchTopic,
const char *,
const uint16_t,
const char *,
const uint16_t,
bool * );
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ bool addSubscription( const char * pcTopicFilterString,
* @param[in] pxSubscriptionList The pointer to the subscription list array.
* @param[in] pcTopicFilterString Topic filter of subscription.
* @param[in] usTopicFilterLength Length of topic filter.
*
* @return `true` if subscription has been removed, `false` if the subscription
* does not exist or deletion failed.
*/
void removeSubscription( const char * pcTopicFilterString,
bool removeSubscription( const char * pcTopicFilterString,
uint16_t usTopicFilterLength );

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ bool addSubscription( const char * pcTopicFilterString,

/*-----------------------------------------------------------*/

void removeSubscription( const char * pcTopicFilterString,
bool removeSubscription( const char * pcTopicFilterString,
uint16_t usTopicFilterLength )
{
bool found = false;

if( ( pcTopicFilterString == NULL ) ||
( usTopicFilterLength == 0U ) )
{
Expand All @@ -142,11 +144,14 @@ void removeSubscription( const char * pcTopicFilterString,
{
if( strncmp( xGlobalSubscriptionList[ lIndex ].pcSubscriptionFilterString, pcTopicFilterString, usTopicFilterLength ) == 0 )
{
found = true;
memset( &( xGlobalSubscriptionList[ lIndex ] ), 0x00, sizeof( SubscriptionElement_t ) );
}
}
}
}

return found;
}

/*-----------------------------------------------------------*/
Expand Down
20 changes: 20 additions & 0 deletions components/aws_iot/coremqtt_agent/integration/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,23 @@ target_link_libraries(freertos-command-pool-test
trusted-firmware-m-mock
)
iot_reference_arm_corstone3xx_add_test(freertos-command-pool-test)

add_executable(mqtt-subscription-manager-test
test_subscription_manager.cpp
../src/subscription_manager.c
)
target_include_directories(mqtt-subscription-manager-test
PRIVATE
.
../../library_mocks/inc

../inc
)
target_link_libraries(mqtt-subscription-manager-test
PRIVATE
fff
coremqtt-agent-test-config-mocks
coremqtt-mock
helpers-logging-mock
)
iot_reference_arm_corstone3xx_add_test(mqtt-subscription-manager-test)
Loading
Loading