From 9217e8c7f07e76626d0f3ea2da2d67360fc54133 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 12 Aug 2021 21:15:24 +0200 Subject: [PATCH] Test CreatePlayer --- test/player_test.cpp | 101 +++++++++++++++++++++++++++++++++++++++- test/player_test.h | 41 ++++++++++++++++ test/writehero_test.cpp | 32 +------------ 3 files changed, 142 insertions(+), 32 deletions(-) create mode 100644 test/player_test.h diff --git a/test/player_test.cpp b/test/player_test.cpp index 803600fe6..d43744057 100644 --- a/test/player_test.cpp +++ b/test/player_test.cpp @@ -1,6 +1,6 @@ -#include +#include "player_test.h" -#include "player.h" +#include using namespace devilution; @@ -80,3 +80,100 @@ TEST(Player, PM_DoGotHit) EXPECT_EQ(BlockData[i][0], RunBlockTest(BlockData[i][1], BlockData[i][2])); } } + +static void AssertPlayer(PlayerStruct &player) +{ + ASSERT_EQ(Count8(player._pSplLvl, 64), 0); + ASSERT_EQ(Count8(player.InvGrid, NUM_INV_GRID_ELEM), 1); + ASSERT_EQ(CountItems(player.InvBody, NUM_INVLOC), 1); + ASSERT_EQ(CountItems(player.InvList, NUM_INV_GRID_ELEM), 1); + ASSERT_EQ(CountItems(player.SpdList, MAXBELTITEMS), 2); + ASSERT_EQ(CountItems(&player.HoldItem, 1), 1); + + ASSERT_EQ(player.position.tile.x, 0); + ASSERT_EQ(player.position.tile.y, 0); + ASSERT_EQ(player.position.future.x, 0); + ASSERT_EQ(player.position.future.y, 0); + ASSERT_EQ(player.plrlevel, 0); + ASSERT_EQ(player.destAction, 0); + ASSERT_STREQ(player._pName, ""); + ASSERT_EQ(player._pClass, HeroClass::Rogue); + ASSERT_EQ(player._pBaseStr, 20); + ASSERT_EQ(player._pStrength, 20); + ASSERT_EQ(player._pBaseMag, 15); + ASSERT_EQ(player._pMagic, 15); + ASSERT_EQ(player._pBaseDex, 30); + ASSERT_EQ(player._pDexterity, 30); + ASSERT_EQ(player._pBaseVit, 20); + ASSERT_EQ(player._pVitality, 20); + ASSERT_EQ(player._pLevel, 1); + ASSERT_EQ(player._pStatPts, 0); + ASSERT_EQ(player._pExperience, 0); + ASSERT_EQ(player._pGold, 100); + ASSERT_EQ(player._pMaxHPBase, 2880); + ASSERT_EQ(player._pHPBase, 2880); + ASSERT_EQ(player._pBaseToBlk, 20); + ASSERT_EQ(player._pMaxManaBase, 1440); + ASSERT_EQ(player._pManaBase, 1440); + ASSERT_EQ(player._pMemSpells, 0); + ASSERT_EQ(player._pNumInv, 1); + ASSERT_EQ(player.wReflections, 0); + ASSERT_EQ(player.pTownWarps, 0); + ASSERT_EQ(player.pDungMsgs, 0); + ASSERT_EQ(player.pDungMsgs2, 0); + ASSERT_EQ(player.pLvlLoad, 0); + ASSERT_EQ(player.pDiabloKillLevel, 0); + ASSERT_EQ(player.pBattleNet, 0); + ASSERT_EQ(player.pManaShield, 0); + ASSERT_EQ(player.pDifficulty, 0); + ASSERT_EQ(player.pDamAcFlags, 0); + + ASSERT_EQ(player._pmode, 0); + ASSERT_EQ(Count8(player.walkpath, MAX_PATH_LENGTH), 0); + ASSERT_EQ(player._pSpell, 0); + ASSERT_EQ(player._pSplType, 0); + ASSERT_EQ(player._pSplFrom, 0); + ASSERT_EQ(player._pTSpell, 0); + ASSERT_EQ(player._pRSpell, 28); + ASSERT_EQ(player._pRSplType, 0); + ASSERT_EQ(player._pSBkSpell, 0); + ASSERT_EQ(player._pAblSpells, 134217728); + ASSERT_EQ(player._pScrlSpells, 0); + ASSERT_EQ(player._pSpellFlags, 0); + ASSERT_EQ(player._pBlockFlag, 0); + ASSERT_EQ(player._pLightRad, 10); + ASSERT_EQ(player._pDamageMod, 0); + ASSERT_EQ(player._pHitPoints, 2880); + ASSERT_EQ(player._pMaxHP, 2880); + ASSERT_EQ(player._pMana, 1440); + ASSERT_EQ(player._pMaxMana, 1440); + ASSERT_EQ(player._pNextExper, 2000); + ASSERT_EQ(player._pMagResist, 0); + ASSERT_EQ(player._pFireResist, 0); + ASSERT_EQ(player._pLghtResist, 0); + ASSERT_EQ(CountBool(player._pLvlVisited, NUMLEVELS), 0); + ASSERT_EQ(CountBool(player._pSLvlVisited, NUMLEVELS), 0); + ASSERT_EQ(player._pIMinDam, 1); + ASSERT_EQ(player._pIMaxDam, 1); + ASSERT_EQ(player._pIAC, 0); + ASSERT_EQ(player._pIBonusDam, 0); + ASSERT_EQ(player._pIBonusToHit, 0); + ASSERT_EQ(player._pIBonusAC, 0); + ASSERT_EQ(player._pIBonusDamMod, 0); + ASSERT_EQ(player._pISpells, 0); + ASSERT_EQ(player._pIFlags, 0); + ASSERT_EQ(player._pIGetHit, 0); + ASSERT_EQ(player._pISplLvlAdd, 0); + ASSERT_EQ(player._pISplDur, 0); + ASSERT_EQ(player._pIEnAc, 0); + ASSERT_EQ(player._pIFMinDam, 0); + ASSERT_EQ(player._pIFMaxDam, 0); + ASSERT_EQ(player._pILMinDam, 0); + ASSERT_EQ(player._pILMaxDam, 0); +} + +TEST(Player, CreatePlayer) +{ + CreatePlayer(0, HeroClass::Rogue); + AssertPlayer(Players[0]); +} diff --git a/test/player_test.h b/test/player_test.h new file mode 100644 index 000000000..7619cad81 --- /dev/null +++ b/test/player_test.h @@ -0,0 +1,41 @@ +/** + * @file player_test.h + * + * Helpers for player related tests. + */ +#pragma once + +#include "player.h" +#include "items.h" + +using namespace devilution; + +static int CountItems(ItemStruct *items, int n) +{ + int count = n; + for (int i = 0; i < n; i++) + if (items[i].isEmpty()) + count--; + + return count; +} + +static int Count8(int8_t *ints, int n) +{ + int count = n; + for (int i = 0; i < n; i++) + if (ints[i] == 0) + count--; + + return count; +} + +static int CountBool(bool *bools, int n) +{ + int count = n; + for (int i = 0; i < n; i++) + if (!bools[i]) + count--; + + return count; +} diff --git a/test/writehero_test.cpp b/test/writehero_test.cpp index f017af5a3..9928f3c30 100644 --- a/test/writehero_test.cpp +++ b/test/writehero_test.cpp @@ -1,3 +1,5 @@ +#include "player_test.h" + #include #include #include @@ -212,36 +214,6 @@ static void PackPlayerTest(PkPlayerStruct *pPack) pPack->_pNumInv = 2; } -static int CountItems(ItemStruct *items, int n) -{ - int count = n; - for (int i = 0; i < n; i++) - if (items[i].isEmpty()) - count--; - - return count; -} - -static int Count8(int8_t *ints, int n) -{ - int count = n; - for (int i = 0; i < n; i++) - if (ints[i] == 0) - count--; - - return count; -} - -static int CountBool(bool *bools, int n) -{ - int count = n; - for (int i = 0; i < n; i++) - if (!bools[i]) - count--; - - return count; -} - static void AssertPlayer(PlayerStruct &player) { ASSERT_EQ(Count8(player._pSplLvl, 64), 23);