Wrap long lines to fit within 80 columns across the codebase

Pure whitespace/line-break reformatting (braces, newlines, and line
continuations matching this codebase's existing wrap conventions) - no
logic, string content, or identifiers changed anywhere. Confirmed via
diff against the pre-change tree and by rebuilding + re-running the
affected test suites, which produce identical pass/fail results.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
2026-09-05 13:13:10 -05:00
co-authored by Claude Sonnet 5
parent de53bebeb8
commit cebd3d81e7
70 changed files with 1025 additions and 425 deletions
+137 -55
View File
@@ -90,7 +90,8 @@ static bool_t loading_slot_has_entry(const assetentry_t *entry) {
// ============================================================
static void test_getEntry_creates_new(void **state) {
assetentry_t *entry = assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *entry =
assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assert_non_null(entry);
assert_int_equal(entry->state, ASSET_ENTRY_STATE_NOT_STARTED);
@@ -101,8 +102,10 @@ static void test_getEntry_creates_new(void **state) {
}
static void test_getEntry_dedup(void **state) {
assetentry_t *a = assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *b = assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *a =
assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *b =
assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assert_ptr_equal(a, b);
assert_int_equal(memoryGetAllocatedCount(), 0);
@@ -121,7 +124,8 @@ static void test_getEntry_distinct_names(void **state) {
// ============================================================
static void test_update_entry_reaches_loaded(void **state) {
assetentry_t *entry = assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *entry =
assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assert_int_equal(entry->state, ASSET_ENTRY_STATE_NOT_STARTED);
assetEntryLock(entry);
@@ -134,7 +138,8 @@ static void test_update_entry_reaches_loaded(void **state) {
}
static void test_update_slot_cleared_after_first_update(void **state) {
assetentry_t *entry = assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *entry =
assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetEntryLock(entry);
assetUpdate();
@@ -149,7 +154,8 @@ static void test_update_slot_cleared_after_first_update(void **state) {
}
static void test_update_slot_stays_cleared_on_further_updates(void **state) {
assetentry_t *entry = assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *entry =
assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetEntryLock(entry);
assetUpdate();
@@ -186,10 +192,12 @@ static void test_update_four_slots_fill_independently(void **state) {
static void test_update_error_state(void **state) {
ASSET_LOADER_CALLBACKS[ASSET_LOADER_TYPE_LOCALE].loadSync = stub_load_fail;
assetentry_t *entry = assetGetEntry("fail.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *entry =
assetGetEntry("fail.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
// First update: dispatches and calls the failing stub.
// assetUpdate itself returns OK here; the error from loadSync is caught internally.
// assetUpdate itself returns OK here; the error from loadSync is
// caught internally.
errorret_t ret = assetUpdate();
assert_true(errorIsOk(ret));
assert_int_equal(entry->state, ASSET_ENTRY_STATE_ERROR);
@@ -209,7 +217,8 @@ static void test_update_noop_on_empty_table(void **state) {
}
static void test_update_loaded_entry_not_redispatched(void **state) {
assetentry_t *entry = assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *entry =
assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetEntryLock(entry);
assetUpdate();
@@ -255,13 +264,17 @@ static void test_update_overflow_queues_entries(void **state) {
for(int i = 0; i < ASSET_LOADING_COUNT_MAX; i++) {
assert_int_equal(entries[i]->state, ASSET_ENTRY_STATE_LOADED);
}
assert_int_equal(entries[ASSET_LOADING_COUNT_MAX]->state, ASSET_ENTRY_STATE_NOT_STARTED);
assert_int_equal(
entries[ASSET_LOADING_COUNT_MAX]->state, ASSET_ENTRY_STATE_NOT_STARTED
);
// Update 2: the slots freed during update 1 are now available, so the
// overflow entry is dispatched and loaded in this pass.
ret = assetUpdate();
assert_true(errorIsOk(ret));
assert_int_equal(entries[ASSET_LOADING_COUNT_MAX]->state, ASSET_ENTRY_STATE_LOADED);
assert_int_equal(
entries[ASSET_LOADING_COUNT_MAX]->state, ASSET_ENTRY_STATE_LOADED
);
for(int i = 0; i < TOTAL; i++) {
assetEntryUnlock(entries[i]);
@@ -273,12 +286,14 @@ static void test_update_overflow_queues_entries(void **state) {
static void test_update_error_slot_stays_occupied(void **state) {
ASSET_LOADER_CALLBACKS[ASSET_LOADER_TYPE_LOCALE].loadSync = stub_load_fail;
assetentry_t *entry = assetGetEntry("fail.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *entry =
assetGetEntry("fail.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetUpdate();
assert_int_equal(entry->state, ASSET_ENTRY_STATE_ERROR);
// Unlike LOADED, the ERROR case does NOT clear the slot - it throws instead.
// Unlike LOADED, the ERROR case does NOT clear the slot - it throws
// instead.
assert_true(loading_slot_has_entry(entry));
errorret_t ret = assetUpdate();
@@ -293,7 +308,8 @@ static void test_update_error_slot_stays_occupied(void **state) {
// ============================================================
static void test_getEntry_null_input_stays_null(void **state) {
assetentry_t *entry = assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *entry =
assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assert_null(entry->input);
assert_int_equal(memoryGetAllocatedCount(), 0);
@@ -304,7 +320,8 @@ static void test_getEntry_input_copied_into_entry(void **state) {
memoryZero(&input, sizeof(input));
input.texture = (textureformat_t)42;
assetentry_t *entry = assetGetEntry("test.texture", ASSET_LOADER_TYPE_TEXTURE, &input);
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);
@@ -338,10 +355,13 @@ static errorret_t reentrant_stub_load(assetloading_t *loading) {
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;
// 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);
assetentry_t *outer =
assetGetEntry("outer.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
errorret_t ret = assetRequireLoaded(outer);
assert_true(errorIsOk(ret));
@@ -360,7 +380,8 @@ static void test_update_reentrant_sync_loader(void **state) {
// ============================================================
static void test_getEntry_returns_loaded_entry(void **state) {
assetentry_t *a = assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *a =
assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetEntryLock(a);
assetUpdate();
@@ -368,7 +389,8 @@ static void test_getEntry_returns_loaded_entry(void **state) {
// A second request for the same name must return the same entry even though
// it is already LOADED rather than NOT_STARTED.
assetentry_t *b = assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *b =
assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assert_ptr_equal(a, b);
assert_int_equal(b->state, ASSET_ENTRY_STATE_LOADED);
assetEntryUnlock(a);
@@ -381,7 +403,8 @@ static void test_getEntry_returns_loaded_entry(void **state) {
// ============================================================
static void test_entry_dispose_clears_entry(void **state) {
assetentry_t *entry = assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *entry =
assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetEntryLock(entry);
assetUpdate();
@@ -427,7 +450,8 @@ static void test_entry_dispose_slot_reusable(void **state) {
// ============================================================
static void test_requireLoaded_already_loaded(void **state) {
assetentry_t *entry = assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *entry =
assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetEntryLock(entry);
assetUpdate();
@@ -442,7 +466,8 @@ static void test_requireLoaded_already_loaded(void **state) {
}
static void test_requireLoaded_spins_to_loaded(void **state) {
assetentry_t *entry = assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *entry =
assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assert_int_equal(entry->state, ASSET_ENTRY_STATE_NOT_STARTED);
// requireLoaded calls assetUpdate internally until LOADED.
@@ -456,10 +481,12 @@ static void test_requireLoaded_spins_to_loaded(void **state) {
static void test_requireLoaded_propagates_error(void **state) {
ASSET_LOADER_CALLBACKS[ASSET_LOADER_TYPE_LOCALE].loadSync = stub_load_fail;
assetentry_t *entry = assetGetEntry("fail.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *entry =
assetGetEntry("fail.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
// requireLoaded spins assetUpdate until LOADED - but the loader always fails,
// so the second assetUpdate sees ERROR and throws, which errorChain propagates.
// requireLoaded spins assetUpdate until LOADED - but the loader
// always fails, so the second assetUpdate sees ERROR and throws, which
// errorChain propagates.
errorret_t ret = assetRequireLoaded(entry);
assert_true(errorIsNotOk(ret));
errorCatch(ret);
@@ -473,7 +500,8 @@ static void test_requireLoaded_propagates_error(void **state) {
// ============================================================
static void test_update_does_not_reap_automatically(void **state) {
assetentry_t *entry = assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *entry =
assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetEntryLock(entry);
assetUpdate();
@@ -497,7 +525,8 @@ static void test_update_does_not_reap_automatically(void **state) {
}
static void test_reapUnused_disposes_zero_ref_loaded(void **state) {
assetentry_t *entry = assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *entry =
assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetEntryLock(entry);
assetUpdate();
@@ -513,7 +542,8 @@ static void test_reapUnused_disposes_zero_ref_loaded(void **state) {
}
static void test_reapUnused_ignores_referenced_entries(void **state) {
assetentry_t *entry = assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *entry =
assetGetEntry("test.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetEntryLock(entry);
assetUpdate();
@@ -548,7 +578,8 @@ static void test_getEntry_reaps_when_pool_full(void **state) {
// The pool is now completely full of zero-ref LOADED entries with no
// ASSET_LOADER_TYPE_NULL slots left. Requesting one more must trigger an
// implicit reap instead of asserting.
assetentry_t *fresh = assetGetEntry("fresh.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assetentry_t *fresh =
assetGetEntry("fresh.locale", ASSET_LOADER_TYPE_LOCALE, NULL);
assert_non_null(fresh);
assert_int_equal(fresh->state, ASSET_ENTRY_STATE_NOT_STARTED);
@@ -572,39 +603,90 @@ int main(void) {
assertInit();
const struct CMUnitTest tests[] = {
// getEntry
cmocka_unit_test_setup_teardown(test_getEntry_creates_new, asset_setup, asset_teardown),
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),
cmocka_unit_test_setup_teardown(
test_getEntry_creates_new, asset_setup, asset_teardown
),
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),
cmocka_unit_test_setup_teardown(test_update_entry_reaches_loaded, asset_setup, asset_teardown),
cmocka_unit_test_setup_teardown(test_update_slot_cleared_after_first_update, asset_setup, asset_teardown),
cmocka_unit_test_setup_teardown(test_update_slot_stays_cleared_on_further_updates, asset_setup, asset_teardown),
cmocka_unit_test_setup_teardown(test_update_four_slots_fill_independently, asset_setup, asset_teardown),
cmocka_unit_test_setup_teardown(test_update_loaded_entry_not_redispatched, asset_setup, asset_teardown),
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),
cmocka_unit_test_setup_teardown(
test_update_noop_on_empty_table, asset_setup, asset_teardown
),
cmocka_unit_test_setup_teardown(
test_update_entry_reaches_loaded, asset_setup, asset_teardown
),
cmocka_unit_test_setup_teardown(
test_update_slot_cleared_after_first_update, asset_setup, asset_teardown
),
cmocka_unit_test_setup_teardown(
test_update_slot_stays_cleared_on_further_updates,
asset_setup, asset_teardown
),
cmocka_unit_test_setup_teardown(
test_update_four_slots_fill_independently, asset_setup, asset_teardown
),
cmocka_unit_test_setup_teardown(
test_update_loaded_entry_not_redispatched, asset_setup, asset_teardown
),
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),
cmocka_unit_test_setup_teardown(test_entry_dispose_slot_reusable, asset_setup, asset_teardown),
cmocka_unit_test_setup_teardown(
test_entry_dispose_clears_entry, asset_setup, asset_teardown
),
cmocka_unit_test_setup_teardown(
test_entry_dispose_slot_reusable, asset_setup, asset_teardown
),
// assetRequireLoaded
cmocka_unit_test_setup_teardown(test_requireLoaded_already_loaded, asset_setup, asset_teardown),
cmocka_unit_test_setup_teardown(test_requireLoaded_spins_to_loaded, asset_setup, asset_teardown),
cmocka_unit_test_setup_teardown(test_requireLoaded_propagates_error, asset_setup, asset_teardown),
cmocka_unit_test_setup_teardown(
test_requireLoaded_already_loaded, asset_setup, asset_teardown
),
cmocka_unit_test_setup_teardown(
test_requireLoaded_spins_to_loaded, asset_setup, asset_teardown
),
cmocka_unit_test_setup_teardown(
test_requireLoaded_propagates_error, asset_setup, asset_teardown
),
// assetReapUnused
cmocka_unit_test_setup_teardown(test_update_does_not_reap_automatically, asset_setup, asset_teardown),
cmocka_unit_test_setup_teardown(test_reapUnused_disposes_zero_ref_loaded, asset_setup, asset_teardown),
cmocka_unit_test_setup_teardown(test_reapUnused_ignores_referenced_entries, asset_setup, asset_teardown),
cmocka_unit_test_setup_teardown(test_getEntry_reaps_when_pool_full, asset_setup, asset_teardown),
cmocka_unit_test_setup_teardown(
test_update_does_not_reap_automatically, asset_setup, asset_teardown
),
cmocka_unit_test_setup_teardown(
test_reapUnused_disposes_zero_ref_loaded, asset_setup, asset_teardown
),
cmocka_unit_test_setup_teardown(
test_reapUnused_ignores_referenced_entries, asset_setup, asset_teardown
),
cmocka_unit_test_setup_teardown(
test_getEntry_reaps_when_pool_full, asset_setup, asset_teardown
),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
+12 -4
View File
@@ -240,10 +240,18 @@ static void test_json_buffer_cleared_after_load(void **state) {
int main(void) {
assertInit();
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(test_json_valid_loads, zip_setup, zip_teardown),
cmocka_unit_test_setup_teardown(test_json_parse_error, zip_setup, zip_teardown),
cmocka_unit_test_setup_teardown(test_json_missing_file, zip_setup, zip_teardown),
cmocka_unit_test_setup_teardown(test_json_buffer_cleared_after_load, zip_setup, zip_teardown),
cmocka_unit_test_setup_teardown(
test_json_valid_loads, zip_setup, zip_teardown
),
cmocka_unit_test_setup_teardown(
test_json_parse_error, zip_setup, zip_teardown
),
cmocka_unit_test_setup_teardown(
test_json_missing_file, zip_setup, zip_teardown
),
cmocka_unit_test_setup_teardown(
test_json_buffer_cleared_after_load, zip_setup, zip_teardown
),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
+53 -22
View File
@@ -104,10 +104,14 @@ static int locale_setup(void **state) {
char_t header[512];
ret = assetLocaleGetString(&g_locale, "", 0, header, sizeof(header));
if(errorIsNotOk(ret)) { errorCatch(ret); assetFileClose(&g_locale.file); goto fail; }
if(errorIsNotOk(ret)) {
errorCatch(ret); assetFileClose(&g_locale.file); goto fail;
}
ret = assetLocaleParseHeader(&g_locale, header, sizeof(header));
if(errorIsNotOk(ret)) { errorCatch(ret); assetFileClose(&g_locale.file); goto fail; }
if(errorIsNotOk(ret)) {
errorCatch(ret); assetFileClose(&g_locale.file); goto fail;
}
return 0;
@@ -309,7 +313,8 @@ static void test_evaluatePlural_less_than_boundary(void **state) {
static void test_getString_simple(void **state) {
char_t result[256];
errorret_t ret = assetLocaleGetString(&g_locale, "greeting", 0, result, sizeof(result));
errorret_t ret =
assetLocaleGetString(&g_locale, "greeting", 0, result, sizeof(result));
assert_true(errorIsOk(ret));
assert_string_equal(result, "Hello, World!");
@@ -321,7 +326,8 @@ static void test_getString_simple(void **state) {
static void test_getString_plural_singular(void **state) {
char_t result[256];
errorret_t ret = assetLocaleGetString(&g_locale, "item", 1, result, sizeof(result));
errorret_t ret =
assetLocaleGetString(&g_locale, "item", 1, result, sizeof(result));
assert_true(errorIsOk(ret));
assert_string_equal(result, "one item");
@@ -330,7 +336,8 @@ static void test_getString_plural_singular(void **state) {
static void test_getString_plural_many(void **state) {
char_t result[256];
errorret_t ret = assetLocaleGetString(&g_locale, "item", 5, result, sizeof(result));
errorret_t ret =
assetLocaleGetString(&g_locale, "item", 5, result, sizeof(result));
assert_true(errorIsOk(ret));
assert_string_equal(result, "many items");
@@ -353,7 +360,8 @@ static void test_getString_multiple_calls(void **state) {
static void test_getString_missing_id(void **state) {
char_t result[256];
errorret_t ret = assetLocaleGetString(&g_locale, "nonexistent", 0, result, sizeof(result));
errorret_t ret =
assetLocaleGetString(&g_locale, "nonexistent", 0, result, sizeof(result));
assert_true(errorIsNotOk(ret));
errorCatch(ret);
@@ -372,7 +380,8 @@ static void test_cache_findMiss_onEmptyCache(void **state) {
char_t result[64];
bool_t hit = true;
errorret_t ret = assetLocaleCacheFind(&locale, "greeting", 0, result, sizeof(result), &hit);
errorret_t ret =
assetLocaleCacheFind(&locale, "greeting", 0, result, sizeof(result), &hit);
assert_true(errorIsOk(ret));
assert_false(hit);
@@ -389,7 +398,8 @@ static void test_cache_insertThenFind_hits(void **state) {
char_t result[64];
bool_t hit = false;
errorret_t ret = assetLocaleCacheFind(&locale, "greeting", 0, result, sizeof(result), &hit);
errorret_t ret =
assetLocaleCacheFind(&locale, "greeting", 0, result, sizeof(result), &hit);
assert_true(errorIsOk(ret));
assert_true(hit);
@@ -409,7 +419,8 @@ static void test_cache_distinguishesByPluralCount(void **state) {
char_t result[64];
bool_t hit = false;
errorret_t ret = assetLocaleCacheFind(&locale, "item", 1, result, sizeof(result), &hit);
errorret_t ret =
assetLocaleCacheFind(&locale, "item", 1, result, sizeof(result), &hit);
assert_true(errorIsOk(ret));
assert_true(hit);
assert_string_equal(result, "one item");
@@ -430,7 +441,8 @@ static void test_cache_find_missOnDifferentMessageId(void **state) {
char_t result[64];
bool_t hit = true;
errorret_t ret = assetLocaleCacheFind(&locale, "farewell", 0, result, sizeof(result), &hit);
errorret_t ret =
assetLocaleCacheFind(&locale, "farewell", 0, result, sizeof(result), &hit);
assert_true(errorIsOk(ret));
assert_false(hit);
@@ -446,7 +458,8 @@ static void test_cache_find_bufferTooSmall_errors(void **state) {
char_t result[4];// too small for "Hello, World!"
bool_t hit = false;
errorret_t ret = assetLocaleCacheFind(&locale, "greeting", 0, result, sizeof(result), &hit);
errorret_t ret =
assetLocaleCacheFind(&locale, "greeting", 0, result, sizeof(result), &hit);
assert_true(errorIsNotOk(ret));
errorCatch(ret);
@@ -502,7 +515,8 @@ static void test_cache_insert_evictsLeastRecentlyUsed(void **state) {
char_t result[32];
bool_t hit = true;
errorret_t ret = assetLocaleCacheFind(&locale, "id0", 0, result, sizeof(result), &hit);
errorret_t ret =
assetLocaleCacheFind(&locale, "id0", 0, result, sizeof(result), &hit);
assert_true(errorIsOk(ret));
assert_false(hit);
@@ -530,7 +544,8 @@ static void test_cache_find_movesHitToFront(void **state) {
char_t result[32];
bool_t hit = false;
errorret_t ret = assetLocaleCacheFind(&locale, "id0", 0, result, sizeof(result), &hit);
errorret_t ret =
assetLocaleCacheFind(&locale, "id0", 0, result, sizeof(result), &hit);
assert_true(errorIsOk(ret));
assert_true(hit);
@@ -594,7 +609,8 @@ static void test_localeDispose_freesCache(void **state) {
zip_source_free(write_src);
zip_error_init(&err);
zip_source_t *read_src = zip_source_buffer_create(zipbuf, (zip_uint64_t)zs.size, 1, &err);
zip_source_t *read_src =
zip_source_buffer_create(zipbuf, (zip_uint64_t)zs.size, 1, &err);
assert_non_null(read_src);
zip_t *zip = zip_open_from_source(read_src, 0, &err);
assert_non_null(zip);
@@ -604,7 +620,8 @@ static void test_localeDispose_freesCache(void **state) {
memoryZero(&entry, sizeof(entry));
entry.type = ASSET_LOADER_TYPE_LOCALE;
errorret_t ret = assetFileInit(&entry.data.locale.file, "en.locale", NULL, NULL);
errorret_t ret =
assetFileInit(&entry.data.locale.file, "en.locale", NULL, NULL);
assert_true(errorIsOk(ret));
ret = assetFileOpen(&entry.data.locale.file);
assert_true(errorIsOk(ret));
@@ -679,15 +696,29 @@ int main(void) {
cmocka_unit_test(test_evaluatePlural_less_than_boundary),
// getString - in-memory ZIP
cmocka_unit_test_setup_teardown(test_getString_simple, locale_setup, locale_teardown),
cmocka_unit_test_setup_teardown(test_getString_plural_singular, locale_setup, locale_teardown),
cmocka_unit_test_setup_teardown(test_getString_plural_many, locale_setup, locale_teardown),
cmocka_unit_test_setup_teardown(test_getString_multiple_calls, locale_setup, locale_teardown),
cmocka_unit_test_setup_teardown(test_getString_missing_id, locale_setup, locale_teardown),
cmocka_unit_test_setup_teardown(
test_getString_simple, locale_setup, locale_teardown
),
cmocka_unit_test_setup_teardown(
test_getString_plural_singular, locale_setup, locale_teardown
),
cmocka_unit_test_setup_teardown(
test_getString_plural_many, locale_setup, locale_teardown
),
cmocka_unit_test_setup_teardown(
test_getString_multiple_calls, locale_setup, locale_teardown
),
cmocka_unit_test_setup_teardown(
test_getString_missing_id, locale_setup, locale_teardown
),
// getStringWithArgs - in-memory ZIP
cmocka_unit_test_setup_teardown(test_getStringWithArgs_int, locale_setup, locale_teardown),
cmocka_unit_test_setup_teardown(test_getStringWithArgs_string, locale_setup, locale_teardown),
cmocka_unit_test_setup_teardown(
test_getStringWithArgs_int, locale_setup, locale_teardown
),
cmocka_unit_test_setup_teardown(
test_getStringWithArgs_string, locale_setup, locale_teardown
),
// assetLocaleCacheFind / assetLocaleCacheInsert - pure
cmocka_unit_test(test_cache_findMiss_onEmptyCache),
+57 -19
View File
@@ -124,7 +124,9 @@ static bool_t run_tileset_async(assetloading_t *loading) {
static zip_t *g_zip = NULL;
static int tileset_zip_add(zip_t *za, const char_t *name, const void *data, size_t len) {
static int tileset_zip_add(
zip_t *za, const char_t *name, const void *data, size_t len
) {
zip_source_t *s = zip_source_buffer(za, data, len, 0);
return (int)zip_file_add(za, name, s, ZIP_FL_OVERWRITE);
}
@@ -139,14 +141,30 @@ static int zip_setup(void **state) {
zip_t *za = zip_open_from_source(write_src, ZIP_TRUNCATE, &err);
if(!za) { zip_source_free(write_src); return -1; }
if(tileset_zip_add(za, "valid.tileset", DTF_VALID, sizeof(DTF_VALID)) < 0 ||
tileset_zip_add(za, "badmagic.tileset", DTF_BAD_MAGIC, sizeof(DTF_BAD_MAGIC)) < 0 ||
tileset_zip_add(za, "badversion.tileset", DTF_BAD_VERSION, sizeof(DTF_BAD_VERSION)) < 0 ||
tileset_zip_add(za, "zerowidth.tileset", DTF_ZERO_WIDTH, sizeof(DTF_ZERO_WIDTH)) < 0 ||
tileset_zip_add(za, "zeroheight.tileset", DTF_ZERO_HEIGHT, sizeof(DTF_ZERO_HEIGHT)) < 0 ||
tileset_zip_add(za, "zerocolumns.tileset", DTF_ZERO_COLUMNS, sizeof(DTF_ZERO_COLUMNS)) < 0 ||
tileset_zip_add(za, "zerorows.tileset", DTF_ZERO_ROWS, sizeof(DTF_ZERO_ROWS)) < 0 ||
tileset_zip_add(za, "invaliduv.tileset", DTF_INVALID_UV, sizeof(DTF_INVALID_UV)) < 0) {
if(
tileset_zip_add(za, "valid.tileset", DTF_VALID, sizeof(DTF_VALID)) < 0 ||
tileset_zip_add(
za, "badmagic.tileset", DTF_BAD_MAGIC, sizeof(DTF_BAD_MAGIC)
) < 0 ||
tileset_zip_add(
za, "badversion.tileset", DTF_BAD_VERSION, sizeof(DTF_BAD_VERSION)
) < 0 ||
tileset_zip_add(
za, "zerowidth.tileset", DTF_ZERO_WIDTH, sizeof(DTF_ZERO_WIDTH)
) < 0 ||
tileset_zip_add(
za, "zeroheight.tileset", DTF_ZERO_HEIGHT, sizeof(DTF_ZERO_HEIGHT)
) < 0 ||
tileset_zip_add(
za, "zerocolumns.tileset", DTF_ZERO_COLUMNS, sizeof(DTF_ZERO_COLUMNS)
) < 0 ||
tileset_zip_add(
za, "zerorows.tileset", DTF_ZERO_ROWS, sizeof(DTF_ZERO_ROWS)
) < 0 ||
tileset_zip_add(
za, "invaliduv.tileset", DTF_INVALID_UV, sizeof(DTF_INVALID_UV)
) < 0
) {
zip_close(za); return -1;
}
@@ -369,16 +387,36 @@ static void test_tileset_missing_file(void **state) {
int main(void) {
assertInit();
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(test_tileset_valid_loads, zip_setup, zip_teardown),
cmocka_unit_test_setup_teardown(test_tileset_data_cleared_after_load, zip_setup, zip_teardown),
cmocka_unit_test_setup_teardown(test_tileset_bad_magic, zip_setup, zip_teardown),
cmocka_unit_test_setup_teardown(test_tileset_bad_version, zip_setup, zip_teardown),
cmocka_unit_test_setup_teardown(test_tileset_zero_tile_width, zip_setup, zip_teardown),
cmocka_unit_test_setup_teardown(test_tileset_zero_tile_height, zip_setup, zip_teardown),
cmocka_unit_test_setup_teardown(test_tileset_zero_columns, zip_setup, zip_teardown),
cmocka_unit_test_setup_teardown(test_tileset_zero_rows, zip_setup, zip_teardown),
cmocka_unit_test_setup_teardown(test_tileset_invalid_uv, zip_setup, zip_teardown),
cmocka_unit_test_setup_teardown(test_tileset_missing_file, zip_setup, zip_teardown),
cmocka_unit_test_setup_teardown(
test_tileset_valid_loads, zip_setup, zip_teardown
),
cmocka_unit_test_setup_teardown(
test_tileset_data_cleared_after_load, zip_setup, zip_teardown
),
cmocka_unit_test_setup_teardown(
test_tileset_bad_magic, zip_setup, zip_teardown
),
cmocka_unit_test_setup_teardown(
test_tileset_bad_version, zip_setup, zip_teardown
),
cmocka_unit_test_setup_teardown(
test_tileset_zero_tile_width, zip_setup, zip_teardown
),
cmocka_unit_test_setup_teardown(
test_tileset_zero_tile_height, zip_setup, zip_teardown
),
cmocka_unit_test_setup_teardown(
test_tileset_zero_columns, zip_setup, zip_teardown
),
cmocka_unit_test_setup_teardown(
test_tileset_zero_rows, zip_setup, zip_teardown
),
cmocka_unit_test_setup_teardown(
test_tileset_invalid_uv, zip_setup, zip_teardown
),
cmocka_unit_test_setup_teardown(
test_tileset_missing_file, zip_setup, zip_teardown
),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}