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 "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 full_check.iif
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_IIF"), err)
0036 
0037             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportiif/full_check.iif"));
0038             imp1.setCodec(QStringLiteral("UTF-8"));
0039             SKGTESTERROR(QStringLiteral("IIF.importFile"), imp1.importFile(), true)
0040         }
0041 
0042         {
0043             SKGAccountObject account(&document1);
0044             SKGTESTERROR(QStringLiteral("IIF.setName"), account.setName(QStringLiteral("Checking")), true)
0045             SKGTESTERROR(QStringLiteral("IIF.load"), account.load(), true)
0046             SKGTEST(QStringLiteral("IIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-36.15"))
0047         }
0048 
0049         {
0050             // Scope of the transaction
0051             SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_IIF"), err)
0052 
0053             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportiif/full_check.iif"));
0054             imp1.setCodec(QStringLiteral("UTF-8"));
0055             SKGTESTERROR(QStringLiteral("IIF.exportFile"), imp1.exportFile(), true)
0056         }
0057     }
0058 
0059     {
0060         // Test import full_deposit.iif
0061         SKGDocumentBank document1;
0062         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0063         SKGError err;
0064         {
0065             // Scope of the transaction
0066             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_IIF"), err)
0067 
0068             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportiif/full_deposit.iif"));
0069             SKGTESTERROR(QStringLiteral("IIF.importFile"), imp1.importFile(), true)
0070         }
0071 
0072         {
0073             SKGAccountObject account(&document1);
0074             SKGTESTERROR(QStringLiteral("IIF.setName"), account.setName(QStringLiteral("Checking")), true)
0075             SKGTESTERROR(QStringLiteral("IIF.load"), account.load(), true)
0076             SKGTEST(QStringLiteral("IIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("10000"))
0077         }
0078     }
0079 
0080     {
0081         // Test import full_bill.iif
0082         SKGDocumentBank document1;
0083         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0084         SKGError err;
0085         {
0086             // Scope of the transaction
0087             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_IIF"), err)
0088 
0089             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportiif/full_bill.iif"));
0090             SKGTESTERROR(QStringLiteral("IIF.importFile"), imp1.importFile(), true)
0091         }
0092 
0093         {
0094             SKGAccountObject account(&document1);
0095             SKGTESTERROR(QStringLiteral("IIF.setName"), account.setName(QStringLiteral("Accounts Payable")), true)
0096             SKGTESTERROR(QStringLiteral("IIF.load"), account.load(), true)
0097             SKGTEST(QStringLiteral("IIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-59.25"))
0098         }
0099     }
0100 
0101     {
0102         // Test import full_cash_sale.iif
0103         SKGDocumentBank document1;
0104         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0105         SKGError err;
0106         {
0107             // Scope of the transaction
0108             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_IIF"), err)
0109 
0110             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportiif/full_cash_sale.iif"));
0111             SKGTESTERROR(QStringLiteral("IIF.importFile"), imp1.importFile(), true)
0112         }
0113 
0114         {
0115             SKGAccountObject account(&document1);
0116             SKGTESTERROR(QStringLiteral("IIF.setName"), account.setName(QStringLiteral("Undeposited Funds")), true)
0117             SKGTESTERROR(QStringLiteral("IIF.load"), account.load(), true)
0118             SKGTEST(QStringLiteral("IIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("1969.98"))
0119         }
0120     }
0121 
0122     {
0123         // Test import full_transfer.iif
0124         SKGDocumentBank document1;
0125         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0126         SKGError err;
0127         {
0128             // Scope of the transaction
0129             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_IIF"), err)
0130 
0131             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportiif/full_transfer.iif"));
0132             SKGTESTERROR(QStringLiteral("IIF.importFile"), imp1.importFile(), true)
0133         }
0134 
0135         {
0136             SKGAccountObject account(&document1);
0137             SKGTESTERROR(QStringLiteral("IIF.setName"), account.setName(QStringLiteral("Checking")), true)
0138             SKGTESTERROR(QStringLiteral("IIF.load"), account.load(), true)
0139             SKGTEST(QStringLiteral("IIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-500"))
0140         }
0141         {
0142             SKGAccountObject account(&document1);
0143             SKGTESTERROR(QStringLiteral("IIF.setName"), account.setName(QStringLiteral("Savings")), true)
0144             SKGTESTERROR(QStringLiteral("IIF.load"), account.load(), true)
0145             SKGTEST(QStringLiteral("IIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("500"))
0146         }
0147     }
0148 
0149     {
0150         // Test import full_bill_payment.iif
0151         SKGDocumentBank document1;
0152         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0153         SKGError err;
0154         {
0155             // Scope of the transaction
0156             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_IIF"), err)
0157 
0158             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportiif/full_bill_payment.iif"));
0159             SKGTESTERROR(QStringLiteral("IIF.importFile"), imp1.importFile(), true)
0160         }
0161 
0162         {
0163             SKGAccountObject account(&document1);
0164             SKGTESTERROR(QStringLiteral("IIF.setName"), account.setName(QStringLiteral("Checking")), true)
0165             SKGTESTERROR(QStringLiteral("IIF.load"), account.load(), true)
0166             SKGTEST(QStringLiteral("IIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-35"))
0167         }
0168 
0169         {
0170             SKGAccountObject account(&document1);
0171             SKGTESTERROR(QStringLiteral("IIF.setName"), account.setName(QStringLiteral("Accounts Payable")), true)
0172             SKGTESTERROR(QStringLiteral("IIF.load"), account.load(), true)
0173             SKGTEST(QStringLiteral("IIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("35"))
0174         }
0175     }
0176 
0177     {
0178         // Test import full_customer_payment.iif
0179         SKGDocumentBank document1;
0180         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0181         SKGError err;
0182         {
0183             // Scope of the transaction
0184             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_IIF"), err)
0185 
0186             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportiif/full_customer_payment.iif"));
0187             SKGTESTERROR(QStringLiteral("IIF.importFile"), imp1.importFile(), true)
0188         }
0189 
0190         SKGAccountObject la;
0191         {
0192             SKGAccountObject account(&document1);
0193             SKGTESTERROR(QStringLiteral("IIF.setName"), account.setName(QStringLiteral("Undeposited Funds")), true)
0194             SKGTESTERROR(QStringLiteral("IIF.load"), account.load(), true)
0195             SKGTEST(QStringLiteral("IIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("53.5"))
0196             la = account;
0197         }
0198 
0199         {
0200             SKGAccountObject account(&document1);
0201             SKGTESTERROR(QStringLiteral("IIF.setName"), account.setName(QStringLiteral("Accounts Receivable")), true)
0202             SKGTESTERROR(QStringLiteral("IIF.load"), account.load(), true)
0203             SKGTEST(QStringLiteral("IIF:getValue"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-53.5"))
0204         }
0205 
0206         {
0207             // Scope of the transaction
0208             SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_IIF"), err)
0209             SKGImportExportManager exp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportiif/export_all.iif"));
0210             SKGTESTERROR(QStringLiteral("IIF.exportFile"), exp1.exportFile(), true)
0211         }
0212         {
0213             // Scope of the transaction
0214             SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_IIF"), err)
0215             SKGImportExportManager exp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportiif/export_la.iif"));
0216             QMap<QString, QString> params;
0217             params[QStringLiteral("uuid_of_selected_accounts_or_operations")] = la.getUniqueID();
0218             exp1.setExportParameters(params);
0219             SKGTESTERROR(QStringLiteral("IIF.exportFile"), exp1.exportFile(), true)
0220         }
0221     }
0222     // End test
0223     SKGENDTEST()
0224 }