Unit test for the error reporting system.
This test file validates that the infix library correctly detects, categorizes, and reports errors to the user. A robust error reporting system is critical for a good developer experience.
The test covers two main areas:
- Signature Parser Error Reporting:
- It feeds the parser a series of deliberately malformed signature strings.
- For each invalid signature, it calls
infix_get_last_error() to retrieve the detailed error information.
- It then asserts that the returned
infix_error_details_t struct contains the correct category, code, position (the byte offset of the error in the string), and a human-readable message.
- This ensures that users receive precise feedback when they make a syntax error in a signature.
- API Hardening Error Reporting:
- It tests how the API handles inputs that are syntactically valid but would lead to dangerous behavior, specifically integer overflows.
- It constructs a signature for an enormous array (e.g.,
[SIZE_MAX:short]) that would cause an overflow when calculating its total size.
- It verifies that the library detects this condition, returns an
INFIX_ERROR_INVALID_ARGUMENT status, and sets the last error code to INFIX_CODE_INTEGER_OVERFLOW. This confirms that security and stability checks are in place and are reported correctly.