yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_editor_v2_test.cc
Go to the documentation of this file.
2
3namespace yaze {
4namespace test {
5
6// ============================================================================
7// Basic Initialization Tests
8// ============================================================================
9
10TEST_F(DungeonEditorV2IntegrationTest, EditorInitialization) {
11 // Initialize should not fail
12 dungeon_editor_v2_->Initialize();
13 EXPECT_TRUE(dungeon_editor_v2_->rom() != nullptr);
14}
15
17 EXPECT_TRUE(dungeon_editor_v2_->IsRomLoaded());
18 std::string status = dungeon_editor_v2_->GetRomStatus();
19 EXPECT_FALSE(status.empty());
20 EXPECT_NE(status, "No ROM loaded");
21}
22
23// ============================================================================
24// Load Tests - Component Delegation
25// ============================================================================
26
28 // Test that Load() properly delegates to room_loader_
29 dungeon_editor_v2_->Initialize();
30 auto status = dungeon_editor_v2_->Load();
31 ASSERT_TRUE(status.ok()) << "Load failed: " << status.message();
32}
33
35 // Test error handling when ROM is not available
36 editor::DungeonEditorV2 editor(nullptr);
37 auto status = editor.Load();
38 EXPECT_FALSE(status.ok());
39 EXPECT_EQ(status.code(), absl::StatusCode::kFailedPrecondition);
40}
41
43 // Test the full initialization sequence
44 dungeon_editor_v2_->Initialize();
45
46 auto load_status = dungeon_editor_v2_->Load();
47 ASSERT_TRUE(load_status.ok());
48
49 // After loading, Update() should work
50 (void)dungeon_editor_v2_->Update();
51}
52
53// ============================================================================
54// Update Tests - UI Coordination
55// ============================================================================
56
58 // Update before Load should show loading message but not crash
59 auto status = dungeon_editor_v2_->Update();
60 EXPECT_TRUE(status.ok());
61}
62
64 dungeon_editor_v2_->Initialize();
65 (void)dungeon_editor_v2_->Load();
66
67 // Update should delegate to components
68 auto status = dungeon_editor_v2_->Update();
69 EXPECT_TRUE(status.ok());
70}
71
72// ============================================================================
73// Save Tests - Component Delegation
74// ============================================================================
75
77 // Test error handling when ROM is not available
78 editor::DungeonEditorV2 editor(nullptr);
79 auto status = editor.Save();
80 EXPECT_FALSE(status.ok());
81 EXPECT_EQ(status.code(), absl::StatusCode::kFailedPrecondition);
82}
83
85 dungeon_editor_v2_->Initialize();
86 auto load_status = dungeon_editor_v2_->Load();
87 ASSERT_TRUE(load_status.ok());
88
89 // Save should delegate to room objects
90 auto save_status = dungeon_editor_v2_->Save();
91 EXPECT_TRUE(save_status.ok());
92}
93
94// ============================================================================
95// Room Management Tests
96// ============================================================================
97
99 dungeon_editor_v2_->Initialize();
100 (void)dungeon_editor_v2_->Load();
101
102 // Add a room tab
103 dungeon_editor_v2_->add_room(kTestRoomId);
104
105 // This should not crash or fail
106 auto status = dungeon_editor_v2_->Update();
107 EXPECT_TRUE(status.ok());
108}
109
111 dungeon_editor_v2_->Initialize();
112 (void)dungeon_editor_v2_->Load();
113
114 // Add multiple rooms
115 dungeon_editor_v2_->add_room(0x00);
116 dungeon_editor_v2_->add_room(0x01);
117 dungeon_editor_v2_->add_room(0x02);
118
119 auto status = dungeon_editor_v2_->Update();
120 EXPECT_TRUE(status.ok());
121}
122
123// ============================================================================
124// Component Delegation Tests
125// ============================================================================
126
128 // Verify that Load() delegates to room_loader_
129 dungeon_editor_v2_->Initialize();
130 auto status = dungeon_editor_v2_->Load();
131
132 // If Load succeeds, room_loader_ must have worked
133 EXPECT_TRUE(status.ok());
134}
135
136TEST_F(DungeonEditorV2IntegrationTest, ComponentsInitializedAfterLoad) {
137 dungeon_editor_v2_->Initialize();
138 auto status = dungeon_editor_v2_->Load();
139 ASSERT_TRUE(status.ok());
140
141 // After Load(), all components should be properly initialized
142 // We can't directly test this, but Update() should work
143 (void)dungeon_editor_v2_->Update();
144}
145
146// ============================================================================
147// ROM Management Tests
148// ============================================================================
149
150TEST_F(DungeonEditorV2IntegrationTest, SetRomAfterConstruction) {
151 // Create editor without ROM
153 EXPECT_EQ(editor.rom(), nullptr);
154
155 // Set ROM
156 editor.set_rom(rom_.get());
157 EXPECT_EQ(editor.rom(), rom_.get());
158 EXPECT_TRUE(editor.IsRomLoaded());
159}
160
162 // Create editor without ROM
164
165 // Set ROM and load
166 editor.set_rom(rom_.get());
167 editor.Initialize();
168 auto status = editor.Load();
169
170 EXPECT_TRUE(status.ok());
171}
172
173// ============================================================================
174// Unimplemented Methods Tests
175// ============================================================================
176
178 // These should return UnimplementedError
179 EXPECT_EQ(dungeon_editor_v2_->Undo().code(),
180 absl::StatusCode::kUnimplemented);
181 EXPECT_EQ(dungeon_editor_v2_->Redo().code(),
182 absl::StatusCode::kUnimplemented);
183 EXPECT_EQ(dungeon_editor_v2_->Cut().code(),
184 absl::StatusCode::kUnimplemented);
185 EXPECT_EQ(dungeon_editor_v2_->Copy().code(),
186 absl::StatusCode::kUnimplemented);
187 EXPECT_EQ(dungeon_editor_v2_->Paste().code(),
188 absl::StatusCode::kUnimplemented);
189 EXPECT_EQ(dungeon_editor_v2_->Find().code(),
190 absl::StatusCode::kUnimplemented);
191}
192
193// ============================================================================
194// Stress Testing
195// ============================================================================
196
198 dungeon_editor_v2_->Initialize();
199 auto load_status = dungeon_editor_v2_->Load();
200 ASSERT_TRUE(load_status.ok());
201
202 // Run multiple update cycles
203 for (int i = 0; i < 10; i++) {
204 (void)dungeon_editor_v2_->Update();
205 }
206}
207
208// ============================================================================
209// Edge Cases
210// ============================================================================
211
213 dungeon_editor_v2_->Initialize();
214 (void)dungeon_editor_v2_->Load();
215
216 // Add invalid room ID (beyond 0x128)
217 dungeon_editor_v2_->add_room(0x200);
218
219 // Update should handle gracefully
220 auto status = dungeon_editor_v2_->Update();
221 EXPECT_TRUE(status.ok());
222}
223
225 dungeon_editor_v2_->Initialize();
226 (void)dungeon_editor_v2_->Load();
227
228 // Add negative room ID
229 dungeon_editor_v2_->add_room(-1);
230
231 // Update should handle gracefully
232 auto status = dungeon_editor_v2_->Update();
233 EXPECT_TRUE(status.ok());
234}
235
237 dungeon_editor_v2_->Initialize();
238
239 // Load twice
240 auto status1 = dungeon_editor_v2_->Load();
241 auto status2 = dungeon_editor_v2_->Load();
242
243 // Both should succeed
244 EXPECT_TRUE(status1.ok());
245 EXPECT_TRUE(status2.ok());
246}
247
248} // namespace test
249} // namespace yaze
250
DungeonEditorV2 - Simplified dungeon editor using component delegation.
void Initialize(gfx::IRenderer *renderer, Rom *rom)
bool IsRomLoaded() const override
Integration test framework for DungeonEditorV2.
TEST_F(DungeonObjectRenderingE2ETests, RunAllTests)
Main namespace for the application.