Files
SPHLite/tests/app/test_worker_contract.c
T
2026-07-05 17:00:13 +08:00

81 lines
2.8 KiB
C

#include "sph_worker_contract.h"
#include <stdio.h>
#include <string.h>
static int fail(const char *message)
{
fprintf(stderr, "%s\n", message);
return 1;
}
static int check_string(const char *actual, const char *expected,
const char *label)
{
if (strcmp(actual, expected) != 0) {
fprintf(stderr, "%s: expected %s, got %s\n", label, expected, actual);
return 1;
}
return 0;
}
int main(void)
{
sphlite_worker_boundary_state_t state;
if ((SPHLITE_WORKER_VALID_POSITION |
SPHLITE_WORKER_VALID_VELOCITY |
SPHLITE_WORKER_VALID_NORMAL) != 7u) {
return fail("valid flag bit layout mismatch");
}
if (check_string(sphlite_worker_v2_field_name(
SPHLITE_WORKER_V2_SOURCE_ID), "source_id",
"source id field") != 0) return 1;
if (check_string(sphlite_worker_v2_field_name(
SPHLITE_WORKER_V2_CONTACT_RADIUS), "contact_radius",
"contact radius field") != 0) return 1;
if (check_string(sphlite_worker_contact_state_name(
SPHLITE_WORKER_CONTACT_TIED), "tied",
"tied contact state") != 0) return 1;
if (check_string(sphlite_worker_contact_state_name(
SPHLITE_WORKER_CONTACT_RELEASED), "released",
"released contact state") != 0) return 1;
if (check_string(sphlite_worker_reject_reason_name(
SPHLITE_WORKER_REJECT_NONFINITE_FORCE), "nonfinite_force",
"force reject reason") != 0) return 1;
if (check_string(sphlite_worker_region_diagnostic_name(
SPHLITE_WORKER_REGION_DISTRIBUTED_MOMENT),
"distributed_moment", "region diagnostic") != 0) return 1;
if (!sphlite_worker_v2_field_is_boundary(
SPHLITE_WORKER_V2_BOUNDARY_PRESSURE) ||
sphlite_worker_v2_field_is_boundary(SPHLITE_WORKER_V2_PAIR_ID)) {
return fail("boundary field predicate mismatch");
}
state.boundary_state_id = 17;
state.ghost_state_id = 23;
state.state_mode = 2;
state.valid_flags = SPHLITE_WORKER_VALID_POSITION |
SPHLITE_WORKER_VALID_PRESSURE;
state.position[0] = 1.0;
state.velocity[1] = 2.0;
state.normal[2] = 3.0;
state.pressure = 4.0;
state.density = 5.0;
state.sound_speed = 6.0;
state.interface_pressure = 7.0;
state.interface_velocity[0] = 8.0;
sphlite_worker_boundary_state_clear(&state);
if (state.boundary_state_id != 0 || state.ghost_state_id != 0 ||
state.state_mode != 0 || state.valid_flags != 0u ||
state.position[0] != 0.0 || state.velocity[1] != 0.0 ||
state.normal[2] != 0.0 || state.pressure != 0.0 ||
state.density != 0.0 || state.sound_speed != 0.0 ||
state.interface_pressure != 0.0 ||
state.interface_velocity[0] != 0.0) {
return fail("boundary state clear mismatch");
}
return 0;
}