xtc/tests/unit/test_core.c

43 lines
1.3 KiB
C
Raw Permalink Normal View History

#include "xtc/xtc.h"
#include "xtc/xtc_engine.h"
2026-10-26 22:51:25 +01:00
#include <math.h>
#include <stdio.h>
#define CHECK(condition) do { \
if (!(condition)) { \
(void)fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #condition); \
return 1; \
} \
} while (0)
int main(void)
{
2026-10-26 23:20:00 +01:00
xtc_app *app = NULL;
xtc_graph *graph = NULL;
2026-10-26 22:51:25 +01:00
size_t node_a = 0U;
size_t node_b = 0U;
float input[4] = {1.0f, -1.0f, 0.5f, 0.0f};
float output[4] = {0.0f, 0.0f, 0.0f, 0.0f};
2026-10-26 23:20:00 +01:00
CHECK(xtc_app_create(&app) == XTC_OK);
2026-10-26 22:51:25 +01:00
CHECK(app != NULL);
2026-10-26 23:20:00 +01:00
xtc_app_destroy(app);
2026-10-26 22:51:25 +01:00
2026-10-26 23:20:00 +01:00
CHECK(xtc_graph_create(4U, &graph) == XTC_OK);
CHECK(xtc_graph_add_gain(graph, 0.5f, &node_a) == XTC_OK);
CHECK(xtc_graph_add_gain(graph, 2.0f, &node_b) == XTC_OK);
CHECK(xtc_graph_connect(graph, node_a, node_b) == XTC_OK);
CHECK(xtc_graph_validate(graph) == XTC_OK);
CHECK(xtc_graph_process_offline(graph, input, output, 4U, 1.0f) == XTC_OK);
2026-10-26 22:51:25 +01:00
CHECK(fabsf(output[0] - 1.0f) < 0.0001f);
CHECK(fabsf(output[1] + 1.0f) < 0.0001f);
CHECK(fabsf(output[2] - 0.5f) < 0.0001f);
2026-10-26 23:20:00 +01:00
CHECK(xtc_graph_connect(graph, node_b, node_a) == XTC_ERR_GRAPH_CYCLE);
CHECK(xtc_graph_validate(graph) == XTC_OK);
2026-10-26 22:51:25 +01:00
2026-10-26 23:20:00 +01:00
xtc_graph_destroy(graph);
(void)puts("All xtc core tests passed.");
2026-10-26 22:51:25 +01:00
return 0;
}