1 /***************************************************************************
2  * SPDX-FileCopyrightText: 2021 S. MANKOWSKI stephane@mankowski.fr
3  * SPDX-FileCopyrightText: 2021 G. DE BURE support@mankowski.fr
4  * SPDX-License-Identifier: GPL-3.0-or-later
5  ***************************************************************************/
6 /** @file
7  * This file is a test script.
8  *
9  * @author Stephane MANKOWSKI / Guillaume DE BURE
10  */
11 #include "skgtestmacro.h"
12 #include "skgbankincludes.h"
13 #include "skgimportexportmanager.h"
14 
15 /**
16  * The main function of the unit test
17  * @param argc the number of arguments
18  * @param argv the list of arguments
19  */
main(int argc,char ** argv)20 int main(int argc, char** argv)
21 {
22     Q_UNUSED(argc)
23     Q_UNUSED(argv)
24 
25     // Init test
26     SKGINITTEST(true) {
27         // Test import PDF skrooge
28         SKGDocumentBank document1;
29         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
30 
31         SKGError err;
32         {
33             // Scope of the transaction
34             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_PDF"), err)
35             QString dir = SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportpdf/";
36             auto listFiles = QDir(dir).entryList(QStringList() << QStringLiteral("*.pdf"), QDir::Files, QDir::Name);
37             for (const auto& file : qAsConst(listFiles)) {
38                 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(dir % file));
39                 SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), true)
40             }
41 
42 
43             document1.dump(DUMPOPERATION | DUMPACCOUNT);
44         }
45 
46         SKGAccountObject account;
47         SKGTESTERROR(QStringLiteral("ACCOUNT.getObjectByName"), SKGNamedObject::getObjectByName(&document1, QStringLiteral("v_account"), QStringLiteral("Facture allopneus"), account), true)
48         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
49         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-2041.24"))
50 
51         int nb = 0;
52         SKGTESTERROR(QStringLiteral("DOC:getNbObjects"), document1.getNbObjects(QStringLiteral("operation"), QLatin1String(""), nb), true)
53         SKGTEST(QStringLiteral("DOC:getNbObjects"), nb, 11)
54 
55         SKGTESTERROR(QStringLiteral("DOC:getNbObjects"), document1.getNbObjects(QStringLiteral("operation"), QStringLiteral("d_date='") + SKGServices::dateToSqlString(QDate::currentDate()) + '\'', nb), true)
56         SKGTEST(QStringLiteral("DOC:getNbObjects"), nb, 0)
57     }
58     // End test
59     SKGENDTEST()
60 }
61