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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
/*
* 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 <sstream>
#include "../utils/logger.h"
#include "testrecordset.h"
// register the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION(RecordSetTest);
using namespace tmwserv::dal;
/**
* Set up fixtures.
*/
void
RecordSetTest::setUp(void)
{
// populate mNonEmptyRs.
Row headers;
headers.push_back("id");
headers.push_back("name");
mNonEmptyRs.setColumnHeaders(headers);
Row r1;
r1.push_back("1");
r1.push_back("john");
mNonEmptyRs.add(r1);
Row r2;
r2.push_back("2");
r2.push_back("mike");
mNonEmptyRs.add(r2);
}
/**
* Tear down fixtures.
*/
void
RecordSetTest::tearDown(void)
{
// NOOP
}
/**
* Test RecordSet::rows() on an empty RecordSet.
*/
void
RecordSetTest::testRows1(void)
{
LOG("RecordSetTest::testRows1()");
CPPUNIT_ASSERT_EQUAL((unsigned int) 0, mEmptyRs.rows());
}
/**
* Test RecordSet::rows() on a non-empty RecordSet.
*/
void
RecordSetTest::testRows2(void)
{
LOG("RecordSetTest::testRows2()");
CPPUNIT_ASSERT_EQUAL((unsigned int) 2, mNonEmptyRs.rows());
}
/**
* Test RecordSet::cols() on an empty RecordSet.
*/
void
RecordSetTest::testCols1(void)
{
LOG("RecordSetTest::testCols1()");
CPPUNIT_ASSERT_EQUAL((unsigned int) 0, mEmptyRs.cols());
}
/**
* Test RecordSet::cols() on a non-empty RecordSet.
*/
void
RecordSetTest::testCols2(void)
{
LOG("RecordSetTest::testCols2()");
CPPUNIT_ASSERT_EQUAL((unsigned int) 2, mNonEmptyRs.cols());
}
/**
* Call RecordSet::isEmpty() from an empty RecordSet.
*/
void
RecordSetTest::testIsEmpty1(void)
{
LOG("RecordSetTest::testIsEmpty1()");
CPPUNIT_ASSERT(mEmptyRs.isEmpty());
}
/**
* Call RecordSet::isEmpty() from a non-empty RecordSet.
*/
void
RecordSetTest::testIsEmpty2(void)
{
LOG("RecordSetTest::testIsEmpty2()");
CPPUNIT_ASSERT(!mNonEmptyRs.isEmpty());
}
/**
* Call RecordSet::operator() from an empty RecordSet.
*/
void
RecordSetTest::testOperator1(void)
{
LOG("RecordSetTest::testOperator1()");
// this should throw std::invalid_argument.
mEmptyRs(0, 0);
}
/**
* Call RecordSet::operator() from a non-empty RecordSet with
* a row index and a column index as parameters.
*/
void
RecordSetTest::testOperator2(void)
{
LOG("RecordSetTest::testRows1()");
const std::string value("mike");
CPPUNIT_ASSERT_EQUAL(value, mNonEmptyRs(1, 1));
}
/**
* Call RecordSet::operator() from a non-empty RecordSet with
* a row index and a column index that are out of range as
* parameters.
*/
void
RecordSetTest::testOperator3(void)
{
LOG("RecordSetTest::testOperator3()");
// this should throw std::out_of_range.
mNonEmptyRs(2, 2);
}
/**
* Call RecordSet::operator() from a non-empty RecordSet with
* a row index and a field name as parameters.
*/
void
RecordSetTest::testOperator4(void)
{
LOG("RecordSetTest::testOperator4()");
const std::string value("1");
CPPUNIT_ASSERT_EQUAL(value, mNonEmptyRs(0, "id"));
}
/**
* Call RecordSet::operator() from a non-empty RecordSet with
* a row index that is out of range and a field name as parameters.
*/
void
RecordSetTest::testOperator5(void)
{
LOG("RecordSetTest::testOperator5()");
// this should throw std::out_of_range.
mNonEmptyRs(3, "id");
}
/**
* Call RecordSet::operator() from a non-empty RecordSet with
* a row index and a field name that does not exist as parameters.
*/
void
RecordSetTest::testOperator6(void)
{
LOG("RecordSetTest::testOperator6()");
// this should throw std::invalid_argument.
mNonEmptyRs(1, "noname");
}
/**
* Test writing an empty RecordSet to an output stream.
*/
void
RecordSetTest::testOutputStream1(void)
{
LOG("RecordSetTest::testOutputStream1()");
const std::string emptyStr;
std::ostringstream os;
os << mEmptyRs;
CPPUNIT_ASSERT_EQUAL(emptyStr, os.str());
}
/**
* Test writing a non-empty RecordSet to an output stream.
*/
void
RecordSetTest::testOutputStream2(void)
{
LOG("RecordSetTest::testOutputStream2()");
std::ostringstream os1;
os1 << "|id|name|" << std::endl << std::endl
<< "|1|john|" << std::endl
<< "|2|mike|" << std::endl;
std::ostringstream os2;
os2 << mNonEmptyRs;
CPPUNIT_ASSERT_EQUAL(os1.str(), os2.str());
}
/**
* Test RecordSet::add() to add a new now.
*/
void
RecordSetTest::testAdd1(void)
{
LOG("RecordSetTest::testAdd1()");
const std::string id("3");
const std::string name("elena");
Row r;
r.push_back(id);
r.push_back(name);
mNonEmptyRs.add(r);
CPPUNIT_ASSERT_EQUAL((unsigned int) 3, mNonEmptyRs.rows());
CPPUNIT_ASSERT_EQUAL((unsigned int) 2, mNonEmptyRs.cols());
CPPUNIT_ASSERT_EQUAL(id, mNonEmptyRs(2, 0));
CPPUNIT_ASSERT_EQUAL(name, mNonEmptyRs(2, 1));
}
/**
* Test RecordSet::add() to add a new now with a different number
* of fields.
*/
void
RecordSetTest::testAdd2(void)
{
LOG("RecordSetTest::testAdd2()");
Row r;
r.push_back("4");
// this should throw std::invalid_argument.
mNonEmptyRs.add(r);
}
/**
* Test RecordSet::add() to add a new now to a RecordSet that does
* not have column headers.
*/
void
RecordSetTest::testAdd3(void)
{
LOG("RecordSetTest::testAdd3()");
Row r;
r.push_back("5");
// this should throw tmw::dal::RsColumnHeadersNotSet.
mEmptyRs.add(r);
}
|