amduat/tests/tgk/test_tgk_error_taxonomy.c

104 lines
2.7 KiB
C
Raw Normal View History

2026-02-22 00:25:56 +01:00
#include "amduat/tgk/store.h"
#include <stdio.h>
#include <string.h>
static amduat_tgk_graph_error_t stub_resolve_edge(void *ctx,
amduat_reference_t ref,
amduat_tgk_edge_body_t *out_body) {
amduat_tgk_graph_error_t *err = (amduat_tgk_graph_error_t *)ctx;
(void)ref;
(void)out_body;
return *err;
}
static int test_not_edge_mapping(void) {
amduat_tgk_store_ops_t ops;
amduat_tgk_store_t store;
amduat_tgk_store_config_t cfg;
amduat_tgk_graph_error_t err = GS_ERR_NOT_EDGE;
memset(&cfg, 0, sizeof(cfg));
memset(&ops, 0, sizeof(ops));
ops.resolve_edge = stub_resolve_edge;
amduat_tgk_store_init(&store, cfg, ops, &err);
if (amduat_tgk_store_resolve_edge(&store, amduat_reference(0, amduat_octets(NULL, 0u)), NULL) !=
GS_ERR_NOT_EDGE) {
return 1;
}
return 0;
}
static int test_artifact_error_mapping(void) {
amduat_tgk_store_ops_t ops;
amduat_tgk_store_t store;
amduat_tgk_store_config_t cfg;
amduat_tgk_graph_error_t err = GS_ERR_ARTIFACT_ERROR;
memset(&cfg, 0, sizeof(cfg));
memset(&ops, 0, sizeof(ops));
ops.resolve_edge = stub_resolve_edge;
amduat_tgk_store_init(&store, cfg, ops, &err);
if (amduat_tgk_store_resolve_edge(&store, amduat_reference(0, amduat_octets(NULL, 0u)), NULL) !=
GS_ERR_ARTIFACT_ERROR) {
return 1;
}
return 0;
}
static int test_unsupported_mapping(void) {
amduat_tgk_store_ops_t ops;
amduat_tgk_store_t store;
amduat_tgk_store_config_t cfg;
memset(&cfg, 0, sizeof(cfg));
memset(&ops, 0, sizeof(ops));
amduat_tgk_store_init(&store, cfg, ops, NULL);
if (amduat_tgk_store_resolve_edge(&store, amduat_reference(0, amduat_octets(NULL, 0u)), NULL) !=
GS_ERR_UNSUPPORTED) {
return 1;
}
return 0;
}
static int test_integrity_mapping(void) {
amduat_tgk_store_ops_t ops;
amduat_tgk_store_t store;
amduat_tgk_store_config_t cfg;
amduat_tgk_graph_error_t err = GS_ERR_INTEGRITY;
memset(&cfg, 0, sizeof(cfg));
memset(&ops, 0, sizeof(ops));
ops.resolve_edge = stub_resolve_edge;
amduat_tgk_store_init(&store, cfg, ops, &err);
if (amduat_tgk_store_resolve_edge(&store, amduat_reference(0, amduat_octets(NULL, 0u)), NULL) !=
GS_ERR_INTEGRITY) {
return 1;
}
return 0;
}
int main(void) {
if (test_not_edge_mapping() != 0) {
fprintf(stderr, "not edge mapping failed\n");
return 1;
}
if (test_artifact_error_mapping() != 0) {
fprintf(stderr, "artifact error mapping failed\n");
return 1;
}
if (test_unsupported_mapping() != 0) {
fprintf(stderr, "unsupported mapping failed\n");
return 1;
}
if (test_integrity_mapping() != 0) {
fprintf(stderr, "integrity mapping failed\n");
return 1;
}
return 0;
}