Add E2E and ZSCustomOverworld test suites for comprehensive testing

- Introduced new E2E test suite for comprehensive ROM testing, validating the complete ROM editing workflow.
- Added ZSCustomOverworld test suite to validate version upgrades and data integrity.
- Updated `EditorManager` to register the new test suites.
- Enhanced CMake configuration to include the new test files.
- Updated README to reflect the new testing capabilities and best practices for AI agent testing.
This commit is contained in:
scawful
2025-09-28 15:11:31 -04:00
parent ddf63165eb
commit 97f00d3fc6
42 changed files with 2090 additions and 5027 deletions

View File

@@ -0,0 +1,189 @@
#define IMGUI_DEFINE_MATH_OPERATORS
#include "test/editor/editor_integration_test.h"
#include <SDL.h>
#include "app/core/window.h"
#include "app/gui/style.h"
#include "imgui/backends/imgui_impl_sdl2.h"
#include "imgui/backends/imgui_impl_sdlrenderer2.h"
#include "imgui/imgui.h"
#include "imgui_test_engine/imgui_te_context.h"
#include "imgui_test_engine/imgui_te_engine.h"
#include "imgui_test_engine/imgui_te_imconfig.h"
#include "imgui_test_engine/imgui_te_ui.h"
namespace yaze {
namespace test {
EditorIntegrationTest::EditorIntegrationTest()
: engine_(nullptr), show_demo_window_(true) {}
EditorIntegrationTest::~EditorIntegrationTest() {
if (engine_) {
ImGuiTestEngine_Stop(engine_);
ImGuiTestEngine_DestroyContext(engine_);
}
}
absl::Status EditorIntegrationTest::Initialize() {
RETURN_IF_ERROR(core::CreateWindow(window_, SDL_WINDOW_RESIZABLE));
IMGUI_CHECKVERSION();
ImGui::CreateContext();
// Initialize Test Engine
engine_ = ImGuiTestEngine_CreateContext();
ImGuiTestEngineIO& test_io = ImGuiTestEngine_GetIO(engine_);
test_io.ConfigVerboseLevel = ImGuiTestVerboseLevel_Info;
test_io.ConfigVerboseLevelOnError = ImGuiTestVerboseLevel_Debug;
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
// Initialize ImGui for SDL
ImGui_ImplSDL2_InitForSDLRenderer(
controller_.window(), yaze::core::Renderer::Get().renderer());
ImGui_ImplSDLRenderer2_Init(yaze::core::Renderer::Get().renderer());
// Register tests
RegisterTests(engine_);
ImGuiTestEngine_Start(engine_, ImGui::GetCurrentContext());
controller_.set_active(true);
// Set the default style
yaze::gui::ColorsYaze();
return absl::OkStatus();
}
int EditorIntegrationTest::RunTest() {
auto status = Initialize();
if (!status.ok()) {
return EXIT_FAILURE;
}
// Build a new ImGui frame
ImGui_ImplSDLRenderer2_NewFrame();
ImGui_ImplSDL2_NewFrame();
while (controller_.IsActive()) {
controller_.OnInput();
auto status = Update();
if (!status.ok()) {
return EXIT_FAILURE;
}
controller_.DoRender();
}
return EXIT_SUCCESS;
}
absl::Status EditorIntegrationTest::Update() {
ImGui::NewFrame();
// Show test engine windows
ImGuiTestEngine_ShowTestEngineWindows(engine_, &show_demo_window_);
return absl::OkStatus();
}
// Helper methods for testing with a ROM
absl::Status EditorIntegrationTest::LoadTestRom(const std::string& filename) {
test_rom_ = std::make_unique<Rom>();
return test_rom_->LoadFromFile(filename);
}
absl::Status EditorIntegrationTest::SaveTestRom(const std::string& filename) {
if (!test_rom_) {
return absl::FailedPreconditionError("No test ROM loaded");
}
Rom::SaveSettings settings;
settings.backup = false;
settings.save_new = false;
settings.filename = filename;
return test_rom_->SaveToFile(settings);
}
absl::Status EditorIntegrationTest::TestEditorInitialize(editor::Editor* editor) {
if (!editor) {
return absl::InternalError("Editor is null");
}
editor->Initialize();
return absl::OkStatus();
}
absl::Status EditorIntegrationTest::TestEditorLoad(editor::Editor* editor) {
if (!editor) {
return absl::InternalError("Editor is null");
}
return editor->Load();
}
absl::Status EditorIntegrationTest::TestEditorSave(editor::Editor* editor) {
if (!editor) {
return absl::InternalError("Editor is null");
}
return editor->Save();
}
absl::Status EditorIntegrationTest::TestEditorUpdate(editor::Editor* editor) {
if (!editor) {
return absl::InternalError("Editor is null");
}
return editor->Update();
}
absl::Status EditorIntegrationTest::TestEditorCut(editor::Editor* editor) {
if (!editor) {
return absl::InternalError("Editor is null");
}
return editor->Cut();
}
absl::Status EditorIntegrationTest::TestEditorCopy(editor::Editor* editor) {
if (!editor) {
return absl::InternalError("Editor is null");
}
return editor->Copy();
}
absl::Status EditorIntegrationTest::TestEditorPaste(editor::Editor* editor) {
if (!editor) {
return absl::InternalError("Editor is null");
}
return editor->Paste();
}
absl::Status EditorIntegrationTest::TestEditorUndo(editor::Editor* editor) {
if (!editor) {
return absl::InternalError("Editor is null");
}
return editor->Undo();
}
absl::Status EditorIntegrationTest::TestEditorRedo(editor::Editor* editor) {
if (!editor) {
return absl::InternalError("Editor is null");
}
return editor->Redo();
}
absl::Status EditorIntegrationTest::TestEditorFind(editor::Editor* editor) {
if (!editor) {
return absl::InternalError("Editor is null");
}
return editor->Find();
}
absl::Status EditorIntegrationTest::TestEditorClear(editor::Editor* editor) {
if (!editor) {
return absl::InternalError("Editor is null");
}
return editor->Clear();
}
} // namespace test
} // namespace yaze

View File

@@ -0,0 +1,78 @@
#ifndef YAZE_TEST_EDITOR_INTEGRATION_TEST_H
#define YAZE_TEST_EDITOR_INTEGRATION_TEST_H
#define IMGUI_DEFINE_MATH_OPERATORS
#include "app/editor/editor.h"
#include "app/rom.h"
#include "app/core/controller.h"
#include "app/core/window.h"
#include "imgui_test_engine/imgui_te_context.h"
#include "imgui_test_engine/imgui_te_engine.h"
namespace yaze {
namespace test {
/**
* @class EditorIntegrationTest
* @brief Base class for editor integration tests
*
* This class provides common functionality for testing editors in the application.
* It sets up the test environment and provides helper methods for ROM operations.
*
* For UI interaction testing, use the ImGui test engine API directly within your test functions:
*
* ImGuiTest* test = IM_REGISTER_TEST(engine, "test_suite", "test_name");
* test->TestFunc = [](ImGuiTestContext* ctx) {
* ctx->SetRef("Window Name");
* ctx->ItemClick("Button Name");
* };
*/
class EditorIntegrationTest {
public:
EditorIntegrationTest();
~EditorIntegrationTest();
// Initialize the test environment
absl::Status Initialize();
// Run the test
int RunTest();
// Register tests for a specific editor
virtual void RegisterTests(ImGuiTestEngine* engine) = 0;
// Update the test environment
virtual absl::Status Update();
protected:
// Helper methods for testing with a ROM
absl::Status LoadTestRom(const std::string& filename);
absl::Status SaveTestRom(const std::string& filename);
// Helper methods for testing with a specific editor
absl::Status TestEditorInitialize(editor::Editor* editor);
absl::Status TestEditorLoad(editor::Editor* editor);
absl::Status TestEditorSave(editor::Editor* editor);
absl::Status TestEditorUpdate(editor::Editor* editor);
absl::Status TestEditorCut(editor::Editor* editor);
absl::Status TestEditorCopy(editor::Editor* editor);
absl::Status TestEditorPaste(editor::Editor* editor);
absl::Status TestEditorUndo(editor::Editor* editor);
absl::Status TestEditorRedo(editor::Editor* editor);
absl::Status TestEditorFind(editor::Editor* editor);
absl::Status TestEditorClear(editor::Editor* editor);
private:
core::Controller controller_;
ImGuiTestEngine* engine_;
std::unique_ptr<Rom> test_rom_;
bool show_demo_window_;
core::Window window_;
};
} // namespace test
} // namespace yaze
#endif // YAZE_TEST_EDITOR_INTEGRATION_TEST_H

View File

@@ -0,0 +1,301 @@
#include "app/editor/overworld/tile16_editor.h"
#include <iostream>
#include <memory>
#include <vector>
#include <gtest/gtest.h>
#include "app/rom.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/tilemap.h"
#include "app/zelda3/overworld/overworld.h"
#include "app/core/window.h"
namespace yaze {
namespace editor {
namespace test {
class Tile16EditorIntegrationTest : public ::testing::Test {
protected:
static void SetUpTestSuite() {
// Initialize SDL and rendering system once for all tests
InitializeTestEnvironment();
}
static void TearDownTestSuite() {
// Clean up SDL
if (window_initialized_) {
auto shutdown_result = core::ShutdownWindow(test_window_);
(void)shutdown_result; // Suppress unused variable warning
window_initialized_ = false;
}
}
void SetUp() override {
#ifdef YAZE_ENABLE_ROM_TESTS
if (!window_initialized_) {
GTEST_SKIP() << "Failed to initialize graphics system";
}
// Load the test ROM
rom_ = std::make_unique<Rom>();
auto load_result = rom_->LoadFromFile(YAZE_TEST_ROM_PATH);
ASSERT_TRUE(load_result.ok()) << "Failed to load test ROM: " << load_result.message();
// Load overworld data
overworld_ = std::make_unique<zelda3::Overworld>(rom_.get());
auto overworld_load_result = overworld_->Load(rom_.get());
ASSERT_TRUE(overworld_load_result.ok()) << "Failed to load overworld: " << overworld_load_result.message();
// Create tile16 blockset
auto tile16_data = overworld_->tile16_blockset_data();
auto palette = overworld_->current_area_palette();
tile16_blockset_ = std::make_unique<gfx::Tilemap>(
gfx::CreateTilemap(tile16_data, 0x80, 0x2000, 16,
zelda3::kNumTile16Individual, palette));
// Create graphics bitmap
current_gfx_bmp_ = std::make_unique<gfx::Bitmap>();
core::Renderer::Get().CreateAndRenderBitmap(0x80, 512, 0x40,
overworld_->current_graphics(),
*current_gfx_bmp_, palette);
// Create tile16 blockset bitmap
tile16_blockset_bmp_ = std::make_unique<gfx::Bitmap>();
core::Renderer::Get().CreateAndRenderBitmap(0x80, 0x2000, 0x08,
tile16_data,
*tile16_blockset_bmp_, palette);
// Initialize the tile16 editor
editor_ = std::make_unique<Tile16Editor>(rom_.get(), tile16_blockset_.get());
auto init_result = editor_->Initialize(*tile16_blockset_bmp_, *current_gfx_bmp_,
*overworld_->mutable_all_tiles_types());
ASSERT_TRUE(init_result.ok()) << "Failed to initialize editor: " << init_result.message();
rom_loaded_ = true;
#else
// Fallback for non-ROM tests
rom_ = std::make_unique<Rom>();
tilemap_ = std::make_unique<gfx::Tilemap>();
editor_ = std::make_unique<Tile16Editor>(rom_.get(), tilemap_.get());
rom_loaded_ = false;
#endif
}
protected:
static void InitializeTestEnvironment() {
auto window_result = core::CreateWindow(test_window_, SDL_WINDOW_HIDDEN);
if (window_result.ok()) {
window_initialized_ = true;
} else {
window_initialized_ = false;
// Log the error but don't fail test setup
std::cerr << "Failed to initialize test window: " << window_result.message() << std::endl;
}
}
static bool window_initialized_;
static core::Window test_window_;
bool rom_loaded_ = false;
std::unique_ptr<Rom> rom_;
std::unique_ptr<gfx::Tilemap> tilemap_;
std::unique_ptr<gfx::Tilemap> tile16_blockset_;
std::unique_ptr<gfx::Bitmap> current_gfx_bmp_;
std::unique_ptr<gfx::Bitmap> tile16_blockset_bmp_;
std::unique_ptr<zelda3::Overworld> overworld_;
std::unique_ptr<Tile16Editor> editor_;
};
// Static member definitions
bool Tile16EditorIntegrationTest::window_initialized_ = false;
core::Window Tile16EditorIntegrationTest::test_window_;
// Basic validation tests (no ROM required)
TEST_F(Tile16EditorIntegrationTest, BasicValidation) {
// Test with invalid tile ID
EXPECT_FALSE(editor_->IsTile16Valid(-1));
EXPECT_FALSE(editor_->IsTile16Valid(9999));
// Test scratch space operations with invalid slots
auto save_invalid = editor_->SaveTile16ToScratchSpace(-1);
EXPECT_FALSE(save_invalid.ok());
EXPECT_EQ(save_invalid.code(), absl::StatusCode::kInvalidArgument);
auto load_invalid = editor_->LoadTile16FromScratchSpace(5);
EXPECT_FALSE(load_invalid.ok());
EXPECT_EQ(load_invalid.code(), absl::StatusCode::kInvalidArgument);
// Test valid scratch space clearing
auto clear_valid = editor_->ClearScratchSpace(0);
EXPECT_TRUE(clear_valid.ok());
}
// ROM-dependent tests
TEST_F(Tile16EditorIntegrationTest, ValidateTile16DataWithROM) {
#ifdef YAZE_ENABLE_ROM_TESTS
if (!rom_loaded_) {
GTEST_SKIP() << "ROM not loaded, skipping integration test";
}
// Test validation with properly loaded ROM
auto status = editor_->ValidateTile16Data();
EXPECT_TRUE(status.ok()) << "Validation failed: " << status.message();
#else
GTEST_SKIP() << "ROM tests disabled";
#endif
}
TEST_F(Tile16EditorIntegrationTest, SetCurrentTileWithROM) {
#ifdef YAZE_ENABLE_ROM_TESTS
if (!rom_loaded_) {
GTEST_SKIP() << "ROM not loaded, skipping integration test";
}
// Test setting a valid tile
auto valid_tile_result = editor_->SetCurrentTile(0);
EXPECT_TRUE(valid_tile_result.ok()) << "Failed to set tile 0: " << valid_tile_result.message();
auto valid_tile_result2 = editor_->SetCurrentTile(100);
EXPECT_TRUE(valid_tile_result2.ok()) << "Failed to set tile 100: " << valid_tile_result2.message();
// Test invalid ranges still fail
auto invalid_low = editor_->SetCurrentTile(-1);
EXPECT_FALSE(invalid_low.ok());
EXPECT_EQ(invalid_low.code(), absl::StatusCode::kOutOfRange);
auto invalid_high = editor_->SetCurrentTile(10000);
EXPECT_FALSE(invalid_high.ok());
EXPECT_EQ(invalid_high.code(), absl::StatusCode::kOutOfRange);
#else
GTEST_SKIP() << "ROM tests disabled";
#endif
}
TEST_F(Tile16EditorIntegrationTest, FlipOperationsWithROM) {
#ifdef YAZE_ENABLE_ROM_TESTS
if (!rom_loaded_) {
GTEST_SKIP() << "ROM not loaded, skipping integration test";
}
// Set a valid tile first
auto set_result = editor_->SetCurrentTile(1);
ASSERT_TRUE(set_result.ok()) << "Failed to set initial tile: " << set_result.message();
// Test flip operations
auto flip_h_result = editor_->FlipTile16Horizontal();
EXPECT_TRUE(flip_h_result.ok()) << "Horizontal flip failed: " << flip_h_result.message();
auto flip_v_result = editor_->FlipTile16Vertical();
EXPECT_TRUE(flip_v_result.ok()) << "Vertical flip failed: " << flip_v_result.message();
auto rotate_result = editor_->RotateTile16();
EXPECT_TRUE(rotate_result.ok()) << "Rotation failed: " << rotate_result.message();
#else
GTEST_SKIP() << "ROM tests disabled";
#endif
}
TEST_F(Tile16EditorIntegrationTest, UndoRedoWithROM) {
#ifdef YAZE_ENABLE_ROM_TESTS
if (!rom_loaded_) {
GTEST_SKIP() << "ROM not loaded, skipping integration test";
}
// Set a tile and perform an operation to create undo state
auto set_result = editor_->SetCurrentTile(1);
ASSERT_TRUE(set_result.ok());
auto clear_result = editor_->ClearTile16();
ASSERT_TRUE(clear_result.ok()) << "Clear operation failed: " << clear_result.message();
// Test undo
auto undo_result = editor_->Undo();
EXPECT_TRUE(undo_result.ok()) << "Undo failed: " << undo_result.message();
// Test redo
auto redo_result = editor_->Redo();
EXPECT_TRUE(redo_result.ok()) << "Redo failed: " << redo_result.message();
#else
GTEST_SKIP() << "ROM tests disabled";
#endif
}
TEST_F(Tile16EditorIntegrationTest, PaletteOperationsWithROM) {
#ifdef YAZE_ENABLE_ROM_TESTS
if (!rom_loaded_) {
GTEST_SKIP() << "ROM not loaded, skipping integration test";
}
// Test palette cycling
auto cycle_forward = editor_->CyclePalette(true);
EXPECT_TRUE(cycle_forward.ok()) << "Palette cycle forward failed: " << cycle_forward.message();
auto cycle_backward = editor_->CyclePalette(false);
EXPECT_TRUE(cycle_backward.ok()) << "Palette cycle backward failed: " << cycle_backward.message();
// Test valid palette preview
auto valid_palette = editor_->PreviewPaletteChange(3);
EXPECT_TRUE(valid_palette.ok()) << "Palette preview failed: " << valid_palette.message();
// Test invalid palette
auto invalid_palette = editor_->PreviewPaletteChange(10);
EXPECT_FALSE(invalid_palette.ok());
EXPECT_EQ(invalid_palette.code(), absl::StatusCode::kInvalidArgument);
#else
GTEST_SKIP() << "ROM tests disabled";
#endif
}
TEST_F(Tile16EditorIntegrationTest, CopyPasteOperationsWithROM) {
#ifdef YAZE_ENABLE_ROM_TESTS
if (!rom_loaded_) {
GTEST_SKIP() << "ROM not loaded, skipping integration test";
}
// Set a tile first
auto set_result = editor_->SetCurrentTile(10);
ASSERT_TRUE(set_result.ok());
// Test copy operation
auto copy_result = editor_->CopyTile16ToClipboard(10);
EXPECT_TRUE(copy_result.ok()) << "Copy failed: " << copy_result.message();
// Test paste operation
auto paste_result = editor_->PasteTile16FromClipboard();
EXPECT_TRUE(paste_result.ok()) << "Paste failed: " << paste_result.message();
#else
GTEST_SKIP() << "ROM tests disabled";
#endif
}
TEST_F(Tile16EditorIntegrationTest, ScratchSpaceWithROM) {
#ifdef YAZE_ENABLE_ROM_TESTS
if (!rom_loaded_) {
GTEST_SKIP() << "ROM not loaded, skipping integration test";
}
// Set a tile first
auto set_result = editor_->SetCurrentTile(15);
ASSERT_TRUE(set_result.ok());
// Test scratch space save
auto save_result = editor_->SaveTile16ToScratchSpace(0);
EXPECT_TRUE(save_result.ok()) << "Scratch save failed: " << save_result.message();
// Test scratch space load
auto load_result = editor_->LoadTile16FromScratchSpace(0);
EXPECT_TRUE(load_result.ok()) << "Scratch load failed: " << load_result.message();
// Test scratch space clear
auto clear_result = editor_->ClearScratchSpace(0);
EXPECT_TRUE(clear_result.ok()) << "Scratch clear failed: " << clear_result.message();
#else
GTEST_SKIP() << "ROM tests disabled";
#endif
}
} // namespace test
} // namespace editor
} // namespace yaze