Skip to content

Commit

Permalink
FEAT: introduce invalid input value status code
Browse files Browse the repository at this point in the history
  • Loading branch information
justadreamer committed Oct 14, 2024
1 parent a815adb commit 0833f95
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 2 additions & 0 deletions fiftyone.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.*/
/**
* @}
*/
Expand Down
5 changes: 3 additions & 2 deletions status.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down Expand Up @@ -157,4 +158,4 @@ const char* fiftyoneDegreesStatusGetMessage(
Snprintf(message, messageSize, defaultMessage, (int)status);
}
return message;
}
}
7 changes: 5 additions & 2 deletions status.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -158,4 +161,4 @@ EXTERNAL const char* fiftyoneDegreesStatusGetMessage(
* @}
*/

#endif
#endif
16 changes: 15 additions & 1 deletion tests/StatusTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,18 @@ TEST(Status, Get_NegativeCode) {
Snprintf(code, 3, "%d", invalidStatus);
assertContains(message, code);
free((void*)message);
}
}

/**
* 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);
}

0 comments on commit 0833f95

Please sign in to comment.