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"
31 std::string
GetName()
const override {
return "Core Systems Tests"; }
49 return absl::OkStatus();
53 ImGui::Text(
"Core Systems Test Configuration");
67 "ContentRegistry testing disabled");
71 auto start_time = std::chrono::steady_clock::now();
84 if (retrieved == &test_rom) {
86 result.
error_message =
"ContentRegistry::Context::SetRom works correctly";
89 result.
error_message =
"ContentRegistry returned wrong ROM pointer";
95 }
catch (
const std::exception& e) {
98 "ContentRegistry SetRom test failed: " + std::string(e.what());
107 "ContentRegistry testing disabled");
111 auto start_time = std::chrono::steady_clock::now();
125 if (retrieved ==
nullptr) {
127 result.
error_message =
"ContentRegistry::Context::Clear works correctly";
130 result.
error_message =
"ContentRegistry::Context::Clear did not reset ROM";
136 }
catch (
const std::exception& e) {
139 "ContentRegistry Clear test failed: " + std::string(e.what());
148 "ContentRegistry testing disabled");
152 auto start_time = std::chrono::steady_clock::now();
159 size_t count_before = panels_before.size();
167 "Panel registry API accessible: %zu panels registered",
168 panels_after.size());
170 }
catch (
const std::exception& e) {
173 "Panel registration test failed: " + std::string(e.what());
182 "ContentRegistry testing disabled");
186 auto start_time = std::chrono::steady_clock::now();
195 Rom test_rom1, test_rom2;
196 bool all_reads_valid =
true;
198 for (
int i = 0; i < 100; ++i) {
201 if (read != &test_rom1 && read != &test_rom2) {
202 all_reads_valid =
false;
207 if (all_reads_valid) {
209 result.
error_message =
"ContentRegistry handles rapid access patterns";
212 result.
error_message =
"ContentRegistry returned invalid pointer during rapid access";
218 }
catch (
const std::exception& e) {
221 "Thread safety test failed: " + std::string(e.what());
230 "ContentRegistry testing disabled");
234 auto start_time = std::chrono::steady_clock::now();
241 std::string GetId()
const override {
return "test.session_panel"; }
242 std::string GetDisplayName()
const override {
return "Test Session"; }
243 std::string GetIcon()
const override {
return ""; }
244 std::string GetEditorCategory()
const override {
return "Test"; }
245 void Draw(
bool*)
override {}
250 std::string GetId()
const override {
return "test.global_panel"; }
251 std::string GetDisplayName()
const override {
return "Test Global"; }
252 std::string GetIcon()
const override {
return ""; }
253 std::string GetEditorCategory()
const override {
return "Test"; }
255 return editor::PanelScope::kGlobal;
257 void Draw(
bool*)
override {}
260 PanelManager panel_manager;
261 panel_manager.RegisterRegistryPanel(std::make_unique<TestSessionPanel>());
262 panel_manager.RegisterRegistryPanel(std::make_unique<TestGlobalPanel>());
263 panel_manager.RegisterRegistryPanelsForSession(0);
264 panel_manager.RegisterRegistryPanelsForSession(1);
266 const auto* session0 =
267 panel_manager.GetPanelDescriptor(0,
"test.session_panel");
268 const auto* session1 =
269 panel_manager.GetPanelDescriptor(1,
"test.session_panel");
270 const auto* global0 =
271 panel_manager.GetPanelDescriptor(0,
"test.global_panel");
272 const auto* global1 =
273 panel_manager.GetPanelDescriptor(1,
"test.global_panel");
275 bool all_ok = (session0 && session1 && global0 && global1);
277 all_ok &= (session0->card_id != session1->card_id);
278 all_ok &= (global0->card_id ==
"test.global_panel");
279 all_ok &= (global1->card_id ==
"test.global_panel");
285 "PanelManager registers session/global descriptors correctly";
289 "Panel scope registration did not create expected descriptors";
291 }
catch (
const std::exception& e) {
294 "Panel scope registration test failed: " + std::string(e.what());
307 "EventBus testing disabled");
311 auto start_time = std::chrono::steady_clock::now();
317 int received_value = 0;
323 received_value =
static_cast<int>(e.session_id);
330 if (call_count == 1 && received_value == 42) {
332 result.
error_message =
"EventBus subscribe/publish works correctly";
336 "EventBus failed: call_count=%d (expected 1), received=%d (expected 42)",
337 call_count, received_value);
340 }
catch (
const std::exception& e) {
343 "EventBus subscribe/publish test failed: " + std::string(e.what());
352 "EventBus testing disabled");
356 auto start_time = std::chrono::steady_clock::now();
369 int count_after_first = call_count;
376 int count_after_second = call_count;
378 if (count_after_first == 1 && count_after_second == 1) {
380 result.
error_message =
"EventBus unsubscribe works correctly";
384 "Unsubscribe failed: after_first=%d, after_second=%d (expected 1, 1)",
385 count_after_first, count_after_second);
388 }
catch (
const std::exception& e) {
391 "EventBus unsubscribe test failed: " + std::string(e.what());
400 "EventBus testing disabled");
404 auto start_time = std::chrono::steady_clock::now();
410 int subscriber1_calls = 0;
411 int subscriber2_calls = 0;
412 int subscriber3_calls = 0;
425 if (subscriber1_calls == 1 && subscriber2_calls == 1 &&
426 subscriber3_calls == 1) {
428 result.
error_message =
"All 3 subscribers received the event";
432 "Multiple subscribers failed: s1=%d, s2=%d, s3=%d (expected 1,1,1)",
433 subscriber1_calls, subscriber2_calls, subscriber3_calls);
436 }
catch (
const std::exception& e) {
439 "Multiple subscribers test failed: " + std::string(e.what());
448 "EventBus testing disabled");
452 auto start_time = std::chrono::steady_clock::now();
457 int rom_loaded_calls = 0;
458 int session_closed_calls = 0;
469 if (rom_loaded_calls == 1 && session_closed_calls == 0) {
472 "EventBus correctly routes events by type";
476 "Type safety failed: rom_loaded=%d, session_closed=%d (expected 1, 0)",
477 rom_loaded_calls, session_closed_calls);
480 }
catch (
const std::exception& e) {
483 "Type safety test failed: " + std::string(e.what());
492 "Core events testing disabled");
496 auto start_time = std::chrono::steady_clock::now();
513 bool all_correct =
true;
514 all_correct &= (rom_loaded.filename ==
"test.sfc");
515 all_correct &= (rom_loaded.session_id == 1);
516 all_correct &= (rom_unloaded.session_id == 2);
517 all_correct &= (rom_modified.address == 0x1000);
518 all_correct &= (rom_modified.byte_count == 16);
519 all_correct &= (session_switched.old_index == 0);
520 all_correct &= (session_switched.new_index == 1);
521 all_correct &= (session_created.index == 4);
522 all_correct &= (session_closed.index == 5);
523 all_correct &= (editor_switched.editor_type == 1);
524 all_correct &= (frame_begin.delta_time > 0.0f);
525 all_correct &= (frame_gui_begin.delta_time > 0.0f);
526 all_correct &= (frame_end.delta_time > 0.0f);
531 "All core event factory methods work correctly";
534 result.
error_message =
"Some event factory methods returned wrong values";
537 }
catch (
const std::exception& e) {
540 "Core events creation test failed: " + std::string(e.what());
551 const std::string& name,
552 std::chrono::time_point<std::chrono::steady_clock> start_time) {
563 std::chrono::time_point<std::chrono::steady_clock> start_time,
565 auto end_time = std::chrono::steady_clock::now();
566 result.
duration = std::chrono::duration_cast<std::chrono::milliseconds>(
567 end_time - start_time);
572 const std::string& reason) {
579 result.
duration = std::chrono::milliseconds{0};
580 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 panel 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< EditorPanel * > GetAll()
Get all registered panels.
PanelScope
Defines whether a panel 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)