Add comprehensive tests for entity dispatch, file system, fixed map, flex archive, isometric controls, and crash setup

- Enhance `entity_dispatch_entry_tests.cpp` with additional assertions for event type checks, group ID increments, and error handling.
- Refactor `file_system_tests.cpp` to streamline probe execution and enhance output validation.
- Extend `fixed_map_tests.cpp` to cover retail map loading, item classification, and process creation scenarios.
- Introduce new checks in `flex_archive_tests.cpp` for usecode loading and event handling, ensuring robust validation of game data.
- Add tests in `isometric_controls_tests.cpp` for controller direction mapping based on scan codes.
- Implement `test_crash_setup.cpp` to initialize crash diagnostics for improved error handling during tests.
This commit is contained in:
Maddo 2026-09-26 15:36:11 +02:00
commit c346b0e1a7
17 changed files with 1207 additions and 92 deletions

View file

@ -33,6 +33,15 @@ int main()
remorse::EntityDispatchEntry::setEventTypeChecked(entry, 0x00f2);
assert(entry.bytes[0x06] == 0xf2);
assert(entry.bytes[0x07] == 0x00);
remorse::EntityDispatchEntry::setEventTypeChecked(entry, 0x0fff);
assert(entry.bytes[0x06] == 0xff && entry.bytes[0x07] == 0x0f);
bool invalidEventType = false;
try {
remorse::EntityDispatchEntry::setEventTypeChecked(entry, 0x1000);
} catch (const std::invalid_argument&) {
invalidEventType = true;
}
assert(invalidEventType && entry.bytes[0x06] == 0 && entry.bytes[0x07] == 0x10);
remorse::EntityDispatchEntry::sleep(entry, 0x12345678, 0x0001003c);
assert(entry.bytes[0x18] == 0x01 && entry.bytes[0x19] == 0x10);
@ -63,8 +72,34 @@ int main()
assert(rejected && entry.bytes[0x08] == 4 && groupCounts[4] == 1);
}
remorse::EntityDispatchEntry::incrementGroupId(entry);
assert(entry.bytes[0x08] == 5);
remorse::ProcessKernel incrementKernel;
incrementKernel.setActiveGroup(4);
remorse::EntityDispatchEntry::incrementGroupId(entry, incrementKernel, groupCounts);
assert(entry.bytes[0x08] == 5 && groupCounts[4] == 0 && groupCounts[5] == 1);
assert(incrementKernel.activeGroup() == 5 && incrementKernel.groupSelectionPending());
bool wrongActiveGroup = false;
try {
remorse::EntityDispatchEntry::incrementGroupId(entry, incrementKernel, groupCounts);
} catch (const std::invalid_argument&) {
wrongActiveGroup = true;
}
assert(!wrongActiveGroup && entry.bytes[0x08] == 6 && incrementKernel.activeGroup() == 6);
incrementKernel.setActiveGroup(7);
try {
remorse::EntityDispatchEntry::incrementGroupId(entry, incrementKernel, groupCounts);
} catch (const std::invalid_argument&) {
wrongActiveGroup = true;
}
assert(wrongActiveGroup && entry.bytes[0x08] == 6 && groupCounts[6] == 1);
remorse::EntityDispatchEntry::setGroupId(entry, 29, groupCounts);
incrementKernel.setActiveGroup(29);
bool groupLimitReached = false;
try {
remorse::EntityDispatchEntry::incrementGroupId(entry, incrementKernel, groupCounts);
} catch (const std::invalid_argument&) {
groupLimitReached = true;
}
assert(groupLimitReached && entry.bytes[0x08] == 29 && groupCounts[29] == 1);
remorse::ProcessKernel kernel;
kernel.setLastAllocationSize(sizeof(entry));
@ -171,8 +206,43 @@ int main()
}
assert(exhausted && fullKernel.processCount() == 1020 && fullGroups[2] == 0);
remorse::ProcessKernel groupKernel;
remorse::u16 groupTable[32]{};
for (int index = 0; index < 3; ++index) {
groupKernel.createProcess(1, groupTable);
}
groupKernel.createProcess(2, groupTable);
groupKernel.createProcess(3, groupTable);
groupKernel.createProcess(30, groupTable);
groupKernel.createProcess(31, groupTable);
groupKernel.refreshActiveGroup(groupTable);
assert(groupKernel.activeGroup() == 1 && !groupKernel.groupSelectionPending());
groupKernel.setActiveGroup(4);
assert(groupKernel.activeGroup() == 4 && groupKernel.groupSelectionPending());
groupKernel.refreshActiveGroup(groupTable);
assert(groupKernel.activeGroup() == 3 && !groupKernel.groupSelectionPending());
groupKernel.terminateProcess(4, groupTable);
groupKernel.clearTerminatedProcesses();
groupKernel.refreshActiveGroup(groupTable);
assert(groupKernel.activeGroup() == 2 && !groupKernel.groupSelectionPending());
for (remorse::u8 invalidGroup : {remorse::u8{0}, remorse::u8{32}}) {
bool rejected = false;
try {
groupKernel.setActiveGroup(invalidGroup);
} catch (const std::invalid_argument&) {
rejected = true;
}
assert(rejected && groupKernel.activeGroup() == 2 && !groupKernel.groupSelectionPending());
}
groupKernel.setActiveGroup(30);
groupKernel.refreshActiveGroup(groupTable);
assert(groupKernel.activeGroup() == 30 && groupKernel.groupSelectionPending());
remorse::ProcessKernel scheduler;
remorse::u16 scheduledGroups[32]{};
assert(scheduler.activeGroup() == 1 && !scheduler.groupSelectionPending());
scheduler.setActiveGroup(1);
assert(!scheduler.groupSelectionPending());
auto* otherGroup = scheduler.createProcess(1, scheduledGroups);
auto* matching = scheduler.createProcess(2, scheduledGroups);
auto* syncingProcess = scheduler.createProcess(2, scheduledGroups);
@ -185,6 +255,7 @@ int main()
};
scheduler.scanRunnableProcesses(2, recordRun, &ran);
assert((ran == std::vector<remorse::u16>{1, 3}));
assert(scheduler.activeGroup() == 2 && scheduler.groupSelectionPending());
assert(syncingProcess->bytes[0x16] == 0 && otherGroup->bytes[0x16] == 0);
ran.clear();
matching->bytes[0x16] = 1;
@ -246,10 +317,37 @@ int main()
assert(sleeper->bytes[offset] == 0);
}
remorse::ProcessKernel timedPassKernel;
remorse::u16 timedPassGroups[32]{};
auto* timedPassSleeper = timedPassKernel.createProcess(1, timedPassGroups);
timedPassKernel.createSystemTimerProcess(1, timedPassGroups);
timedPassKernel.deliverSystemTimerEvent();
remorse::EntityDispatchEntry::sleep(*timedPassSleeper, 1, 1);
std::vector<remorse::u16> timedPassRuns;
const auto advanceTimer = [](void* context) {
static_cast<remorse::ProcessKernel*>(context)->deliverSystemTimerEvent();
};
assert(timedPassKernel.runTimedSchedulerPass(1, recordRun, &timedPassRuns,
advanceTimer, &timedPassKernel) == 1);
assert(timedPassRuns.empty() && timedPassKernel.systemTimerTick() == 2);
assert(timedPassKernel.runTimedSchedulerPass(1, recordRun, &timedPassRuns,
advanceTimer, &timedPassKernel) == 1);
assert(timedPassRuns.empty() && timedPassKernel.systemTimerTick() == 3);
assert(timedPassKernel.runTimedSchedulerPass(1, recordRun, &timedPassRuns,
advanceTimer, &timedPassKernel) == 1);
assert((timedPassRuns == std::vector<remorse::u16>{0}));
remorse::ProcessKernel standKernel;
remorse::u16 standGroups[32]{};
standKernel.createProcess(2, standGroups);
assert(!standKernel.itemHasProcess(0x1234) && !standKernel.itemHasProcess(0x1235));
bool oversizedStandRejected = false;
try {
standKernel.createStandProcess(2, 0x2400, standGroups);
} catch (const std::out_of_range&) {
oversizedStandRejected = true;
}
assert(oversizedStandRejected && standGroups[2] == 1 && standKernel.processCount() == 1);
auto* standEntry = standKernel.createStandProcess(2, 0x1234, standGroups);
auto* standing = &standEntry->base;
assert(standKernel.processAt(1) == standing && standKernel.allocationSizeAt(1) == 0x42);
@ -260,6 +358,72 @@ int main()
assert(standing->bytes[0x17] == 0x03 && standEntry->extra[0] == 0x01 && standEntry->extra[1] == 0x01);
assert(standEntry->extra[0x0e] == 0x34 && standEntry->extra[0x0f] == 0x12);
assert(standKernel.itemHasProcess(0x1234) && !standKernel.itemHasProcess(0x1235));
remorse::ProcessKernel cachedItemKernel;
remorse::u16 cachedItemGroups[32]{};
for (int index = 0; index < 3; ++index) {
cachedItemKernel.createProcess(1, cachedItemGroups);
}
auto* itemProcess = cachedItemKernel.createItemProcess(1, 0x100, cachedItemGroups);
assert(cachedItemKernel.processAt(3) == itemProcess && cachedItemKernel.allocationSizeAt(3) == 0x32);
assert(std::strcmp(cachedItemKernel.processNameAt(3), "ItemProcess") == 0);
assert(itemProcess->bytes[0] == 0x2f && itemProcess->bytes[1] == 0x10);
assert(itemProcess->bytes[4] == 0 && itemProcess->bytes[5] == 1);
assert(itemProcess->bytes[6] == 0xf1 && itemProcess->bytes[7] == 0);
assert(cachedItemKernel.itemHasProcess(0x100) && cachedItemKernel.itemProcessTypes(0x100) == 2);
assert(cachedItemGroups[1] == 4);
auto* sharedItemProcess = cachedItemKernel.createItemProcess(1, 0x100, cachedItemGroups);
assert(cachedItemKernel.itemProcessTypes(0x100) == 2);
cachedItemKernel.setProcessSourceType(*sharedItemProcess, 0x101);
assert(cachedItemKernel.itemHasProcess(0x100) && cachedItemKernel.itemHasProcess(0x101));
assert(cachedItemKernel.itemProcessTypes(0x100) == 2 && cachedItemKernel.itemProcessTypes(0x101) == 2);
cachedItemKernel.setProcessEventTypeChecked(*sharedItemProcess, 0xf2);
assert(cachedItemKernel.itemProcessTypes(0x101) == 4);
cachedItemKernel.setProcessSourceType(*sharedItemProcess, 0);
assert(!cachedItemKernel.itemHasProcess(0x101) && cachedItemKernel.itemProcessTypes(0x101) == 0);
cachedItemKernel.setProcessSourceType(*sharedItemProcess, 0x102);
assert(cachedItemKernel.itemHasProcess(0x102) && cachedItemKernel.itemProcessTypes(0x102) == 4);
cachedItemKernel.setProcessSourceType(*sharedItemProcess, 0x23ff);
assert(cachedItemKernel.itemHasProcess(0x23ff) && cachedItemKernel.itemProcessTypes(0x23ff) == 4);
bool invalidItemNumber = false;
try {
cachedItemKernel.setProcessSourceType(*sharedItemProcess, 0x2400);
} catch (const std::out_of_range&) {
invalidItemNumber = true;
}
assert(invalidItemNumber && cachedItemKernel.itemHasProcess(0x23ff));
assert(!cachedItemKernel.itemHasProcess(0x2400) && cachedItemKernel.itemProcessTypes(0x2400) == 0);
cachedItemKernel.setProcessSourceType(*sharedItemProcess, 0x102);
cachedItemKernel.terminateProcess(4, cachedItemGroups);
cachedItemKernel.clearTerminatedProcesses();
assert(!cachedItemKernel.itemHasProcess(0x102) && cachedItemKernel.itemProcessTypes(0x102) == 0);
bool missingReleaseRejected = false;
try {
remorse::ItemProcess::run(*itemProcess, cachedItemKernel, cachedItemGroups, nullptr, nullptr);
} catch (const std::invalid_argument&) {
missingReleaseRejected = true;
}
assert(missingReleaseRejected && cachedItemKernel.itemHasProcess(0x100) && cachedItemGroups[1] == 4);
remorse::u16 releasedItem = 0;
struct ItemRunContext {
remorse::ProcessKernel* kernel;
remorse::u16 (*groups)[32];
remorse::u16* released;
} itemRunContext{&cachedItemKernel, &cachedItemGroups, &releasedItem};
cachedItemKernel.scanRunnableProcesses(1, [](remorse::EntityDispatchEntryBase& process, void* context) {
auto& state = *static_cast<ItemRunContext*>(context);
if (process.bytes[0] == 0x2f && process.bytes[1] == 0x10) {
remorse::ItemProcess::run(process, *state.kernel, *state.groups,
[](remorse::u16 itemNumber, remorse::u32 eventMask, remorse::u16 eventId, void* result) {
assert(eventMask == 0x200 && eventId == 9);
*static_cast<remorse::u16*>(result) = itemNumber;
},
state.released);
}
}, &itemRunContext);
assert(releasedItem == 0x100 && !cachedItemKernel.itemHasProcess(0x100));
assert(cachedItemKernel.itemProcessTypes(0x100) == 0);
assert(cachedItemKernel.processAt(3) == nullptr && cachedItemGroups[1] == 3);
bool itemTeardownRejected = false;
try {
standKernel.terminateProcess(1, standGroups);