backend-infra-engineer: Release v0.3.3 snapshot

This commit is contained in:
scawful
2025-11-21 21:35:50 -05:00
parent 3d71417f62
commit 476dd1cd1c
818 changed files with 65706 additions and 35514 deletions

View File

@@ -4,8 +4,8 @@
#include <SDL.h>
#include "app/platform/window.h"
#include "app/gui/core/style.h"
#include "app/platform/window.h"
#include "imgui/backends/imgui_impl_sdl2.h"
#include "imgui/backends/imgui_impl_sdlrenderer2.h"
#include "imgui/imgui.h"
@@ -20,13 +20,15 @@
namespace yaze {
namespace test {
EditorIntegrationTest::EditorIntegrationTest()
EditorIntegrationTest::EditorIntegrationTest()
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
: engine_(nullptr), show_demo_window_(true)
: engine_(nullptr),
show_demo_window_(true)
#else
#endif
{}
{
}
EditorIntegrationTest::~EditorIntegrationTest() {
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
@@ -40,7 +42,8 @@ EditorIntegrationTest::~EditorIntegrationTest() {
absl::Status EditorIntegrationTest::Initialize() {
// Create renderer for test
test_renderer_ = std::make_unique<gfx::SDL2Renderer>();
RETURN_IF_ERROR(core::CreateWindow(window_, test_renderer_.get(), SDL_WINDOW_RESIZABLE));
RETURN_IF_ERROR(
core::CreateWindow(window_, test_renderer_.get(), SDL_WINDOW_RESIZABLE));
IMGUI_CHECKVERSION();
ImGui::CreateContext();
@@ -57,7 +60,8 @@ absl::Status EditorIntegrationTest::Initialize() {
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
// Initialize ImGui for SDL
SDL_Renderer* sdl_renderer = static_cast<SDL_Renderer*>(test_renderer_->GetBackendRenderer());
SDL_Renderer* sdl_renderer =
static_cast<SDL_Renderer*>(test_renderer_->GetBackendRenderer());
ImGui_ImplSDL2_InitForSDLRenderer(controller_.window(), sdl_renderer);
ImGui_ImplSDLRenderer2_Init(sdl_renderer);
@@ -98,16 +102,15 @@ int EditorIntegrationTest::RunTest() {
absl::Status EditorIntegrationTest::Update() {
ImGui::NewFrame();
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
// Show test engine windows
ImGuiTestEngine_ShowTestEngineWindows(engine_, &show_demo_window_);
#endif
return absl::OkStatus();
}
// Helper methods for testing with a ROM
absl::Status EditorIntegrationTest::LoadTestRom(const std::string& filename) {
test_rom_ = std::make_unique<Rom>();
@@ -125,7 +128,8 @@ absl::Status EditorIntegrationTest::SaveTestRom(const std::string& filename) {
return test_rom_->SaveToFile(settings);
}
absl::Status EditorIntegrationTest::TestEditorInitialize(editor::Editor* editor) {
absl::Status EditorIntegrationTest::TestEditorInitialize(
editor::Editor* editor) {
if (!editor) {
return absl::InternalError("Editor is null");
}
@@ -204,4 +208,4 @@ absl::Status EditorIntegrationTest::TestEditorClear(editor::Editor* editor) {
}
} // namespace test
} // namespace yaze
} // namespace yaze

View File

@@ -3,12 +3,12 @@
#define IMGUI_DEFINE_MATH_OPERATORS
#include "imgui/imgui.h"
#include "app/editor/editor.h"
#include "app/rom.h"
#include "app/controller.h"
#include "app/platform/window.h"
#include "app/editor/editor.h"
#include "app/gfx/backend/sdl2_renderer.h"
#include "app/platform/window.h"
#include "app/rom.h"
#include "imgui/imgui.h"
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
#include "imgui_test_engine/imgui_te_context.h"
@@ -21,12 +21,14 @@ 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:
*
*
* 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");
@@ -40,10 +42,10 @@ class EditorIntegrationTest {
// Initialize the test environment
absl::Status Initialize();
// Run the test
int RunTest();
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
// Register tests for a specific editor
virtual void RegisterTests(ImGuiTestEngine* engine) = 0;
@@ -51,16 +53,15 @@ class EditorIntegrationTest {
// Default implementation when ImGui Test Engine is disabled
virtual void RegisterTests(void* engine) {}
#endif
// 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);
@@ -88,4 +89,4 @@ class EditorIntegrationTest {
} // namespace test
} // namespace yaze
#endif // YAZE_TEST_EDITOR_INTEGRATION_TEST_H
#endif // YAZE_TEST_EDITOR_INTEGRATION_TEST_H

View File

@@ -1,17 +1,18 @@
#include "app/editor/overworld/tile16_editor.h"
#include <gtest/gtest.h>
#include <iostream>
#include <memory>
#include <vector>
#include <gtest/gtest.h>
#include "app/rom.h"
#include "app/gfx/resource/arena.h"
#include "app/gfx/backend/sdl2_renderer.h"
#include "app/gfx/core/bitmap.h"
#include "app/gfx/render/tilemap.h"
#include "zelda3/overworld/overworld.h"
#include "app/gfx/resource/arena.h"
#include "app/platform/window.h"
#include "app/rom.h"
#include "zelda3/overworld/overworld.h"
namespace yaze {
namespace editor {
@@ -28,7 +29,7 @@ class Tile16EditorIntegrationTest : public ::testing::Test {
// Clean up SDL
if (window_initialized_) {
auto shutdown_result = core::ShutdownWindow(test_window_);
(void)shutdown_result; // Suppress unused variable warning
(void)shutdown_result; // Suppress unused variable warning
window_initialized_ = false;
}
}
@@ -42,41 +43,46 @@ class Tile16EditorIntegrationTest : public ::testing::Test {
// 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();
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();
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(nullptr, tile16_data, 0x80, 0x2000, 16,
zelda3::kNumTile16Individual, palette));
gfx::CreateTilemap(nullptr, tile16_data, 0x80, 0x2000, 16,
zelda3::kNumTile16Individual, palette));
// Create graphics bitmap
current_gfx_bmp_ = std::make_unique<gfx::Bitmap>();
current_gfx_bmp_->Create(0x80, 512, 0x40, overworld_->current_graphics());
current_gfx_bmp_->SetPalette(palette);
gfx::Arena::Get().QueueTextureCommand(
gfx::Arena::TextureCommandType::CREATE, current_gfx_bmp_.get());
// Create tile16 blockset bitmap
tile16_blockset_bmp_ = std::make_unique<gfx::Bitmap>();
tile16_blockset_bmp_->Create(0x80, 0x2000, 0x08, tile16_data);
tile16_blockset_bmp_->SetPalette(palette);
gfx::Arena::Get().QueueTextureCommand(
gfx::Arena::TextureCommandType::CREATE, tile16_blockset_bmp_.get());
// 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();
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
@@ -87,17 +93,19 @@ class Tile16EditorIntegrationTest : public ::testing::Test {
#endif
}
protected:
protected:
static void InitializeTestEnvironment() {
// Create renderer for test
test_renderer_ = std::make_unique<gfx::SDL2Renderer>();
auto window_result = core::CreateWindow(test_window_, test_renderer_.get(), SDL_WINDOW_HIDDEN);
auto window_result = core::CreateWindow(test_window_, test_renderer_.get(),
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;
std::cerr << "Failed to initialize test window: "
<< window_result.message() << std::endl;
}
}
@@ -125,16 +133,16 @@ 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());
@@ -146,7 +154,7 @@ TEST_F(Tile16EditorIntegrationTest, ValidateTile16DataWithROM) {
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();
@@ -160,19 +168,21 @@ TEST_F(Tile16EditorIntegrationTest, SetCurrentTileWithROM) {
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();
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();
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);
@@ -186,20 +196,24 @@ TEST_F(Tile16EditorIntegrationTest, FlipOperationsWithROM) {
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();
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();
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();
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();
EXPECT_TRUE(rotate_result.ok())
<< "Rotation failed: " << rotate_result.message();
#else
GTEST_SKIP() << "ROM tests disabled";
#endif
@@ -210,18 +224,19 @@ TEST_F(Tile16EditorIntegrationTest, UndoRedoWithROM) {
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();
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();
@@ -235,18 +250,21 @@ TEST_F(Tile16EditorIntegrationTest, PaletteOperationsWithROM) {
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();
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();
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();
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());
@@ -261,15 +279,15 @@ TEST_F(Tile16EditorIntegrationTest, CopyPasteOperationsWithROM) {
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();
@@ -283,22 +301,25 @@ TEST_F(Tile16EditorIntegrationTest, ScratchSpaceWithROM) {
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();
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();
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();
EXPECT_TRUE(clear_result.ok())
<< "Scratch clear failed: " << clear_result.message();
#else
GTEST_SKIP() << "ROM tests disabled";
#endif