feat(zig): native Arboricx bundle parser and C ABI
This commit is contained in:
57
ext/zig/tests/c_abi_test.c
Normal file
57
ext/zig/tests/c_abi_test.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#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);
|
||||
|
||||
arboricx_free(ctx);
|
||||
printf("\nAll C ABI tests passed.\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user