Entropyk/bindings/c/tests/test_errors.c
Sepehr fa480ed303 feat: implement mass balance validation for Story 7.1
- Added port_mass_flows to Component trait and implements for core components.
- Added System::check_mass_balance and integrated it into the solver.
- Restored connect methods for ExpansionValve, Compressor, and Pipe to fix integration tests.
- Updated Python and C bindings for validation errors.
- Updated sprint status and story documentation.
2026-02-21 23:21:34 +01:00

69 lines
2.7 KiB
C

/**
* Test: Error code verification
*
* Verifies that error codes are correctly returned and mapped.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "entropyk.h"
int main() {
printf("Test: Error codes\n");
/* Test 1: Error strings */
printf(" Test 1: Error strings are non-null... ");
assert(entropyk_error_string(ENTROPYK_OK) != NULL);
assert(entropyk_error_string(ENTROPYK_NON_CONVERGENCE) != NULL);
assert(entropyk_error_string(ENTROPYK_TIMEOUT) != NULL);
assert(entropyk_error_string(ENTROPYK_CONTROL_SATURATION) != NULL);
assert(entropyk_error_string(ENTROPYK_FLUID_ERROR) != NULL);
assert(entropyk_error_string(ENTROPYK_INVALID_STATE) != NULL);
assert(entropyk_error_string(ENTROPYK_VALIDATION_ERROR) != NULL);
assert(entropyk_error_string(ENTROPYK_NULL_POINTER) != NULL);
assert(entropyk_error_string(ENTROPYK_INVALID_ARGUMENT) != NULL);
assert(entropyk_error_string(ENTROPYK_NOT_FINALIZED) != NULL);
assert(entropyk_error_string(ENTROPYK_TOPOLOGY_ERROR) != NULL);
assert(entropyk_error_string(ENTROPYK_COMPONENT_ERROR) != NULL);
assert(entropyk_error_string(ENTROPYK_UNKNOWN) != NULL);
printf("PASS\n");
/* Test 2: OK message */
printf(" Test 2: OK message contains 'Success'... ");
const char* ok_msg = entropyk_error_string(ENTROPYK_OK);
assert(strstr(ok_msg, "Success") != NULL);
printf("PASS\n");
/* Test 3: Null pointer error */
printf(" Test 3: Null pointer returns ENTROPYK_NULL_POINTER... ");
EntropykErrorCode err = entropyk_system_add_edge(NULL, 0, 1);
assert(err == ENTROPYK_NULL_POINTER);
printf("PASS\n");
/* Test 4: Component with invalid parameters */
printf(" Test 4: Invalid parameters return null... ");
EntropykComponent* comp = entropyk_condenser_create(-1.0); /* Invalid UA */
assert(comp == NULL);
comp = entropyk_evaporator_create(0.0); /* Invalid UA */
assert(comp == NULL);
comp = entropyk_compressor_create(NULL, 10); /* Null coefficients */
assert(comp == NULL);
double coeffs[5] = {1, 2, 3, 4, 5};
comp = entropyk_compressor_create(coeffs, 5); /* Wrong count */
assert(comp == NULL);
printf("PASS\n");
/* Test 5: Not finalized error */
printf(" Test 5: Finalize returns NOT_FINALIZED for empty system... ");
EntropykSystem* sys = entropyk_system_create();
/* Empty system may not finalize properly - this tests error handling */
entropyk_system_finalize(sys); /* May return error for empty system */
entropyk_system_free(sys);
printf("PASS\n");
printf("All error code tests PASSED\n");
return 0;
}