/* Independent source-binding failure injection; no hardware or product codec oracle. */ #include #include #include #include "iec104_source.h" #define CHECK(x) do { if (!(x)) { fprintf(stderr, "line %d: %s\n", __LINE__, #x); exit(1); } } while (0) static uint16_t special_id; static float special_value; static unsigned apply_count; static bool read_parameter(void *ctx, uint16_t id, float *out) { (void)ctx; if (id == special_id) { *out = special_value; return true; } *out = id == 17U ? 250.0f : id == 20U ? 100.0f : 1.0f; return true; } static bool apply_parameter(void *ctx, const iec104_source_change_t *changes, size_t count, bool validate) { (void)ctx; (void)changes; (void)count; if (!validate) { ++apply_count; } return true; } static bool measurement(void *ctx, uint16_t addr, float *v, uint8_t *q) { (void)ctx; (void)addr; *v = 12.5f; *q = 0x51U; return true; } static void invalid_read(uint32_t ioa, uint16_t id, float value) { iec104_source_value_t out; special_id = id; special_value = value; if (iec104_source_remote_read(0U, ioa, &out)) { fprintf(stderr, "unexpected readable ioa=%lx semantic=%u input=%g tag=%u\n", (unsigned long)ioa, id, value, out.tag); exit(1); } } int main(void) { iec104_source_bindings_t bind = {0}; iec104_source_object_t object; iec104_source_stats_t stats; bind.parameter_read = read_parameter; bind.parameter_apply = apply_parameter; bind.measurement = measurement; iec104_source_init(); iec104_source_bind(&bind); /* Mapped profile entries: bool8841 -> semantic1; float8842 ->2. * There is no mapped UShort callback entry: do not fake one to claim coverage. */ invalid_read(0x8841U, 1U, 2.0f); invalid_read(0x8841U, 1U, 1.5f); invalid_read(0x8842U, 2U, NAN); invalid_read(0x8842U, 2U, INFINITY); special_id = 0U; CHECK(iec104_source_find(0x4001U, &object)); CHECK(object.measurement.value == 12.5f); CHECK(object.measurement.quality == 0x51U); iec104_source_stats(&stats); CHECK(stats.physical_do_actions == 0U && apply_count == 0U); puts("source binding typed fail-closed/quality: PASS"); return 0; }