Browse Source

Test CreatePlayer

pull/2531/head
Anders Jenbo 5 years ago
parent
commit
9217e8c7f0
  1. 101
      test/player_test.cpp
  2. 41
      test/player_test.h
  3. 32
      test/writehero_test.cpp

101
test/player_test.cpp

@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include "player_test.h"
#include "player.h"
#include <gtest/gtest.h>
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]);
}

41
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;
}

32
test/writehero_test.cpp

@ -1,3 +1,5 @@
#include "player_test.h"
#include <cstdio>
#include <fstream>
#include <gtest/gtest.h>
@ -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);

Loading…
Cancel
Save