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

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     QStringList extensions;
0029     extensions << QStringLiteral("csv") << QStringLiteral("cfo") << QStringLiteral("gnucash") << QStringLiteral("gsb") << QStringLiteral("kmy") << QStringLiteral("mmb") << QStringLiteral("mt940") << QStringLiteral("ofx") << QStringLiteral("qif") << QStringLiteral("skg") << QStringLiteral("xhb");
0030 
0031     int nb = extensions.count();
0032     for (int i = 0; i < nb; ++i) {
0033         const QString& ext = extensions.at(i);
0034         QString filename = "https://skrooge.org/files/skgtestimporturl/test." % ext;
0035         SKGTRACE << i + 1 << "/" << nb << ": Import " << filename << SKGENDL;
0036 
0037         // Test import
0038         SKGDocumentBank document1;
0039         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0040         SKGError err;
0041         {
0042             // Scope of the transaction
0043             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0044 
0045             SKGImportExportManager imp1(&document1, QUrl::fromUserInput(filename));
0046             SKGTESTERROR(ext % ".importFile", imp1.importFile(), true)
0047         }
0048 
0049         if (ext == QStringLiteral("skg") && SKGServices::getEnvVariable(QStringLiteral("USER")) == QStringLiteral("s")) {
0050             QStringList extensionsExport;
0051             extensionsExport.push_back(QStringLiteral("csv"));
0052             extensionsExport.push_back(QStringLiteral("kmy"));
0053             extensionsExport.push_back(QStringLiteral("qif"));
0054             extensionsExport.push_back(QStringLiteral("skg"));
0055             extensionsExport.push_back(QStringLiteral("xml"));
0056             extensionsExport.push_back(QStringLiteral("sqlite"));
0057 
0058             int nb2 = extensionsExport.count();
0059             for (int j = 0; j < nb2; ++j) {
0060                 const QString& ext2 = extensionsExport.at(j);
0061                 QString filename2 = "ftp://skrooge.org/files/skgtestimporturl/output/test." % ext2;
0062                 SKGTRACE << "    " << j + 1 << "/" << nb2 << ": Export " << filename2 << SKGENDL;
0063 
0064                 // Scope of the transaction
0065                 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT"), err)
0066 
0067                 SKGImportExportManager imp1(&document1,  QUrl::fromUserInput(filename2));
0068                 SKGTESTERROR(ext2 % ".exportFile", imp1.exportFile(), true)
0069             }
0070         }
0071     }
0072 
0073     {
0074         SKGDocumentBank document1;
0075         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0076         SKGTESTERROR(QStringLiteral("document1.load()"), document1.load(QStringLiteral("https://skrooge.org/files/skgtestimporturl/test.skg")), true)
0077     }
0078 
0079     // End test
0080     SKGENDTEST()
0081 }