1 #include "testOutOfGame.h"
2 #include "setupHelpers.h"
3 #include "signalHelpers.h"
4 #include <sigc++/functors/mem_fun.h>
5 #include <cassert>
6 #include <Eris/PollDefault.h>
7 #include <Eris/Entity.h>
8 #include <Atlas/Objects/Entity.h>
9
testLogin()10 void testLogin()
11 {
12 AutoConnection con = stdConnect();
13 AutoAccount player(new Eris::Account(con.get()));
14
15 SignalCounter0 loginCount;
16 player->LoginSuccess.connect(sigc::mem_fun(loginCount, &SignalCounter0::fired));
17
18 SignalCounter1<const std::string&> loginErrorCounter;
19 player->LoginFailure.connect(sigc::mem_fun(loginErrorCounter, &SignalCounter1<const std::string&>::fired));
20
21 player->login("account_A", "pumpkin");
22
23 while (!loginCount.fireCount() && !loginErrorCounter.fireCount())
24 {
25 Eris::PollDefault::poll();
26 }
27
28 assert(loginErrorCounter.fireCount() == 0);
29
30 assert(player->getId() == "_23_account_A");
31 assert(player->isLoggedIn());
32 }
33
testBadLogin()34 void testBadLogin()
35 {
36 AutoConnection con = stdConnect();
37 AutoAccount player(new Eris::Account(con.get()));
38
39 SignalCounter0 loginCount;
40 player->LoginSuccess.connect(sigc::mem_fun(loginCount, &SignalCounter0::fired));
41
42 SignalCounter1<const std::string&> loginErrorCounter;
43 player->LoginFailure.connect(sigc::mem_fun(loginErrorCounter, &SignalCounter1<const std::string&>::fired));
44
45 player->login("account_B", "zark!!!!ojijiksapumpkin");
46
47 while (!loginCount.fireCount() && !loginErrorCounter.fireCount())
48 {
49 Eris::PollDefault::poll();
50 }
51
52 assert(loginErrorCounter.fireCount() == 1);
53 assert(loginCount.fireCount() == 0);
54 assert(!player->isLoggedIn());
55 }
56
testBadLogin2()57 void testBadLogin2()
58 {
59 AutoConnection con = stdConnect();
60 AutoAccount player(new Eris::Account(con.get()));
61
62 SignalCounter0 loginCount;
63 player->LoginSuccess.connect(sigc::mem_fun(loginCount, &SignalCounter0::fired));
64
65 SignalCounter1<const std::string&> loginErrorCounter;
66 player->LoginFailure.connect(sigc::mem_fun(loginErrorCounter, &SignalCounter1<const std::string&>::fired));
67
68 player->login("_timeout_", "foo");
69
70 while (!loginCount.fireCount() && !loginErrorCounter.fireCount())
71 {
72 Eris::PollDefault::poll();
73 }
74
75 assert(loginErrorCounter.fireCount() == 1);
76 assert(loginCount.fireCount() == 0);
77 assert(!player->isLoggedIn());
78 }
79
testAccCreate()80 void testAccCreate()
81 {
82 AutoConnection con = stdConnect();
83 AutoAccount player(new Eris::Account(con.get()));
84
85 SignalCounter0 loginCount;
86 player->LoginSuccess.connect(sigc::mem_fun(loginCount, &SignalCounter0::fired));
87
88 SignalCounter1<const std::string&> loginErrorCounter;
89 player->LoginFailure.connect(sigc::mem_fun(loginErrorCounter, &SignalCounter1<const std::string&>::fired));
90
91 player->createAccount("account_D", "John Doe", "lemon");
92
93 while (!loginCount.fireCount() && !loginErrorCounter.fireCount())
94 {
95 Eris::PollDefault::poll();
96 }
97
98 assert(loginErrorCounter.fireCount() == 0);
99
100 assert(player->getUsername() == "account_D");
101 assert(player->isLoggedIn());
102 }
103
testDuplicateCreate()104 void testDuplicateCreate()
105 {
106 AutoConnection con = stdConnect();
107 AutoAccount player(new Eris::Account(con.get()));
108
109 SignalCounter0 loginCount;
110 player->LoginSuccess.connect(sigc::mem_fun(loginCount, &SignalCounter0::fired));
111
112 SignalCounter1<const std::string&> loginErrorCounter;
113 player->LoginFailure.connect(sigc::mem_fun(loginErrorCounter, &SignalCounter1<const std::string&>::fired));
114 player->createAccount("account_C", "John Doe", "lemon");
115
116 while (!loginCount.fireCount() && !loginErrorCounter.fireCount())
117 {
118 Eris::PollDefault::poll();
119 }
120
121 assert(loginErrorCounter.fireCount() == 1);
122 }
123
testAccountCharacters()124 void testAccountCharacters()
125 {
126 AutoConnection con = stdConnect();
127 AutoAccount player = stdLogin("account_B", "sweede", con.get());
128
129 SignalCounter0 gotChars;
130 player->GotAllCharacters.connect(sigc::mem_fun(gotChars, &SignalCounter0::fired));
131 player->refreshCharacterInfo();
132
133 while (gotChars.fireCount() == 0)
134 {
135 Eris::PollDefault::poll();
136 }
137
138 const Eris::CharacterMap& chars = player->getCharacters();
139 Eris::CharacterMap::const_iterator C = chars.find("acc_b_character");
140 assert(C != chars.end());
141 assert(C->second->getName() == "Joe Blow");
142 }
143
testLogout()144 void testLogout()
145 {
146 AutoConnection con = stdConnect();
147 AutoAccount player = stdLogin("account_C", "turnip", con.get());
148
149 SignalCounter1<bool> gotLogout;
150 player->LogoutComplete.connect(sigc::mem_fun(gotLogout, &SignalCounter1<bool>::fired));
151 player->logout();
152
153 while (gotLogout.fireCount() == 0) Eris::PollDefault::poll();
154
155 assert(!player->isLoggedIn());
156 }
157
testBadTake()158 void testBadTake()
159 {
160 AutoConnection con = stdConnect();
161 AutoAccount player = stdLogin("account_B", "sweede", con.get());
162
163 AvatarGetter g(player.get());
164 g.expectFailure();
165 AutoAvatar av2 = g.take("_fail_");
166 assert(av2.get() == NULL);
167 }
168
testServerInfo()169 void testServerInfo()
170 {
171 AutoConnection con = stdConnect();
172
173 Eris::ServerInfo sinfo;
174 con->getServerInfo(sinfo);
175 assert(sinfo.getStatus() == Eris::ServerInfo::INVALID);
176
177 SignalCounter0 counter;
178 con->GotServerInfo.connect(sigc::mem_fun(counter, &SignalCounter0::fired));
179
180 con->refreshServerInfo();
181
182 while (!counter.fireCount()) {
183 Eris::PollDefault::poll();
184 }
185
186 con->getServerInfo(sinfo);
187 assert(sinfo.getStatus() == Eris::ServerInfo::VALID);
188 assert(sinfo.getHostname() == "localhost");
189 assert(sinfo.getServername() == "Bob's StubServer");
190 assert(sinfo.getRuleset() == "stub-world");
191 }
192