infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
860_error_handling.c File Reference

Unit test for the error reporting system. More...

#include "common/double_tap.h"
#include <infix/infix.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for 860_error_handling.c:

Macros

#define DBLTAP_IMPLEMENTATION
 

Functions

 subtest ("Signature Parser Error Reporting")
 
 subtest ("API Hardening Error Reporting")
 

Variables

 TEST
 

Detailed Description

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:

  1. 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.
  2. 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.

Macro Definition Documentation

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

Function Documentation

◆ subtest() [1/2]

subtest ( "API Hardening Error Reporting"  )

◆ subtest() [2/2]

subtest ( "Signature Parser Error Reporting"  )

Variable Documentation

◆ TEST

TEST
Initial value:
{
plan(2)
#define plan(count)
Definition double_tap.h:163