From 0833f95f70e391cf64df3be77c7da787ebf9cfa5 Mon Sep 17 00:00:00 2001 From: Eugene Dorfman Date: Mon, 14 Oct 2024 13:57:40 +0200 Subject: [PATCH] FEAT: introduce invalid input value status code --- fiftyone.h | 2 ++ status.c | 5 +++-- status.h | 7 +++++-- tests/StatusTests.cpp | 16 +++++++++++++++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/fiftyone.h b/fiftyone.h index d7cffebc..92ec4a16 100644 --- a/fiftyone.h +++ b/fiftyone.h @@ -435,6 +435,8 @@ MAP_TYPE(KeyValuePairArray) #define TEMP_FILE_ERROR FIFTYONE_DEGREES_STATUS_TEMP_FILE_ERROR /**< Synonym for #FIFTYONE_DEGREES_STATUS_INCORRECT_IP_ADDRESS_FORMAT status code. */ #define DATA_FILE_NEEDS_UPDATED FIFTYONE_DEGREES_STATUS_DATA_FILE_NEEDS_UPDATED /**< Synonym for #FIFTYONE_DEGREES_STATUS_DATA_FILE_NEEDS_UPDATED status code. */ #define INSUFFICIENT_CAPACITY FIFTYONE_DEGREES_STATUS_INSUFFICIENT_CAPACITY /**< Synonym for #FIFTYONE_DEGREES_STATUS_INSUFFICIENT_CAPACITY status code. */ +#define INVALID_INPUT FIFTYONE_DEGREES_STATUS_INVALID_INPUT /**< Synonym for + #FIFTYONE_DEGREES_STATUS_INVALID_INPUT status code.*/ /** * @} */ diff --git a/status.c b/status.c index cf27a3d4..f91fdcd0 100644 --- a/status.c +++ b/status.c @@ -120,7 +120,8 @@ static StatusMessage messages[] = { "string has correct format. If passing a byte array, verify the " "associated input data is also consistent." }, { TEMP_FILE_ERROR, - "Error occurs during the creation of a temporary file."} + "Error occurs during the creation of a temporary file."}, + { INVALID_INPUT, "The input value is invalid: misformatted or semantically inconsistent."}, }; static char defaultMessage[] = "Status code %i does not have any message text."; @@ -157,4 +158,4 @@ const char* fiftyoneDegreesStatusGetMessage( Snprintf(message, messageSize, defaultMessage, (int)status); } return message; -} \ No newline at end of file +} diff --git a/status.h b/status.h index edb8bdd8..485e35eb 100644 --- a/status.h +++ b/status.h @@ -138,7 +138,10 @@ typedef enum e_fiftyone_degrees_status_code { FIFTYONE_DEGREES_STATUS_INCORRECT_IP_ADDRESS_FORMAT, /**< IP address format is incorrect */ FIFTYONE_DEGREES_STATUS_TEMP_FILE_ERROR, /**< Error creating temp file */ - FIFTYONE_DEGREES_STATUS_INSUFFICIENT_CAPACITY, + FIFTYONE_DEGREES_STATUS_INSUFFICIENT_CAPACITY, /**< Insufficient capacity of + the array to hold all the items*/ + FIFTYONE_DEGREES_STATUS_INVALID_INPUT, /**< Invalid input data (f.e. base64 / JSON + misformat or semantic inconsistency) */ } fiftyoneDegreesStatusCode; /** @@ -158,4 +161,4 @@ EXTERNAL const char* fiftyoneDegreesStatusGetMessage( * @} */ -#endif \ No newline at end of file +#endif diff --git a/tests/StatusTests.cpp b/tests/StatusTests.cpp index 6d1b44f0..85c4ea55 100644 --- a/tests/StatusTests.cpp +++ b/tests/StatusTests.cpp @@ -274,4 +274,18 @@ TEST(Status, Get_NegativeCode) { Snprintf(code, 3, "%d", invalidStatus); assertContains(message, code); free((void*)message); -} \ No newline at end of file +} + +/** + * Check that a message is still returned for a negative status code which does + * not (and cannot) exist and the message contains the code as a string. + */ +TEST(Status, Get_InvalidInput) { + const char *message = fiftyoneDegreesStatusGetMessage( + FIFTYONE_DEGREES_STATUS_INVALID_INPUT, + NULL); + assertValidMessage(message); + assertContains(message, "invalid"); + assertContains(message, "input value"); + free((void*)message); +}