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 "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 XHB
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_XHB"), err)
0036             SKGImportExportManager impmissing(&document1, QUrl::fromLocalFile(QStringLiteral("missingfile.xhb")));
0037             SKGTESTERROR(QStringLiteral("imp1.importFile"), impmissing.importFile(), false)
0038 
0039             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportxhb/test.xhb"));
0040             SKGTESTERROR(QStringLiteral("XHB.importFile"), imp1.importFile(), true)
0041         }
0042 
0043         {
0044             SKGAccountObject account(&document1);
0045             SKGTESTERROR(QStringLiteral("XHB.setName"), account.setName(QStringLiteral("COURANT")), true)
0046             SKGTESTERROR(QStringLiteral("XHB.load"), account.load(), true)
0047             SKGTEST(QStringLiteral("XHB:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("35"))
0048         }
0049 
0050         // test multi import
0051         {
0052             // Scope of the transaction
0053             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_XHB"), err)
0054 
0055             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportxhb/test.xhb"));
0056             SKGTESTERROR(QStringLiteral("XHB.importFile"), imp1.importFile(), true)
0057         }
0058     }
0059 
0060     {
0061         // Test import XHB
0062         SKGDocumentBank document1;
0063         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0064         SKGError err;
0065         {
0066             // Scope of the transaction
0067             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_XHB"), err)
0068 
0069             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportxhb/example_budget.xhb"));
0070             SKGTESTERROR(QStringLiteral("XHB.importFile"), imp1.importFile(), true)
0071         }
0072 
0073         {
0074             SKGAccountObject account(&document1);
0075             SKGTESTERROR(QStringLiteral("XHB.setName"), account.setName(QStringLiteral("Cheque Account")), true)
0076             SKGTESTERROR(QStringLiteral("XHB.load"), account.load(), true)
0077             SKGTEST(QStringLiteral("XHB:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("5758.22"))
0078         }
0079         {
0080             SKGAccountObject account(&document1);
0081             SKGTESTERROR(QStringLiteral("XHB.setName"), account.setName(QStringLiteral("Savings Account")), true)
0082             SKGTESTERROR(QStringLiteral("XHB.load"), account.load(), true)
0083             SKGTEST(QStringLiteral("XHB:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("1024.66"))
0084         }
0085     }
0086 
0087     {
0088         // Test import XHB
0089         SKGDocumentBank document1;
0090         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0091         SKGError err;
0092         {
0093             // Scope of the transaction
0094             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_XHB"), err)
0095 
0096             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportxhb/comptes.xhb"));
0097             SKGTESTERROR(QStringLiteral("XHB.importFile"), imp1.importFile(), true)
0098         }
0099 
0100         {
0101             SKGStringListList result;
0102             SKGTESTERROR(QStringLiteral("XHB.executeSelectSqliteOrder"), document1.executeSelectSqliteOrder(QStringLiteral("SELECT distinct t_type FROM account"), result), true)
0103             SKGTEST(QStringLiteral("XHB:distinct t_type"), result.count(), 6)
0104         }
0105     }
0106 
0107 
0108     {
0109         // Test import wallet
0110         SKGDocumentBank document1;
0111         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0112         SKGError err;
0113         {
0114             // Scope of the transaction
0115             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_XHB"), err)
0116 
0117             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportxhb/wallet.xhb"));
0118             SKGTESTERROR(QStringLiteral("XHB.importFile"), imp1.importFile(), true)
0119         }
0120 
0121         {
0122             SKGAccountObject account(&document1);
0123             SKGTESTERROR(QStringLiteral("XHB.setName"), account.setName(QStringLiteral("Espece")), true)
0124             SKGTESTERROR(QStringLiteral("XHB.load"), account.load(), true)
0125             SKGBankObject bank;
0126             SKGTESTERROR(QStringLiteral("XHB.load"), account.getBank(bank), true)
0127             SKGTEST(QStringLiteral("XHB:getName"), bank.getName(), QLatin1String(""))
0128         }
0129         {
0130             SKGAccountObject account(&document1);
0131             SKGTESTERROR(QStringLiteral("XHB.setName"), account.setName(QStringLiteral("Courant")), true)
0132             SKGTESTERROR(QStringLiteral("XHB.load"), account.load(), true)
0133             SKGBankObject bank;
0134             SKGTESTERROR(QStringLiteral("XHB.load"), account.getBank(bank), true)
0135             SKGTEST(QStringLiteral("XHB:getName"), bank.getName(), QStringLiteral("HOMEBANK"))
0136         }
0137     }
0138 
0139     {
0140         // Test import
0141         SKGDocumentBank document1;
0142         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0143         SKGError err;
0144         {
0145             // Scope of the transaction
0146             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_XHB"), err)
0147 
0148             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportxhb/error_import.xhb"));
0149             SKGTESTERROR(QStringLiteral("XHB.importFile"), imp1.importFile(), true)
0150         }
0151     }
0152 
0153     {
0154         // Test import 481144
0155         SKGDocumentBank document1;
0156         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0157         SKGError err;
0158         {
0159             // Scope of the transaction
0160             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_XHB"), err)
0161 
0162             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportxhb/481144.xhb"));
0163             SKGTESTERROR(QStringLiteral("XHB.importFile"), imp1.importFile(), true)
0164         }
0165 
0166         {
0167             SKGStringListList result;
0168             SKGTESTERROR(QStringLiteral("XHB.executeSelectSqliteOrder"), document1.executeSelectSqliteOrder(QStringLiteral("SELECT count(1) FROM refund"), result), true)
0169             SKGTEST(QStringLiteral("XHB:tracker"), result.at(1).at(0), "1")
0170         }
0171     }    
0172     // End test
0173     SKGENDTEST()
0174 }