1 /***************************************************************************
2 * SPDX-FileCopyrightText: 2021 S. MANKOWSKI stephane@mankowski.fr
3 * SPDX-FileCopyrightText: 2021 G. DE BURE support@mankowski.fr
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 ***************************************************************************/
6 /** @file
7 * This file is a test script.
8 *
9 * @author Stephane MANKOWSKI / Guillaume DE BURE
10 */
11 #include "skgtestmacro.h"
12 #include "skgbankincludes.h"
13 #include "skgimportexportmanager.h"
14
15 /**
16 * The main function of the unit test
17 * @param argc the number of arguments
18 * @param argv the list of arguments
19 */
main(int argc,char ** argv)20 int main(int argc, char** argv)
21 {
22 Q_UNUSED(argc)
23 Q_UNUSED(argv)
24
25 // Init test
26 SKGINITTEST(true)
27
28 QDate d(1970, 1, 1);
29
30 {
31 // 275963
32 SKGDocumentBank document1;
33 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
34 SKGBankObject bank(&document1);
35 SKGUnitObject unit_euro(&document1);
36 SKGUnitObject unit_dollar(&document1);
37 SKGError err;
38 {
39 SKGAccountObject account;
40
41 // Scope of the transaction
42 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_INIT"), err)
43
44 // Creation unit
45 SKGTESTERROR(QStringLiteral("UNIT:setName"), unit_euro.setName(QStringLiteral("euro")), true)
46 SKGTESTERROR(QStringLiteral("UNIT:setSymbol"), unit_euro.setSymbol(QStringLiteral("EUR")), true)
47 SKGTESTERROR(QStringLiteral("UNIT:setType"), unit_euro.setType(SKGUnitObject::PRIMARY), true)
48 SKGTESTERROR(QStringLiteral("UNIT:save"), unit_euro.save(), true)
49
50 // Creation unitvalue
51 SKGUnitValueObject unit_euro_val1;
52 SKGTESTERROR(QStringLiteral("UNIT:addUnitValue"), unit_euro.addUnitValue(unit_euro_val1), true)
53 SKGTESTERROR(QStringLiteral("UNITVALUE:setQuantity"), unit_euro_val1.setQuantity(1), true)
54 SKGTESTERROR(QStringLiteral("UNITVALUE:setDate"), unit_euro_val1.setDate(d), true)
55 SKGTESTERROR(QStringLiteral("UNITVALUE:save"), unit_euro_val1.save(), true)
56
57 // Creation unit
58 SKGTESTERROR(QStringLiteral("UNIT:setName"), unit_dollar.setName(QStringLiteral("dollar")), true)
59 SKGTESTERROR(QStringLiteral("UNIT:setSymbol"), unit_dollar.setSymbol(QStringLiteral("USD")), true)
60 SKGTESTERROR(QStringLiteral("UNIT:setType"), unit_dollar.setType(SKGUnitObject::CURRENCY), true)
61 SKGTESTERROR(QStringLiteral("UNIT:save"), unit_dollar.save(), true)
62
63 // Creation unitvalue
64 SKGUnitValueObject unit_dollar_val1;
65 SKGTESTERROR(QStringLiteral("UNIT:addUnitValue"), unit_dollar.addUnitValue(unit_dollar_val1), true)
66 SKGTESTERROR(QStringLiteral("UNITVALUE:setQuantity"), unit_dollar_val1.setQuantity(2), true)
67 SKGTESTERROR(QStringLiteral("UNITVALUE:setDate"), unit_dollar_val1.setDate(d), true)
68 SKGTESTERROR(QStringLiteral("UNITVALUE:save"), unit_dollar_val1.save(), true)
69
70 // Creation bank
71 SKGTESTERROR(QStringLiteral("BANK:setName"), bank.setName(QStringLiteral("CREDIT COOP")), true)
72 SKGTESTERROR(QStringLiteral("BANK:setNumber"), bank.setNumber(QStringLiteral("0003")), true)
73 SKGTESTERROR(QStringLiteral("BANK:save"), bank.save(), true)
74
75 // Creation account
76 SKGTESTERROR(QStringLiteral("BANK:addAccount"), bank.addAccount(account), true)
77 SKGTESTERROR(QStringLiteral("ACCOUNT:setName"), account.setName(QStringLiteral("CODEVI")), true)
78 SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account.save(), true)
79 SKGTESTERROR(QStringLiteral("ACCOUNT:setInitialBalance"), account.setInitialBalance(100, unit_dollar), true)
80 SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account.save(), true)
81 }
82
83
84 {
85 // Scope of the transaction
86 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
87
88 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportqif2/t2.qif"));
89 SKGTESTERROR(QStringLiteral("QIF.importFile"), imp1.importFile(), true)
90 }
91 {
92 SKGAccountObject account(&document1);
93 SKGTESTERROR(QStringLiteral("QIF.setName"), account.setName(QStringLiteral("CODEVI")), true)
94 SKGTESTERROR(QStringLiteral("QIF.load"), account.load(), true)
95 SKGTEST(QStringLiteral("QIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-9335.94"))
96 }
97 }
98
99 {
100 // 275963
101 SKGDocumentBank document1;
102 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.load(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportqif2/export_qif.skg"), true)
103 SKGError err;
104 {
105 // Scope of the transaction
106 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_BP_QIF"), err)
107 SKGImportExportManager exp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportqif2/export_qif.qif"));
108 SKGTESTERROR(QStringLiteral("QIF.exportFile"), exp1.exportFile(), true)
109 }
110 }
111
112 {
113 // Support qif file having Type:Class with description
114 SKGDocumentBank document1;
115 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
116 SKGError err;
117 SKGAccountObject la;
118 {
119 // Scope of the transaction
120 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
121
122 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportqif2/MoneydanceExportExample.qif"));
123 SKGTESTERROR(QStringLiteral("QIF.importFile"), imp1.importFile(), true)
124
125 SKGObjectBase::SKGListSKGObjectBase result;
126 SKGTESTERROR(QStringLiteral("DOC.getObjects"), document1.getObjects(QStringLiteral("account"), QStringLiteral("t_name='Wells Fargo:Checking'"), result), true)
127 SKGTEST(QStringLiteral("DOC.getObjects.count"), result.count(), 1)
128 if (result.count() != 0) {
129 la = result.at(0);
130 }
131 }
132 {
133 // Scope of the transaction
134 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_QIF"), err)
135 SKGImportExportManager exp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportqif2/export_all.qif"));
136 SKGTESTERROR(QStringLiteral("QIF.exportFile"), exp1.exportFile(), true)
137 }
138 {
139 // Scope of the transaction
140 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_QIF"), err)
141 SKGImportExportManager exp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportqif2/export_la.qif"));
142 QMap<QString, QString> params;
143 params[QStringLiteral("uuid_of_selected_accounts_or_operations")] = la.getUniqueID();
144 exp1.setExportParameters(params);
145 SKGTESTERROR(QStringLiteral("QIF.exportFile"), exp1.exportFile(), true)
146 }
147 }
148
149 {
150 // Default account
151 SKGDocumentBank document1;
152 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
153 SKGError err;
154 {
155 // Scope of the transaction
156 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
157
158 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportqif2/LA-1234567@ing.qif"));
159 SKGTESTERROR(QStringLiteral("QIF.importFile"), imp1.importFile(), true)
160 }
161
162 {
163 SKGBEGINTRANSACTION(document1, QStringLiteral("MODIF"), err)
164 SKGObjectBase::SKGListSKGObjectBase result;
165 SKGTESTERROR(QStringLiteral("DOC.getObjects"), document1.getObjects(QStringLiteral("bank"), QStringLiteral("t_name='ing'"), result), true)
166 SKGTEST(QStringLiteral("DOC.getObjects.count"), result.count(), 1)
167
168 SKGBankObject bank(result.at(0));
169 SKGTESTERROR(QStringLiteral("BANK.setName"), bank.setName(QStringLiteral("ING Direct")), true)
170 SKGTESTERROR(QStringLiteral("BANK.save"), bank.save(), true)
171
172 SKGTESTERROR(QStringLiteral("DOC.getObjects"), document1.getObjects(QStringLiteral("account"), QStringLiteral("t_number='1234567'"), result), true)
173 SKGTEST(QStringLiteral("DOC.getObjects.count"), result.count(), 1)
174
175 SKGTESTERROR(QStringLiteral("DOC.getObjects"), document1.getObjects(QStringLiteral("account"), QStringLiteral("t_name='LA'"), result), true)
176 SKGTEST(QStringLiteral("DOC.getObjects.count"), result.count(), 1)
177
178 SKGAccountObject acc(result.at(0));
179 SKGTESTERROR(QStringLiteral("ACC.setName"), acc.setName(QStringLiteral("Livret A")), true)
180 SKGTESTERROR(QStringLiteral("ACC.save"), acc.save(), true)
181 }
182
183 {
184 // Scope of the transaction
185 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
186
187 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportqif2/LA-1234567@ing.qif"));
188 SKGTESTERROR(QStringLiteral("QIF.importFile"), imp1.importFile(), true)
189 }
190
191 document1.dump(DUMPACCOUNT);
192 {
193 SKGObjectBase::SKGListSKGObjectBase result;
194 SKGTESTERROR(QStringLiteral("DOC.getObjects"), document1.getObjects(QStringLiteral("account"), QStringLiteral("t_number='1234567'"), result), true)
195 SKGTEST(QStringLiteral("DOC.getObjects.count"), result.count(), 1)
196 }
197 }
198
199 {
200 // Bug import date
201 SKGDocumentBank document1;
202 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
203 SKGError err;
204 {
205 // Scope of the transaction
206 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
207
208 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportqif2/date_money.qif"));
209 SKGTESTERROR(QStringLiteral("QIF.importFile"), imp1.importFile(), true)
210 }
211 }
212
213 {
214 // Autorepair
215 SKGDocumentBank document1;
216 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
217 SKGError err;
218 {
219 // Scope of the transaction
220 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
221
222 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportqif2/autorepair.qif"));
223 SKGTESTERROR(QStringLiteral("QIF.importFile"), imp1.importFile(), true)
224 }
225 {
226 SKGAccountObject account(&document1);
227 SKGTESTERROR(QStringLiteral("QIF.setName"), account.setName(QStringLiteral("autorepair")), true)
228 SKGTESTERROR(QStringLiteral("QIF.load"), account.load(), true)
229 SKGTEST(QStringLiteral("QIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-400"))
230 }
231 }
232
233 {
234 // Error
235 SKGDocumentBank document1;
236 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
237 SKGError err;
238 {
239 // Scope of the transaction
240 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
241
242 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportqif2/error.qif"));
243 SKGTESTERROR(QStringLiteral("QIF.importFile"), imp1.importFile(), true)
244 }
245 }
246
247 {
248 // Split and transfer
249 SKGDocumentBank document1;
250 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
251 SKGError err;
252 {
253 // Scope of the transaction
254 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
255
256 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportqif2/split_and_transfer.qif"));
257 SKGTESTERROR(QStringLiteral("QIF.importFile"), imp1.importFile(), true)
258 }
259 {
260 SKGAccountObject account(&document1);
261 SKGTESTERROR(QStringLiteral("QIF.setName"), account.setName(QStringLiteral("Joint Checking")), true)
262 SKGTESTERROR(QStringLiteral("QIF.load"), account.load(), true)
263 SKGTEST(QStringLiteral("QIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-1181.25")) // -600 if sum of splits
264 }
265 {
266 SKGAccountObject account(&document1);
267 SKGTESTERROR(QStringLiteral("QIF.setName"), account.setName(QStringLiteral("2012 Acadia Loan")), true)
268 SKGTESTERROR(QStringLiteral("QIF.load"), account.load(), true)
269 SKGTEST(QStringLiteral("QIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("1162.5")) // 581.25 if sum of splits
270 }
271 }
272
273 {
274 // Split and transfer 2
275 SKGDocumentBank document1;
276 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
277 SKGError err;
278 {
279 // Scope of the transaction
280 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
281
282 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportqif2/split_and_transfer_2.qif"));
283 SKGTESTERROR(QStringLiteral("QIF.importFile"), imp1.importFile(), true)
284 }
285 {
286 SKGAccountObject account(&document1);
287 SKGTESTERROR(QStringLiteral("QIF.setName"), account.setName(QStringLiteral("Joint Checking")), true)
288 SKGTESTERROR(QStringLiteral("QIF.load"), account.load(), true)
289 SKGTEST(QStringLiteral("QIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("2714.31"))
290 }
291 {
292 SKGAccountObject account(&document1);
293 SKGTESTERROR(QStringLiteral("QIF.setName"), account.setName(QStringLiteral("Credit Union")), true)
294 SKGTESTERROR(QStringLiteral("QIF.load"), account.load(), true)
295 SKGTEST(QStringLiteral("QIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("400"))
296 }
297 {
298 SKGAccountObject account(&document1);
299 SKGTESTERROR(QStringLiteral("QIF.setName"), account.setName(QStringLiteral("TSP")), true)
300 SKGTESTERROR(QStringLiteral("QIF.load"), account.load(), true)
301 SKGTEST(QStringLiteral("QIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("437.88"))
302 }
303 {
304 SKGAccountObject account(&document1);
305 SKGTESTERROR(QStringLiteral("QIF.setName"), account.setName(QStringLiteral("FSA")), true)
306 SKGTESTERROR(QStringLiteral("QIF.load"), account.load(), true)
307 SKGTEST(QStringLiteral("QIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("88.26"))
308 }
309 {
310 SKGAccountObject account(&document1);
311 SKGTESTERROR(QStringLiteral("QIF.setName"), account.setName(QStringLiteral("TSP - Roth")), true)
312 SKGTESTERROR(QStringLiteral("QIF.load"), account.load(), true)
313 SKGTEST(QStringLiteral("QIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("250"))
314 }
315 }
316
317 {
318 // 400724
319 SKGDocumentBank document1;
320 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
321 SKGError err;
322 {
323 // Scope of the transaction
324 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
325
326 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportqif2/400724.qif"));
327 SKGTESTERROR(QStringLiteral("QIF.importFile"), imp1.importFile(), true)
328 }
329 }
330
331 {
332 // 402330
333 SKGDocumentBank document1;
334 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
335 SKGError err;
336 {
337 // Scope of the transaction
338 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
339
340 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportqif2/402330.qif"));
341 SKGTESTERROR(QStringLiteral("QIF.importFile"), imp1.importFile(), true)
342 }
343 }
344
345 {
346 // 403725
347 SKGDocumentBank document1;
348 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
349 SKGError err;
350 {
351 // Scope of the transaction
352 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
353
354 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportqif2/403725.qif"));
355 SKGTESTERROR(QStringLiteral("QIF.importFile"), imp1.importFile(), true)
356 }
357
358 SKGObjectBase::SKGListSKGObjectBase result;
359 SKGTESTERROR(QStringLiteral("DOC.getObjects"), document1.getObjects(QStringLiteral("refund"), QLatin1String(""), result), true)
360 SKGTEST(QStringLiteral("DOC.getObjects.count"), result.count(), 2)
361 }
362
363 {
364 // 406243
365 SKGDocumentBank document1;
366 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
367 SKGError err;
368 {
369 // Scope of the transaction
370 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
371
372 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportqif2/406243.qif"));
373 SKGTESTERROR(QStringLiteral("QIF.importFile"), imp1.importFile(), true)
374 }
375
376 {
377 SKGAccountObject account(&document1);
378 SKGTESTERROR(QStringLiteral("QIF.setName"), account.setName(QStringLiteral("406243")), true)
379 SKGTESTERROR(QStringLiteral("QIF.load"), account.load(), true)
380 SKGTEST(QStringLiteral("QIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("794"))
381 }
382 }
383
384 {
385 // 406243
386 SKGDocumentBank document1;
387 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
388 SKGError err;
389 {
390 // Scope of the transaction
391 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
392
393 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportqif2/406271.qif"));
394 SKGTESTERROR(QStringLiteral("QIF.importFile"), imp1.importFile(), true)
395 }
396
397 {
398 SKGTrackerObject tracker(&document1);
399 SKGTESTERROR(QStringLiteral("QIF.setName"), tracker.setName(QStringLiteral("Jane")), true)
400 SKGTESTERROR(QStringLiteral("QIF.load"), tracker.load(), true)
401 SKGTEST(QStringLiteral("QIF:getComment"), tracker.getComment(), QStringLiteral("expenses that Jane incurs"))
402 }
403 }
404
405 {
406 // 406266
407 SKGDocumentBank document1;
408 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
409 SKGError err;
410 {
411 // Scope of the transaction
412 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
413
414 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportqif2/406266.qif"));
415 SKGTESTERROR(QStringLiteral("QIF.importFile"), imp1.importFile(), true)
416 }
417
418 {
419 SKGUnitObject unit(&document1);
420 SKGTESTERROR(QStringLiteral("QIF.setName"), unit.setName(QStringLiteral("ACME CORP")), true)
421 SKGTESTERROR(QStringLiteral("QIF.load"), unit.load(), true)
422 SKGTEST(QStringLiteral("QIF:getSymbol"), unit.getSymbol(), QStringLiteral("ACMW"))
423 SKGTEST(QStringLiteral("QIF:getSymbol"), static_cast<unsigned int>(unit.getType()), static_cast<unsigned int>(SKGUnitObject::SHARE))
424 }
425 }
426
427 {
428 // 406270
429 SKGDocumentBank document1;
430 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
431 SKGError err;
432 {
433 // Scope of the transaction
434 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
435
436 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportqif2/406270.qif"));
437 SKGTESTERROR(QStringLiteral("QIF.importFile"), imp1.importFile(), true)
438 }
439
440 SKGObjectBase::SKGListSKGObjectBase result;
441 SKGTESTERROR(QStringLiteral("DOC.getObjects"), document1.getObjects(QStringLiteral("unit"), QLatin1String(""), result), true)
442 SKGTEST(QStringLiteral("DOC.getObjects.count"), static_cast<unsigned int>(result.count()), static_cast<unsigned int>(1))
443 }
444 // End test
445 SKGENDTEST()
446 }
447