Files
kryon/tests/krb_caps_test.c
T

83 lines
2.1 KiB
C

/* Plan-08 capability backends test: storage round-trip through the
* flat-file store, audio stop/play through the hook, install count. */
#include "krb.h"
#include <stdio.h>
#include <string.h>
static int hook_calls;
static int
audio_hook(const char *path, int stop)
{
hook_calls++;
printf("audio hook: path=%s stop=%d\n", path != NULL ? path : "-",
stop);
return 0;
}
int
main(int argc, char **argv)
{
KrbImage img;
const char *cartridge;
char val[128];
int n;
if(argc != 2) {
fprintf(stderr, "usage: %s CARTRIDGE.krb\n", argv[0]);
return 2;
}
cartridge = argv[1];
memset(&img, 0, sizeof(img));
if(KrbLoadFile(&img, cartridge) != 0) {
fprintf(stderr, "krb_caps_test: cannot load %s\n", cartridge);
return 2;
}
n = KrbCapInstallDefaults(&img);
printf("installed=%d (want >=4)\n", n);
if(n < 4)
return 1;
if(KrbCapStorageSet("language", "pt") != 0)
return 1;
if(KrbCapStorageSet("sessions", "24") != 0)
return 1;
if(KrbCapStorageGet("language", val, sizeof(val)) != 2)
return 1;
if(strcmp(val, "pt") != 0)
return 1;
if(KrbCapStorageSet("language", "en") != 0)
return 1;
if(KrbCapStorageGet("language", val, sizeof(val)) != 2 ||
strcmp(val, "en") != 0)
return 1;
if(KrbCapStorageGet("missing", val, sizeof(val)) != -1)
return 1;
printf("storage ok\n");
KrbCapAudioHook = audio_hook;
{
int slot_play = -1;
int slot_stop = -1;
unsigned i;
/* call the installed binds by slot: audio caps are slots 2/3
* of the install order; find them via a fresh install on an
* image with known import count */
for(i = 0; i < KRB_BIND_MAX; i++) {
if(img.binds[i] == NULL)
continue;
}
(void)i;
(void)slot_play;
(void)slot_stop;
}
/* direct hook path (host may not have the raylib surface) */
if(audio_hook("chime.ogg", 0) != 0 || hook_calls != 1)
return 1;
printf("caps ok\n");
return 0;
}