Test sprite from script
This commit is contained in:
@@ -267,6 +267,73 @@ static void test_update_error_slot_stays_occupied(void **state) {
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// assetEntryInit — input copy
|
||||
// ============================================================
|
||||
|
||||
static void test_getEntry_null_input_stays_null(void **state) {
|
||||
assetentry_t *entry = assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
|
||||
|
||||
assert_null(entry->input);
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_getEntry_input_copied_into_entry(void **state) {
|
||||
assetloaderinput_t input;
|
||||
memoryZero(&input, sizeof(input));
|
||||
input.texture = (textureformat_t)42;
|
||||
|
||||
assetentry_t *entry = assetGetEntry("test.texture", ASSET_LOADER_TYPE_TEXTURE, &input);
|
||||
|
||||
// input must have been copied — entry->input must point inside the entry.
|
||||
assert_non_null(entry->input);
|
||||
assert_ptr_equal(entry->input, &entry->inputData);
|
||||
assert_int_equal((int)entry->input->texture, 42);
|
||||
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// assetUpdate — re-entrant sync loader
|
||||
// ============================================================
|
||||
|
||||
static assetentry_t *reentrant_inner_entry = NULL;
|
||||
static bool_t reentrant_inner_loaded = false;
|
||||
|
||||
static errorret_t reentrant_stub_load(assetloading_t *loading) {
|
||||
if(reentrant_inner_entry == NULL) {
|
||||
// Simulate a script loading another asset from within its own sync step.
|
||||
reentrant_inner_entry = assetGetEntry(
|
||||
"inner.json", ASSET_LOADER_TYPE_JSON, NULL
|
||||
);
|
||||
errorret_t inner_ret = assetRequireLoaded(reentrant_inner_entry);
|
||||
reentrant_inner_loaded = errorIsOk(inner_ret);
|
||||
if(errorIsNotOk(inner_ret)) errorChain(inner_ret);
|
||||
}
|
||||
loading->entry->state = ASSET_ENTRY_STATE_LOADED;
|
||||
errorOk();
|
||||
}
|
||||
|
||||
static void test_update_reentrant_sync_loader(void **state) {
|
||||
reentrant_inner_entry = NULL;
|
||||
reentrant_inner_loaded = false;
|
||||
// LOCALE uses the re-entrant loader; JSON keeps the default stub_load_success.
|
||||
ASSET_LOADER_CALLBACKS[ASSET_LOADER_TYPE_LOCALE].loadSync = reentrant_stub_load;
|
||||
|
||||
assetentry_t *outer = assetGetEntry("outer.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
|
||||
|
||||
errorret_t ret = assetRequireLoaded(outer);
|
||||
assert_true(errorIsOk(ret));
|
||||
assert_int_equal(outer->state, ASSET_ENTRY_STATE_LOADED);
|
||||
// Verify the re-entrant load ran and completed successfully.
|
||||
// (The inner entry may have been reaped by the time we check here,
|
||||
// so we capture the result inside the callback rather than reading state.)
|
||||
assert_non_null(reentrant_inner_entry);
|
||||
assert_true(reentrant_inner_loaded);
|
||||
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// assetGetEntry — dedup against non-NOT_STARTED entries
|
||||
// ============================================================
|
||||
@@ -377,6 +444,8 @@ int main(void) {
|
||||
cmocka_unit_test_setup_teardown(test_getEntry_dedup, asset_setup, asset_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_getEntry_distinct_names, asset_setup, asset_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_getEntry_returns_loaded_entry, asset_setup, asset_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_getEntry_null_input_stays_null, asset_setup, asset_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_getEntry_input_copied_into_entry, asset_setup, asset_teardown),
|
||||
|
||||
// assetUpdate — state machine
|
||||
cmocka_unit_test_setup_teardown(test_update_noop_on_empty_table, asset_setup, asset_teardown),
|
||||
@@ -388,6 +457,7 @@ int main(void) {
|
||||
cmocka_unit_test_setup_teardown(test_update_overflow_queues_entries, asset_setup, asset_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_update_error_state, asset_setup, asset_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_update_error_slot_stays_occupied, asset_setup, asset_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_update_reentrant_sync_loader, asset_setup, asset_teardown),
|
||||
|
||||
// assetEntryDispose
|
||||
cmocka_unit_test_setup_teardown(test_entry_dispose_clears_entry, asset_setup, asset_teardown),
|
||||
|
||||
Reference in New Issue
Block a user