Browse Source

Test paths fixes

1. Load assets from the bundle on Mac.
2. In timedemo_test, load MPQs before overriding pref path,
   so that they can also be loaded from the user/system location.
3. Fix various double directory separators ("build//assets" etc).
pull/7584/head
Gleb Mazovetskiy 1 year ago committed by Anders Jenbo
parent
commit
940ce3fb64
  1. 2
      Source/diablo.h
  2. 2
      test/drlg_l1_test.cpp
  3. 189
      test/drlg_test.hpp
  4. 6
      test/main.cpp
  5. 8
      test/timedemo_test.cpp
  6. 10
      test/writehero_test.cpp

2
Source/diablo.h

@ -59,7 +59,7 @@ enum class MouseActionType : uint8_t {
};
extern uint32_t DungeonSeeds[NUMLEVELS];
extern std::optional<uint32_t> LevelSeeds[NUMLEVELS];
extern DVL_API_FOR_TEST std::optional<uint32_t> LevelSeeds[NUMLEVELS];
extern Point MousePosition;
extern DVL_API_FOR_TEST bool gbRunGame;
extern bool gbRunGameResult;

2
test/drlg_l1_test.cpp

@ -205,7 +205,6 @@ TEST(Drlg_l1, CreateL5Dungeon_crypt_1_2122696790)
{
LoadExpectedLevelData("hellfire/21-2122696790.dun");
paths::SetAssetsPath(paths::BasePath() + "/assets");
TestInitGame();
TestCreateDungeon(21, 2122696790, ENTRY_TWARPDN);
@ -244,7 +243,6 @@ TEST(Drlg_l1, CreateL5Dungeon_crypt_4_1324803725)
{
LoadExpectedLevelData("hellfire/24-1324803725.dun");
paths::SetAssetsPath(paths::BasePath() + "/assets");
TestInitGame();
TestCreateDungeon(24, 1324803725, ENTRY_MAIN);

189
test/drlg_test.hpp

@ -1,95 +1,94 @@
/**
* @file drlg_test.hpp
*
* Helpers for dungeon related tests.
*/
#pragma once
#include "engine/load_file.hpp"
#include "levels/themes.h"
#include "multi.h"
#include "player.h"
#include "quests.h"
#include "utils/paths.h"
using namespace devilution;
int GetTileCount(dungeon_type levelType)
{
switch (levelType) {
case DTYPE_TOWN:
return 376;
case DTYPE_CATHEDRAL:
return 206;
case DTYPE_CATACOMBS:
return 160;
case DTYPE_CAVES:
return 206;
case DTYPE_HELL:
return 137;
case DTYPE_NEST:
return 166;
case DTYPE_CRYPT:
return 217;
default:
app_fatal("Invalid level type");
}
}
std::unique_ptr<uint16_t[]> DunData;
void LoadExpectedLevelData(const char *fixture)
{
std::string dunPath = "test/fixtures/";
paths::SetPrefPath(paths::BasePath());
paths::SetAssetsPath(paths::BasePath() + "/" + dunPath);
dunPath.append(fixture);
DunData = LoadFileInMem<uint16_t>(dunPath.c_str());
ASSERT_NE(DunData, nullptr) << "Unable to load test fixture " << dunPath;
ASSERT_EQ(WorldTileSize(DMAXX, DMAXY), GetDunSize(DunData.get()));
}
void TestInitGame(bool fullQuests = true, bool originalCathedral = true)
{
Players.resize(1);
MyPlayer = &Players[0];
MyPlayer->pOriginalCathedral = originalCathedral;
sgGameInitInfo.fullQuests = fullQuests ? 1 : 0;
gbIsMultiplayer = !fullQuests;
InitQuests();
}
void TestCreateDungeon(int level, uint32_t seed, lvl_entry entry)
{
currlevel = level;
leveltype = GetLevelType(level);
pMegaTiles = std::make_unique<MegaTile[]>(GetTileCount(leveltype));
CreateDungeon(seed, entry);
CreateThemeRooms();
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;
}
}
}
/**
* @file drlg_test.hpp
*
* Helpers for dungeon related tests.
*/
#pragma once
#include <gtest/gtest.h>
#include "engine/load_file.hpp"
#include "levels/themes.h"
#include "multi.h"
#include "player.h"
#include "quests.h"
#include "utils/paths.h"
using namespace devilution;
int GetTileCount(dungeon_type levelType)
{
switch (levelType) {
case DTYPE_TOWN:
return 376;
case DTYPE_CATHEDRAL:
return 206;
case DTYPE_CATACOMBS:
return 160;
case DTYPE_CAVES:
return 206;
case DTYPE_HELL:
return 137;
case DTYPE_NEST:
return 166;
case DTYPE_CRYPT:
return 217;
default:
app_fatal("Invalid level type");
}
}
std::unique_ptr<uint16_t[]> DunData;
void LoadExpectedLevelData(const char *fixture)
{
// Set look up path to the location to load set pieces from later:
paths::SetPrefPath(paths::BasePath() + "test/fixtures/");
DunData = LoadFileInMem<uint16_t>(fixture);
ASSERT_NE(DunData, nullptr) << "Unable to load test fixture " << fixture;
ASSERT_EQ(WorldTileSize(DMAXX, DMAXY), GetDunSize(DunData.get()));
}
void TestInitGame(bool fullQuests = true, bool originalCathedral = true)
{
Players.resize(1);
MyPlayer = &Players[0];
MyPlayer->pOriginalCathedral = originalCathedral;
sgGameInitInfo.fullQuests = fullQuests ? 1 : 0;
gbIsMultiplayer = !fullQuests;
InitQuests();
}
void TestCreateDungeon(int level, uint32_t seed, lvl_entry entry)
{
LevelSeeds[level] = std::nullopt;
currlevel = level;
leveltype = GetLevelType(level);
pMegaTiles = std::make_unique<MegaTile[]>(GetTileCount(leveltype));
CreateDungeon(seed, entry);
CreateThemeRooms();
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;
}
}
}

6
test/main.cpp

@ -2,6 +2,7 @@
#include "diablo.h"
#include "options.h"
#include "utils/paths.h"
int main(int argc, char **argv)
{
@ -13,6 +14,11 @@ int main(int argc, char **argv)
devilution::sgOptions.Graphics.hardwareCursor.SetValue(false);
#endif
#ifdef __APPLE__
devilution::paths::SetAssetsPath(
devilution::paths::BasePath() + "devilutionx.app/Contents/Resources/");
#endif
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

8
test/timedemo_test.cpp

@ -33,9 +33,7 @@ void RunTimedemo(std::string timedemoFolderName)
<= -1) {
ErrSdl();
}
std::string unitTestFolderCompletePath = paths::BasePath() + "/test/fixtures/timedemo/" + timedemoFolderName;
paths::SetPrefPath(unitTestFolderCompletePath);
paths::SetConfigPath(unitTestFolderCompletePath);
LoadCoreArchives();
LoadGameArchives();
@ -43,6 +41,10 @@ void RunTimedemo(std::string timedemoFolderName)
// Please provide them so that the tests can run successfully
ASSERT_TRUE(HaveSpawn() || HaveDiabdat());
std::string unitTestFolderCompletePath = paths::BasePath() + "test/fixtures/timedemo/" + timedemoFolderName;
paths::SetPrefPath(unitTestFolderCompletePath);
paths::SetConfigPath(unitTestFolderCompletePath);
InitKeymapActions();
LoadOptions();
LuaInitialize();

10
test/writehero_test.cpp

@ -369,8 +369,9 @@ TEST(Writehero, pfile_write_hero)
// Please provide them so that the tests can run successfully
ASSERT_TRUE(HaveSpawn() || HaveDiabdat());
paths::SetPrefPath(".");
std::remove("multi_0.sv");
const std::string savePath = paths::BasePath() + "multi_0.sv";
paths::SetPrefPath(paths::BasePath());
RemoveFile(savePath.c_str());
gbVanilla = true;
gbIsHellfire = false;
@ -397,11 +398,10 @@ TEST(Writehero, pfile_write_hero)
AssertPlayer(Players[0]);
pfile_write_hero();
const char *path = "multi_0.sv";
uintmax_t fileSize;
ASSERT_TRUE(GetFileSize(path, &fileSize));
ASSERT_TRUE(GetFileSize(savePath.c_str(), &fileSize));
size_t size = static_cast<size_t>(fileSize);
FILE *f = std::fopen(path, "rb");
FILE *f = OpenFile(savePath.c_str(), "rb");
ASSERT_TRUE(f != nullptr);
std::unique_ptr<char[]> data { new char[size] };
ASSERT_EQ(std::fread(data.get(), size, 1, f), 1);

Loading…
Cancel
Save