diff --git a/test/drlg_test.hpp b/test/drlg_test.hpp index 9906116c4ff..0ae2af1709e 100644 --- a/test/drlg_test.hpp +++ b/test/drlg_test.hpp @@ -1,95 +1,95 @@ -/** - * @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 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(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(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(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; - } - } -} +/** + * @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 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(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(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(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; + } + } +} diff --git a/test/main.cpp b/test/main.cpp index a0941846e57..d09ffee62c6 100644 --- a/test/main.cpp +++ b/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 +#if __APPLE__ + devilution::paths::SetAssetsPath( + devilution::paths::BasePath() + "devilutionx.app/Contents/Resources/"); +#endif + testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/test/timedemo_test.cpp b/test/timedemo_test.cpp index afb60a00a46..ac04292e42f 100644 --- a/test/timedemo_test.cpp +++ b/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(); diff --git a/test/writehero_test.cpp b/test/writehero_test.cpp index e2c483d1d87..913a565e77a 100644 --- a/test/writehero_test.cpp +++ b/test/writehero_test.cpp @@ -369,7 +369,7 @@ TEST(Writehero, pfile_write_hero) // Please provide them so that the tests can run successfully ASSERT_TRUE(HaveSpawn() || HaveDiabdat()); - paths::SetPrefPath("."); + paths::SetPrefPath(paths::BasePath()); std::remove("multi_0.sv"); gbVanilla = true;