AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
IntegrationTestFixture Class Reference

#include "IntegrationTestFixture.h"

Inheritance diagram for IntegrationTestFixture:

Protected Member Functions

void SetUp () override
 
void TearDown () override
 
TestPlayerCreateTestPlayer (ObjectGuid::LowType guidLow=1, std::string const &name="TestPlayer", AccountTypes security=SEC_PLAYER)
 
TestCreatureCreateTestCreature (ObjectGuid::LowType guidLow, uint32 entry, uint32 factionId)
 
NiceMock< WorldMock > * GetWorldMock ()
 
TestMapGetTestMap ()
 

Static Private Member Functions

static void EnsureFactionTemplates ()
 

Private Attributes

IWorld_originalWorld = nullptr
 
NiceMock< WorldMock > * _worldMock = nullptr
 
TestMap_testMap = nullptr
 
std::vector< TestPlayer * > _trackedPlayers
 
std::vector< TestCreature * > _trackedCreatures
 
std::vector< CreatureTemplate * > _ownedCreatureTemplates
 

Detailed Description

Member Function Documentation

◆ CreateTestCreature()

TestCreature * IntegrationTestFixture::CreateTestCreature ( ObjectGuid::LowType  guidLow,
uint32  entry,
uint32  factionId 
)
inlineprotected
119 {
120 // CreatureTemplate must be heap-allocated AFTER WorldMock is installed
121 // because CreatureMovementData() constructor calls sWorld->getIntConfig()
122 auto* tmpl = new CreatureTemplate();
123 tmpl->Entry = entry;
124 tmpl->faction = factionId;
125 tmpl->minlevel = 80;
126 tmpl->maxlevel = 80;
127 tmpl->unit_class = CLASS_WARRIOR;
128 tmpl->DamageModifier = 1.0f;
129 tmpl->BaseAttackTime = 2000;
130 tmpl->RangeAttackTime = 2000;
131 tmpl->BaseVariance = 1.0f;
132 tmpl->RangeVariance = 1.0f;
133 tmpl->ModHealth = 1.0f;
134 _ownedCreatureTemplates.push_back(tmpl);
135
136 auto* creature = new TestCreature();
137 creature->ForceInitValues(guidLow, entry);
138 creature->SetTestMap(_testMap);
139 creature->SetInWorld(true);
140 creature->SetAlive(true);
141 creature->SetPhase(1);
142 creature->SetFaction(factionId);
143 creature->SetLevel(80);
144 creature->SetMaxHealth(10000);
145 creature->SetHealth(10000);
146 creature->InitializeThreatManager();
147 _trackedCreatures.push_back(creature);
148
149 return creature;
150 }
@ CLASS_WARRIOR
Definition SharedDefines.h:126
std::vector< CreatureTemplate * > _ownedCreatureTemplates
Definition IntegrationTestFixture.h:189
TestMap * _testMap
Definition IntegrationTestFixture.h:186
std::vector< TestCreature * > _trackedCreatures
Definition IntegrationTestFixture.h:188
Definition TestCreature.h:36
Definition CreatureData.h:187

References _ownedCreatureTemplates, _testMap, _trackedCreatures, and CLASS_WARRIOR.

◆ CreateTestPlayer()

TestPlayer * IntegrationTestFixture::CreateTestPlayer ( ObjectGuid::LowType  guidLow = 1,
std::string const &  name = "TestPlayer",
AccountTypes  security = SEC_PLAYER 
)
inlineprotected
100 {
101 auto* session = new WorldSession(guidLow, std::string(name), 0, nullptr, security,
102 EXPANSION_WRATH_OF_THE_LICH_KING, 0, LOCALE_enUS, 0, false, false, 0);
103 // Pre-allocate RBAC data so Player's ctor (which calls
104 // GetSession()->HasPermission) doesn't try to load from DB.
105 session->InitRBACDataForTest();
106
107 auto* player = new TestPlayer(session);
108 player->ForceInitValues(guidLow);
109 session->SetPlayer(player);
110 player->SetSession(session);
111 player->SetMap(_testMap);
112 player->AddToWorld();
113 _trackedPlayers.push_back(player);
114
115 return player;
116 }
@ LOCALE_enUS
Definition Common.h:126
@ EXPANSION_WRATH_OF_THE_LICH_KING
Definition SharedDefines.h:55
std::vector< TestPlayer * > _trackedPlayers
Definition IntegrationTestFixture.h:187
Definition TestPlayer.h:24
Player session in the World.
Definition WorldSession.h:409

References _testMap, _trackedPlayers, EXPANSION_WRATH_OF_THE_LICH_KING, and LOCALE_enUS.

◆ EnsureFactionTemplates()

static void IntegrationTestFixture::EnsureFactionTemplates ( )
inlinestaticprivate
157 {
158 static bool initialized = false;
159 if (initialized)
160 return;
161 initialized = true;
162
163 // Faction 90001: "player-like" — ourMask=1 (FACTION_MASK_PLAYER), hostile to monsters (hostileMask=8)
164 auto* f1 = new FactionTemplateEntry();
165 std::memset(f1, 0, sizeof(FactionTemplateEntry));
168 f1->ourMask = 0x1; // FACTION_MASK_PLAYER
169 f1->friendlyMask = 0x1; // friendly to players
170 f1->hostileMask = 0x8; // hostile to monsters
172
173 // Faction 90002: "monster" — ourMask=8 (FACTION_MASK_MONSTER), hostile to players (hostileMask=1)
174 auto* f2 = new FactionTemplateEntry();
175 std::memset(f2, 0, sizeof(FactionTemplateEntry));
177 f2->faction = TEST_FACTION_HOSTILE_TO_ALL;
178 f2->ourMask = 0x8; // FACTION_MASK_MONSTER
179 f2->friendlyMask = 0x0; // friendly to none
180 f2->hostileMask = 0x1; // hostile to players
182 }
DBCStorage< FactionTemplateEntry > sFactionTemplateStore(FactionTemplateEntryfmt)
static constexpr uint32 TEST_FACTION_HOSTILE_TO_ALL
Definition IntegrationTestFixture.h:36
static constexpr uint32 TEST_FACTION_HOSTILE_TO_MONSTERS
Definition IntegrationTestFixture.h:35
Definition DBCStructure.h:939

References sFactionTemplateStore, TEST_FACTION_HOSTILE_TO_ALL, and TEST_FACTION_HOSTILE_TO_MONSTERS.

Referenced by SetUp().

◆ GetTestMap()

TestMap * IntegrationTestFixture::GetTestMap ( )
inlineprotected
153{ return _testMap; }

References _testMap.

◆ GetWorldMock()

NiceMock< WorldMock > * IntegrationTestFixture::GetWorldMock ( )
inlineprotected
152{ return _worldMock; }
NiceMock< WorldMock > * _worldMock
Definition IntegrationTestFixture.h:185

References _worldMock.

◆ SetUp()

void IntegrationTestFixture::SetUp ( )
inlineoverrideprotected
42 {
45
46 _originalWorld = sWorld.release();
47 _worldMock = new NiceMock<WorldMock>();
48 sWorld.reset(_worldMock);
49
50 static std::string emptyString;
51 ON_CALL(*_worldMock, GetDataPath()).WillByDefault(ReturnRef(emptyString));
52 ON_CALL(*_worldMock, GetRealmName()).WillByDefault(ReturnRef(emptyString));
53 ON_CALL(*_worldMock, GetDefaultDbcLocale()).WillByDefault(Return(LOCALE_enUS));
54 ON_CALL(*_worldMock, getRate(_)).WillByDefault(Return(1.0f));
55 ON_CALL(*_worldMock, getBoolConfig(_)).WillByDefault(Return(false));
56 ON_CALL(*_worldMock, getIntConfig(_)).WillByDefault(Return(0));
57 ON_CALL(*_worldMock, getFloatConfig(_)).WillByDefault(Return(0.0f));
58 ON_CALL(*_worldMock, GetPlayerSecurityLimit()).WillByDefault(Return(SEC_PLAYER));
59
60 _testMap = new TestMap();
61 }
@ SEC_PLAYER
Definition Common.h:57
IWorld * _originalWorld
Definition IntegrationTestFixture.h:184
static void EnsureFactionTemplates()
Definition IntegrationTestFixture.h:156
Definition TestMap.h:33
static void EnsureDBC()
Definition TestMap.cpp:41
#define sWorld
Definition World.h:318

References _originalWorld, _testMap, _worldMock, TestMap::EnsureDBC(), EnsureFactionTemplates(), LOCALE_enUS, SEC_PLAYER, and sWorld.

◆ TearDown()

void IntegrationTestFixture::TearDown ( )
inlineoverrideprotected
64 {
65 for (auto* creature : _trackedCreatures)
66 {
67 if (creature->IsInWorld())
68 creature->RemoveFromWorld();
69 delete creature;
70 }
71 _trackedCreatures.clear();
72
73 for (auto* player : _trackedPlayers)
74 {
75 if (player->IsInWorld())
76 player->RemoveFromWorld();
77 }
78 _trackedPlayers.clear();
79
80 for (auto* tmpl : _ownedCreatureTemplates)
81 delete tmpl;
83
84 delete _testMap;
85 _testMap = nullptr;
86
87 IWorld* currentWorld = sWorld.release();
88 delete currentWorld;
89 _worldMock = nullptr;
90
92 _originalWorld = nullptr;
93
94 // Intentional leaks of session/player to avoid database access in destructors
95 }
Definition IWorld.h:63

References _originalWorld, _ownedCreatureTemplates, _testMap, _trackedCreatures, _trackedPlayers, _worldMock, and sWorld.

Member Data Documentation

◆ _originalWorld

IWorld* IntegrationTestFixture::_originalWorld = nullptr
private

Referenced by SetUp(), and TearDown().

◆ _ownedCreatureTemplates

std::vector<CreatureTemplate*> IntegrationTestFixture::_ownedCreatureTemplates
private

Referenced by CreateTestCreature(), and TearDown().

◆ _testMap

TestMap* IntegrationTestFixture::_testMap = nullptr
private

◆ _trackedCreatures

std::vector<TestCreature*> IntegrationTestFixture::_trackedCreatures
private

Referenced by CreateTestCreature(), and TearDown().

◆ _trackedPlayers

std::vector<TestPlayer*> IntegrationTestFixture::_trackedPlayers
private

Referenced by CreateTestPlayer(), and TearDown().

◆ _worldMock

NiceMock<WorldMock>* IntegrationTestFixture::_worldMock = nullptr
private

Referenced by GetWorldMock(), SetUp(), and TearDown().


The documentation for this class was generated from the following file: