Unit test for the named type registry system.
This test file validates the complete functionality of the type registry, ensuring that named types can be defined, resolved, and used correctly in both forward and reverse FFI calls.
The test covers:
- Lifecycle and Basic Definitions: Verifying that a registry can be created and destroyed, that simple types can be registered, and that attempting to redefine a type correctly produces an error.
- Usage in FFI Calls: Demonstrates using a registered named type (e.g.,
@Point) in a signature string to create both forward and reverse trampolines, and verifies that the resulting FFI calls work correctly.
- Advanced Definitions: Tests the registry's ability to handle complex scenarios like recursive type definitions (
struct Node { struct Node* next; }) and mutually-recursive types using forward declarations. It uses introspection to verify that the resulting type graphs have the correct circular structure.
- Error Handling: Ensures that the system fails gracefully with the correct error codes when using unregistered types, unresolved forward declarations, or when using the
@Name syntax with a NULL registry.