Files
dusk/test/rpg/cutscene/test_cutscenemaparea.c
T
YourWishesandClaude Sonnet 5 68cebce04a Remove per-item cutscene authoring macros
Every CUTSCENE_XXX(...) shorthand (CUTSCENE_WAIT, CUTSCENE_TEXT,
CUTSCENE_ENTITY_WALK_TO, etc.) existed to build a cutsceneitem_t literal
in C; real cutscenes are now authored exclusively as .jsonc files, and
the only other users were test fixtures. Deletes all ~55 of these
macros (and the shared CUTSCENE_ITEM(...) helper they built on) along
with their doc comments, leaving each item's struct/enum/Start/Update/
Load declarations untouched.

test_battle.c, test_cutscenecontrol.c, test_cutscenemaparea.c,
test_cutscenesystem.c and test_entityinteract.c now build their
cutsceneitem_t fixtures as plain struct literals instead.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
2026-09-14 11:20:58 -05:00

176 lines
5.0 KiB
C

/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "dusktest.h"
#include "rpg/cutscene/cutscenesystem.h"
#include "rpg/overworld/maparea.h"
#include "util/memory.h"
static void resetMapAreas(void) {
memoryZero(MAP_AREAS, sizeof(MAP_AREAS));
}
static void test_cutsceneMapAreaAddCreatesAreaAndStoresLastCreated(
void **state
) {
resetMapAreas();
cutsceneitem_t item = {
.type = CUTSCENE_ITEM_TYPE_MAP_AREA_ADD,
.mapAreaAdd = {
.min = { 0, 0, 0 }, .max = { 5, 5, 0 },
.callback = mapAreaNoopCallback,
.notify = MAP_AREA_NOTIFY_ALL, .trigger = MAP_TRIGGER_ALL
}
};
cutsceneitemdata_t data;
cutsceneMapAreaAddStart(&item, &data);
assert_true(cutsceneMapAreaAddUpdate(&item, &data));
uint8_t id = CUTSCENE_SYSTEM.areaLastCreated;
assert_ptr_equal(MAP_AREAS[id].callback, mapAreaNoopCallback);
assert_int_equal(MAP_AREAS[id].max.x, 5);
}
static void test_cutsceneMapAreaRemoveClearsSlot(void **state) {
resetMapAreas();
uint8_t id = mapAreaAdd(
(worldpos_t){ 0, 0, 0 }, (worldpos_t){ 5, 5, 0 },
mapAreaNoopCallback, MAP_AREA_NOTIFY_ALL, MAP_TRIGGER_ALL
);
cutsceneitem_t item = {
.type = CUTSCENE_ITEM_TYPE_MAP_AREA_REMOVE,
.mapAreaRemove = { .areaId = id }
};
cutsceneitemdata_t data;
cutsceneMapAreaRemoveStart(&item, &data);
assert_true(cutsceneMapAreaRemoveUpdate(&item, &data));
assert_null(MAP_AREAS[id].callback);
}
static void test_cutsceneMapAreaRemoveResolvesLastCreatedSentinel(
void **state
) {
resetMapAreas();
cutsceneitem_t addItem = {
.type = CUTSCENE_ITEM_TYPE_MAP_AREA_ADD,
.mapAreaAdd = {
.min = { 0, 0, 0 }, .max = { 5, 5, 0 },
.callback = mapAreaNoopCallback,
.notify = MAP_AREA_NOTIFY_ALL, .trigger = MAP_TRIGGER_ALL
}
};
cutsceneitemdata_t data;
cutsceneMapAreaAddStart(&addItem, &data);
uint8_t id = CUTSCENE_SYSTEM.areaLastCreated;
cutsceneitem_t removeItem = {
.type = CUTSCENE_ITEM_TYPE_MAP_AREA_REMOVE,
.mapAreaRemove = { .areaId = CUTSCENE_AREA_LAST_CREATED }
};
cutsceneMapAreaRemoveStart(&removeItem, &data);
assert_null(MAP_AREAS[id].callback);
}
static void test_cutsceneMapAreaWaitCompletesWhenTriggerCountChanges(
void **state
) {
resetMapAreas();
uint8_t id = mapAreaAdd(
(worldpos_t){ 0, 0, 0 }, (worldpos_t){ 5, 5, 0 },
mapAreaNoopCallback, MAP_AREA_NOTIFY_ALL, MAP_TRIGGER_ALL
);
cutsceneitem_t item = {
.type = CUTSCENE_ITEM_TYPE_MAP_AREA_WAIT,
.mapAreaWait = { .areaIds = { id }, .count = 1 }
};
cutsceneitemdata_t data;
cutsceneMapAreaWaitStart(&item, &data);
assert_false(cutsceneMapAreaWaitUpdate(&item, &data));
MAP_AREAS[id].triggerCount++;// simulates the area's callback firing
assert_true(cutsceneMapAreaWaitUpdate(&item, &data));
}
static void test_cutsceneMapAreaWaitCompletesWhenAnyWatchedAreaChanges(
void **state
) {
resetMapAreas();
uint8_t idA = mapAreaAdd(
(worldpos_t){ 0, 0, 0 }, (worldpos_t){ 5, 5, 0 },
mapAreaNoopCallback, MAP_AREA_NOTIFY_ALL, MAP_TRIGGER_ALL
);
uint8_t idB = mapAreaAdd(
(worldpos_t){ 10, 10, 0 }, (worldpos_t){ 15, 15, 0 },
mapAreaNoopCallback, MAP_AREA_NOTIFY_ALL, MAP_TRIGGER_ALL
);
cutsceneitem_t item = {
.type = CUTSCENE_ITEM_TYPE_MAP_AREA_WAIT,
.mapAreaWait = { .areaIds = { idA, idB }, .count = 2 }
};
cutsceneitemdata_t data;
cutsceneMapAreaWaitStart(&item, &data);
assert_false(cutsceneMapAreaWaitUpdate(&item, &data));
MAP_AREAS[idB].triggerCount++;// only the second watched area fires
assert_true(cutsceneMapAreaWaitUpdate(&item, &data));
}
static void test_cutsceneMapAreaWaitResolvesLastCreatedSentinel(
void **state
) {
resetMapAreas();
cutsceneitem_t addItem = {
.type = CUTSCENE_ITEM_TYPE_MAP_AREA_ADD,
.mapAreaAdd = {
.min = { 0, 0, 0 }, .max = { 5, 5, 0 },
.callback = mapAreaNoopCallback,
.notify = MAP_AREA_NOTIFY_ALL, .trigger = MAP_TRIGGER_ALL
}
};
cutsceneitemdata_t data;
cutsceneMapAreaAddStart(&addItem, &data);
uint8_t id = CUTSCENE_SYSTEM.areaLastCreated;
cutsceneitem_t waitItem = {
.type = CUTSCENE_ITEM_TYPE_MAP_AREA_WAIT,
.mapAreaWait = { .areaIds = { CUTSCENE_AREA_LAST_CREATED }, .count = 1 }
};
cutsceneMapAreaWaitStart(&waitItem, &data);
assert_false(cutsceneMapAreaWaitUpdate(&waitItem, &data));
MAP_AREAS[id].triggerCount++;
assert_true(cutsceneMapAreaWaitUpdate(&waitItem, &data));
}
int main(int argc, char** argv) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_cutsceneMapAreaAddCreatesAreaAndStoresLastCreated),
cmocka_unit_test(test_cutsceneMapAreaRemoveClearsSlot),
cmocka_unit_test(test_cutsceneMapAreaRemoveResolvesLastCreatedSentinel),
cmocka_unit_test(test_cutsceneMapAreaWaitCompletesWhenTriggerCountChanges),
cmocka_unit_test(
test_cutsceneMapAreaWaitCompletesWhenAnyWatchedAreaChanges
),
cmocka_unit_test(test_cutsceneMapAreaWaitResolvesLastCreatedSentinel),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}