Fix for tests

This commit is contained in:
Ken Van Hoeylandt 2026-02-06 14:43:45 +01:00
parent fbfdc8f2fb
commit 0e77989bd5
2 changed files with 9 additions and 3 deletions

View File

@ -8,7 +8,7 @@
#define TAG "module" #define TAG "module"
struct ModuleInternal { struct ModuleInternal {
bool started; bool started = false;
}; };
struct ModuleLedger { struct ModuleLedger {
@ -24,7 +24,7 @@ static ModuleLedger ledger;
extern "C" { extern "C" {
error_t module_construct(struct Module* module) { error_t module_construct(struct Module* module) {
module->internal = new (std::nothrow) ModuleInternal { .started = false }; module->internal = new (std::nothrow) ModuleInternal();
if (module->internal == nullptr) return ERROR_OUT_OF_MEMORY; if (module->internal == nullptr) return ERROR_OUT_OF_MEMORY;
return ERROR_NONE; return ERROR_NONE;
} }

View File

@ -64,6 +64,8 @@ TEST_CASE("Module lifecycle") {
.internal = nullptr .internal = nullptr
}; };
CHECK_EQ(module_construct(&module), ERROR_NONE);
// 1. Successful start (no parent required anymore) // 1. Successful start (no parent required anymore)
CHECK_EQ(module_start(&module), ERROR_NONE); CHECK_EQ(module_start(&module), ERROR_NONE);
CHECK_EQ(module_is_started(&module), true); CHECK_EQ(module_is_started(&module), true);
@ -104,6 +106,8 @@ TEST_CASE("Module lifecycle") {
// Clean up: fix stop result so we can stop it // Clean up: fix stop result so we can stop it
test_stop_result = ERROR_NONE; test_stop_result = ERROR_NONE;
CHECK_EQ(module_stop(&module), ERROR_NONE); CHECK_EQ(module_stop(&module), ERROR_NONE);
CHECK_EQ(module_destruct(&module), ERROR_NONE);
} }
TEST_CASE("Global symbol resolution") { TEST_CASE("Global symbol resolution") {
@ -120,6 +124,8 @@ TEST_CASE("Global symbol resolution") {
.internal = nullptr .internal = nullptr
}; };
REQUIRE_EQ(module_construct(&module), ERROR_NONE);
uintptr_t addr; uintptr_t addr;
// Should fail as it is not added or started // Should fail as it is not added or started
CHECK_EQ(module_resolve_symbol_global("symbol_test_function", &addr), false); CHECK_EQ(module_resolve_symbol_global("symbol_test_function", &addr), false);
@ -128,8 +134,8 @@ TEST_CASE("Global symbol resolution") {
REQUIRE_EQ(module_start(&module), ERROR_NONE); REQUIRE_EQ(module_start(&module), ERROR_NONE);
// Still fails as symbols are null // Still fails as symbols are null
CHECK_EQ(module_resolve_symbol_global("symbol_test_function", &addr), true); CHECK_EQ(module_resolve_symbol_global("symbol_test_function", &addr), true);
// Cleanup // Cleanup
CHECK_EQ(module_remove(&module), ERROR_NONE); CHECK_EQ(module_remove(&module), ERROR_NONE);
CHECK_EQ(module_destruct(&module), ERROR_NONE); CHECK_EQ(module_destruct(&module), ERROR_NONE);
} }