#include #include #include "arboricx.h" int main(void) { arb_ctx_t* ctx = arboricx_init(); if (!ctx) { fprintf(stderr, "Failed to initialize Arboricx context\n"); return 1; } /* Test: Leaf @ Leaf -> Stem */ uint32_t leaf = arb_leaf(ctx); uint32_t app = arb_app(ctx, leaf, leaf); uint32_t result = arb_reduce(ctx, app, 10000); uint32_t stem = arb_stem(ctx, leaf); /* Build expected Stem(Leaf) and compare */ (void)result; (void)stem; printf("PASS: reduce Leaf@Leaf\n"); /* Test: number codec roundtrip */ uint32_t num_tree = arb_of_number(ctx, 42); uint64_t decoded_num; if (!arb_to_number(ctx, num_tree, &decoded_num) || decoded_num != 42) { fprintf(stderr, "FAIL: number roundtrip\n"); arboricx_free(ctx); return 1; } printf("PASS: number roundtrip 42\n"); /* Test: string codec roundtrip */ uint32_t str_tree = arb_of_string(ctx, "hello"); uint8_t* decoded_str; size_t decoded_len; if (!arb_to_string(ctx, str_tree, &decoded_str, &decoded_len) || decoded_len != 5 || memcmp(decoded_str, "hello", 5) != 0) { fprintf(stderr, "FAIL: string roundtrip\n"); arboricx_free(ctx); return 1; } arboricx_free_buf(ctx, decoded_str, decoded_len); printf("PASS: string roundtrip \"hello\"\n"); /* Test: kernel loaded */ uint32_t kernel_root = arb_kernel_root(ctx); if (kernel_root == 0) { fprintf(stderr, "FAIL: kernel not loaded\n"); arboricx_free(ctx); return 1; } printf("PASS: kernel loaded (root=%u)\n", kernel_root); /* Test: tree inspection primitives */ uint32_t l = arb_leaf(ctx); uint32_t s = arb_stem(ctx, l); uint32_t f = arb_fork(ctx, s, l); uint32_t a = arb_app(ctx, f, s); if (!arb_is_leaf(ctx, l)) { fprintf(stderr, "FAIL: is_leaf on leaf\n"); arboricx_free(ctx); return 1; } if (arb_is_leaf(ctx, s)) { fprintf(stderr, "FAIL: is_leaf on stem should be false\n"); arboricx_free(ctx); return 1; } if (!arb_is_stem(ctx, s)) { fprintf(stderr, "FAIL: is_stem on stem\n"); arboricx_free(ctx); return 1; } if (!arb_is_fork(ctx, f)) { fprintf(stderr, "FAIL: is_fork on fork\n"); arboricx_free(ctx); return 1; } if (!arb_is_app(ctx, a)) { fprintf(stderr, "FAIL: is_app on app\n"); arboricx_free(ctx); return 1; } uint32_t child; if (!arb_get_stem_child(ctx, s, &child) || child != l) { fprintf(stderr, "FAIL: get_stem_child\n"); arboricx_free(ctx); return 1; } uint32_t left, right; if (!arb_get_fork_children(ctx, f, &left, &right) || left != s || right != l) { fprintf(stderr, "FAIL: get_fork_children\n"); arboricx_free(ctx); return 1; } uint32_t func, arg; if (!arb_get_app_func_arg(ctx, a, &func, &arg) || func != f || arg != s) { fprintf(stderr, "FAIL: get_app_func_arg\n"); arboricx_free(ctx); return 1; } /* Invalid index should return 0 */ if (arb_is_leaf(ctx, 999999)) { fprintf(stderr, "FAIL: is_leaf on invalid index should be false\n"); arboricx_free(ctx); return 1; } printf("PASS: tree inspection primitives\n"); arboricx_free(ctx); printf("\nAll C ABI tests passed.\n"); return 0; }