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 struct test {
0017     QString fileName;
0018     QString password;
0019     QMap<QString, double> expectedAccountAmount;
0020 };
0021 
0022 /**
0023  * The main function of the unit test
0024  * @param argc the number of arguments
0025  * @param argv the list of arguments
0026  */
0027 int main(int argc, char** argv)
0028 {
0029     Q_UNUSED(argc)
0030     Q_UNUSED(argv)
0031 
0032     // Init test
0033     SKGINITTEST(true)
0034 
0035     {
0036         // Test import MNY
0037         SKGDocumentBank document1;
0038         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0039         SKGError err;
0040         {
0041             // Scope of the transaction
0042             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_MNY"), err)
0043             SKGImportExportManager impmissing(&document1, QUrl::fromLocalFile(QStringLiteral("/not-existing/missingfile.mny")));
0044             {
0045                 QMap<QString, QString> params = impmissing.getImportParameters();
0046                 params[QStringLiteral("install_sunriise")] = 'Y';
0047                 impmissing.setImportParameters(params);
0048             }
0049             SKGTESTERROR(QStringLiteral("imp1.importFile"), impmissing.importFile(), false)
0050 
0051             SKGImportExportManager impwrong(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportmny1/wrongfile.mny"));
0052             {
0053                 QMap<QString, QString> params = impwrong.getImportParameters();
0054                 params[QStringLiteral("install_sunriise")] = 'Y';
0055                 impwrong.setImportParameters(params);
0056             }
0057             SKGTESTERROR(QStringLiteral("imp1.importFile"), impwrong.importFile(), false)
0058 
0059             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportmny1/money2004-pwd-123@ABC!.mny"));
0060             {
0061                 QMap<QString, QString> params = imp1.getImportParameters();
0062                 params[QStringLiteral("password")] = QStringLiteral("wrong password");
0063                 params[QStringLiteral("install_sunriise")] = 'Y';
0064                 imp1.setImportParameters(params);
0065             }
0066             SKGTEST(QStringLiteral("imp1.importFile"), imp1.importFile().getReturnCode(), ERR_ENCRYPTION)
0067         }
0068     }
0069 
0070 
0071     QVector<test> listTests;
0072     {
0073         test t1;
0074         t1.fileName = QStringLiteral("A B/money2002.mny");
0075 
0076         QMap<QString, double> accounts;
0077         accounts[QStringLiteral("None Investment (Cash)")] = 0.0;
0078         accounts[QStringLiteral("Investments to Watch")] = 0.0;
0079         accounts[QStringLiteral("None Investment")] = 1.49;
0080         t1.expectedAccountAmount = accounts;
0081         listTests << t1;
0082     }
0083     {
0084         test t1;
0085         t1.fileName = QStringLiteral("money2001.mny");
0086 
0087         QMap<QString, double> accounts;
0088         accounts[QStringLiteral("Investments to Watch")] = 0.0;
0089         t1.expectedAccountAmount = accounts;
0090         listTests << t1;
0091     }
0092     {
0093         test t1;
0094         t1.fileName = QStringLiteral("money2004-pwd-123@ABC!.mny");
0095         t1.password = QStringLiteral("123@ABC!");
0096 
0097         QMap<QString, double> accounts;
0098         accounts[QStringLiteral("Investments to Watch")] = 0.0;
0099         t1.expectedAccountAmount = accounts;
0100         listTests << t1;
0101     }
0102     {
0103         test t1;
0104         t1.fileName = QStringLiteral("money2005-pwd-123@ABC!.mny");
0105         t1.password = QStringLiteral("123@ABC!");
0106 
0107         QMap<QString, double> accounts;
0108         accounts[QStringLiteral("George's Pension Plan")] = 250.0;
0109         accounts[QStringLiteral("Investments to Watch")] = 0.0;
0110         accounts[QStringLiteral("Invoice Sales Ledger")] = 1780.71;
0111         accounts[QStringLiteral("Stocks and Shares")] = 830.5;
0112         accounts[QStringLiteral("Stocks and Shares (Cash)")] = -178.0;
0113         accounts[QStringLiteral("Woodgrove Bank Credit Card")] = 1013.0;
0114         accounts[QStringLiteral("Woodgrove Bank Current")] = 20280.14;
0115         accounts[QStringLiteral("Woodgrove Bank Savings")] = 800.0;
0116         t1.expectedAccountAmount = accounts;
0117         listTests << t1;
0118     }
0119     {
0120         test t1;
0121         t1.fileName = QStringLiteral("money2008-pwd-TEST12345.mny");
0122         t1.password = QStringLiteral("TEST12345");
0123 
0124         QMap<QString, double> accounts;
0125         accounts[QStringLiteral("Investments to Watch")] = 0.0;
0126         t1.expectedAccountAmount = accounts;
0127         listTests << t1;
0128     }
0129 
0130     for (const auto& t : qAsConst(listTests)) {
0131         // Test import MNY
0132         SKGDocumentBank document1;
0133         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0134         SKGError err;
0135         {
0136             // Scope of the transaction
0137             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_MNY"), err)
0138 
0139             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportmny1/" % t.fileName));
0140             QMap<QString, QString> params = imp1.getImportParameters();
0141             params[QStringLiteral("password")] = t.password;
0142             params[QStringLiteral("install_sunriise")] = 'Y';
0143             imp1.setImportParameters(params);
0144             SKGTESTERROR(t.fileName % ".importFile", imp1.importFile(), true)
0145         }
0146 
0147         QStringList keys = t.expectedAccountAmount.keys();
0148         for (const auto& k : qAsConst(keys)) {
0149             SKGAccountObject account(&document1);
0150             SKGTESTERROR(t.fileName % ".setName(QStringLiteral(" % k % "))", account.setName(k), true)
0151             SKGTESTERROR(t.fileName % ".load(QStringLiteral(" % k % "))", account.load(), true)
0152             SKGTEST(t.fileName % ".getCurrentAmount(" % k % ")", SKGServices::doubleToString(account.getCurrentAmount()), SKGServices::doubleToString(t.expectedAccountAmount[k]))
0153         }
0154 
0155         if (t.fileName == QStringLiteral("money2005-pwd-123@ABC!.mny")) {
0156             bool check = false;
0157             SKGTESTERROR(t.fileName % ".existObjects", document1.existObjects(QStringLiteral("v_operation"), QStringLiteral("t_TRANSFER='Y'"), check), true)
0158             SKGTESTBOOL(t.fileName % ".existObjects", check, true)
0159         }
0160     }
0161     // End test
0162     SKGENDTEST()
0163 }