File indexing completed on 2024-05-12 16:45:24

0001 /***************************************************************************
0002  * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr
0003  * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  ***************************************************************************/
0006 /** @file
0007  * This file is a test script.
0008  *
0009  * @author Stephane MANKOWSKI / Guillaume DE BURE
0010  */
0011 #include "skgaccountobject.h"
0012 #include "skgtestmacro.h"
0013 #include "skgbankincludes.h"
0014 #include "skgimportexportmanager.h"
0015 
0016 /**
0017  * The main function of the unit test
0018  * @param argc the number of arguments
0019  * @param argv the list of arguments
0020  */
0021 int main(int argc, char** argv)
0022 {
0023     Q_UNUSED(argc)
0024     Q_UNUSED(argv)
0025 
0026     // Init test
0027     SKGINITTEST(true)
0028 
0029     {
0030         // Test import XML
0031         SKGDocumentBank document1;
0032         SKGError err;
0033         {
0034             SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0035 
0036             for (int i = 1; !err && i <= 2; ++i) {
0037                 {
0038                     // Scope of the transaction
0039                     SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_XML"), err)
0040                     SKGImportExportManager impmissing(&document1, QUrl::fromLocalFile(QStringLiteral("/not-existing/missingfile.xml")));
0041                     SKGTESTERROR(QStringLiteral("imp1.importFile") + SKGServices::intToString(i), impmissing.importFile(), false)
0042 
0043                     SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportxml/input.xml"));
0044                     SKGTESTERROR(QStringLiteral("XML.importFile") + SKGServices::intToString(i), imp1.importFile(), true)
0045                 }
0046 
0047                 {
0048                     SKGAccountObject account(&document1);
0049                     SKGTESTERROR(QStringLiteral("XML.setName") + SKGServices::intToString(i), account.setName(QStringLiteral("COURANT")), true)
0050                     SKGTESTERROR(QStringLiteral("XML.load") + SKGServices::intToString(i), account.load(), true)
0051                     SKGTEST(QStringLiteral("XML:getCurrentAmount") + SKGServices::intToString(i), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-15255"))
0052                 }
0053 
0054                 {
0055                     SKGAccountObject account(&document1);
0056                     SKGTESTERROR(QStringLiteral("XML.setName") + SKGServices::intToString(i), account.setName(QStringLiteral("EPARGNE")), true)
0057                     SKGTESTERROR(QStringLiteral("XML.load") + SKGServices::intToString(i), account.load(), true)
0058                     SKGTEST(QStringLiteral("XML:getCurrentAmount") + SKGServices::intToString(i), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("197.8444982"))
0059                 }
0060             }
0061         }
0062         {
0063             SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) {
0064                 SKGTESTERROR(QStringLiteral("DOC:changePassword"), document1.changePassword(QStringLiteral("test")), true)
0065 
0066                 // Scope of the transaction
0067                 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_ISO20022"), err)
0068 
0069                 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportxml/camt_053_ver_2_extended_uk_account.xml"));
0070                 SKGTESTERROR(QStringLiteral("ISO20022.importFile"), imp1.importFile(), true)
0071             }
0072 
0073             {
0074                 SKGAccountObject account(&document1);
0075                 SKGTESTERROR(QStringLiteral("ISO20022.setName"), account.setName(QStringLiteral("GB87HAND40516218000025")), true)
0076                 SKGTESTERROR(QStringLiteral("ISO20022.load"), account.load(), true)
0077                 SKGTEST(QStringLiteral("ISO20022:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-0.1"))
0078             }
0079         }
0080         {
0081             SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) {
0082 
0083                 // Scope of the transaction
0084                 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_UNKNOWN"), err)
0085 
0086                 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportxml/unknown.xml"));
0087                 SKGTESTERROR(QStringLiteral("ISO20022.importFile"), imp1.importFile(), false)
0088             }
0089         }
0090         {
0091             SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) {
0092 
0093                 // Scope of the transaction
0094                 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_UNKNOWN"), err)
0095 
0096                 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportxml/paket_2.xml"));
0097                 SKGTESTERROR(QStringLiteral("ISO20022.importFile"), imp1.importFile(), true)
0098             }
0099             {
0100                 SKGAccountObject account(&document1);
0101                 SKGTESTERROR(QStringLiteral("ISO20022.setName"), account.setName(QStringLiteral("SI56123456789012345")), true)
0102                 SKGTESTERROR(QStringLiteral("ISO20022.load"), account.load(), true)
0103                 SKGTEST(QStringLiteral("ISO20022:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("1999.01"))
0104             }
0105         }
0106 
0107         {
0108             SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) {
0109 
0110                 // Scope of the transaction
0111                 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_1"), err)
0112 
0113                 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportxml/472392_1.xml"));
0114                 SKGTESTERROR(QStringLiteral("ISO20022.importFile"), imp1.importFile(), true)
0115 
0116                 // 472390
0117                 SKGAccountObject account(&document1);
0118                 SKGTESTERROR(QStringLiteral("ACT:setName"), account.setName("SI5___3"), true)
0119                 SKGTESTBOOL("ACT:exist", account.exist(), false)
0120             }
0121 
0122             {
0123 
0124                 // Scope of the transaction
0125                 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_2"), err)
0126 
0127                 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportxml/472392_2.xml"));
0128                 SKGTESTERROR(QStringLiteral("ISO20022.importFile"), imp1.importFile(), true)
0129             }
0130         }
0131     }
0132 
0133     // End test
0134     SKGENDTEST()
0135 }