Skip to content

Commit

Permalink
Include all SntpStatus_t values in Sntp_StatusToStr (#83)
Browse files Browse the repository at this point in the history
* Include all SntpStatus_t values in Sntp_StatusToStr

Withtout this change, the function Sntp_StatusToStr would return
"Invalid status code!" for the following valid status codes:

- SntpRejectedResponse
- SntpErrorSendTimeout
- SntpErrorResponseTimeout
- SntpNoResponseReceived
- SntpErrorContextNotInitialized

This issue was reported here - #82

Signed-off-by: Gaurav Aggarwal <[email protected]>

* Fix memory estimates

Signed-off-by: Gaurav Aggarwal <[email protected]>

* Fix spell check

Signed-off-by: Gaurav Aggarwal <[email protected]>

---------

Signed-off-by: Gaurav Aggarwal <[email protected]>
  • Loading branch information
aggarg committed Jan 7, 2024
1 parent 3409007 commit c5face5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/.cSpellWords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ lcov
ldms
lums
misra
nondet
sinclude
sntp
utest
Expand Down
8 changes: 4 additions & 4 deletions docs/doxygen/include/size_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</tr>
<tr>
<td>core_sntp_client.c</td>
<td><center>1.5K</center></td>
<td><center>1.2K</center></td>
<td><center>1.7K</center></td>
<td><center>1.4K</center></td>
</tr>
<tr>
<td>core_sntp_serializer.c</td>
Expand All @@ -19,7 +19,7 @@
</tr>
<tr>
<td><b>Total estimates</b></td>
<td><b><center>2.5K</center></b></td>
<td><b><center>2.0K</center></b></td>
<td><b><center>2.7K</center></b></td>
<td><b><center>2.2K</center></b></td>
</tr>
</table>
20 changes: 20 additions & 0 deletions source/core_sntp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,10 @@ const char * Sntp_StatusToStr( SntpStatus_t status )
pString = "SntpErrorBadParameter";
break;

case SntpRejectedResponse:
pString = "SntpRejectedResponse";
break;

case SntpRejectedResponseChangeServer:
pString = "SntpRejectedResponseChangeServer";
break;
Expand Down Expand Up @@ -975,6 +979,22 @@ const char * Sntp_StatusToStr( SntpStatus_t status )
pString = "SntpErrorAuthFailure";
break;

case SntpErrorSendTimeout:
pString = "SntpErrorSendTimeout";
break;

case SntpErrorResponseTimeout:
pString = "SntpErrorResponseTimeout";
break;

case SntpNoResponseReceived:
pString = "SntpNoResponseReceived";
break;

case SntpErrorContextNotInitialized:
pString = "SntpErrorContextNotInitialized";
break;

default:
pString = "Invalid status code!";
break;
Expand Down
6 changes: 6 additions & 0 deletions test/unit-test/core_sntp_client_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,7 @@ void test_StatusToStr( void )
{
TEST_ASSERT_EQUAL_STRING( "SntpSuccess", Sntp_StatusToStr( SntpSuccess ) );
TEST_ASSERT_EQUAL_STRING( "SntpErrorBadParameter", Sntp_StatusToStr( SntpErrorBadParameter ) );
TEST_ASSERT_EQUAL_STRING( "SntpRejectedResponse", Sntp_StatusToStr( SntpRejectedResponse ) );
TEST_ASSERT_EQUAL_STRING( "SntpRejectedResponseChangeServer", Sntp_StatusToStr( SntpRejectedResponseChangeServer ) );
TEST_ASSERT_EQUAL_STRING( "SntpRejectedResponseRetryWithBackoff", Sntp_StatusToStr( SntpRejectedResponseRetryWithBackoff ) );
TEST_ASSERT_EQUAL_STRING( "SntpRejectedResponseOtherCode", Sntp_StatusToStr( SntpRejectedResponseOtherCode ) );
Expand All @@ -1378,5 +1379,10 @@ void test_StatusToStr( void )
TEST_ASSERT_EQUAL_STRING( "SntpErrorNetworkFailure", Sntp_StatusToStr( SntpErrorNetworkFailure ) );
TEST_ASSERT_EQUAL_STRING( "SntpServerNotAuthenticated", Sntp_StatusToStr( SntpServerNotAuthenticated ) );
TEST_ASSERT_EQUAL_STRING( "SntpErrorAuthFailure", Sntp_StatusToStr( SntpErrorAuthFailure ) );
TEST_ASSERT_EQUAL_STRING( "SntpErrorSendTimeout", Sntp_StatusToStr( SntpErrorSendTimeout ) );
TEST_ASSERT_EQUAL_STRING( "SntpErrorResponseTimeout", Sntp_StatusToStr( SntpErrorResponseTimeout ) );
TEST_ASSERT_EQUAL_STRING( "SntpNoResponseReceived", Sntp_StatusToStr( SntpNoResponseReceived ) );
TEST_ASSERT_EQUAL_STRING( "SntpErrorContextNotInitialized", Sntp_StatusToStr( SntpErrorContextNotInitialized ) );

TEST_ASSERT_EQUAL_STRING( "Invalid status code!", Sntp_StatusToStr( 100 ) );
}

0 comments on commit c5face5

Please sign in to comment.