diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2405adc39..2dd6f7f7b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -20,6 +20,7 @@ set(tests diablo_test drlg_common_test drlg_l1_test + drlg_l2_test effects_test file_util_test inv_test diff --git a/test/drlg_l1_test.cpp b/test/drlg_l1_test.cpp index 005f61fdf..e6ec81d6b 100644 --- a/test/drlg_l1_test.cpp +++ b/test/drlg_l1_test.cpp @@ -35,7 +35,7 @@ void TestCreateL5Dungeon(bool hellfire, int level, uint32_t seed, lvl_entry entr pMegaTiles = std::make_unique(206); leveltype = DTYPE_CATHEDRAL; } else if (level >= 21 && level <= 24) { - pMegaTiles = std::make_unique(216); + pMegaTiles = std::make_unique(217); leveltype = DTYPE_CRYPT; } @@ -60,7 +60,7 @@ void TestCreateL5Dungeon(bool hellfire, int level, uint32_t seed, lvl_entry entr for (int x = 0; x < DMAXX; x++) { auto tileId = static_cast(SDL_SwapLE16(*tileLayer)); tileLayer++; - ASSERT_EQ(dungeon[x][y], tileId); + ASSERT_EQ(dungeon[x][y], tileId) << "Tiles don't match at " << x << "x" << y; } } @@ -70,7 +70,7 @@ void TestCreateL5Dungeon(bool hellfire, int level, uint32_t seed, lvl_entry entr for (int x = 16; x < 16 + DMAXX * 2; x++) { auto sectorId = static_cast(SDL_SwapLE16(*transparentLayer)); transparentLayer++; - ASSERT_EQ(dTransVal[x][y], sectorId) << "Room/region indexes don't match"; + ASSERT_EQ(dTransVal[x][y], sectorId) << "Room/region indexes don't match at " << x << "x" << y; } } } diff --git a/test/drlg_l2_test.cpp b/test/drlg_l2_test.cpp new file mode 100644 index 000000000..9b9cc13f3 --- /dev/null +++ b/test/drlg_l2_test.cpp @@ -0,0 +1,90 @@ +#include +#include + +#include "drlg_l2.h" +#include "engine/load_file.hpp" +#include "gendung.h" +#include "utils/paths.h" + +using namespace devilution; + +namespace { + +void TestCreateL2Dungeon(int level, uint32_t seed, lvl_entry entry) +{ + pMegaTiles = std::make_unique(160); + leveltype = DTYPE_CATACOMBS; + + currlevel = level; + CreateL2Dungeon(seed, entry); + + std::string path = paths::BasePath(); + + paths::SetPrefPath(path); + std::string dunPath = fmt::format("../test/fixtures/diablo/{}-{}.dun", level, seed); + auto dunData = LoadFileInMem(dunPath.c_str()); + ASSERT_EQ(DMAXX, dunData[0]); + ASSERT_EQ(DMAXY, dunData[1]); + + const uint16_t *tileLayer = &dunData[2]; + + for (int y = 0; y < DMAXY; y++) { + for (int x = 0; x < DMAXX; x++) { + auto tileId = static_cast(SDL_SwapLE16(*tileLayer)); + tileLayer++; + ASSERT_EQ(dungeon[x][y], tileId) << "Tiles don't match at " << x << "x" << y; + } + } + + const uint16_t *transparentLayer = &dunData[2 + DMAXX * DMAXY * 13]; + + for (int y = 16; y < 16 + DMAXY * 2; y++) { + for (int x = 16; x < 16 + DMAXX * 2; x++) { + auto sectorId = static_cast(SDL_SwapLE16(*transparentLayer)); + transparentLayer++; + ASSERT_EQ(dTransVal[x][y], sectorId) << "Room/region indexes don't match at " << x << "x" << y; + } + } +} + +TEST(Drlg_l1, CreateL2Dungeon_diablo_5_1677631846) +{ + TestCreateL2Dungeon(5, 1677631846, ENTRY_MAIN); + EXPECT_EQ(ViewPosition.x, 27); + EXPECT_EQ(ViewPosition.y, 28); + TestCreateL2Dungeon(5, 1677631846, ENTRY_PREV); + EXPECT_EQ(ViewPosition.x, 26); + EXPECT_EQ(ViewPosition.y, 62); +} + +TEST(Drlg_l1, CreateL2Dungeon_diablo_6_2034738122) +{ + TestCreateL2Dungeon(6, 2034738122, ENTRY_MAIN); + EXPECT_EQ(ViewPosition.x, 33); + EXPECT_EQ(ViewPosition.y, 26); + TestCreateL2Dungeon(6, 2034738122, ENTRY_PREV); + EXPECT_EQ(ViewPosition.x, 34); + EXPECT_EQ(ViewPosition.y, 52); +} + +TEST(Drlg_l1, CreateL2Dungeon_diablo_7_680552750) +{ + TestCreateL2Dungeon(7, 680552750, ENTRY_MAIN); + EXPECT_EQ(ViewPosition.x, 27); + EXPECT_EQ(ViewPosition.y, 26); + TestCreateL2Dungeon(7, 680552750, ENTRY_PREV); + EXPECT_EQ(ViewPosition.x, 78); + EXPECT_EQ(ViewPosition.y, 52); +} + +TEST(Drlg_l1, CreateL2Dungeon_diablo_8_1999936419) +{ + TestCreateL2Dungeon(8, 1999936419, ENTRY_MAIN); + EXPECT_EQ(ViewPosition.x, 39); + EXPECT_EQ(ViewPosition.y, 74); + TestCreateL2Dungeon(8, 1999936419, ENTRY_PREV); + EXPECT_EQ(ViewPosition.x, 48); + EXPECT_EQ(ViewPosition.y, 46); +} + +} // namespace diff --git a/test/fixtures/diablo/5-1677631846.dun b/test/fixtures/diablo/5-1677631846.dun new file mode 100644 index 000000000..f31c5084f Binary files /dev/null and b/test/fixtures/diablo/5-1677631846.dun differ diff --git a/test/fixtures/diablo/6-2034738122.dun b/test/fixtures/diablo/6-2034738122.dun new file mode 100644 index 000000000..1013ed861 Binary files /dev/null and b/test/fixtures/diablo/6-2034738122.dun differ diff --git a/test/fixtures/diablo/7-680552750.dun b/test/fixtures/diablo/7-680552750.dun new file mode 100644 index 000000000..b49804292 Binary files /dev/null and b/test/fixtures/diablo/7-680552750.dun differ diff --git a/test/fixtures/diablo/8-1999936419.dun b/test/fixtures/diablo/8-1999936419.dun new file mode 100644 index 000000000..1a8daaa2a Binary files /dev/null and b/test/fixtures/diablo/8-1999936419.dun differ