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

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 <klocalizedstring.h>
0012 
0013 #include "skgbankincludes.h"
0014 #include "skgimportexportmanager.h"
0015 #include "skgtestmacro.h"
0016 
0017 /**
0018  * The main function of the unit test
0019  * @param argc the number of arguments
0020  * @param argv the list of arguments
0021  */
0022 int main(int argc, char** argv)
0023 {
0024     Q_UNUSED(argc)
0025     Q_UNUSED(argv)
0026 
0027     // Init test
0028     SKGINITTEST(true)
0029 
0030     {
0031         // Test import GSK
0032         SKGDocumentBank document1;
0033         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0034         SKGError err;
0035         {
0036             // Scope of the transaction
0037             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_GSB"), err)
0038             SKGImportExportManager impmissing(&document1, QUrl::fromLocalFile(QStringLiteral("missingfile.gsb")));
0039             SKGTESTERROR(QStringLiteral("imp1.importFile"), impmissing.importFile(), false)
0040 
0041             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportgsb/test-obfuscated.gsb"));
0042             SKGTESTERROR(QStringLiteral("GSB.importFile"), imp1.importFile(), true)
0043         }
0044 
0045         {
0046             SKGAccountObject account(&document1);
0047             SKGTESTERROR(QStringLiteral("GSB.setName"), account.setName(QStringLiteral("Account 0")), true)
0048             SKGTESTERROR(QStringLiteral("GSB.load"), account.load(), true)
0049             SKGTEST(QStringLiteral("GSB:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("1029"))
0050         }
0051         {
0052             SKGAccountObject account(&document1);
0053             SKGTESTERROR(QStringLiteral("GSB.setName"), account.setName(QStringLiteral("Account 4")), true)
0054             SKGTESTERROR(QStringLiteral("GSB.load"), account.load(), true)
0055             SKGTEST(QStringLiteral("GSB:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("7.5"))
0056         }
0057         {
0058             SKGAccountObject account(&document1);
0059             SKGTESTERROR(QStringLiteral("GSB.setName"), account.setName(QStringLiteral("Account 1")), true)
0060             SKGTESTERROR(QStringLiteral("GSB.load"), account.load(), true)
0061             SKGTEST(QStringLiteral("GSB:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("757.5"))
0062         }
0063         {
0064             SKGAccountObject account(&document1);
0065             SKGTESTERROR(QStringLiteral("GSB.setName"), account.setName(QStringLiteral("Account 3")), true)
0066             SKGTESTERROR(QStringLiteral("GSB.load"), account.load(), true)
0067             SKGTEST(QStringLiteral("GSB:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("43.5"))
0068         }
0069     }
0070 
0071     {
0072         // Test import GSK
0073         SKGDocumentBank document1;
0074         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0075         SKGError err;
0076         {
0077             // Scope of the transaction
0078             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_GSB"), err)
0079 
0080             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportgsb/version_0.5.9.gsb"));
0081             SKGTESTERROR(QStringLiteral("GSB.importFile"), imp1.importFile(), false)
0082         }
0083     }
0084 
0085     {
0086         // Double import
0087         SKGDocumentBank document1;
0088         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0089         SKGError err;
0090         {
0091             // Scope of the transaction
0092             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_GSB"), err)
0093 
0094             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportgsb/essai.gsb"));
0095             SKGTESTERROR(QStringLiteral("GSB.importFile"), imp1.importFile(), true)
0096         }
0097         {
0098             // Scope of the transaction
0099             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_GSB"), err)
0100 
0101             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportgsb/essai.gsb"));
0102             SKGTESTERROR(QStringLiteral("GSB.importFile"), imp1.importFile(), true)
0103         }
0104     }
0105 
0106     {
0107         // Split
0108         SKGDocumentBank document1;
0109         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0110         SKGError err;
0111         {
0112             // Scope of the transaction
0113             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_GSB"), err)
0114 
0115             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportgsb/split.gsb"));
0116             SKGTESTERROR(QStringLiteral("GSB.importFile"), imp1.importFile(), true)
0117         }
0118         {
0119             SKGAccountObject account(&document1);
0120             SKGTESTERROR(QStringLiteral("GSB.setName"), account.setName(QStringLiteral("Compte banque A")), true)
0121             SKGTESTERROR(QStringLiteral("GSB.load"), account.load(), true)
0122             SKGTEST(QStringLiteral("GSB:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("350"))
0123         }
0124         {
0125             SKGAccountObject account(&document1);
0126             SKGTESTERROR(QStringLiteral("GSB.setName"), account.setName(QStringLiteral("Compte banque B")), true)
0127             SKGTESTERROR(QStringLiteral("GSB.load"), account.load(), true)
0128             SKGTEST(QStringLiteral("GSB:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-9400"))
0129         }
0130     }
0131 
0132     {
0133         // Budget
0134         SKGDocumentBank document1;
0135         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0136         SKGError err;
0137         {
0138             // Scope of the transaction
0139             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_GSB"), err)
0140 
0141             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportgsb/imputations_budgetaires.gsb"));
0142             SKGTESTERROR(QStringLiteral("GSB.importFile"), imp1.importFile(), true)
0143         }
0144         {
0145             SKGObjectBase::SKGListSKGObjectBase transactions;
0146             SKGTESTERROR(QStringLiteral("GSB.getObjects"), document1.getObjects(QStringLiteral("v_operation_display"), QStringLiteral("d_date='2013-08-11'"), transactions), true)
0147             SKGTEST(QStringLiteral("GSB:count"), transactions.count(), 1)
0148             SKGOperationObject op(transactions[0]);
0149             SKGTEST(QStringLiteral("GSB:Budgetary allocation"), op.getProperty(i18nc("Noun", "Budgetary allocation")), QStringLiteral("imputation1"))
0150             SKGTEST(QStringLiteral("GSB:Fiscal year"), op.getProperty(i18nc("Noun", "Fiscal year")), QStringLiteral("2013"))
0151             SKGTEST(QStringLiteral("GSB:category"), op.getAttribute(QStringLiteral("t_CATEGORY")), QStringLiteral("categorie1"))
0152         }
0153         {
0154             SKGObjectBase::SKGListSKGObjectBase transactions;
0155             SKGTESTERROR(QStringLiteral("GSB.getObjects"), document1.getObjects(QStringLiteral("v_operation_display"), QStringLiteral("d_date='2013-08-12'"), transactions), true)
0156             SKGTEST(QStringLiteral("GSB:count"), transactions.count(), 1)
0157             SKGOperationObject op(transactions[0]);
0158             SKGTEST(QStringLiteral("GSB:Budgetary allocation"), op.getProperty(i18nc("Noun", "Budgetary allocation")), "imputation1" % OBJECTSEPARATOR % "subimputation1")
0159             SKGTEST(QStringLiteral("GSB:Fiscal year"), op.getProperty(i18nc("Noun", "Fiscal year")), QStringLiteral("2013"))
0160             SKGTEST(QStringLiteral("GSB:category"), op.getAttribute(QStringLiteral("t_CATEGORY")), "categorie1" % OBJECTSEPARATOR % "subcategorie1")
0161         }
0162     }
0163     // End test
0164     SKGENDTEST()
0165 }