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
|
/***************************************************************************
mymoneyinstitutiontest.cpp
-------------------
copyright : (C) 2002 by Thomas Baumgart
email : ipwizard@users.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program 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 *
* (at your option) any later version. *
* *
***************************************************************************/
#include "mymoneyinstitutiontest.h"
#include <kmymoney/mymoneyexception.h>
MyMoneyInstitutionTest::MyMoneyInstitutionTest()
{
}
void MyMoneyInstitutionTest::setUp () {
m = new MyMoneyInstitution();
n = new MyMoneyInstitution("name", "town", "street", "postcode",
"telephone", "manager", "sortcode");
}
void MyMoneyInstitutionTest::tearDown () {
delete m;
delete n;
}
void MyMoneyInstitutionTest::testEmptyConstructor() {
CPPUNIT_ASSERT(m->id().isEmpty());
CPPUNIT_ASSERT(m->street().isEmpty());
CPPUNIT_ASSERT(m->town().isEmpty());
CPPUNIT_ASSERT(m->postcode().isEmpty());
CPPUNIT_ASSERT(m->telephone().isEmpty());
CPPUNIT_ASSERT(m->manager().isEmpty());
CPPUNIT_ASSERT(m->accountCount() == 0);
}
void MyMoneyInstitutionTest::testSetFunctions() {
m->setStreet("street");
m->setTown("town");
m->setPostcode("postcode");
m->setTelephone("telephone");
m->setManager("manager");
m->setName("name");
CPPUNIT_ASSERT(m->id().isEmpty());
CPPUNIT_ASSERT(m->street() == "street");
CPPUNIT_ASSERT(m->town() == "town");
CPPUNIT_ASSERT(m->postcode() == "postcode");
CPPUNIT_ASSERT(m->telephone() == "telephone");
CPPUNIT_ASSERT(m->manager() == "manager");
CPPUNIT_ASSERT(m->name() == "name");
}
void MyMoneyInstitutionTest::testNonemptyConstructor() {
CPPUNIT_ASSERT(n->id().isEmpty());
CPPUNIT_ASSERT(n->street() == "street");
CPPUNIT_ASSERT(n->town() == "town");
CPPUNIT_ASSERT(n->postcode() == "postcode");
CPPUNIT_ASSERT(n->telephone() == "telephone");
CPPUNIT_ASSERT(n->manager() == "manager");
CPPUNIT_ASSERT(n->name() == "name");
CPPUNIT_ASSERT(n->sortcode() == "sortcode");
}
void MyMoneyInstitutionTest::testCopyConstructor() {
MyMoneyInstitution* n1 = new MyMoneyInstitution("GUID1", *n);
MyMoneyInstitution n2(*n1);
CPPUNIT_ASSERT(*n1 == n2);
delete n1;
}
void MyMoneyInstitutionTest::testMyMoneyFileConstructor() {
MyMoneyInstitution *t = new MyMoneyInstitution("GUID", *n);
CPPUNIT_ASSERT(t->id() == "GUID");
CPPUNIT_ASSERT(t->street() == "street");
CPPUNIT_ASSERT(t->town() == "town");
CPPUNIT_ASSERT(t->postcode() == "postcode");
CPPUNIT_ASSERT(t->telephone() == "telephone");
CPPUNIT_ASSERT(t->manager() == "manager");
CPPUNIT_ASSERT(t->name() == "name");
CPPUNIT_ASSERT(t->sortcode() == "sortcode");
delete t;
}
void MyMoneyInstitutionTest::testEquality () {
MyMoneyInstitution t("name", "town", "street", "postcode",
"telephone", "manager", "sortcode");
CPPUNIT_ASSERT(t == *n);
t.setStreet("x");
CPPUNIT_ASSERT(!(t == *n));
t.setStreet("street");
CPPUNIT_ASSERT(t == *n);
t.setName("x");
CPPUNIT_ASSERT(!(t == *n));
t.setName("name");
CPPUNIT_ASSERT(t == *n);
t.setTown("x");
CPPUNIT_ASSERT(!(t == *n));
t.setTown("town");
CPPUNIT_ASSERT(t == *n);
t.setPostcode("x");
CPPUNIT_ASSERT(!(t == *n));
t.setPostcode("postcode");
CPPUNIT_ASSERT(t == *n);
t.setTelephone("x");
CPPUNIT_ASSERT(!(t == *n));
t.setTelephone("telephone");
CPPUNIT_ASSERT(t == *n);
t.setManager("x");
CPPUNIT_ASSERT(!(t == *n));
t.setManager("manager");
CPPUNIT_ASSERT(t == *n);
MyMoneyInstitution* n1 = new MyMoneyInstitution("GUID1", *n);
MyMoneyInstitution* n2 = new MyMoneyInstitution("GUID1", *n);
n1->addAccountId("A000001");
n2->addAccountId("A000001");
CPPUNIT_ASSERT(*n1 == *n2);
delete n1;
delete n2;
}
void MyMoneyInstitutionTest::testInequality () {
MyMoneyInstitution* n1 = new MyMoneyInstitution("GUID0", *n);
MyMoneyInstitution* n2 = new MyMoneyInstitution("GUID1", *n);
MyMoneyInstitution* n3 = new MyMoneyInstitution("GUID2", *n);
MyMoneyInstitution* n4 = new MyMoneyInstitution("GUID2", *n);
CPPUNIT_ASSERT(!(*n1 == *n2));
CPPUNIT_ASSERT(!(*n1 == *n3));
CPPUNIT_ASSERT(*n3 == *n4);
n3->addAccountId("A000001");
n4->addAccountId("A000002");
CPPUNIT_ASSERT(!(*n3 == *n4));
delete n1;
delete n2;
delete n3;
delete n4;
}
void MyMoneyInstitutionTest::testAccountIDList () {
MyMoneyInstitution institution;
TQStringList list;
TQString id;
// list must be empty
list = institution.accountList();
CPPUNIT_ASSERT(list.count() == 0);
// add one account
institution.addAccountId("A000002");
list = institution.accountList();
CPPUNIT_ASSERT(list.count() == 1);
CPPUNIT_ASSERT(list.tqcontains("A000002") == 1);
// adding same account shouldn't make a difference
institution.addAccountId("A000002");
list = institution.accountList();
CPPUNIT_ASSERT(list.count() == 1);
CPPUNIT_ASSERT(list.tqcontains("A000002") == 1);
// now add another account
institution.addAccountId("A000001");
list = institution.accountList();
CPPUNIT_ASSERT(list.count() == 2);
CPPUNIT_ASSERT(list.tqcontains("A000002") == 1);
CPPUNIT_ASSERT(list.tqcontains("A000001") == 1);
id = institution.removeAccountId("A000001");
CPPUNIT_ASSERT(id == "A000001");
list = institution.accountList();
CPPUNIT_ASSERT(list.count() == 1);
CPPUNIT_ASSERT(list.tqcontains("A000002") == 1);
}
void MyMoneyInstitutionTest::testWriteXML() {
MyMoneyKeyValueContainer kvp;
n->addAccountId("A000001");
n->addAccountId("A000003");
n->setValue(TQString("key"), "value");
TQDomDocument doc("TEST");
TQDomElement el = doc.createElement("INSTITUTION-CONTAINER");
doc.appendChild(el);
MyMoneyInstitution i("I00001", *n);
i.writeXML(doc, el);
TQString ref = TQString(
"<!DOCTYPE TEST>\n"
"<INSTITUTION-CONTAINER>\n"
" <INSTITUTION sortcode=\"sortcode\" id=\"I00001\" manager=\"manager\" name=\"name\" >\n"
" <ADDRESS street=\"street\" zip=\"postcode\" city=\"town\" telephone=\"telephone\" />\n"
" <ACCOUNTIDS>\n"
" <ACCOUNTID id=\"A000001\" />\n"
" <ACCOUNTID id=\"A000003\" />\n"
" </ACCOUNTIDS>\n"
" <KEYVALUEPAIRS>\n"
" <PAIR key=\"key\" value=\"value\" />\n"
" </KEYVALUEPAIRS>\n"
" </INSTITUTION>\n"
"</INSTITUTION-CONTAINER>\n");
CPPUNIT_ASSERT(doc.toString() == ref);
}
void MyMoneyInstitutionTest::testReadXML() {
MyMoneyInstitution i;
TQString ref_ok = TQString(
"<!DOCTYPE TEST>\n"
"<INSTITUTION-CONTAINER>\n"
" <INSTITUTION sortcode=\"sortcode\" id=\"I00001\" manager=\"manager\" name=\"name\" >\n"
" <ADDRESS street=\"street\" zip=\"postcode\" city=\"town\" telephone=\"telephone\" />\n"
" <ACCOUNTIDS>\n"
" <ACCOUNTID id=\"A000001\" />\n"
" <ACCOUNTID id=\"A000003\" />\n"
" </ACCOUNTIDS>\n"
" <KEYVALUEPAIRS>\n"
" <PAIR key=\"key\" value=\"value\" />\n"
" </KEYVALUEPAIRS>\n"
" </INSTITUTION>\n"
"</INSTITUTION-CONTAINER>\n");
TQString ref_false = TQString(
"<!DOCTYPE TEST>\n"
"<INSTITUTION-CONTAINER>\n"
" <KINSTITUTION sortcode=\"sortcode\" id=\"I00001\" manager=\"manager\" name=\"name\" >\n"
" <ADDRESS street=\"street\" zip=\"postcode\" city=\"town\" telephone=\"telephone\" />\n"
" <ACCOUNTIDS>\n"
" <ACCOUNTID id=\"A000001\" />\n"
" <ACCOUNTID id=\"A000003\" />\n"
" </ACCOUNTIDS>\n"
" </KINSTITUTION>\n"
"</INSTITUTION-CONTAINER>\n");
TQDomDocument doc;
TQDomElement node;
doc.setContent(ref_false);
node = doc.documentElement().firstChild().toElement();
try {
i = MyMoneyInstitution(node);
CPPUNIT_FAIL("Missing expected exception");
} catch(MyMoneyException *e) {
delete e;
}
i.addAccountId("TEST");
doc.setContent(ref_ok);
node = doc.documentElement().firstChild().toElement();
try {
TQStringList alist;
alist << "A000001" << "A000003";
i = MyMoneyInstitution(node);
CPPUNIT_ASSERT(i.sortcode() == "sortcode");
CPPUNIT_ASSERT(i.id() == "I00001");
CPPUNIT_ASSERT(i.manager() == "manager");
CPPUNIT_ASSERT(i.name() == "name");
CPPUNIT_ASSERT(i.street() == "street");
CPPUNIT_ASSERT(i.postcode() == "postcode");
CPPUNIT_ASSERT(i.city() == "town");
CPPUNIT_ASSERT(i.telephone() == "telephone");
CPPUNIT_ASSERT(i.accountList() == alist);
CPPUNIT_ASSERT(i.value(TQString("key")) == "value");
} catch(MyMoneyException *e) {
delete e;
CPPUNIT_FAIL("Unexpected exception");
}
}
|