diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0c3676bbf..2c450ae74 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -21,6 +21,7 @@ set(tests drlg_common_test drlg_l1_test drlg_l2_test + drlg_l3_test drlg_l4_test effects_test file_util_test diff --git a/test/Fixtures.cmake b/test/Fixtures.cmake index 560f91b78..5a067bf8f 100644 --- a/test/Fixtures.cmake +++ b/test/Fixtures.cmake @@ -11,14 +11,22 @@ set(devilutionx_fixtures diablo/6-2034738122.dun diablo/7-680552750.dun diablo/8-1999936419.dun + diablo/9-262005438.dun + diablo/10-1630062353.dun + diablo/11-384626536.dun + diablo/12-2104541047.dun diablo/13-428074402.dun diablo/14-717625719.dun - diablo/15-1583642716.dun diablo/15-1583642716-changed.dun + diablo/15-1583642716.dun hellfire/1-401921334.dun hellfire/2-128964898.dun hellfire/3-1799396623.dun hellfire/4-1190318991.dun + hellfire/17-19770182.dun + hellfire/18-1522546307.dun + hellfire/19-125121312.dun + hellfire/20-1511478689.dun hellfire/21-2122696790.dun hellfire/22-1191662129.dun hellfire/23-97055268.dun diff --git a/test/drlg_l2_test.cpp b/test/drlg_l2_test.cpp index de3c24db7..dc6b36121 100644 --- a/test/drlg_l2_test.cpp +++ b/test/drlg_l2_test.cpp @@ -47,7 +47,7 @@ void TestCreateL2Dungeon(int level, uint32_t seed, lvl_entry entry) } } -TEST(Drlg_l1, CreateL2Dungeon_diablo_5_1677631846) +TEST(Drlg_l2, CreateL2Dungeon_diablo_5_1677631846) { TestCreateL2Dungeon(5, 1677631846, ENTRY_MAIN); EXPECT_EQ(ViewPosition, Point(27, 28)); @@ -55,7 +55,7 @@ TEST(Drlg_l1, CreateL2Dungeon_diablo_5_1677631846) EXPECT_EQ(ViewPosition, Point(26, 62)); } -TEST(Drlg_l1, CreateL2Dungeon_diablo_6_2034738122) +TEST(Drlg_l2, CreateL2Dungeon_diablo_6_2034738122) { TestCreateL2Dungeon(6, 2034738122, ENTRY_MAIN); EXPECT_EQ(ViewPosition, Point(33, 26)); @@ -63,7 +63,7 @@ TEST(Drlg_l1, CreateL2Dungeon_diablo_6_2034738122) EXPECT_EQ(ViewPosition, Point(34, 52)); } -TEST(Drlg_l1, CreateL2Dungeon_diablo_7_680552750) +TEST(Drlg_l2, CreateL2Dungeon_diablo_7_680552750) { TestCreateL2Dungeon(7, 680552750, ENTRY_MAIN); EXPECT_EQ(ViewPosition, Point(27, 26)); @@ -71,7 +71,7 @@ TEST(Drlg_l1, CreateL2Dungeon_diablo_7_680552750) EXPECT_EQ(ViewPosition, Point(78, 52)); } -TEST(Drlg_l1, CreateL2Dungeon_diablo_8_1999936419) +TEST(Drlg_l2, CreateL2Dungeon_diablo_8_1999936419) { TestCreateL2Dungeon(8, 1999936419, ENTRY_MAIN); EXPECT_EQ(ViewPosition, Point(39, 74)); diff --git a/test/drlg_l3_test.cpp b/test/drlg_l3_test.cpp new file mode 100644 index 000000000..16ff59ac3 --- /dev/null +++ b/test/drlg_l3_test.cpp @@ -0,0 +1,124 @@ +#include +#include + +#include "drlg_l3.h" +#include "engine/load_file.hpp" +#include "gendung.h" +#include "quests.h" +#include "utils/paths.h" + +using namespace devilution; + +namespace { + +void TestCreateL3Dungeon(int level, uint32_t seed, lvl_entry entry) +{ + paths::SetPrefPath(paths::BasePath()); + + std::string dunPath; + + if (level >= 9 && level <= 12) { + dunPath = fmt::format("test/fixtures/diablo/{}-{}.dun", level, seed); + pMegaTiles = std::make_unique(206); + leveltype = DTYPE_CAVES; + } else if (level >= 17 && level <= 20) { + dunPath = fmt::format("test/fixtures/hellfire/{}-{}.dun", level, seed); + pMegaTiles = std::make_unique(166); + leveltype = DTYPE_NEST; + } + + currlevel = level; + CreateL3Dungeon(seed, entry); + + auto dunData = LoadFileInMem(dunPath.c_str()); + ASSERT_NE(dunData, nullptr) << "Unable to load test fixture " << dunPath; + ASSERT_EQ(Size(DMAXX, DMAXY), Size(dunData[0], 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_l3, CreateL3Dungeon_diablo_9_262005438) +{ + TestCreateL3Dungeon(9, 262005438, ENTRY_MAIN); + EXPECT_EQ(ViewPosition, Point(41, 73)); + TestCreateL3Dungeon(9, 262005438, ENTRY_PREV); + EXPECT_EQ(ViewPosition, Point(73, 59)); +} + +TEST(Drlg_l3, CreateL3Dungeon_diablo_10_1630062353) +{ + Quests[Q_ANVIL]._qactive = QUEST_NOTAVAIL; + + TestCreateL3Dungeon(10, 1630062353, ENTRY_MAIN); + EXPECT_EQ(ViewPosition, Point(55, 37)); + TestCreateL3Dungeon(10, 1630062353, ENTRY_PREV); + EXPECT_EQ(ViewPosition, Point(19, 47)); +} + +TEST(Drlg_l3, CreateL3Dungeon_diablo_11_384626536) +{ + TestCreateL3Dungeon(11, 384626536, ENTRY_MAIN); + EXPECT_EQ(ViewPosition, Point(29, 19)); + TestCreateL3Dungeon(11, 384626536, ENTRY_PREV); + EXPECT_EQ(ViewPosition, Point(65, 65)); +} + +TEST(Drlg_l3, CreateL3Dungeon_diablo_12_2104541047) +{ + TestCreateL3Dungeon(12, 2104541047, ENTRY_MAIN); + EXPECT_EQ(ViewPosition, Point(35, 23)); + TestCreateL3Dungeon(12, 2104541047, ENTRY_PREV); + EXPECT_EQ(ViewPosition, Point(21, 83)); +} + +TEST(Drlg_l3, CreateL3Dungeon_hive_1_19770182) +{ + TestCreateL3Dungeon(17, 19770182, ENTRY_TWARPUP); + EXPECT_EQ(ViewPosition, Point(75, 81)); + TestCreateL3Dungeon(17, 19770182, ENTRY_PREV); + EXPECT_EQ(ViewPosition, Point(59, 41)); +} + +TEST(Drlg_l3, CreateL3Dungeon_hive_2_1522546307) +{ + TestCreateL3Dungeon(18, 1522546307, ENTRY_MAIN); + EXPECT_EQ(ViewPosition, Point(47, 19)); + TestCreateL3Dungeon(18, 1522546307, ENTRY_PREV); + EXPECT_EQ(ViewPosition, Point(33, 35)); +} + +TEST(Drlg_l3, CreateL3Dungeon_hive_3_125121312) +{ + TestCreateL3Dungeon(19, 125121312, ENTRY_MAIN); + EXPECT_EQ(ViewPosition, Point(61, 25)); + TestCreateL3Dungeon(19, 125121312, ENTRY_PREV); + EXPECT_EQ(ViewPosition, Point(21, 85)); +} + +TEST(Drlg_l3, CreateL3Dungeon_hive_4_1511478689) +{ + TestCreateL3Dungeon(20, 1511478689, ENTRY_MAIN); + EXPECT_EQ(ViewPosition, Point(65, 41)); + TestCreateL3Dungeon(20, 1511478689, ENTRY_PREV); + EXPECT_EQ(ViewPosition, Point(65, 41)); +} + +} // namespace diff --git a/test/drlg_l4_test.cpp b/test/drlg_l4_test.cpp index 6fa2c94d0..5abee77cc 100644 --- a/test/drlg_l4_test.cpp +++ b/test/drlg_l4_test.cpp @@ -52,7 +52,7 @@ void TestCreateL4Dungeon(bool changed, int level, uint32_t seed, lvl_entry entry } } -TEST(Drlg_l1, CreateL4Dungeon_diablo_13_428074402) +TEST(Drlg_l4, CreateL4Dungeon_diablo_13_428074402) { TestCreateL4Dungeon(false, 13, 428074402, ENTRY_MAIN); EXPECT_EQ(ViewPosition, Point(26, 64)); @@ -60,7 +60,7 @@ TEST(Drlg_l1, CreateL4Dungeon_diablo_13_428074402) EXPECT_EQ(ViewPosition, Point(47, 79)); } -TEST(Drlg_l1, CreateL4Dungeon_diablo_14_717625719) +TEST(Drlg_l4, CreateL4Dungeon_diablo_14_717625719) { TestCreateL4Dungeon(false, 14, 717625719, ENTRY_MAIN); EXPECT_EQ(ViewPosition, Point(90, 64)); @@ -68,7 +68,7 @@ TEST(Drlg_l1, CreateL4Dungeon_diablo_14_717625719) EXPECT_EQ(ViewPosition, Point(49, 31)); } -TEST(Drlg_l1, CreateL4Dungeon_diablo_15_1583642716) +TEST(Drlg_l4, CreateL4Dungeon_diablo_15_1583642716) { Quests[Q_DIABLO]._qactive = QUEST_INIT; TestCreateL4Dungeon(false, 15, 1583642716, ENTRY_MAIN); diff --git a/test/fixtures/diablo/10-1630062353.dun b/test/fixtures/diablo/10-1630062353.dun new file mode 100644 index 000000000..f84ccdf72 Binary files /dev/null and b/test/fixtures/diablo/10-1630062353.dun differ diff --git a/test/fixtures/diablo/11-384626536.dun b/test/fixtures/diablo/11-384626536.dun new file mode 100644 index 000000000..28287f102 Binary files /dev/null and b/test/fixtures/diablo/11-384626536.dun differ diff --git a/test/fixtures/diablo/12-2104541047.dun b/test/fixtures/diablo/12-2104541047.dun new file mode 100644 index 000000000..e352a5dea Binary files /dev/null and b/test/fixtures/diablo/12-2104541047.dun differ diff --git a/test/fixtures/diablo/9-262005438.dun b/test/fixtures/diablo/9-262005438.dun new file mode 100644 index 000000000..b38c9841d Binary files /dev/null and b/test/fixtures/diablo/9-262005438.dun differ diff --git a/test/fixtures/hellfire/17-19770182.dun b/test/fixtures/hellfire/17-19770182.dun new file mode 100644 index 000000000..ddd954a09 Binary files /dev/null and b/test/fixtures/hellfire/17-19770182.dun differ diff --git a/test/fixtures/hellfire/18-1522546307.dun b/test/fixtures/hellfire/18-1522546307.dun new file mode 100644 index 000000000..98df25ac9 Binary files /dev/null and b/test/fixtures/hellfire/18-1522546307.dun differ diff --git a/test/fixtures/hellfire/19-125121312.dun b/test/fixtures/hellfire/19-125121312.dun new file mode 100644 index 000000000..c891b25b3 Binary files /dev/null and b/test/fixtures/hellfire/19-125121312.dun differ diff --git a/test/fixtures/hellfire/20-1511478689.dun b/test/fixtures/hellfire/20-1511478689.dun new file mode 100644 index 000000000..51b34099e Binary files /dev/null and b/test/fixtures/hellfire/20-1511478689.dun differ