1
0
Fork 0
forked from hanez/xtc
xtc/tests/unit/test_core.c

43 lines
1.3 KiB
C

#include "xtc/xtc.h"
#include "xtc/xtc_engine.h"
#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)
{
xt_app *app = NULL;
xt_graph *graph = NULL;
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};
CHECK(xt_app_create(&app) == XT_OK);
CHECK(app != NULL);
xt_app_destroy(app);
CHECK(xt_graph_create(4U, &graph) == XT_OK);
CHECK(xt_graph_add_gain(graph, 0.5f, &node_a) == XT_OK);
CHECK(xt_graph_add_gain(graph, 2.0f, &node_b) == XT_OK);
CHECK(xt_graph_connect(graph, node_a, node_b) == XT_OK);
CHECK(xt_graph_validate(graph) == XT_OK);
CHECK(xt_graph_process_offline(graph, input, output, 4U, 1.0f) == XT_OK);
CHECK(fabsf(output[0] - 1.0f) < 0.0001f);
CHECK(fabsf(output[1] + 1.0f) < 0.0001f);
CHECK(fabsf(output[2] - 0.5f) < 0.0001f);
CHECK(xt_graph_connect(graph, node_b, node_a) == XT_OK);
CHECK(xt_graph_validate(graph) == XT_ERR_GRAPH_CYCLE);
xt_graph_destroy(graph);
(void)puts("All xtc core tests passed.");
return 0;
}