Skip to content

Commit fe73897

Browse files
authored
Merge pull request #14 from bradleysmith23/main
Fix build warnings for unit tests
2 parents 07ec076 + 978d0b5 commit fe73897

File tree

4 files changed

+31
-46
lines changed

4 files changed

+31
-46
lines changed

test/unit-test/downloader_base64_utest.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
/* ============================ TEST GLOBALS ============================= */
2222
const size_t destLength = mqttFileDownloader_CONFIG_BLOCK_SIZE;
23-
const uint8_t * encodedTest = "dGVzdA=="; /* The string 'test' base64 encoded */
23+
const uint8_t * encodedTest = ( const uint8_t * ) "dGVzdA=="; /* The string 'test' base64 encoded */
2424
size_t encodedTestLen = 8U;
2525
size_t decodedTestLen = 4U;
2626

@@ -73,7 +73,7 @@ void test_base64Decode_decodesDataSuccessfully_2Chars( void )
7373
/* Setting to an error before the test to make sure it's the function which succeeds */
7474
decodeStatus = Base64NullPointerInput;
7575

76-
decodeStatus = base64_Decode( destBuffer, destLength, &decodeLen, "dHk=", 4U );
76+
decodeStatus = base64_Decode( destBuffer, destLength, &decodeLen, ( const uint8_t * ) "dHk=", 4U );
7777

7878
TEST_ASSERT_EQUAL( Base64Success, decodeStatus );
7979
TEST_ASSERT_EQUAL( 2, decodeLen );
@@ -84,7 +84,7 @@ void test_base64Decode_decodesDataSuccessfully_3Chars( void )
8484
/* Setting to an error before the test to make sure it's the function which succeeds */
8585
decodeStatus = Base64NullPointerInput;
8686

87-
decodeStatus = base64_Decode( destBuffer, destLength, &decodeLen, "dHJ5", 3U );
87+
decodeStatus = base64_Decode( destBuffer, destLength, &decodeLen, ( const uint8_t * ) "dHJ5", 3U );
8888

8989
TEST_ASSERT_EQUAL( Base64NonZeroPadding, decodeStatus );
9090
}

test/unit-test/downloader_cbor_utest.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
#define CBOR_GETSTREAMREQUEST_ITEM_COUNT 6
2424

2525
/* ============================ TEST GLOBALS ============================= */
26-
const uint8_t * decodeMessageBuffer = "decodeMessageBuffer";
27-
uint8_t * encodeMessageBuffer = "encodeMessageBuffer";
28-
const uint8_t * blockBitmap = "blockBitmap";
26+
const uint8_t * decodeMessageBuffer = ( const uint8_t * ) "decodeMessageBuffer";
27+
uint8_t * encodeMessageBuffer = ( uint8_t * ) "encodeMessageBuffer";
28+
const uint8_t * blockBitmap = ( const uint8_t * ) "blockBitmap";
2929
const char * clientToken = "clientToken";
3030
int32_t blockId = 1;
3131
int32_t blockSize = 2;
@@ -102,7 +102,7 @@ void cborFindsBlockIdKey( void )
102102

103103
void cborBlockIdKeyCorrectType( void )
104104
{
105-
cbor_value_get_type_ExpectAndReturn( &cborValue, CborNoError );
105+
cbor_value_get_type_ExpectAndReturn( &cborValue, ( CborType ) CborNoError );
106106
cbor_value_get_int_ExpectAndReturn( &cborValue, &blockId, CborNoError );
107107
}
108108

@@ -115,7 +115,7 @@ void cborFindsBlockSizeKey( void )
115115

116116
void cborBlockSizeKeyCorrectType( void )
117117
{
118-
cbor_value_get_type_ExpectAndReturn( &cborValue, CborNoError );
118+
cbor_value_get_type_ExpectAndReturn( &cborValue, ( CborType ) CborNoError );
119119
cbor_value_get_int_ExpectAndReturn( &cborValue, &blockSize, CborNoError );
120120
}
121121

@@ -187,7 +187,6 @@ void cborEncodesNumberOfBlocks( void )
187187

188188
void test_Decode_succeeds( void )
189189
{
190-
uint8_t payload;
191190
uint8_t * payloadPtr;
192191

193192
payloadSizeReceived = payloadSize - 1;
@@ -324,7 +323,7 @@ void test_Decode_returnsFalse_cannotGetBlockIdValue( void )
324323
cborFindsFileIdKey();
325324
cborFileIdKeyCorrectType();
326325
cborFindsBlockIdKey();
327-
cbor_value_get_type_ExpectAndReturn( &cborValue, CborNoError );
326+
cbor_value_get_type_ExpectAndReturn( &cborValue, ( CborType ) CborNoError );
328327
cbor_value_get_int_ExpectAndReturn( &cborValue, &blockId, CborUnknownError );
329328

330329
result = CBOR_Decode_GetStreamResponseMessage( decodeMessageBuffer, 1234U, &fileId, &blockId, &blockSize, payload, &payloadSize );
@@ -354,7 +353,7 @@ void test_Decode_returnsFalse_blockSizeWrongTypeInMap( void )
354353
cborFindsBlockIdKey();
355354
cborBlockIdKeyCorrectType();
356355
cborFindsBlockSizeKey();
357-
cbor_value_get_type_ExpectAndReturn( &cborValue, CborUnknownError );
356+
cbor_value_get_type_ExpectAndReturn( &cborValue, ( CborType ) CborUnknownError );
358357

359358
result = CBOR_Decode_GetStreamResponseMessage( decodeMessageBuffer, 1234U, &fileId, &blockId, &blockSize, payload, &payloadSize );
360359
TEST_ASSERT_FALSE( result );
@@ -369,7 +368,7 @@ void test_Decode_returnsFalse_cannotGetBlockSizeValue( void )
369368
cborFindsBlockIdKey();
370369
cborBlockIdKeyCorrectType();
371370
cborFindsBlockSizeKey();
372-
cbor_value_get_type_ExpectAndReturn( &cborValue, CborNoError );
371+
cbor_value_get_type_ExpectAndReturn( &cborValue, ( CborType ) CborNoError );
373372
cbor_value_get_int_ExpectAndReturn( &cborValue, &blockSize, CborUnknownError );
374373

375374
result = CBOR_Decode_GetStreamResponseMessage( decodeMessageBuffer, 1234U, &fileId, &blockId, &blockSize, payload, &payloadSize );
@@ -404,7 +403,7 @@ void test_Decode_returnsFalse_blockPayloadWrongTypeInMap( void )
404403
cborBlockSizeKeyCorrectType();
405404
cborFindsPayloadKeyInMap();
406405

407-
cbor_value_get_type_ExpectAndReturn( &cborValue, CborUnknownError );
406+
cbor_value_get_type_ExpectAndReturn( &cborValue, ( CborType ) CborUnknownError );
408407

409408
result = CBOR_Decode_GetStreamResponseMessage( decodeMessageBuffer, 1234U, &fileId, &blockId, &blockSize, payload, &payloadSize );
410409
TEST_ASSERT_FALSE( result );
@@ -451,7 +450,6 @@ void test_Decode_returnsFalse_blockPayloadLargerThanBuffer( void )
451450

452451
void test_Decode_returnsFalse_failsCopyingPayloadByteString( void )
453452
{
454-
uint8_t payload;
455453
uint8_t * payloadPtr;
456454

457455
payloadSizeReceived = payloadSize - 1;

test/unit-test/downloader_utest.c

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,15 @@ int suiteTearDown( int numFailures )
5757
/* ============================= CALLBACKS ============================= */
5858

5959
bool mqtt_subscribe_stream_json_true( char * topic,
60-
size_t topicLength,
61-
int NumCalls )
60+
size_t topicLength )
6261
{
6362
TEST_ASSERT_EQUAL_MEMORY( "$aws/things/thingname/streams/stream-name/data/json", topic, strlen( "$aws/things/thingname/streams/stream-name/data/json" ) );
6463
TEST_ASSERT_EQUAL_INT( strlen( "$aws/things/thingname/streams/stream-name/data/json" ), topicLength );
6564
return true;
6665
}
6766

6867
bool mqtt_subscribe_stream_json_false( char * topic,
69-
size_t topicLength,
70-
int NumCalls )
68+
size_t topicLength )
7169
{
7270
TEST_ASSERT_EQUAL_MEMORY( "$aws/things/thingname/streams/stream-name/data/json", topic, strlen( "$aws/things/thingname/streams/stream-name/data/json" ) );
7371
TEST_ASSERT_EQUAL_INT( strlen( "$aws/things/thingname/streams/stream-name/data/json" ), topicLength );
@@ -76,17 +74,15 @@ bool mqtt_subscribe_stream_json_false( char * topic,
7674

7775

7876
bool mqtt_subscribe_stream_cbor_true( char * topic,
79-
size_t topicLength,
80-
int NumCalls )
77+
size_t topicLength )
8178
{
8279
TEST_ASSERT_EQUAL_MEMORY( "$aws/things/thingname/streams/stream-name/data/cbor", topic, strlen( "$aws/things/thingname/streams/stream-name/data/cbor" ) );
8380
TEST_ASSERT_EQUAL_INT( strlen( "$aws/things/thingname/streams/stream-name/data/cbor" ), topicLength );
8481
return true;
8582
}
8683

8784
bool mqtt_subscribe_stream_cbor_false( char * topic,
88-
size_t topicLength,
89-
int NumCalls )
85+
size_t topicLength )
9086
{
9187
TEST_ASSERT_EQUAL_MEMORY( "$aws/things/thingname/streams/stream-name/data/cbor", topic, strlen( "$aws/things/thingname/streams/stream-name/data/cbor" ) );
9288
TEST_ASSERT_EQUAL_INT( strlen( "$aws/things/thingname/streams/stream-name/data/cbor" ), topicLength );
@@ -96,8 +92,7 @@ bool mqtt_subscribe_stream_cbor_false( char * topic,
9692
bool mqtt_publish_request_json_true( char * topic,
9793
size_t topicLength,
9894
uint8_t * message,
99-
size_t messageLength,
100-
int NumCalls )
95+
size_t messageLength )
10196
{
10297
TEST_ASSERT_EQUAL_MEMORY( getStreamTopic, topic, getStreamTopicLength );
10398
TEST_ASSERT_EQUAL_INT( getStreamTopicLength, topicLength );
@@ -109,8 +104,7 @@ bool mqtt_publish_request_json_true( char * topic,
109104
bool mqtt_publish_request_json_false( char * topic,
110105
size_t topicLength,
111106
uint8_t * message,
112-
size_t messageLength,
113-
int NumCalls )
107+
size_t messageLength )
114108
{
115109
TEST_ASSERT_EQUAL_MEMORY( getStreamTopic, topic, getStreamTopicLength );
116110
TEST_ASSERT_EQUAL_INT( getStreamTopicLength, topicLength );
@@ -208,7 +202,7 @@ void test_createGetDataBlockRequest_succeedsForCBORDataType( void )
208202
char * encodedMessage = "expected-message";
209203
size_t expectedCborSize = 9999U;
210204

211-
CBOR_Encode_GetStreamRequestMessage_ExpectAndReturn( getStreamRequest,
205+
CBOR_Encode_GetStreamRequestMessage_ExpectAndReturn( ( uint8_t * ) &getStreamRequest,
212206
GET_STREAM_REQUEST_BUFFER_SIZE,
213207
NULL,
214208
"rdy",
@@ -223,7 +217,7 @@ void test_createGetDataBlockRequest_succeedsForCBORDataType( void )
223217
CBOR_Encode_GetStreamRequestMessage_IgnoreArg_encodedMessageSize();
224218
CBOR_Encode_GetStreamRequestMessage_IgnoreArg_messageBuffer();
225219
CBOR_Encode_GetStreamRequestMessage_ReturnThruPtr_encodedMessageSize( &expectedCborSize );
226-
CBOR_Encode_GetStreamRequestMessage_ReturnThruPtr_messageBuffer( encodedMessage );
220+
CBOR_Encode_GetStreamRequestMessage_ReturnThruPtr_messageBuffer( ( uint8_t * ) encodedMessage );
227221

228222
requestLength = mqttDownloader_createGetDataBlockRequest( DATA_TYPE_CBOR, 4U, 3U, 2U, 1U, getStreamRequest, getStreamRequestLength );
229223
TEST_ASSERT_EQUAL( expectedCborSize, requestLength );
@@ -235,9 +229,6 @@ void test_createGetDataBlockRequest_FailsWhenGetStreamRequestLengthTooSmall( voi
235229
char getStreamRequest[ GET_STREAM_REQUEST_BUFFER_SIZE ];
236230
size_t getStreamRequestLength = 0;
237231

238-
char * encodedMessage = "expected-message";
239-
size_t expectedCborSize = 9999U;
240-
241232
requestLength = mqttDownloader_createGetDataBlockRequest( DATA_TYPE_JSON, 4U, 3U, 2U, 1U, getStreamRequest, getStreamRequestLength );
242233
TEST_ASSERT_EQUAL( 0, requestLength );
243234
}
@@ -246,9 +237,6 @@ void test_createGetDataBlockRequest_FailsWhenGetStreamRequestBufferIsNull( void
246237
{
247238
size_t getStreamRequestLength = GET_STREAM_REQUEST_BUFFER_SIZE;
248239

249-
char * encodedMessage = "expected-message";
250-
size_t expectedCborSize = 9999U;
251-
252240
requestLength = mqttDownloader_createGetDataBlockRequest( DATA_TYPE_JSON, 4U, 3U, 2U, 1U, NULL, getStreamRequestLength );
253241
TEST_ASSERT_EQUAL( 0, requestLength );
254242
}
@@ -313,7 +301,7 @@ void test_processReceivedDataBlock_processesJSONBlock( void )
313301
uint8_t decodedData[ mqttFileDownloader_CONFIG_BLOCK_SIZE ];
314302
size_t dataLength = 0;
315303

316-
bool result = mqttDownloader_processReceivedDataBlock( &context, "{\"p\": \"dGVzdA==\"}", strlen( "{\"p\": \"dGVzdA==\"}" ), decodedData, &dataLength );
304+
bool result = mqttDownloader_processReceivedDataBlock( &context, ( uint8_t * ) "{\"p\": \"dGVzdA==\"}", strlen( "{\"p\": \"dGVzdA==\"}" ), decodedData, &dataLength );
317305

318306
TEST_ASSERT_TRUE( result );
319307
TEST_ASSERT_EQUAL( 4, dataLength );
@@ -328,7 +316,7 @@ void test_processReceivedDataBlock_invalidJSONBlock( void )
328316
uint8_t decodedData[ mqttFileDownloader_CONFIG_BLOCK_SIZE ];
329317
size_t dataLength = 0;
330318

331-
MQTTFileDownloaderStatus_t result = mqttDownloader_processReceivedDataBlock( &context, "{\"wrongKey\": \"dGVzdA==\"}", strlen( "{\"wrongKey\": \"dGVzdA==\"}" ), decodedData, &dataLength );
319+
MQTTFileDownloaderStatus_t result = mqttDownloader_processReceivedDataBlock( &context, ( uint8_t * ) "{\"wrongKey\": \"dGVzdA==\"}", strlen( "{\"wrongKey\": \"dGVzdA==\"}" ), decodedData, &dataLength );
332320

333321
TEST_ASSERT_EQUAL( 7, result );
334322
TEST_ASSERT_EQUAL( 0, dataLength );
@@ -343,7 +331,7 @@ void test_processReceivedDataBlock_invalidEncodingJSONBlock( void )
343331
uint8_t decodedData[ mqttFileDownloader_CONFIG_BLOCK_SIZE ];
344332
size_t dataLength = 0;
345333

346-
MQTTFileDownloaderStatus_t result = mqttDownloader_processReceivedDataBlock( &context, "{\"p\": \"notEncoded\"}", strlen( "{\"p\": \"notEncoded\"}" ), decodedData, &dataLength );
334+
MQTTFileDownloaderStatus_t result = mqttDownloader_processReceivedDataBlock( &context, ( uint8_t * ) "{\"p\": \"notEncoded\"}", strlen( "{\"p\": \"notEncoded\"}" ), decodedData, &dataLength );
347335

348336
TEST_ASSERT_EQUAL( 7, result );
349337
TEST_ASSERT_EQUAL( 0, dataLength );
@@ -360,15 +348,15 @@ void test_processReceivedDataBlock_processesCBORBlock( void )
360348
uint8_t decodedData[ mqttFileDownloader_CONFIG_BLOCK_SIZE ];
361349
size_t dataLength = 0;
362350

363-
CBOR_Decode_GetStreamResponseMessage_ExpectAndReturn( validCBORMsg, strlen( validCBORMsg ), NULL, NULL, NULL, NULL, NULL, true );
351+
CBOR_Decode_GetStreamResponseMessage_ExpectAndReturn( ( const uint8_t * ) validCBORMsg, strlen( validCBORMsg ), NULL, NULL, NULL, NULL, NULL, true );
364352
CBOR_Decode_GetStreamResponseMessage_IgnoreArg_fileId();
365353
CBOR_Decode_GetStreamResponseMessage_IgnoreArg_blockSize();
366354
CBOR_Decode_GetStreamResponseMessage_IgnoreArg_blockId();
367355
CBOR_Decode_GetStreamResponseMessage_IgnoreArg_payload();
368356
CBOR_Decode_GetStreamResponseMessage_IgnoreArg_payloadSize();
369357
CBOR_Decode_GetStreamResponseMessage_ReturnThruPtr_payloadSize( &expectedProcessedDataLength );
370358

371-
bool result = mqttDownloader_processReceivedDataBlock( &context, validCBORMsg, strlen( validCBORMsg ), decodedData, &dataLength );
359+
bool result = mqttDownloader_processReceivedDataBlock( &context, ( uint8_t * ) validCBORMsg, strlen( validCBORMsg ), decodedData, &dataLength );
372360

373361
TEST_ASSERT_TRUE( result );
374362
TEST_ASSERT_EQUAL( expectedProcessedDataLength, dataLength );
@@ -385,15 +373,15 @@ void test_processReceivedDataBlock_invalidCBORBlock( void )
385373
uint8_t decodedData[ mqttFileDownloader_CONFIG_BLOCK_SIZE ];
386374
size_t dataLength = 0;
387375

388-
CBOR_Decode_GetStreamResponseMessage_ExpectAndReturn( invalidCBORMsg, strlen( invalidCBORMsg ), NULL, NULL, NULL, NULL, NULL, false );
376+
CBOR_Decode_GetStreamResponseMessage_ExpectAndReturn( ( const uint8_t * ) invalidCBORMsg, strlen( invalidCBORMsg ), NULL, NULL, NULL, NULL, NULL, false );
389377
CBOR_Decode_GetStreamResponseMessage_IgnoreArg_fileId();
390378
CBOR_Decode_GetStreamResponseMessage_IgnoreArg_blockSize();
391379
CBOR_Decode_GetStreamResponseMessage_IgnoreArg_blockId();
392380
CBOR_Decode_GetStreamResponseMessage_IgnoreArg_payload();
393381
CBOR_Decode_GetStreamResponseMessage_IgnoreArg_payloadSize();
394382
CBOR_Decode_GetStreamResponseMessage_ReturnThruPtr_payloadSize( &notExpectedProcessedDataLength );
395383

396-
MQTTFileDownloaderStatus_t result = mqttDownloader_processReceivedDataBlock( &context, invalidCBORMsg, strlen( invalidCBORMsg ), decodedData, &dataLength );
384+
MQTTFileDownloaderStatus_t result = mqttDownloader_processReceivedDataBlock( &context, ( uint8_t * ) invalidCBORMsg, strlen( invalidCBORMsg ), decodedData, &dataLength );
397385

398386
TEST_ASSERT_EQUAL( 7, result );
399387
TEST_ASSERT_EQUAL( 0, dataLength );
@@ -421,7 +409,7 @@ void test_processReceivedDataBlock_returnsFailureWhenMessageLengthZero( void )
421409
uint8_t decodedData[ mqttFileDownloader_CONFIG_BLOCK_SIZE ];
422410
size_t dataLength = 0;
423411

424-
uintResult = mqttDownloader_processReceivedDataBlock( &context, "{\"p\": \"dGVzdA==\"}", 0U, decodedData, &dataLength );
412+
uintResult = mqttDownloader_processReceivedDataBlock( &context, ( uint8_t * ) "{\"p\": \"dGVzdA==\"}", 0U, decodedData, &dataLength );
425413
TEST_ASSERT_EQUAL( MQTTFileDownloaderFailure, uintResult );
426414
}
427415

@@ -431,10 +419,9 @@ void test_processReceivedDataBlock_returnsFailureWhenDataIsNull( void )
431419

432420
context.dataType = DATA_TYPE_JSON;
433421

434-
uint8_t decodedData[ mqttFileDownloader_CONFIG_BLOCK_SIZE ];
435422
size_t dataLength = 0;
436423

437-
uintResult = mqttDownloader_processReceivedDataBlock( &context, "{\"p\": \"dGVzdA==\"}", strlen( "{\"p\": \"dGVzdA==\"}" ), NULL, &dataLength );
424+
uintResult = mqttDownloader_processReceivedDataBlock( &context, ( uint8_t * ) "{\"p\": \"dGVzdA==\"}", strlen( "{\"p\": \"dGVzdA==\"}" ), NULL, &dataLength );
438425
TEST_ASSERT_EQUAL( MQTTFileDownloaderFailure, uintResult );
439426
}
440427

@@ -447,6 +434,6 @@ void test_processReceivedDataBlock_returnsFailureWhenDataLengthIsNull( void )
447434
uint8_t decodedData[ mqttFileDownloader_CONFIG_BLOCK_SIZE ];
448435
size_t * dataLength = NULL;
449436

450-
uintResult = mqttDownloader_processReceivedDataBlock( &context, "{\"p\": \"dGVzdA==\"}", strlen( "{\"p\": \"dGVzdA==\"}" ), decodedData, dataLength );
437+
uintResult = mqttDownloader_processReceivedDataBlock( &context, ( uint8_t * ) "{\"p\": \"dGVzdA==\"}", strlen( "{\"p\": \"dGVzdA==\"}" ), decodedData, dataLength );
451438
TEST_ASSERT_EQUAL( MQTTFileDownloaderFailure, uintResult );
452439
}

tools/cmock/create_test.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function(create_test test_name test_src link_list dep_list include_list)
1515
add_executable(${test_name} ${test_src} ${test_name}_runner.c)
1616
set_target_properties(
1717
${test_name}
18-
PROPERTIES COMPILE_FLAG "-O0 -ggdb"
18+
PROPERTIES COMPILE_FLAG "-O0 -ggdb -Werror -Wall"
1919
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/tests"
2020
INSTALL_RPATH_USE_LINK_PATH TRUE
2121
LINK_FLAGS " \

0 commit comments

Comments
 (0)