1#ifndef YAZE_APP_TEST_CORE_SYSTEMS_TEST_SUITE_H_
2#define YAZE_APP_TEST_CORE_SYSTEMS_TEST_SUITE_H_
9#include "absl/strings/str_format.h"
32 std::string
GetName()
const override {
return "Core Systems Tests"; }
50 return absl::OkStatus();
54 ImGui::Text(
"Core Systems Test Configuration");
68 "ContentRegistry testing disabled");
72 auto start_time = std::chrono::steady_clock::now();
74 CreateResult(
"ContentRegistry_Context_SetRom", start_time);
85 if (retrieved == &test_rom) {
88 "ContentRegistry::Context::SetRom works correctly";
91 result.
error_message =
"ContentRegistry returned wrong ROM pointer";
97 }
catch (
const std::exception& e) {
100 "ContentRegistry SetRom test failed: " + std::string(e.what());
109 "ContentRegistry testing disabled");
113 auto start_time = std::chrono::steady_clock::now();
115 CreateResult(
"ContentRegistry_Context_Clear", start_time);
127 if (retrieved ==
nullptr) {
130 "ContentRegistry::Context::Clear works correctly";
134 "ContentRegistry::Context::Clear did not reset ROM";
140 }
catch (
const std::exception& e) {
143 "ContentRegistry Clear test failed: " + std::string(e.what());
152 "ContentRegistry testing disabled");
156 auto start_time = std::chrono::steady_clock::now();
158 CreateResult(
"ContentRegistry_Panel_Registration", start_time);
163 size_t count_before = panels_before.size();
171 "Panel registry API accessible: %zu panels registered",
172 panels_after.size());
174 }
catch (
const std::exception& e) {
177 "Panel registration test failed: " + std::string(e.what());
186 "ContentRegistry testing disabled");
190 auto start_time = std::chrono::steady_clock::now();
192 CreateResult(
"ContentRegistry_Thread_Safety", start_time);
199 Rom test_rom1, test_rom2;
200 bool all_reads_valid =
true;
202 for (
int i = 0; i < 100; ++i) {
206 if (read != &test_rom1 && read != &test_rom2) {
207 all_reads_valid =
false;
212 if (all_reads_valid) {
214 result.
error_message =
"ContentRegistry handles rapid access patterns";
218 "ContentRegistry returned invalid pointer during rapid access";
224 }
catch (
const std::exception& e) {
227 "Thread safety test failed: " + std::string(e.what());
236 "ContentRegistry testing disabled");
240 auto start_time = std::chrono::steady_clock::now();
242 CreateResult(
"PanelManager_Scope_Registration", start_time);
247 std::string GetId()
const override {
return "test.session_panel"; }
248 std::string GetDisplayName()
const override {
return "Test Session"; }
249 std::string GetIcon()
const override {
return ""; }
250 std::string GetEditorCategory()
const override {
return "Test"; }
251 void Draw(
bool*)
override {}
256 std::string GetId()
const override {
return "test.global_panel"; }
257 std::string GetDisplayName()
const override {
return "Test Global"; }
258 std::string GetIcon()
const override {
return ""; }
259 std::string GetEditorCategory()
const override {
return "Test"; }
261 return editor::WindowScope::kGlobal;
263 void Draw(
bool*)
override {}
266 PanelManager panel_manager;
267 panel_manager.RegisterRegistryPanel(std::make_unique<TestSessionPanel>());
268 panel_manager.RegisterRegistryPanel(std::make_unique<TestGlobalPanel>());
269 panel_manager.RegisterRegistryPanelsForSession(0);
270 panel_manager.RegisterRegistryPanelsForSession(1);
272 const auto* session0 =
273 panel_manager.GetPanelDescriptor(0,
"test.session_panel");
274 const auto* session1 =
275 panel_manager.GetPanelDescriptor(1,
"test.session_panel");
276 const auto* global0 =
277 panel_manager.GetPanelDescriptor(0,
"test.global_panel");
278 const auto* global1 =
279 panel_manager.GetPanelDescriptor(1,
"test.global_panel");
281 bool all_ok = (session0 && session1 && global0 && global1);
283 all_ok &= (session0->card_id != session1->card_id);
284 all_ok &= (global0->card_id ==
"test.global_panel");
285 all_ok &= (global1->card_id ==
"test.global_panel");
291 "PanelManager registers session/global descriptors correctly";
295 "Panel scope registration did not create expected descriptors";
297 }
catch (
const std::exception& e) {
300 "Panel scope registration test failed: " + std::string(e.what());
313 "EventBus testing disabled");
317 auto start_time = std::chrono::steady_clock::now();
323 int received_value = 0;
329 received_value =
static_cast<int>(e.session_id);
336 if (call_count == 1 && received_value == 42) {
338 result.
error_message =
"EventBus subscribe/publish works correctly";
342 "EventBus failed: call_count=%d (expected 1), received=%d "
344 call_count, received_value);
347 }
catch (
const std::exception& e) {
350 "EventBus subscribe/publish test failed: " + std::string(e.what());
359 "EventBus testing disabled");
363 auto start_time = std::chrono::steady_clock::now();
376 int count_after_first = call_count;
383 int count_after_second = call_count;
385 if (count_after_first == 1 && count_after_second == 1) {
387 result.
error_message =
"EventBus unsubscribe works correctly";
391 "Unsubscribe failed: after_first=%d, after_second=%d (expected 1, "
393 count_after_first, count_after_second);
396 }
catch (
const std::exception& e) {
399 "EventBus unsubscribe test failed: " + std::string(e.what());
408 "EventBus testing disabled");
412 auto start_time = std::chrono::steady_clock::now();
414 CreateResult(
"EventBus_Multiple_Subscribers", start_time);
418 int subscriber1_calls = 0;
419 int subscriber2_calls = 0;
420 int subscriber3_calls = 0;
433 if (subscriber1_calls == 1 && subscriber2_calls == 1 &&
434 subscriber3_calls == 1) {
436 result.
error_message =
"All 3 subscribers received the event";
440 "Multiple subscribers failed: s1=%d, s2=%d, s3=%d (expected 1,1,1)",
441 subscriber1_calls, subscriber2_calls, subscriber3_calls);
444 }
catch (
const std::exception& e) {
447 "Multiple subscribers test failed: " + std::string(e.what());
456 "EventBus testing disabled");
460 auto start_time = std::chrono::steady_clock::now();
465 int rom_loaded_calls = 0;
466 int session_closed_calls = 0;
477 if (rom_loaded_calls == 1 && session_closed_calls == 0) {
479 result.
error_message =
"EventBus correctly routes events by type";
483 "Type safety failed: rom_loaded=%d, session_closed=%d (expected 1, "
485 rom_loaded_calls, session_closed_calls);
488 }
catch (
const std::exception& e) {
491 "Type safety test failed: " + std::string(e.what());
500 "Core events testing disabled");
504 auto start_time = std::chrono::steady_clock::now();
513 auto session_switched =
523 bool all_correct =
true;
524 all_correct &= (rom_loaded.filename ==
"test.sfc");
525 all_correct &= (rom_loaded.session_id == 1);
526 all_correct &= (rom_unloaded.session_id == 2);
527 all_correct &= (rom_modified.address == 0x1000);
528 all_correct &= (rom_modified.byte_count == 16);
529 all_correct &= (session_switched.old_index == 0);
530 all_correct &= (session_switched.new_index == 1);
531 all_correct &= (session_created.index == 4);
532 all_correct &= (session_closed.index == 5);
533 all_correct &= (editor_switched.editor_type == 1);
534 all_correct &= (frame_begin.delta_time > 0.0f);
535 all_correct &= (frame_gui_begin.delta_time > 0.0f);
536 all_correct &= (frame_end.delta_time > 0.0f);
540 result.
error_message =
"All core event factory methods work correctly";
544 "Some event factory methods returned wrong values";
547 }
catch (
const std::exception& e) {
550 "Core events creation test failed: " + std::string(e.what());
561 const std::string& name,
562 std::chrono::time_point<std::chrono::steady_clock> start_time) {
573 std::chrono::time_point<std::chrono::steady_clock> start_time,
575 auto end_time = std::chrono::steady_clock::now();
576 result.
duration = std::chrono::duration_cast<std::chrono::milliseconds>(
577 end_time - start_time);
582 const std::string& reason) {
589 result.
duration = std::chrono::milliseconds{0};
590 result.
timestamp = std::chrono::steady_clock::now();
void Publish(const T &event)
void Unsubscribe(HandlerId id)
HandlerId Subscribe(std::function< void(const T &)> handler)
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Base interface for all logical window content components.
Test suite for core infrastructure: ContentRegistry and EventBus.
void DrawConfiguration() override
void RunEventBusTypeSafetyTest(TestResults &results)
bool test_content_registry_
std::string GetName() const override
void RunEventBusUnsubscribeTest(TestResults &results)
void RunCoreEventsCreationTest(TestResults &results)
void RunContentRegistryPanelRegistrationTest(TestResults &results)
void RunEventBusMultipleSubscribersTest(TestResults &results)
void RunContentRegistryContextClearTest(TestResults &results)
void AddSkippedResult(TestResults &results, const std::string &name, const std::string &reason)
~CoreSystemsTestSuite() override=default
CoreSystemsTestSuite()=default
absl::Status RunTests(TestResults &results) override
TestCategory GetCategory() const override
void FinalizeResult(TestResult &result, std::chrono::time_point< std::chrono::steady_clock > start_time, TestResults &results)
TestResult CreateResult(const std::string &name, std::chrono::time_point< std::chrono::steady_clock > start_time)
void RunContentRegistryThreadSafetyTest(TestResults &results)
void RunPanelScopeRegistrationTest(TestResults &results)
void RunContentRegistryContextSetRomTest(TestResults &results)
void RunEventBusSubscribePublishTest(TestResults &results)
Rom * rom()
Get the current ROM instance.
void SetRom(Rom *rom)
Set the current ROM instance.
void Clear()
Clear all context state.
std::vector< WindowContent * > GetAll()
Get all registered panels.
WindowScope
Defines whether a window is session-scoped or global.
static EditorSwitchedEvent Create(int type, void *ed)
static FrameBeginEvent Create(float dt)
static FrameEndEvent Create(float dt)
Published after ImGui::NewFrame and dockspace creation.
static FrameGuiBeginEvent Create(float dt)
Published when a ROM is successfully loaded into a session.
static RomLoadedEvent Create(Rom *r, const std::string &file, size_t session)
static RomModifiedEvent Create(Rom *r, size_t session, uint32_t addr=0, size_t bytes=0)
static RomUnloadedEvent Create(size_t session)
Published when a session is closed.
static SessionClosedEvent Create(size_t idx)
static SessionCreatedEvent Create(size_t idx, RomSession *sess)
static SessionSwitchedEvent Create(size_t old_idx, size_t new_idx, RomSession *sess)
std::chrono::milliseconds duration
std::string error_message
std::chrono::time_point< std::chrono::steady_clock > timestamp
void AddResult(const TestResult &result)