Browse Source

Test Catacomb level generation (#4651)

pull/4652/head
Anders Jenbo 4 years ago committed by GitHub
parent
commit
848222b8f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      test/CMakeLists.txt
  2. 6
      test/drlg_l1_test.cpp
  3. 90
      test/drlg_l2_test.cpp
  4. BIN
      test/fixtures/diablo/5-1677631846.dun
  5. BIN
      test/fixtures/diablo/6-2034738122.dun
  6. BIN
      test/fixtures/diablo/7-680552750.dun
  7. BIN
      test/fixtures/diablo/8-1999936419.dun

1
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

6
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<MegaTile[]>(206);
leveltype = DTYPE_CATHEDRAL;
} else if (level >= 21 && level <= 24) {
pMegaTiles = std::make_unique<MegaTile[]>(216);
pMegaTiles = std::make_unique<MegaTile[]>(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<uint8_t>(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<uint8_t>(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;
}
}
}

90
test/drlg_l2_test.cpp

@ -0,0 +1,90 @@
#include <fmt/format.h>
#include <gtest/gtest.h>
#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<MegaTile[]>(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<uint16_t>(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<uint8_t>(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<uint8_t>(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

BIN
test/fixtures/diablo/5-1677631846.dun vendored

Binary file not shown.

BIN
test/fixtures/diablo/6-2034738122.dun vendored

Binary file not shown.

BIN
test/fixtures/diablo/7-680552750.dun vendored

Binary file not shown.

BIN
test/fixtures/diablo/8-1999936419.dun vendored

Binary file not shown.
Loading…
Cancel
Save