test(rom): add role-based ROM selection

This commit is contained in:
scawful
2025-12-22 14:49:04 -05:00
parent df866b3f7f
commit 42ae359abc
30 changed files with 488 additions and 265 deletions

View File

@@ -21,7 +21,7 @@ namespace test {
*/
void E2ETest_AIVisionVerification(ImGuiTestContext* ctx) {
// Load ROM first
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
// Open the overworld editor
gui::OpenEditorInTest(ctx, "Overworld");
@@ -80,7 +80,7 @@ void E2ETest_AIVisionVerification(ImGuiTestContext* ctx) {
* using pixel-level comparison against reference images.
*/
void E2ETest_ScreenshotAssertion(ImGuiTestContext* ctx) {
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
gui::OpenEditorInTest(ctx, "Graphics");
ctx->Yield(10);
@@ -144,7 +144,7 @@ void E2ETest_ScreenshotAssertion(ImGuiTestContext* ctx) {
* for comprehensive UI testing.
*/
void E2ETest_HybridAIScreenshotTest(ImGuiTestContext* ctx) {
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
gui::OpenEditorInTest(ctx, "Dungeon");
ctx->Yield(10);

View File

@@ -5,7 +5,7 @@
#include "test_utils.h"
void E2ETest_CanvasSelectionTest(ImGuiTestContext* ctx) {
yaze::test::gui::LoadRomInTest(ctx, "zelda3.sfc");
yaze::test::gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
yaze::Controller* controller = (yaze::Controller*)ctx->Test->UserData;
yaze::zelda3::Overworld* overworld = controller->overworld();

View File

@@ -109,7 +109,7 @@ void E2ETest_DungeonCanvas_PanZoom(ImGuiTestContext* ctx) {
// Load ROM
ctx->LogInfo("Loading ROM...");
yaze::test::gui::LoadRomInTest(ctx, "zelda3.sfc");
yaze::test::gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
// Open dungeon editor and room
ctx->LogInfo("Opening Dungeon Editor...");
@@ -219,7 +219,7 @@ void E2ETest_DungeonCanvas_ObjectSelection(ImGuiTestContext* ctx) {
// Load ROM
ctx->LogInfo("Loading ROM...");
yaze::test::gui::LoadRomInTest(ctx, "zelda3.sfc");
yaze::test::gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
// Open dungeon editor
ctx->LogInfo("Opening Dungeon Editor...");
@@ -307,7 +307,7 @@ void E2ETest_DungeonCanvas_GridSnap(ImGuiTestContext* ctx) {
// Load ROM
ctx->LogInfo("Loading ROM...");
yaze::test::gui::LoadRomInTest(ctx, "zelda3.sfc");
yaze::test::gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
// Open dungeon editor
ctx->LogInfo("Opening Dungeon Editor...");
@@ -414,7 +414,7 @@ void E2ETest_DungeonCanvas_MultiSelect(ImGuiTestContext* ctx) {
// Load ROM
ctx->LogInfo("Loading ROM...");
yaze::test::gui::LoadRomInTest(ctx, "zelda3.sfc");
yaze::test::gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
// Open dungeon editor
ctx->LogInfo("Opening Dungeon Editor...");

View File

@@ -17,7 +17,7 @@ void E2ETest_DungeonEditorV2SmokeTest(ImGuiTestContext* ctx) {
// Load ROM first
ctx->LogInfo("Loading ROM...");
yaze::test::gui::LoadRomInTest(ctx, "zelda3.sfc");
yaze::test::gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
ctx->LogInfo("ROM loaded successfully");
// Open the Dungeon Editor

View File

@@ -52,7 +52,7 @@ bool SetupDungeonEditorWithRoom(ImGuiTestContext* ctx,
const char* room_hex = "0x00") {
// Load ROM
ctx->LogInfo("Loading ROM...");
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
// Open Dungeon Editor
ctx->LogInfo("Opening Dungeon Editor...");

View File

@@ -141,7 +141,7 @@ void E2ETest_DungeonObjectDrawing_BasicPlacement(ImGuiTestContext* ctx) {
// Step 1: Load ROM
ctx->LogInfo("Step 1: Loading ROM...");
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
ctx->Yield(10);
// Step 2: Open Dungeon Editor
@@ -216,7 +216,7 @@ void E2ETest_DungeonObjectDrawing_MultiLayerObjects(ImGuiTestContext* ctx) {
// Step 1: Load ROM and open editor
ctx->LogInfo("Step 1: Loading ROM and opening editor...");
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
gui::OpenEditorInTest(ctx, "Dungeon");
ctx->Yield(20);
@@ -287,7 +287,7 @@ void E2ETest_DungeonObjectDrawing_ObjectDeletion(ImGuiTestContext* ctx) {
// Step 1: Load ROM and open editor
ctx->LogInfo("Step 1: Loading ROM and opening editor...");
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
gui::OpenEditorInTest(ctx, "Dungeon");
ctx->Yield(20);
@@ -357,7 +357,7 @@ void E2ETest_DungeonObjectDrawing_ObjectRepositioning(ImGuiTestContext* ctx) {
// Step 1: Load ROM and open editor
ctx->LogInfo("Step 1: Loading ROM and opening editor...");
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
gui::OpenEditorInTest(ctx, "Dungeon");
ctx->Yield(20);

View File

@@ -14,7 +14,7 @@
* - Object repositioning via drag
*
* Requires:
* - ROM file for testing (zelda3.sfc)
* - ROM file for testing (alttp_vanilla.sfc)
* - GUI test mode (--ui flag)
*/

View File

@@ -49,7 +49,7 @@ void E2ETest_VisualVerification_BasicRoomRendering(ImGuiTestContext* ctx) {
// Load ROM
ctx->LogInfo("Loading ROM...");
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
// Open Dungeon Editor
ctx->LogInfo("Opening Dungeon Editor...");
@@ -102,7 +102,7 @@ void E2ETest_VisualVerification_LayerVisibility(ImGuiTestContext* ctx) {
ctx->LogInfo("=== Visual Verification: Layer Visibility ===");
// Load ROM and open editor
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
gui::OpenEditorInTest(ctx, "Dungeon");
ctx->Yield(20);
@@ -157,7 +157,7 @@ void E2ETest_VisualVerification_LayerVisibility(ImGuiTestContext* ctx) {
void E2ETest_VisualVerification_ObjectEditor(ImGuiTestContext* ctx) {
ctx->LogInfo("=== Visual Verification: Object Editor ===");
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
gui::OpenEditorInTest(ctx, "Dungeon");
ctx->Yield(20);
@@ -190,7 +190,7 @@ void E2ETest_VisualVerification_ObjectEditor(ImGuiTestContext* ctx) {
void E2ETest_VisualVerification_MultiRoomNavigation(ImGuiTestContext* ctx) {
ctx->LogInfo("=== Visual Verification: Multi-Room Navigation ===");
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
gui::OpenEditorInTest(ctx, "Dungeon");
ctx->Yield(20);

View File

@@ -16,7 +16,7 @@ namespace test {
* as single operations when the PC is at a JSR/JSL instruction.
*/
void E2ETest_EmulatorStepOver(ImGuiTestContext* ctx) {
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
// Open emulator
ctx->SetRef("Yaze");
@@ -61,7 +61,7 @@ void E2ETest_EmulatorStepOver(ImGuiTestContext* ctx) {
* subroutine returns (RTS/RTL).
*/
void E2ETest_EmulatorStepOut(ImGuiTestContext* ctx) {
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
ctx->SetRef("Yaze");
ctx->MenuClick("Emulation/Launch Emulator");
@@ -95,7 +95,7 @@ void E2ETest_EmulatorStepOut(ImGuiTestContext* ctx) {
* across JSR/JSL calls and RTS/RTL returns.
*/
void E2ETest_EmulatorCallStackTracking(ImGuiTestContext* ctx) {
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
ctx->SetRef("Yaze");
ctx->MenuClick("Emulation/Launch Emulator");
@@ -138,7 +138,7 @@ void E2ETest_EmulatorCallStackTracking(ImGuiTestContext* ctx) {
* This test verifies running execution until a specific address is reached.
*/
void E2ETest_EmulatorRunToAddress(ImGuiTestContext* ctx) {
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
ctx->SetRef("Yaze");
ctx->MenuClick("Emulation/Launch Emulator");
@@ -168,7 +168,7 @@ void E2ETest_EmulatorRunToAddress(ImGuiTestContext* ctx) {
* for AI-driven analysis or automation.
*/
void E2ETest_EmulatorInstructionCallback(ImGuiTestContext* ctx) {
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
ctx->SetRef("Yaze");
ctx->MenuClick("Emulation/Launch Emulator");

View File

@@ -9,7 +9,7 @@
// It opens a window, clicks a button, and verifies that the button was clicked.
// The GUI for this test is rendered in `test/yaze_test.cc`.
void E2ETest_FrameworkSmokeTest(ImGuiTestContext* ctx) {
yaze::test::gui::LoadRomInTest(ctx, "zelda3.sfc");
yaze::test::gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
ctx->SetRef("Hello World Window");
ctx->ItemClick("Button");
ctx->ItemCheck("Clicked 1 times");

View File

@@ -102,7 +102,7 @@ void E2ETest_ImGuiMouseInteraction(ImGuiTestContext* ctx) {
* - Arrow keys for navigation
*/
void E2ETest_ImGuiKeyboardShortcuts(ImGuiTestContext* ctx) {
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
ctx->SetRef("Yaze");
ctx->WindowFocus("Overworld Editor");
@@ -169,7 +169,7 @@ void E2ETest_ImGuiWidgetState(ImGuiTestContext* ctx) {
* the ImGui Test Engine for comprehensive visual verification.
*/
void E2ETest_ImGuiWithScreenshotAssertion(ImGuiTestContext* ctx) {
gui::LoadRomInTest(ctx, "zelda3.sfc");
gui::LoadRomInTest(ctx, yaze::test::TestRomManager::GetTestRomPath());
ctx->SetRef("Yaze");
ctx->MenuClick("View/Graphics Editor");

View File

@@ -8,6 +8,7 @@
#include "rom/rom.h"
#include "rom/transaction.h"
#include "test/test_utils.h"
#include "testing.h"
#include "util/macro.h"
@@ -27,18 +28,10 @@ namespace test {
class E2ERomDependentTest : public ::testing::Test {
protected:
void SetUp() override {
// Skip tests if ROM is not available
if (getenv("YAZE_SKIP_ROM_TESTS")) {
GTEST_SKIP() << "ROM tests disabled";
}
// Get ROM path from environment or use default
const char* rom_path_env = getenv("YAZE_TEST_ROM_PATH");
vanilla_rom_path_ = rom_path_env ? rom_path_env : "zelda3.sfc";
if (!std::filesystem::exists(vanilla_rom_path_)) {
GTEST_SKIP() << "Test ROM not found: " << vanilla_rom_path_;
}
yaze::test::TestRomManager::SkipIfRomMissing(
yaze::test::RomRole::kVanilla, "E2ERomDependentTest");
vanilla_rom_path_ =
yaze::test::TestRomManager::GetRomPath(yaze::test::RomRole::kVanilla);
// Create test ROM copies
test_rom_path_ = "test_rom_edit.sfc";
@@ -69,10 +62,10 @@ class E2ERomDependentTest : public ::testing::Test {
EXPECT_EQ(rom->size(), 0x200000) << "ROM size should be 2MB";
EXPECT_NE(rom->data(), nullptr) << "ROM data should not be null";
// Check ROM header
auto header_byte = rom->ReadByte(0x7FC0);
RETURN_IF_ERROR(header_byte.status());
EXPECT_EQ(*header_byte, 0x21) << "ROM should be LoROM format";
// Check ROM mapping mode (LoROM expected)
auto map_mode = rom->ReadByte(0x7FD5);
RETURN_IF_ERROR(map_mode.status());
EXPECT_EQ(*map_mode & 0x01, 0) << "ROM should be LoROM format";
return absl::OkStatus();
}
@@ -273,4 +266,4 @@ TEST_F(E2ERomDependentTest, LargeScaleEditing) {
}
} // namespace test
} // namespace yaze
} // namespace yaze

View File

@@ -12,9 +12,11 @@
#include "absl/status/status.h"
#include "rom/rom.h"
#include "rom/snes.h"
#include "test/test_utils.h"
#include "testing.h"
#include "util/macro.h"
#include "zelda.h"
#include "zelda3/overworld/overworld_version_helper.h"
namespace yaze {
namespace test {
@@ -30,28 +32,6 @@ struct RomVersionInfo {
uint8_t zscustom_version; // 0xFF = vanilla, 0x02 = v2, 0x03+ = v3+
};
/**
* @brief Environment variable names for ROM paths
*/
struct RomEnvVars {
static constexpr const char* kDefaultRomPath = "YAZE_TEST_ROM_PATH";
static constexpr const char* kSkipRomTests = "YAZE_SKIP_ROM_TESTS";
static constexpr const char* kJpRomPath = "YAZE_TEST_ROM_JP_PATH";
static constexpr const char* kUsRomPath = "YAZE_TEST_ROM_US_PATH";
static constexpr const char* kEuRomPath = "YAZE_TEST_ROM_EU_PATH";
static constexpr const char* kExpandedRomPath = "YAZE_TEST_ROM_EXPANDED_PATH";
};
/**
* @brief Default ROM paths relative to workspace (roms/ directory)
*/
struct DefaultRomPaths {
static constexpr const char* kVanilla = "roms/alttp_vanilla.sfc";
static constexpr const char* kUsRom = "roms/Legend of Zelda, The - A Link to the Past (USA).sfc";
static constexpr const char* kExpanded = "roms/oos168.sfc";
static constexpr const char* kFallback = "zelda3.sfc";
};
/**
* @brief Base test fixture for E2E editor save tests
*
@@ -64,24 +44,8 @@ struct DefaultRomPaths {
class EditorSaveTestBase : public ::testing::Test {
protected:
void SetUp() override {
// Skip tests if ROM tests are disabled
if (getenv(RomEnvVars::kSkipRomTests)) {
GTEST_SKIP() << "ROM tests disabled via YAZE_SKIP_ROM_TESTS";
}
// Determine ROM path
const char* rom_path_env = getenv(RomEnvVars::kDefaultRomPath);
if (rom_path_env && std::filesystem::exists(rom_path_env)) {
vanilla_rom_path_ = rom_path_env;
} else if (std::filesystem::exists(DefaultRomPaths::kVanilla)) {
vanilla_rom_path_ = DefaultRomPaths::kVanilla;
} else if (std::filesystem::exists(DefaultRomPaths::kUsRom)) {
vanilla_rom_path_ = DefaultRomPaths::kUsRom;
} else if (std::filesystem::exists(DefaultRomPaths::kFallback)) {
vanilla_rom_path_ = DefaultRomPaths::kFallback;
} else {
GTEST_SKIP() << "No test ROM found. Set YAZE_TEST_ROM_PATH or place ROM in roms/";
}
TestRomManager::SkipIfRomMissing(RomRole::kVanilla, "EditorSaveTestBase");
vanilla_rom_path_ = TestRomManager::GetRomPath(RomRole::kVanilla);
// Create test file paths with unique names per test
test_id_ = ::testing::UnitTest::GetInstance()->current_test_info()->name();
@@ -163,7 +127,7 @@ class EditorSaveTestBase : public ::testing::Test {
Rom::SaveSettings settings;
settings.filename = path;
settings.backup = false; // We handle backups ourselves
settings.save_new = true;
settings.save_new = false; // Overwrite the test copy for persistence checks
return rom->SaveToFile(settings);
}
@@ -183,9 +147,11 @@ class EditorSaveTestBase : public ::testing::Test {
auto version_byte = rom.ReadByte(0x140145);
info.zscustom_version = version_byte.ok() ? *version_byte : 0xFF;
// Detect expanded tile16
auto tile16_check = rom.ReadByte(0x02FD28);
info.is_expanded_tile16 = tile16_check.ok() && *tile16_check != 0x0F;
// Detect expanded tile16 based on applied ASM version (v1+ uses expanded space)
const auto overworld_version =
zelda3::OverworldVersionHelper::GetVersion(rom);
info.is_expanded_tile16 =
zelda3::OverworldVersionHelper::SupportsExpandedSpace(overworld_version);
// Detect expanded tile32
auto tile32_check = rom.ReadByte(0x01772E);
@@ -347,24 +313,14 @@ class EditorSaveTestBase : public ::testing::Test {
* @brief Get path to expanded ROM for v3 feature tests
*/
std::string GetExpandedRomPath() {
const char* expanded_path = getenv(RomEnvVars::kExpandedRomPath);
if (expanded_path && std::filesystem::exists(expanded_path)) {
return expanded_path;
}
if (std::filesystem::exists(DefaultRomPaths::kExpanded)) {
return DefaultRomPaths::kExpanded;
}
return ""; // Not available
return TestRomManager::GetRomPath(RomRole::kExpanded);
}
/**
* @brief Skip test if expanded ROM is required but not available
*/
void RequireExpandedRom() {
std::string path = GetExpandedRomPath();
if (path.empty()) {
GTEST_SKIP() << "Expanded ROM not available for v3 feature tests";
}
TestRomManager::SkipIfRomMissing(RomRole::kExpanded, "ExpandedRomSaveTest");
}
// ===========================================================================
@@ -386,21 +342,9 @@ class MultiVersionEditorSaveTest : public EditorSaveTestBase {
EditorSaveTestBase::SetUp();
// Check for additional ROM versions
const char* jp_path = getenv(RomEnvVars::kJpRomPath);
const char* us_path = getenv(RomEnvVars::kUsRomPath);
const char* eu_path = getenv(RomEnvVars::kEuRomPath);
if (jp_path && std::filesystem::exists(jp_path)) {
jp_rom_path_ = jp_path;
}
if (us_path && std::filesystem::exists(us_path)) {
us_rom_path_ = us_path;
} else if (std::filesystem::exists(DefaultRomPaths::kUsRom)) {
us_rom_path_ = DefaultRomPaths::kUsRom;
}
if (eu_path && std::filesystem::exists(eu_path)) {
eu_rom_path_ = eu_path;
}
jp_rom_path_ = TestRomManager::GetRomPath(RomRole::kJp);
us_rom_path_ = TestRomManager::GetRomPath(RomRole::kUs);
eu_rom_path_ = TestRomManager::GetRomPath(RomRole::kEu);
}
bool HasJpRom() const { return !jp_rom_path_.empty(); }
@@ -418,27 +362,11 @@ class MultiVersionEditorSaveTest : public EditorSaveTestBase {
class ExpandedRomSaveTest : public EditorSaveTestBase {
protected:
void SetUp() override {
// Skip if ROM tests disabled
if (getenv(RomEnvVars::kSkipRomTests)) {
GTEST_SKIP() << "ROM tests disabled via YAZE_SKIP_ROM_TESTS";
}
// Get expanded ROM path
const char* expanded_path = getenv(RomEnvVars::kExpandedRomPath);
if (expanded_path && std::filesystem::exists(expanded_path)) {
expanded_rom_path_ = expanded_path;
} else if (std::filesystem::exists(DefaultRomPaths::kExpanded)) {
expanded_rom_path_ = DefaultRomPaths::kExpanded;
} else {
GTEST_SKIP() << "Expanded ROM not available. Set YAZE_TEST_ROM_EXPANDED_PATH";
}
TestRomManager::SkipIfRomMissing(RomRole::kExpanded, "ExpandedRomSaveTest");
expanded_rom_path_ = TestRomManager::GetRomPath(RomRole::kExpanded);
// Use vanilla for baseline comparison
if (std::filesystem::exists(DefaultRomPaths::kVanilla)) {
vanilla_rom_path_ = DefaultRomPaths::kVanilla;
} else {
vanilla_rom_path_ = "";
}
vanilla_rom_path_ = TestRomManager::GetRomPath(RomRole::kVanilla);
// Create test file paths
test_id_ = ::testing::UnitTest::GetInstance()->current_test_info()->name();