yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
overworld_test.cc
Go to the documentation of this file.
1#include <gtest/gtest.h>
2#include <memory>
3
4#include "app/rom.h"
7
8namespace yaze {
9namespace zelda3 {
10
11class OverworldTest : public ::testing::Test {
12 protected:
13 void SetUp() override {
14 // Skip tests on Linux for automated github builds
15#if defined(__linux__)
16 GTEST_SKIP();
17#endif
18 // Create a mock ROM for testing
19 rom_ = std::make_unique<Rom>();
20 // Initialize with minimal ROM data for testing
21 std::vector<uint8_t> mock_rom_data(0x200000, 0x00); // 2MB ROM filled with 0x00
22
23 // Set up some basic ROM data that OverworldMap expects
24 mock_rom_data[0x140145] = 0xFF; // OverworldCustomASMHasBeenApplied = vanilla
25
26 // Message IDs (2 bytes per map)
27 for (int i = 0; i < 160; i++) { // 160 maps total
28 mock_rom_data[0x3F51D + (i * 2)] = 0x00;
29 mock_rom_data[0x3F51D + (i * 2) + 1] = 0x00;
30 }
31
32 // Area graphics (1 byte per map)
33 for (int i = 0; i < 160; i++) {
34 mock_rom_data[0x7C9C + i] = 0x00;
35 }
36
37 // Area palettes (1 byte per map)
38 for (int i = 0; i < 160; i++) {
39 mock_rom_data[0x7D1C + i] = 0x00;
40 }
41
42 // Screen sizes (1 byte per map)
43 for (int i = 0; i < 160; i++) {
44 mock_rom_data[0x1788D + i] = 0x01; // Small area by default
45 }
46
47 // Sprite sets (1 byte per map)
48 for (int i = 0; i < 160; i++) {
49 mock_rom_data[0x7A41 + i] = 0x00;
50 }
51
52 // Sprite palettes (1 byte per map)
53 for (int i = 0; i < 160; i++) {
54 mock_rom_data[0x7B41 + i] = 0x00;
55 }
56
57 // Music (1 byte per map)
58 for (int i = 0; i < 160; i++) {
59 mock_rom_data[0x14303 + i] = 0x00;
60 mock_rom_data[0x14303 + 0x40 + i] = 0x00;
61 mock_rom_data[0x14303 + 0x80 + i] = 0x00;
62 mock_rom_data[0x14303 + 0xC0 + i] = 0x00;
63 }
64
65 // Dark World music
66 for (int i = 0; i < 64; i++) {
67 mock_rom_data[0x14403 + i] = 0x00;
68 }
69
70 // Special world graphics and palettes
71 for (int i = 0; i < 32; i++) {
72 mock_rom_data[0x16821 + i] = 0x00;
73 mock_rom_data[0x16831 + i] = 0x00;
74 }
75
76 // Special world sprite graphics and palettes
77 for (int i = 0; i < 32; i++) {
78 mock_rom_data[0x0166E1 + i] = 0x00;
79 mock_rom_data[0x016701 + i] = 0x00;
80 }
81
82 rom_->LoadFromData(mock_rom_data);
83
84 overworld_ = std::make_unique<Overworld>(rom_.get());
85 }
86
87 void TearDown() override {
88 overworld_.reset();
89 rom_.reset();
90 }
91
92 std::unique_ptr<Rom> rom_;
93 std::unique_ptr<Overworld> overworld_;
94};
95
96TEST_F(OverworldTest, OverworldMapInitialization) {
97 // Test that OverworldMap can be created with valid parameters
98 OverworldMap map(0, rom_.get());
99
100 EXPECT_EQ(map.area_graphics(), 0);
101 EXPECT_EQ(map.area_palette(), 0);
102 EXPECT_EQ(map.message_id(), 0);
103 EXPECT_EQ(map.area_size(), AreaSizeEnum::SmallArea);
104 EXPECT_EQ(map.main_palette(), 0);
105 EXPECT_EQ(map.area_specific_bg_color(), 0);
106 EXPECT_EQ(map.subscreen_overlay(), 0);
107 EXPECT_EQ(map.animated_gfx(), 0);
108}
109
110TEST_F(OverworldTest, AreaSizeEnumValues) {
111 // Test that AreaSizeEnum has correct values
112 EXPECT_EQ(static_cast<int>(AreaSizeEnum::SmallArea), 0);
113 EXPECT_EQ(static_cast<int>(AreaSizeEnum::LargeArea), 1);
114 EXPECT_EQ(static_cast<int>(AreaSizeEnum::WideArea), 2);
115 EXPECT_EQ(static_cast<int>(AreaSizeEnum::TallArea), 3);
116}
117
118TEST_F(OverworldTest, OverworldMapSetters) {
119 OverworldMap map(0, rom_.get());
120
121 // Test main palette setter
122 map.set_main_palette(5);
123 EXPECT_EQ(map.main_palette(), 5);
124
125 // Test area-specific background color setter
126 map.set_area_specific_bg_color(0x7FFF);
127 EXPECT_EQ(map.area_specific_bg_color(), 0x7FFF);
128
129 // Test subscreen overlay setter
130 map.set_subscreen_overlay(0x1234);
131 EXPECT_EQ(map.subscreen_overlay(), 0x1234);
132
133 // Test animated GFX setter
134 map.set_animated_gfx(10);
135 EXPECT_EQ(map.animated_gfx(), 10);
136
137 // Test custom tileset setter
138 map.set_custom_tileset(0, 20);
139 EXPECT_EQ(map.custom_tileset(0), 20);
140
141 // Test area size setter
143 EXPECT_EQ(map.area_size(), AreaSizeEnum::LargeArea);
144}
145
146TEST_F(OverworldTest, OverworldMapLargeMapSetup) {
147 OverworldMap map(0, rom_.get());
148
149 // Test SetAsLargeMap
150 map.SetAsLargeMap(10, 2);
151 EXPECT_EQ(map.parent(), 10);
152 EXPECT_EQ(map.large_index(), 2);
153 EXPECT_TRUE(map.is_large_map());
154 EXPECT_EQ(map.area_size(), AreaSizeEnum::LargeArea);
155
156 // Test SetAsSmallMap
157 map.SetAsSmallMap(5);
158 EXPECT_EQ(map.parent(), 5);
159 EXPECT_EQ(map.large_index(), 0);
160 EXPECT_FALSE(map.is_large_map());
161 EXPECT_EQ(map.area_size(), AreaSizeEnum::SmallArea);
162}
163
164TEST_F(OverworldTest, OverworldMapCustomTilesetArray) {
165 OverworldMap map(0, rom_.get());
166
167 // Test setting all 8 custom tileset slots
168 for (int i = 0; i < 8; i++) {
169 map.set_custom_tileset(i, i + 10);
170 EXPECT_EQ(map.custom_tileset(i), i + 10);
171 }
172
173 // Test mutable access
174 for (int i = 0; i < 8; i++) {
175 *map.mutable_custom_tileset(i) = i + 20;
176 EXPECT_EQ(map.custom_tileset(i), i + 20);
177 }
178}
179
180TEST_F(OverworldTest, OverworldMapSpriteProperties) {
181 OverworldMap map(0, rom_.get());
182
183 // Test sprite graphics setters
184 map.set_sprite_graphics(0, 1);
185 map.set_sprite_graphics(1, 2);
186 map.set_sprite_graphics(2, 3);
187
188 EXPECT_EQ(map.sprite_graphics(0), 1);
189 EXPECT_EQ(map.sprite_graphics(1), 2);
190 EXPECT_EQ(map.sprite_graphics(2), 3);
191
192 // Test sprite palette setters
193 map.set_sprite_palette(0, 4);
194 map.set_sprite_palette(1, 5);
195 map.set_sprite_palette(2, 6);
196
197 EXPECT_EQ(map.sprite_palette(0), 4);
198 EXPECT_EQ(map.sprite_palette(1), 5);
199 EXPECT_EQ(map.sprite_palette(2), 6);
200}
201
202TEST_F(OverworldTest, OverworldMapBasicProperties) {
203 OverworldMap map(0, rom_.get());
204
205 // Test basic property setters
206 map.set_area_graphics(15);
207 EXPECT_EQ(map.area_graphics(), 15);
208
209 map.set_area_palette(8);
210 EXPECT_EQ(map.area_palette(), 8);
211
212 map.set_message_id(0x1234);
213 EXPECT_EQ(map.message_id(), 0x1234);
214}
215
216TEST_F(OverworldTest, OverworldMapMutableAccessors) {
217 OverworldMap map(0, rom_.get());
218
219 // Test mutable accessors
220 *map.mutable_area_graphics() = 25;
221 EXPECT_EQ(map.area_graphics(), 25);
222
223 *map.mutable_area_palette() = 12;
224 EXPECT_EQ(map.area_palette(), 12);
225
226 *map.mutable_message_id() = 0x5678;
227 EXPECT_EQ(map.message_id(), 0x5678);
228
229 *map.mutable_main_palette() = 7;
230 EXPECT_EQ(map.main_palette(), 7);
231
232 *map.mutable_animated_gfx() = 15;
233 EXPECT_EQ(map.animated_gfx(), 15);
234
235 *map.mutable_subscreen_overlay() = 0x9ABC;
236 EXPECT_EQ(map.subscreen_overlay(), 0x9ABC);
237}
238
239TEST_F(OverworldTest, OverworldMapDestroy) {
240 OverworldMap map(0, rom_.get());
241
242 // Set some properties
243 map.set_area_graphics(10);
244 map.set_main_palette(5);
246
247 // Destroy and verify reset
248 map.Destroy();
249
250 EXPECT_EQ(map.area_graphics(), 0);
251 EXPECT_EQ(map.main_palette(), 0);
252 EXPECT_EQ(map.area_size(), AreaSizeEnum::SmallArea);
253 EXPECT_FALSE(map.is_initialized());
254}
255
256// Integration test for world-based sprite filtering
257TEST_F(OverworldTest, WorldBasedSpriteFiltering) {
258 // This test verifies the logic used in DrawOverworldSprites
259 // for filtering sprites by world
260
261 int current_world = 1; // Dark World
262 int sprite_map_id = 0x50; // Map 0x50 (Dark World)
263
264 // Test that sprite should be shown for Dark World
265 bool should_show = (sprite_map_id < 0x40 + (current_world * 0x40) &&
266 sprite_map_id >= (current_world * 0x40));
267 EXPECT_TRUE(should_show);
268
269 // Test that sprite should NOT be shown for Light World
270 current_world = 0; // Light World
271 should_show = (sprite_map_id < 0x40 + (current_world * 0x40) &&
272 sprite_map_id >= (current_world * 0x40));
273 EXPECT_FALSE(should_show);
274
275 // Test boundary conditions
276 current_world = 1; // Dark World
277 sprite_map_id = 0x40; // First Dark World map
278 should_show = (sprite_map_id < 0x40 + (current_world * 0x40) &&
279 sprite_map_id >= (current_world * 0x40));
280 EXPECT_TRUE(should_show);
281
282 sprite_map_id = 0x7F; // Last Dark World map
283 should_show = (sprite_map_id < 0x40 + (current_world * 0x40) &&
284 sprite_map_id >= (current_world * 0x40));
285 EXPECT_TRUE(should_show);
286
287 sprite_map_id = 0x80; // First Special World map
288 should_show = (sprite_map_id < 0x40 + (current_world * 0x40) &&
289 sprite_map_id >= (current_world * 0x40));
290 EXPECT_FALSE(should_show);
291}
292
293} // namespace zelda3
294} // namespace yaze
Represents a single Overworld map screen.
auto set_area_palette(uint8_t value)
void SetAsLargeMap(int parent_index, int quadrant)
void set_main_palette(uint8_t palette)
void SetAsSmallMap(int index=-1)
auto set_message_id(uint16_t value)
auto set_sprite_palette(int i, uint8_t value)
void set_custom_tileset(int index, uint8_t value)
void set_area_specific_bg_color(uint16_t color)
auto sprite_graphics(int i) const
void SetAreaSize(AreaSizeEnum size)
auto custom_tileset(int index) const
void set_animated_gfx(uint8_t gfx)
auto set_area_graphics(uint8_t value)
void set_subscreen_overlay(uint16_t overlay)
auto area_specific_bg_color() const
auto sprite_palette(int i) const
uint8_t * mutable_custom_tileset(int index)
auto set_sprite_graphics(int i, uint8_t value)
std::unique_ptr< Rom > rom_
std::unique_ptr< Overworld > overworld_
TEST_F(DungeonEditorSystemIntegrationTest, BasicInitialization)
Main namespace for the application.