File indexing completed on 2024-05-19 16:18:17

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 imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportmny1/A B/money2002.mny"));
0044             QMap<QString, QString> params = imp1.getImportParameters();
0045             params[QStringLiteral("install_sunriise")] = 'Y';
0046             imp1.setImportParameters(params);
0047             SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), true)
0048 
0049             SKGAccountObject account(&document1);
0050             SKGTESTERROR(QStringLiteral("MNY.setName"), account.setName(QStringLiteral("None Investment")), true)
0051             SKGTESTERROR(QStringLiteral("MNY.load"), account.load(), true)
0052             SKGTEST(QStringLiteral("MNY.getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("1.49"))
0053         }
0054 
0055         {
0056             // Scope of the transaction
0057             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_MNY"), err)
0058             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportmny1/A B/money2002.mny"));
0059             QMap<QString, QString> params = imp1.getImportParameters();
0060             params[QStringLiteral("install_sunriise")] = 'Y';
0061             imp1.setImportParameters(params);
0062             SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), true)
0063 
0064             SKGAccountObject account(&document1);
0065             SKGTESTERROR(QStringLiteral("MNY.setName"), account.setName(QStringLiteral("None Investment")), true)
0066             SKGTESTERROR(QStringLiteral("MNY.load"), account.load(), true)
0067             SKGTEST(QStringLiteral("MNY.getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("1.49"))
0068         }
0069     }
0070 
0071     {
0072         // Test import MNY
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_MNY"), err)
0079             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportmny1/notreadable.mny"));
0080             QMap<QString, QString> params = imp1.getImportParameters();
0081             params[QStringLiteral("install_sunriise")] = 'Y';
0082             imp1.setImportParameters(params);
0083             SKGTEST(QStringLiteral("imp1.importFile"), imp1.importFile().getReturnCode(), ERR_READACCESS)
0084         }
0085     }
0086 
0087     {
0088         // Test import MNY
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_MNY"), err)
0095             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportmny3/transfer_and_mode.mny"));
0096             QMap<QString, QString> params = imp1.getImportParameters();
0097             params[QStringLiteral("install_sunriise")] = 'Y';
0098             imp1.setImportParameters(params);
0099             SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), true)
0100         }
0101 
0102         bool test2 = false;
0103         SKGTESTERROR(QStringLiteral("MNY.existObjects"), document1.existObjects(QStringLiteral("operation"), QStringLiteral("t_comment='Mode should be ''text''' AND t_mode='text'"), test2), true)
0104         SKGTEST(QStringLiteral("MNY.existObjects-test"), static_cast<unsigned int>(test2), static_cast<unsigned int>(true))
0105 
0106         SKGTESTERROR(QStringLiteral("MNY.existObjects"), document1.existObjects(QStringLiteral("operation"), QStringLiteral("t_comment='Number should be 123456' AND t_number='123456'"), test2), true)
0107         SKGTEST(QStringLiteral("MNY.existObjects-test"), static_cast<unsigned int>(test2), static_cast<unsigned int>(true))
0108 
0109         SKGTESTERROR(QStringLiteral("MNY.existObjects"), document1.existObjects(QStringLiteral("operation"), QStringLiteral("t_comment='True transfert' AND i_group_id<>0"), test2), true)
0110         SKGTEST(QStringLiteral("MNY.existObjects-test"), static_cast<unsigned int>(test2), static_cast<unsigned int>(true))
0111 
0112         SKGTESTERROR(QStringLiteral("MNY.existObjects"), document1.existObjects(QStringLiteral("operation"), QStringLiteral("t_comment='Not a transfert, just same date/amount' AND i_group_id=0"), test2), true)
0113         SKGTEST(QStringLiteral("MNY.existObjects-test"), static_cast<unsigned int>(test2), static_cast<unsigned int>(true))
0114     }
0115 
0116     // End test
0117     SKGENDTEST()
0118 }