summaryrefslogtreecommitdiff
path: root/src/testaccount.cpp
blob: 0198ff136a9d65d1fc871c7f5e49650fdee9e170 (plain) (blame)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
 *  The Mana World Server
 *  Copyright 2004 The Mana World Development Team
 *
 *  This file is part of The Mana World.
 *
 *  The Mana World  is free software; you can redistribute  it and/or modify it
 *  under the terms of the GNU General  Public License as published by the Free
 *  Software Foundation; either version 2 of the License, or any later version.
 *
 *  The Mana  World is  distributed in  the hope  that it  will be  useful, but
 *  WITHOUT ANY WARRANTY; without even  the implied warranty of MERCHANTABILITY
 *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 *  more details.
 *
 *  You should  have received a  copy of the  GNU General Public  License along
 *  with The Mana  World; if not, write to the  Free Software Foundation, Inc.,
 *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 *  $Id$
 */


#include "testaccount.h"


// register the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION(AccountTest);


using namespace tmwserv;


/**
 * Set up fixtures.
 */
void
AccountTest::setUp(void)
{
    Being* sam = new Being("sam", 1, 1, 1, 1, 1, 1, 1, 1);
    Being* merry = new Being("merry", 1, 1, 1, 1, 1, 1, 1, 1);
    Being* pippin = new Being("pippin", 1, 1, 1, 1, 1, 1, 1, 1);
    mCharacters.push_back(sam);
    mCharacters.push_back(merry);
    mCharacters.push_back(pippin);

    mAccount = new Account("frodo",
                           "baggins",
                           "frodo@theshire.com",
                           mCharacters);
}


/**
 * Tear down fixtures.
 */
void
AccountTest::tearDown(void)
{
    for (Beings::iterator it = mCharacters.begin();
         it != mCharacters.end();
         ++it)
    {
        delete (*it);
    }

    delete mAccount;
}


/**
 * Test creating an Account using the default constructor
 * and setting the account info using the mutators.
 */
void
AccountTest::testCreate1(void)
{
    const std::string name("frodo");
    const std::string password("baggins");
    const std::string encrypted("d70d266f4c276b5706881a46f43a88b0");
    const std::string email("frodo@theshire.com");

    Account account;
    account.setName(name);
    account.setPassword(password);
    account.setEmail(email);
    account.setCharacters(mCharacters);

    CPPUNIT_ASSERT_EQUAL(account.getName(), name);
    CPPUNIT_ASSERT_EQUAL(account.getPassword(), encrypted);
    CPPUNIT_ASSERT_EQUAL(account.getEmail(), email);

    CPPUNIT_ASSERT_EQUAL(mAccount->getCharacters().size(),
                         mCharacters.size());

    Beings& characters = account.getCharacters();

    for (int i = 0; i < mCharacters.size(); ++i) {
        CPPUNIT_ASSERT_EQUAL(characters[i]->getName(),
                             mCharacters[i]->getName());
    }
}


/**
 * Test creating an Account passing the initial account info
 * to the constructor.
 */
void
AccountTest::testCreate2(void)
{
    const std::string name("frodo");
    const std::string password("baggins");
    const std::string encrypted("d70d266f4c276b5706881a46f43a88b0");
    const std::string email("frodo@theshire.com");

    Account account(name, password, email, mCharacters);

    CPPUNIT_ASSERT_EQUAL(account.getName(), name);
    CPPUNIT_ASSERT_EQUAL(account.getPassword(), encrypted);
    CPPUNIT_ASSERT_EQUAL(account.getEmail(), email);

    CPPUNIT_ASSERT_EQUAL(mAccount->getCharacters().size(),
                         mCharacters.size());

    Beings& characters = account.getCharacters();

    for (int i = 0; i < mCharacters.size(); ++i) {
        CPPUNIT_ASSERT_EQUAL(characters[i]->getName(),
                             mCharacters[i]->getName());
    }
}


/**
 * Test adding a new character.
 */
void
AccountTest::testAddCharacter1(void)
{
    Being* bilbo = new Being("bilbo", 1, 1, 1, 1, 1, 1, 1, 1);

    mAccount->addCharacter(bilbo);

    CPPUNIT_ASSERT_EQUAL(mAccount->getCharacters().size(), (size_t) 4);

    std::vector<std::string> names;
    names.push_back("sam");
    names.push_back("merry");
    names.push_back("pippin");
    names.push_back("bilbo");

    for (int i = 0; i < mCharacters.size(); ++i) {
        CPPUNIT_ASSERT_EQUAL(mCharacters[i]->getName(), names[i]);
    }

    delete bilbo;
}


/**
 * Test passing a NULL pointer to addCharacter().
 */
void
AccountTest::testAddCharacter2(void)
{
    mAccount->addCharacter(NULL);

    CPPUNIT_ASSERT_EQUAL(mAccount->getCharacters().size(), (size_t) 3);

    std::vector<std::string> names;
    names.push_back("sam");
    names.push_back("merry");
    names.push_back("pippin");

    for (int i = 0; i < mCharacters.size(); ++i) {
        CPPUNIT_ASSERT_EQUAL(mCharacters[i]->getName(), names[i]);
    }
}


/**
 * Test the accessor getCharacter() with a valid name.
 */
void
AccountTest::testGetCharacter1(void)
{
    const std::string name("merry");

    Being* merry = mAccount->getCharacter(name);

    CPPUNIT_ASSERT(merry != 0);
    CPPUNIT_ASSERT_EQUAL(merry->getName(), name);
}


/**
 * Test the accessor getCharacter() with an unexisting name.
 */
void
AccountTest::testGetCharacter2(void)
{
    Being* nobody = mAccount->getCharacter("johndoe");

    CPPUNIT_ASSERT(nobody == 0);
}