Files
neoLegacy-mac/tests/support/iggy_api_functions_test_support.c

309 lines
13 KiB
C

/*
* Host harness for the reconstructed iggy_api_functions translation unit.
*
* iggy_api_functions is Iggy's PUBLIC C API surface: the IggyPlayer* / IggyLibrary*
* / IggyGeneric* entry points a host application calls. It exports EXACTLY 65
* entry points on all four platforms (durango / orbis / ps3 / vita).
*
* BODY SHAPES (recovered from raw/durango, classified):
* - THIN _core WRAPPERS (16 imported *_core targets). Two idioms:
* (a) reentrancy-guarded: acquire player->api_lock (0x3534) via
* rrAtomicCmpXchg32, call IggyPlayerX_core, release, on a failed
* acquire raise iggy_send_error and skip the _core (Draw / DrawTile /
* DrawTilesEnd / Tick / CallFunctionRS / CallMethodRS / DispatchEventRS /
* GotoFrameRS / InitializeAndTickRS / SetFocusRS + FlushAll->flush_core).
* (b) bare pass-through: just `return IggyPlayerX_core(args)` with no guard
* (CreateFromFileAndPlay / Cut / PasteUTF16 / PasteUTF8 / SetStageRotation).
* - EXCEPTION setjmp GUARDS (3): GarbageCollect / SetAntialiasing /
* SetBitmapFontCaching bump player->exception_depth, _setjmp into
* player->exception_frames, run the work, and on longjmp clear
* player->initialized.
* - CAS-guarded REAL bodies (5): ConfigureGCBehavior, DrawTilesStart(->
* iggy_draw_tiles_begin), SetAudioVolume(-> iggy_audio_update),
* LibraryFlushAll(-> IggyPlayerFlushAll), GenericSetTextureFromResource.
* - DIRECT real bodies (41): getters/setters over player fields, the library
* manager (iggy_add_library / iggy_get_library / iggy_free_library_id /
* iggy_libraries / iggy_core_destroy), IggyPlayerCreateFromMemory /
* IggyLibraryCreateFromMemory (iggy_create_from_memory), the API primitives
* (iggy_API_begin/end, iggy_begin/end_execution, iggy_callback_begin/end),
* and the global setters (IggySetTextCursorPixelWidth ->
* iggy_cursor_width, IggyPlayerDoubleClickTime -> iggy_double_click_time,
* IggySetFontCachingCalculationBuffer -> iggy_max_visible_chars /
* iggy_char_buffer, the two owned globals).
*
* OWNED DATA GLOBALS (durango, retail objdump): exactly TWO -- iggy_max_visible_chars
* (' D ' .data, 4 bytes, initialized to 2000 == d0 07 00 00) and iggy_char_buffer
* (' C ' common/bss, 8 bytes, the scratch pointer, zero). The other 39 external
* non-function symbols are MSVC artifacts: 36 ??_C@ rodata string COMDATs (error
* messages + the __FILE__ path) and 3 __real@ float-constant COMDATs -- not owned
* exported data. The two genuine globals are DEFINED BY THE MODULE, never here.
*
* IMPORTS: this harness defines every genuine nm ' U ' import so the durango
* dylib resolves. SATISFIED-by-shipped-modules ones are implemented for real
* (rrAtomicCmpXchg32 as a genuine CAS; rrUTF8toUTF16 / rrUTF16toUTF8 as ASCII
* transcoders). The 16 *_core targets (IggyPlayerGotoFrameRS_core is DONE via
* swf_playhead; the rest belong to the unbuilt swf_play cluster) and the iggy_main /
* draw / audio callbacks are modeled as recording / controllable stubs. The five
* data-global imports (iggy_libraries, iggy_tm_normal, iggy_double_click_time,
* iggy_cursor_width, iggy_gdraw) are defined as real globals the tests drive.
*
* DEFERRED (flagged structural, NOT runtime-pinned): the deep pipelines behind the
* _core calls (the full Draw / Tick / DispatchEvent / GarbageCollect passes are
* imports), the resource-install loop of IggyGenericInstallResourceFile (iggy_gdraw
* vtable dispatch), the explorer attach dance of IggyUseExplorer, and the longjmp
* re-entry of the exception-setjmp guards. The runtime test pins the tractable
* slices: the CAS reentrancy guard, the bare _core pass-through, the exec / callback
* primitives, the library manager, IggyPlayerCreateFromMemory, and the owned /
* imported global setters.
*/
#include <stdint.h>
#include <stddef.h>
/* ==================================================================== *
* Data-global imports the module READS/WRITES (genuine nm ' U ' data
* symbols owned by sibling units). Real globals; the tests drive them.
* ==================================================================== */
#define IGGY_API_MAX_LIBRARIES 32
void *iggy_libraries[IGGY_API_MAX_LIBRARIES]; /* &iggy_libraries + lib*8. */
void *iggy_tm_normal; /* tick-manager; NULL => profiling calls skipped. */
float iggy_double_click_time; /* set by IggyPlayerDoubleClickTime. */
float iggy_cursor_width; /* set by IggySetTextCursorPixelWidth. */
uint8_t iggy_gdraw[0x400]; /* gdraw vtable base (unused on tested paths). */
/* ---- Controllable returns / overrides. ---- */
static void *create_result;
static int add_library_result;
static void *get_library_result;
static int cut_core_result;
static int32_t utf8_forced_result; /* < -1 sentinel means "use real convert". */
/* ---- Recording counters. ---- */
static size_t cas_count;
static size_t send_error_count;
static size_t draw_core_count;
static size_t tick_core_count;
static size_t cut_core_count;
static size_t gc_core_count;
static size_t create_from_memory_count;
static size_t add_library_count;
static size_t get_library_count;
static size_t free_library_id_count;
static size_t core_destroy_count;
static size_t as3vm_init_count;
/* ---- Captures. ---- */
static long create_last_is_library;
static void *create_last_data;
static long free_library_id_last;
static void *core_destroy_last;
void iggy_api_functions_test_reset(void) {
for (size_t i = 0; i < IGGY_API_MAX_LIBRARIES; ++i) {
iggy_libraries[i] = 0;
}
iggy_tm_normal = 0;
iggy_double_click_time = 0.0f;
iggy_cursor_width = 0.0f;
create_result = 0;
add_library_result = 0;
get_library_result = 0;
cut_core_result = 0;
utf8_forced_result = -2; /* real conversion by default. */
cas_count = send_error_count = 0;
draw_core_count = tick_core_count = cut_core_count = gc_core_count = 0;
create_from_memory_count = add_library_count = get_library_count = 0;
free_library_id_count = core_destroy_count = as3vm_init_count = 0;
create_last_is_library = 0;
create_last_data = 0;
free_library_id_last = 0;
core_destroy_last = 0;
}
/* ---- Controls. ---- */
void iggy_api_functions_test_set_create_result(void *p) { create_result = p; }
void iggy_api_functions_test_set_add_library_result(int v) { add_library_result = v; }
void iggy_api_functions_test_set_get_library_result(void *p) { get_library_result = p; }
void iggy_api_functions_test_set_cut_core_result(int v) { cut_core_result = v; }
void iggy_api_functions_test_set_utf8_result(int32_t v) { utf8_forced_result = v; }
/* ---- Accessors. ---- */
size_t iggy_api_functions_test_cas_count(void) { return cas_count; }
size_t iggy_api_functions_test_send_error_count(void) { return send_error_count; }
size_t iggy_api_functions_test_draw_core_count(void) { return draw_core_count; }
size_t iggy_api_functions_test_tick_core_count(void) { return tick_core_count; }
size_t iggy_api_functions_test_cut_core_count(void) { return cut_core_count; }
size_t iggy_api_functions_test_gc_core_count(void) { return gc_core_count; }
size_t iggy_api_functions_test_create_count(void) { return create_from_memory_count; }
size_t iggy_api_functions_test_add_library_count(void) { return add_library_count; }
size_t iggy_api_functions_test_get_library_count(void) { return get_library_count; }
size_t iggy_api_functions_test_free_library_id_count(void) { return free_library_id_count; }
size_t iggy_api_functions_test_core_destroy_count(void) { return core_destroy_count; }
size_t iggy_api_functions_test_as3vm_init_count(void) { return as3vm_init_count; }
long iggy_api_functions_test_create_last_is_library(void) { return create_last_is_library; }
void *iggy_api_functions_test_create_last_data(void) { return create_last_data; }
long iggy_api_functions_test_free_library_id_last(void) { return free_library_id_last; }
void *iggy_api_functions_test_core_destroy_last(void) { return core_destroy_last; }
/* ==================================================================== *
* SATISFIED imports (shipped modules) -- implemented for real.
* ==================================================================== */
/* Genuine compare-and-swap: writes exchange when *destination == comparand,
* always returns the prior value (the module keys its lock logic on that). */
int32_t rrAtomicCmpXchg32(int32_t *destination, int32_t exchange,
int32_t comparand) {
int32_t old = *destination;
++cas_count;
if (old == comparand) {
*destination = exchange;
}
return old;
}
/* ASCII-only UTF-8 -> UTF-16 transcode; returns the unit count, or the forced
* negative sentinel (drives the invalid-URL error path of LibraryCreateFromMemory). */
int32_t rrUTF8toUTF16(uint16_t *destination, int32_t destination_units,
const uint8_t *source, int32_t source_bytes,
int32_t replacement, int32_t truncate) {
(void)replacement;
(void)truncate;
if (utf8_forced_result >= -1) {
return utf8_forced_result;
}
int32_t n = 0;
if (source && destination) {
while ((source_bytes < 0 || n < source_bytes) && source[n] != 0 &&
n + 1 < destination_units) {
destination[n] = source[n];
++n;
}
destination[n] = 0;
}
return n;
}
int32_t rrUTF16toUTF8(uint8_t *destination, int32_t destination_bytes,
const uint16_t *source, int32_t source_units,
int32_t truncate) {
(void)destination;
(void)destination_bytes;
(void)source;
(void)source_units;
(void)truncate;
return 0;
}
/* ==================================================================== *
* iggy_main / draw / audio callbacks -- recording / controllable stubs.
* ==================================================================== */
void iggy_send_error(void *iggy, int code, const char *fmt, ...) {
(void)iggy;
(void)code;
(void)fmt;
++send_error_count;
}
void *iggy_create_from_memory(long is_library, void *url, void *data,
unsigned size, void *config, long spill) {
(void)url;
(void)size;
(void)config;
(void)spill;
++create_from_memory_count;
create_last_is_library = is_library;
create_last_data = data;
return create_result;
}
int iggy_add_library(void *core) {
(void)core;
++add_library_count;
return add_library_result;
}
void *iggy_get_library(long lib) {
(void)lib;
++get_library_count;
return get_library_result;
}
void iggy_free_library_id(long lib) {
++free_library_id_count;
free_library_id_last = lib;
}
void iggy_core_destroy(void *core) {
++core_destroy_count;
core_destroy_last = core;
}
void iggy_player_flush_core(void *player, int flag) {
(void)player;
(void)flag;
}
void as3vm_interpreter_initialize(void *vm) {
(void)vm;
++as3vm_init_count;
}
void iggy_audio_update(void *iggy) { (void)iggy; }
void iggy_fontcache_flush(void *iggy) { (void)iggy; }
void iggy_flush_triangulation_caches(void *iggy) { (void)iggy; }
void iggy_draw_tiles_begin(void *iggy, int flag) { (void)iggy; (void)flag; }
void iggy_setup_3d_transform(float a, float b, void *c, void *d) {
(void)a; (void)b; (void)c; (void)d;
}
void iggy_update_root_scale(void) { }
void iggy_gdraw_FreeTexture(void *iggy, long tex, void *slot) {
(void)iggy; (void)tex; (void)slot;
}
/* ==================================================================== *
* The 16 imported *_core targets -- recording / controllable stubs.
* Only Draw / Tick / Cut / GarbageCollect are exercised; the rest exist
* so the reentrancy-wrapper exports resolve at load.
* ==================================================================== */
void IggyPlayerDraw_core(void *f) { (void)f; ++draw_core_count; }
void IggyPlayerTickRS_core(void *f) { (void)f; ++tick_core_count; }
int IggyPlayerCut_core(void *f) { (void)f; ++cut_core_count; return cut_core_result; }
void IggyPlayerGarbageCollect_core(void *f, int strength) {
(void)f; (void)strength; ++gc_core_count;
}
void IggyPlayerDrawTile_core(void *f, int x0, int y0, int x1, int y1,
int pad, const char *name) {
(void)f; (void)x0; (void)y0; (void)x1; (void)y1; (void)pad; (void)name;
}
void IggyPlayerDrawTilesEnd_core(void *f) { (void)f; }
int IggyPlayerCallFunctionRS_core(void *p, void *r, void *fn, int n, void *a) {
(void)p; (void)r; (void)fn; (void)n; (void)a; return 0;
}
int IggyPlayerCallMethodRS_core(void *p, void *r, void *t, void *m, int n,
void *a) {
(void)p; (void)r; (void)t; (void)m; (void)n; (void)a; return 0;
}
int IggyPlayerDispatchEventRS_core(void *p, void *e, void *r) {
(void)p; (void)e; (void)r; return 0;
}
void IggyPlayerGotoFrameRS_core(void *f, int frame, int stop) {
(void)f; (void)frame; (void)stop;
}
void IggyPlayerInitializeAndTickRS_core(void *p) { (void)p; }
int IggyPlayerPasteUTF16_core(void *f, void *s, int n) {
(void)f; (void)s; (void)n; return 0;
}
int IggyPlayerPasteUTF8_core(void *f, void *s, int n) {
(void)f; (void)s; (void)n; return 0;
}
void IggyPlayerSetFocus_core(void *f, void *obj, int key) {
(void)f; (void)obj; (void)key;
}
void IggyPlayerSetStageRotation_core(void *f, int rot) { (void)f; (void)rot; }
void *IggyPlayerCreateFromFileAndPlay_core(void *name, void *config) {
(void)name; (void)config; return 0;
}