3333#include <string.h>
3434#include <time.h>
3535#include <unistd.h>
36- #include "demo_config.h"
36+ #include <stdio.h>
3737#include "core_mqtt.h"
3838#include "core_mqtt_state.h"
39- #include "clock.h"
4039#include "unity.h"
4140#include "unity_fixture.h"
4241
9089/**
9190 * @brief Sample topic filter to subscribe to.
9291 */
93- #define TEST_MQTT_TOPIC CLIENT_IDENTIFIER "/iot/integration/test"
92+ #define TEST_MQTT_TOPIC MQTT_TEST_CLIENT_IDENTIFIER "/iot/integration/test"
9493
9594/**
9695 * @brief Sample topic filter to test MQTT retainted message.
9796 */
98- #define TEST_MQTT_RETAIN_TOPIC CLIENT_IDENTIFIER "/iot/integration/testretain"
97+ #define TEST_MQTT_RETAIN_TOPIC MQTT_TEST_CLIENT_IDENTIFIER "/iot/integration/testretain"
9998
10099/**
101100 * @brief Length of sample topic filter.
105104/**
106105 * @brief Sample topic filter to subscribe to.
107106 */
108- #define TEST_MQTT_LWT_TOPIC CLIENT_IDENTIFIER "/iot/integration/test/lwt"
107+ #define TEST_MQTT_LWT_TOPIC MQTT_TEST_CLIENT_IDENTIFIER "/iot/integration/test/lwt"
109108
110109/**
111110 * @brief Length of sample topic filter.
112111 */
113112#define TEST_MQTT_LWT_TOPIC_LENGTH ( sizeof( TEST_MQTT_LWT_TOPIC ) - 1 )
114113
115- /**
116- * @brief Client identifier for MQTT session in the tests.
117- */
118- #define TEST_CLIENT_IDENTIFIER CLIENT_IDENTIFIER
119-
120114/**
121115 * @brief Length of the client identifier.
122116 */
123- #define TEST_CLIENT_IDENTIFIER_LENGTH ( sizeof( TEST_CLIENT_IDENTIFIER ) - 1u )
117+ #define TEST_CLIENT_IDENTIFIER_LENGTH ( sizeof( MQTT_TEST_CLIENT_IDENTIFIER ) - 1u )
124118
125119/**
126120 * @brief Client identifier for use in LWT tests.
127121 */
128- #define TEST_CLIENT_IDENTIFIER_LWT CLIENT_IDENTIFIER "-LWT"
122+ #define TEST_CLIENT_IDENTIFIER_LWT MQTT_TEST_CLIENT_IDENTIFIER "-LWT"
129123
130124/**
131125 * @brief Length of LWT client identifier.
@@ -378,7 +372,7 @@ static void establishMqttSession( MQTTContext_t * pContext,
378372 assert ( pContext != NULL );
379373
380374 /* The network buffer must remain valid for the lifetime of the MQTT context. */
381- static uint8_t buffer [ NETWORK_BUFFER_SIZE ];
375+ static uint8_t buffer [ MQTT_TEST_NETWORK_BUFFER_SIZE ];
382376
383377 /* Buffer for storing client ID with random integer.
384378 * Note: Size value is chosen to accommodate both LWT and non-LWT client ID
@@ -388,7 +382,7 @@ static void establishMqttSession( MQTTContext_t * pContext,
388382
389383 /* Fill the values for network buffer. */
390384 networkBuffer .pBuffer = buffer ;
391- networkBuffer .size = NETWORK_BUFFER_SIZE ;
385+ networkBuffer .size = MQTT_TEST_NETWORK_BUFFER_SIZE ;
392386
393387 transport .pNetworkContext = pNetworkContext ;
394388 transport .send = testParam .pTransport -> send ;
@@ -400,7 +394,7 @@ static void establishMqttSession( MQTTContext_t * pContext,
400394 /* Initialize MQTT library. */
401395 TEST_ASSERT_EQUAL ( MQTTSuccess , MQTT_Init ( pContext ,
402396 & transport ,
403- Clock_GetTimeMs ,
397+ testParam . pGetTimeMs ,
404398 eventCallback ,
405399 & networkBuffer ) );
406400 }
@@ -426,7 +420,7 @@ static void establishMqttSession( MQTTContext_t * pContext,
426420 snprintf ( clientIdBuffer ,
427421 sizeof ( clientIdBuffer ),
428422 "%d%s" , clientIdRandNumber ,
429- TEST_CLIENT_IDENTIFIER );
423+ MQTT_TEST_CLIENT_IDENTIFIER );
430424 connectInfo .pClientIdentifier = clientIdBuffer ;
431425 }
432426
@@ -749,8 +743,6 @@ static MQTTStatus_t publishToTopic( MQTTContext_t * pContext,
749743 */
750744TEST_SETUP ( MqttTest )
751745{
752- struct timespec tp ;
753-
754746 /* Reset file-scoped global variables. */
755747 receivedSubAck = false;
756748 receivedUnsubAck = false;
@@ -764,14 +756,8 @@ TEST_SETUP( MqttTest )
764756 packetTypeForDisconnection = MQTT_PACKET_TYPE_INVALID ;
765757 memset ( & incomingInfo , 0u , sizeof ( MQTTPublishInfo_t ) );
766758
767- /* Get current time to seed pseudo random number generator. */
768- ( void ) clock_gettime ( CLOCK_REALTIME , & tp );
769-
770- /* Seed pseudo random number generator with nanoseconds. */
771- srand ( tp .tv_nsec );
772-
773759 /* Generate a random number to use in the client identifier. */
774- clientIdRandNumber = ( rand () % ( MAX_RAND_NUMBER_FOR_CLIENT_ID + 1u ) );
760+ clientIdRandNumber = ( FRTest_GenerateRandInt () % ( MAX_RAND_NUMBER_FOR_CLIENT_ID + 1u ) );
775761
776762 /* Establish a TCP connection with the server endpoint, then
777763 * establish TLS session on top of TCP connection. */
0 commit comments