The media wire envelope now lives in CultLib, so this side can use it rather than reimplement it. The receiver decodes each media-channel payload into a GameCultMediaWireRecord, and the ABI carries a kind alongside the bytes so a caller routes video and audio without parsing anything itself. That was the last piece stopping this repo from reading a real stream. A payload that arrives and fails to decode becomes Undecodable and increments a counter reachable from C. It is not dropped. A consumer that silently discards what it cannot parse leaves a producer no way to discover its stream is unreadable — which is exactly how the previous receiver and sender drifted apart while both were being maintained. Feedback records decode but yield no payload: they travel the other way and carry no media, so a caller asking for payloads is not handed one. Pinned to CultLib a3e6877 on claude/cultmesh-media-stream-contract, which is a branch rather than main. That pin moves when the branch does. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
84 lines
3.7 KiB
C
84 lines
3.7 KiB
C
/* Proves the C ABI is callable and behaves as its header claims.
|
|
*
|
|
* Loads the cdylib at runtime rather than linking it. That keeps the test
|
|
* compiler-agnostic — the production plugin is built with MSVC, this runs
|
|
* anywhere — and it exercises the library the way a host actually loads it.
|
|
*/
|
|
#include "ratatoskr.h"
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <windows.h>
|
|
|
|
static int failures = 0;
|
|
static void check(int ok, const char *what)
|
|
{
|
|
if (!ok) { printf("FAIL %s\n", what); failures++; }
|
|
else { printf("ok %s\n", what); }
|
|
}
|
|
|
|
typedef int (*open_fn)(const char *, const char *, unsigned int, RatatoskrHandle **);
|
|
typedef int (*poll_fn)(RatatoskrHandle *);
|
|
typedef int (*next_fn)(RatatoskrHandle *, uint8_t *, size_t, size_t *, int *);
|
|
typedef uint16_t (*port_fn)(RatatoskrHandle *);
|
|
typedef void (*delivered_fn)(RatatoskrHandle *, uint64_t *, uint64_t *);
|
|
typedef size_t (*err_fn)(char *, size_t);
|
|
typedef void (*close_fn)(RatatoskrHandle *);
|
|
typedef uint64_t (*undecodable_fn)(RatatoskrHandle *);
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
const char *dll = argc > 1 ? argv[1] : "ratatoskr_core.dll";
|
|
HMODULE lib = LoadLibraryA(dll);
|
|
if (!lib) { printf("FAIL could not load %s (error %lu)\n", dll, GetLastError()); return 1; }
|
|
|
|
open_fn r_open = (open_fn)(void *)GetProcAddress(lib, "ratatoskr_receiver_open");
|
|
poll_fn r_poll = (poll_fn)(void *)GetProcAddress(lib, "ratatoskr_receiver_poll");
|
|
next_fn r_next = (next_fn)(void *)GetProcAddress(lib, "ratatoskr_receiver_next_payload");
|
|
port_fn r_port = (port_fn)(void *)GetProcAddress(lib, "ratatoskr_receiver_local_port");
|
|
delivered_fn r_delivered = (delivered_fn)(void *)GetProcAddress(lib, "ratatoskr_receiver_delivered");
|
|
err_fn r_err = (err_fn)(void *)GetProcAddress(lib, "ratatoskr_last_error");
|
|
close_fn r_close = (close_fn)(void *)GetProcAddress(lib, "ratatoskr_receiver_close");
|
|
check(r_open && r_poll && r_next && r_port && r_delivered && r_err && r_close,
|
|
"every documented symbol is exported");
|
|
if (failures) { printf("ABI SMOKE FAILED\n"); return 1; }
|
|
|
|
RatatoskrHandle *handle = NULL;
|
|
check(r_open("127.0.0.1:0", "ratatoskr-abi-smoke", 0x0BE00001u, &handle) == RATATOSKR_OK,
|
|
"open returns OK");
|
|
check(handle != NULL, "open yields a handle");
|
|
check(r_port(handle) != 0, "ephemeral bind resolves to a real port");
|
|
check(r_poll(handle) == 0, "idle poll reports nothing waiting");
|
|
|
|
size_t out_len = 12345;
|
|
int kind = -99;
|
|
unsigned char buffer[64];
|
|
check(r_next(handle, buffer, sizeof buffer, &out_len, &kind) == RATATOSKR_NONE,
|
|
"empty queue reports NONE, not an error");
|
|
check(out_len == 0, "NONE writes a zero length");
|
|
|
|
uint64_t payloads = 7, bytes = 7;
|
|
r_delivered(handle, &payloads, &bytes);
|
|
check(payloads == 0 && bytes == 0, "delivered counts start at zero");
|
|
|
|
undecodable_fn r_undecodable =
|
|
(undecodable_fn)(void *)GetProcAddress(lib, "ratatoskr_receiver_undecodable");
|
|
check(r_undecodable != NULL, "undecodable counter is exported");
|
|
check(r_undecodable(handle) == 0, "nothing has failed to decode yet");
|
|
r_close(handle);
|
|
|
|
handle = NULL;
|
|
check(r_open("not-an-address", "x", 1, &handle) == RATATOSKR_ERR_ARGUMENT,
|
|
"a bad bind address is refused");
|
|
check(handle == NULL, "a refused open leaves no handle");
|
|
|
|
char message[256];
|
|
check(r_err(message, sizeof message) > 0, "a failure leaves a message");
|
|
check(strstr(message, "not-an-address") != NULL, "the message names the bad input");
|
|
|
|
r_close(NULL);
|
|
check(r_poll(NULL) == RATATOSKR_ERR_ARGUMENT, "null handle is refused");
|
|
check(r_port(NULL) == 0, "null handle reports no port");
|
|
|
|
printf("%s\n", failures ? "ABI SMOKE FAILED" : "ABI SMOKE PASSED");
|
|
return failures ? 1 : 0;
|
|
}
|