yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
graphics_editor_test_suite.h
Go to the documentation of this file.
1#ifndef YAZE_APP_TEST_GRAPHICS_EDITOR_TEST_SUITE_H
2#define YAZE_APP_TEST_GRAPHICS_EDITOR_TEST_SUITE_H
3
4#include <chrono>
5#include <vector>
6
7#include "absl/strings/str_format.h"
11#include "rom/rom.h"
12#include "zelda3/game_data.h"
13
14namespace yaze {
15namespace test {
16
18 public:
20 ~GraphicsEditorTestSuite() override = default;
21
22 std::string GetName() const override { return "Graphics Editor Tests"; }
23 TestCategory GetCategory() const override {
25 }
26
27 absl::Status RunTests(TestResults& results) override {
28 Rom* current_rom = TestManager::Get().GetCurrentRom();
29
30 if (!current_rom || !current_rom->is_loaded()) {
31 AddSkippedTest(results, "Graphics_Editor_Check", "No ROM loaded");
32 return absl::OkStatus();
33 }
34
36 RunPixelEditingTest(results, current_rom);
37 }
38
40 RunPaletteEditingTest(results, current_rom);
41 }
42
43 return absl::OkStatus();
44 }
45
46 void DrawConfiguration() override {
47 ImGui::Text("%s Graphics Editor Test Configuration", ICON_MD_PALETTE);
48 ImGui::Separator();
49 ImGui::Checkbox("Test Pixel Editing", &test_pixel_editing_);
50 ImGui::Checkbox("Test Palette Editing", &test_palette_editing_);
51 }
52
53 private:
54 void AddSkippedTest(TestResults& results, const std::string& test_name,
55 const std::string& reason) {
56 TestResult result;
57 result.name = test_name;
58 result.suite_name = GetName();
59 result.category = GetCategory();
61 result.error_message = reason;
62 result.duration = std::chrono::milliseconds{0};
63 result.timestamp = std::chrono::steady_clock::now();
64 results.AddResult(result);
65 }
66
67 void RunPixelEditingTest(TestResults& results, Rom* rom) {
68 auto start_time = std::chrono::steady_clock::now();
69
70 TestResult result;
71 result.name = "Graphics_Pixel_Editing";
72 result.suite_name = GetName();
73 result.category = GetCategory();
74 result.timestamp = start_time;
75
76 try {
77 auto& test_manager = TestManager::Get();
78 auto test_status =
79 test_manager.TestRomWithCopy(rom, [&](Rom* test_rom) -> absl::Status {
80 zelda3::GameData game_data;
81 RETURN_IF_ERROR(zelda3::LoadGameData(*test_rom, game_data));
82
83 editor::GraphicsEditor editor(test_rom);
84 editor.SetGameData(&game_data);
85
86 // Initialize and Load
87 editor.Initialize();
88 RETURN_IF_ERROR(editor.Load());
89
90 // Test Sheet 0 (Link's graphics usually)
91 uint16_t sheet_id = 0;
92 editor.SelectSheet(sheet_id);
93
94 // Directly modify a pixel in GameData to simulate editing
95 // and then verify we can "save" it.
96 // In a real GUI edit, the PixelEditorPanel would handle this.
97 if (game_data.gfx_bitmaps.empty()) {
98 return absl::InternalError("No graphics sheets loaded");
99 }
100
101 auto& sheet = game_data.gfx_bitmaps[sheet_id];
102 uint8_t original_pixel = sheet.GetPixel(0, 0);
103 uint8_t new_pixel = (original_pixel + 1) % 16;
104
105 sheet.SetPixel(0, 0, new_pixel);
106
107 if (sheet.GetPixel(0, 0) != new_pixel) {
108 return absl::InternalError("Failed to set pixel in bitmap");
109 }
110
111 // Verify saving (this would write back to ROM or internal buffers)
112 // RETURN_IF_ERROR(editor.Save());
113
114 return absl::OkStatus();
115 });
116
117 if (test_status.ok()) {
119 result.error_message = "Pixel editing verified in data layer";
120 } else {
122 result.error_message = test_status.ToString();
123 }
124
125 } catch (const std::exception& e) {
127 result.error_message = std::string(e.what());
128 }
129
130 auto end_time = std::chrono::steady_clock::now();
131 result.duration = std::chrono::duration_cast<std::chrono::milliseconds>(
132 end_time - start_time);
133
134 results.AddResult(result);
135 }
136
137 void RunPaletteEditingTest(TestResults& results, Rom* rom) {
138 auto start_time = std::chrono::steady_clock::now();
139
140 TestResult result;
141 result.name = "Graphics_Palette_Editing";
142 result.suite_name = GetName();
143 result.category = GetCategory();
144 result.timestamp = start_time;
145
146 try {
147 auto& test_manager = TestManager::Get();
148 auto test_status =
149 test_manager.TestRomWithCopy(rom, [&](Rom* test_rom) -> absl::Status {
150 zelda3::GameData game_data;
151 RETURN_IF_ERROR(zelda3::LoadGameData(*test_rom, game_data));
152
153 editor::GraphicsEditor editor(test_rom);
154 editor.SetGameData(&game_data);
155 editor.Initialize();
156 RETURN_IF_ERROR(editor.Load());
157
158 // Test modifying a palette color
159 if (game_data.palette_groups.dungeons.empty()) {
160 return absl::InternalError("No dungeon palettes loaded");
161 }
162
163 auto& palette = game_data.palette_groups.dungeons[0];
164 SDL_Color original_color = palette.GetColor(0);
165 SDL_Color new_color = {255, 0, 0, 255}; // Bright Red
166
167 palette.SetColor(0, new_color);
168
169 SDL_Color actual_color = palette.GetColor(0);
170 if (actual_color.r != 255 || actual_color.g != 0 || actual_color.b != 0) {
171 return absl::InternalError("Palette color update failed");
172 }
173
174 return absl::OkStatus();
175 });
176
177 if (test_status.ok()) {
179 result.error_message = "Palette editing verified in data layer";
180 } else {
182 result.error_message = test_status.ToString();
183 }
184
185 } catch (const std::exception& e) {
187 result.error_message = std::string(e.what());
188 }
189
190 auto end_time = std::chrono::steady_clock::now();
191 result.duration = std::chrono::duration_cast<std::chrono::milliseconds>(
192 end_time - start_time);
193
194 results.AddResult(result);
195 }
196
199};
200
201} // namespace test
202} // namespace yaze
203
204#endif // YAZE_APP_TEST_GRAPHICS_EDITOR_TEST_SUITE_H
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:28
bool is_loaded() const
Definition rom.h:132
Allows the user to edit graphics sheets from the game or view prototype graphics.
void SelectSheet(uint16_t sheet_id)
absl::Status Load() override
void SetGameData(zelda3::GameData *game_data) override
void RunPaletteEditingTest(TestResults &results, Rom *rom)
~GraphicsEditorTestSuite() override=default
void RunPixelEditingTest(TestResults &results, Rom *rom)
absl::Status RunTests(TestResults &results) override
void AddSkippedTest(TestResults &results, const std::string &test_name, const std::string &reason)
Rom * GetCurrentRom() const
static TestManager & Get()
#define ICON_MD_PALETTE
Definition icons.h:1370
absl::Status LoadGameData(Rom &rom, GameData &data, const LoadOptions &options)
Loads all Zelda3-specific game data from a generic ROM.
Definition game_data.cc:123
#define RETURN_IF_ERROR(expr)
Definition snes.cc:22
std::chrono::milliseconds duration
std::string error_message
std::chrono::time_point< std::chrono::steady_clock > timestamp
void AddResult(const TestResult &result)
gfx::PaletteGroupMap palette_groups
Definition game_data.h:89
std::array< gfx::Bitmap, kNumGfxSheets > gfx_bitmaps
Definition game_data.h:84