Files
kryon/tests/krb_host_click_test.c
T
waozi e5fa60bb2f Add krb cartridge tests
- krb_walk_test: load 02_buttons.krb, check node/import counts, bind, draw.
- krb_mount_test: hand-build an image, exercise KrbMount/KrbBindMem and the
  typed read/write, plus OP_SET_I32 and OP_CALL_HOST through KrbExec.
- krb_host_click_test + krb_cartridge_test.sh: compile 02_buttons.kry to a
  .krb, link the generated C host, and verify a button press increments the
  mounted click_count and updates last_action; also checks the magic,
  size budget, and string-table contents.
2026-08-12 19:03:23 -05:00

35 lines
1000 B
C

#include "02_buttons.krb.h"
#include "krb.h"
#include <stdio.h>
#include <string.h>
int
main(void)
{
int clicks = -1;
char action[128];
KryBackendSelect(&KryBackendNull);
if(ButtonsExample_krb_read_i32("click_count", &clicks) != 0 || clicks != 0) {
fprintf(stderr, "initial click_count got %d\n", clicks);
return 1;
}
if(ButtonsExample_krb_press("primary_button") != 1)
return 1;
if(ButtonsExample_krb_press("danger_button") != 1)
return 1;
if(ButtonsExample_krb_read_i32("click_count", &clicks) != 0 || clicks != 2) {
fprintf(stderr, "after press click_count got %d\n", clicks);
return 1;
}
if(ButtonsExample_krb_read_cstr("last_action", action, sizeof(action)) != 0 ||
strcmp(action, "Danger Button clicked.") != 0) {
fprintf(stderr, "last_action got '%s'\n", action);
return 1;
}
ButtonsExample_krb_draw(0, 0, 800, 600);
printf("ok clicks=%d\n", clicks);
return 0;
}