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  * 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         // Test import PDF skrooge
0028         SKGDocumentBank document1;
0029         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0030 
0031         SKGError err;
0032         {
0033             // Scope of the transaction
0034             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_PDF"), err)
0035             QString dir = SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportpdf/";
0036             auto listFiles = QDir(dir).entryList(QStringList() << QStringLiteral("*.pdf"), QDir::Files, QDir::Name);
0037             for (const auto& file : qAsConst(listFiles)) {
0038                 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(dir % file));
0039                 SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), true)
0040             }
0041 
0042 
0043             document1.dump(DUMPOPERATION | DUMPACCOUNT);
0044         }
0045 
0046         SKGAccountObject account;
0047         SKGTESTERROR(QStringLiteral("ACCOUNT.getObjectByName"), SKGNamedObject::getObjectByName(&document1, QStringLiteral("v_account"), QStringLiteral("Facture allopneus"), account), true)
0048         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0049         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-2041.24"))
0050 
0051         int nb = 0;
0052         SKGTESTERROR(QStringLiteral("DOC:getNbObjects"), document1.getNbObjects(QStringLiteral("operation"), QLatin1String(""), nb), true)
0053         SKGTEST(QStringLiteral("DOC:getNbObjects"), nb, 11)
0054 
0055         SKGTESTERROR(QStringLiteral("DOC:getNbObjects"), document1.getNbObjects(QStringLiteral("operation"), QStringLiteral("d_date='") + SKGServices::dateToSqlString(QDate::currentDate()) + '\'', nb), true)
0056         SKGTEST(QStringLiteral("DOC:getNbObjects"), nb, 0)
0057     }
0058     // End test
0059     SKGENDTEST()
0060 }