-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathgm_gameworld_test.cpp
More file actions
129 lines (105 loc) · 4.43 KB
/
gm_gameworld_test.cpp
File metadata and controls
129 lines (105 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <gtest/gtest.h>
#include "gm_gameworld.h"
#include "gamecontent/map.h"
#include "console.h"
#include "gamecontent/creature.h"
#include "gamecontent/globalvars.h"
// Test fixture for GM_Gameworld
class GM_GameworldTest : public ::testing::Test {
protected:
GM_Gameworld* gameworld;
void SetUp() override {
gameworld = NULL; g_game = NULL; // precaution in case previous attempt failed
char * cmdline = "./gm_gameworld_test"; // ideally we'd get argv[0] et al; or as backup, TEST_TARGET; but we can't get former easily, and latter might not be populated if test is directly run
yatc_fopen_init(cmdline); // needed so data files can be found in .runfiles
Objects::getInstance()->loadDat("Tibia.dat"); // TODO: should not try to present winOutfit_t and thus require loading outift and dat!
gameworld = new GM_Gameworld();
g_game = gameworld;
}
void TearDown() override {
if (Objects::getInstance()) {
Objects::getInstance()->unloadDat();
Objects::destroyInstance();
}
// TODO: unload gfx?
delete gameworld;
g_game = NULL;
}
};
// Test onCreatureSpeak with SPEAK_PRIVATE_NP
TEST_F(GM_GameworldTest, OnCreatureSpeak_PrivateNP) {
std::string name = "NPC";
std::string message = "Hello, player!";
Position pos = {100, 100, 7};
gameworld->onCreatureSpeak(SPEAK_PRIVATE_NP, 0, name, 0, pos, message);
auto console = gameworld->findConsole("NPCs");
ASSERT_NE(console, nullptr);
const auto& lastEntry = console->getLastEntry();
EXPECT_EQ(lastEntry.getFullText(), message);
EXPECT_EQ(lastEntry.getSpeaker(), name);
EXPECT_EQ(lastEntry.getColor(), TEXTCOLOR_LIGHTBLUE);
}
// Test onCreatureSpeak with SPEAK_MONSTER_SAY
TEST_F(GM_GameworldTest, OnCreatureSpeak_MonsterSay) {
std::string name = "Monster";
std::string message = "Roar!";
Position pos = {100, 100, 7};
gameworld->onCreatureSpeak(SPEAK_MONSTER_SAY, 0, name, 0, pos, message);
auto map = Map::getInstance();
const auto& publicMessage = map.getPublicMessages().back();
EXPECT_EQ(publicMessage.getText(), message);
EXPECT_EQ(publicMessage.getSender(), name);
EXPECT_EQ(publicMessage.getColor(), TEXTCOLOR_ORANGE);
}
// Test onCreatureSpeak with SPEAK_WHISPER
TEST_F(GM_GameworldTest, OnCreatureSpeak_Whisper) {
std::string name = "Player";
std::string message = "Psst!";
Position pos = {100, 100, 7};
gameworld->onCreatureSpeak(SPEAK_WHISPER, 0, name, 0, pos, message);
auto console = gameworld->getDefaultConsole();
ASSERT_NE(console, nullptr);
const auto& lastEntry = console->getLastEntry();
EXPECT_EQ(lastEntry.getFullText(), message);
EXPECT_EQ(lastEntry.getSpeaker(), name);
EXPECT_EQ(lastEntry.getColor(), TEXTCOLOR_YELLOW);
}
// Test onCreatureSpeak with SPEAK_SAY
TEST_F(GM_GameworldTest, OnCreatureSpeak_Say) {
std::string name = "Player";
std::string message = "Hello!";
Position pos = {100, 100, 7};
gameworld->onCreatureSpeak(SPEAK_SAY, 0, name, 0, pos, message);
auto console = gameworld->getDefaultConsole();
ASSERT_NE(console, nullptr);
const auto& lastEntry = console->getLastEntry();
EXPECT_EQ(lastEntry.getFullText(), message);
EXPECT_EQ(lastEntry.getSpeaker(), name);
EXPECT_EQ(lastEntry.getColor(), TEXTCOLOR_YELLOW);
}
// Test onCreatureSpeak with SPEAK_YELL
TEST_F(GM_GameworldTest, OnCreatureSpeak_Yell) {
std::string name = "Player";
std::string message = "Hey!";
Position pos = {100, 100, 7};
gameworld->onCreatureSpeak(SPEAK_YELL, 0, name, 0, pos, message);
auto console = gameworld->getDefaultConsole();
ASSERT_NE(console, nullptr);
const auto& lastEntry = console->getLastEntry();
EXPECT_EQ(lastEntry.getFullText(), message);
EXPECT_EQ(lastEntry.getSpeaker(), name);
EXPECT_EQ(lastEntry.getColor(), TEXTCOLOR_YELLOW);
}
// Test onCreatureSpeak with SPEAK_PRIVATE
TEST_F(GM_GameworldTest, OnCreatureSpeak_Private) {
std::string name = "Player";
std::string message = "Private message";
Position pos = {100, 100, 7};
gameworld->onCreatureSpeak(SPEAK_PRIVATE, 0, name, 0, pos, message);
auto console = gameworld->findConsole(name);
ASSERT_NE(console, nullptr);
const auto& lastEntry = console->getLastEntry();
EXPECT_EQ(lastEntry.getFullText(), message);
EXPECT_EQ(lastEntry.getSpeaker(), name);
EXPECT_EQ(lastEntry.getColor(), TEXTCOLOR_LIGHTBLUE);
}