Refactor dungeon room initialization for clarity and add unit tests for room loading functionality

This commit is contained in:
scawful
2024-11-08 00:18:33 -05:00
parent e196388f6c
commit 3d23922f71
2 changed files with 39 additions and 2 deletions

View File

@@ -72,7 +72,7 @@ absl::Status DungeonEditor::Update() {
absl::Status DungeonEditor::Initialize() {
auto dungeon_man_pal_group = rom()->palette_group().dungeon_main;
for (int i = 0; i < 0x100 + 40; i++) {
rooms_.emplace_back(zelda3::dungeon::Room(i));
rooms_.emplace_back(zelda3::dungeon::Room(/*room_id=*/i));
rooms_[i].LoadHeader();
rooms_[i].LoadRoomFromROM();
if (flags()->kDrawDungeonRoomGraphics) {
@@ -827,4 +827,4 @@ void DungeonEditor::DrawUsageGrid() {
} // namespace editor
} // namespace app
} // namespace yaze
} // namespace yaze

View File

@@ -0,0 +1,37 @@
#include "app/zelda3/dungeon/room.h"
#include "gtest/gtest.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "app/rom.h"
namespace yaze {
namespace test {
namespace zelda3 {
class DungeonRoomTest : public ::testing::Test, public app::SharedRom {
protected:
void SetUp() override {
// Skip tests on Linux for automated github builds
#if defined(__linux__)
GTEST_SKIP();
#else
if (!rom()->LoadFromFile("./zelda3.sfc").ok()) {
GTEST_SKIP_("Failed to load test ROM");
}
#endif
}
void TearDown() override {}
};
TEST_F(DungeonRoomTest, SingleRoomLoadOk) {
app::zelda3::dungeon::Room test_room(/*room_id=*/0);
test_room.LoadHeader();
// Do some assertions based on the output in ZS
test_room.LoadRoomFromROM();
}
} // namespace zelda3
} // namespace test
} // namespace yaze