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

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 "skgtestmacro.h"
0012 #include "skgbankincludes.h"
0013 #include "skgimportexportmanager.h"
0014 
0015 /**
0016  * The main function of the unit test
0017  * @param argc the number of arguments
0018  * @param argv the list of arguments
0019  */
0020 int main(int argc, char** argv)
0021 {
0022     Q_UNUSED(argc)
0023     Q_UNUSED(argv)
0024 
0025     // Init test
0026     SKGINITTEST(true)
0027 
0028     {
0029         // Test import GSK
0030         SKGDocumentBank document1;
0031         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0032         SKGError err;
0033         {
0034             // Scope of the transaction
0035             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_MMB"), err)
0036             SKGImportExportManager impmissing(&document1, QUrl::fromLocalFile(QStringLiteral("missingfile.mmb")));
0037             SKGTESTERROR(QStringLiteral("imp1.importFile"), impmissing.importFile(), false)
0038 
0039             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportmmb/test.mmb"));
0040             SKGTESTERROR(QStringLiteral("MMB.importFile"), imp1.importFile(), true)
0041         }
0042 
0043         {
0044             SKGAccountObject account(&document1);
0045             SKGTESTERROR(QStringLiteral("MMB.setName"), account.setName(QStringLiteral("COURANT")), true)
0046             SKGTESTERROR(QStringLiteral("MMB.load"), account.load(), true)
0047             SKGTEST(QStringLiteral("GSB:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-144.05"))
0048         }
0049         {
0050             SKGAccountObject account(&document1);
0051             SKGTESTERROR(QStringLiteral("MMB.setName"), account.setName(QStringLiteral("CPT2")), true)
0052             SKGTESTERROR(QStringLiteral("MMB.load"), account.load(), true)
0053             SKGTEST(QStringLiteral("GSB:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("40"))
0054         }
0055         {
0056             SKGAccountObject account(&document1);
0057             SKGTESTERROR(QStringLiteral("MMB.setName"), account.setName(QStringLiteral("NOTFAVORITE")), true)
0058             SKGTESTERROR(QStringLiteral("MMB.load"), account.load(), true)
0059             SKGTEST(QStringLiteral("GSB:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("150"))
0060         }
0061         {
0062             SKGAccountObject account(&document1);
0063             SKGTESTERROR(QStringLiteral("MMB.setName"), account.setName(QStringLiteral("LEP")), true)
0064             SKGTESTERROR(QStringLiteral("MMB.load"), account.load(), true)
0065             SKGTEST(QStringLiteral("GSB:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("6000"))
0066         }
0067     }
0068 
0069     {
0070         // Test import GSK
0071         SKGDocumentBank document1;
0072         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0073         SKGError err;
0074         {
0075             // Scope of the transaction
0076             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_MMB"), err)
0077 
0078             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportmmb/jd.mmb"));
0079             SKGTESTERROR(QStringLiteral("MMB.importFile"), imp1.importFile(), true)
0080         }
0081 
0082         {
0083             SKGAccountObject account(&document1);
0084             SKGTESTERROR(QStringLiteral("MMB.setName"), account.setName(QStringLiteral("credit")), true)
0085             SKGTESTERROR(QStringLiteral("MMB.load"), account.load(), true)
0086             SKGTEST(QStringLiteral("GSB:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-974.04"))
0087         }
0088     }
0089     // End test
0090     SKGENDTEST()
0091 }