File indexing completed on 2024-05-12 16:45:21
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 SKGError err; 0028 { 0029 // Test import SKGImportExportManager::CSV skrooge 0030 SKGDocumentBank document1; 0031 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) { 0032 // Scope of the transaction 0033 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err) { 0034 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsvunit/notfound.csv")); 0035 QMap<QString, QString> parameters = imp1.getImportParameters(); 0036 parameters[QStringLiteral("mode_csv_unit")] = 'Y'; 0037 imp1.setImportParameters(parameters); 0038 SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), false) // FILE NOT FOUND 0039 } 0040 { 0041 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsvunit/test.csv")); 0042 QMap<QString, QString> parameters = imp1.getImportParameters(); 0043 parameters[QStringLiteral("mode_csv_unit")] = 'Y'; 0044 imp1.setImportParameters(parameters); 0045 SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), true) 0046 } 0047 { 0048 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsvunit/test2.csv")); 0049 QMap<QString, QString> parameters = imp1.getImportParameters(); 0050 parameters[QStringLiteral("mode_csv_unit")] = 'Y'; 0051 imp1.setImportParameters(parameters); 0052 SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), true) 0053 } 0054 } 0055 document1.dump(DUMPUNIT); 0056 { 0057 SKGUnitObject unit(&document1); 0058 SKGTESTERROR(QStringLiteral("UNIT.setName"), unit.setName(QStringLiteral("test")), true) 0059 SKGTESTERROR(QStringLiteral("UNIT.load"), unit.load(), true) 0060 SKGUnitValueObject UnitValue; 0061 SKGTESTERROR(QStringLiteral("UNIT.getLastUnitValue"), unit.getLastUnitValue(UnitValue), true) 0062 SKGTEST(QStringLiteral("UNIT:getQuantity"), SKGServices::doubleToString(UnitValue.getQuantity()), QStringLiteral("50")) 0063 } 0064 { 0065 SKGUnitObject unit(&document1); 0066 SKGTESTERROR(QStringLiteral("UNIT.setName"), unit.setName(QStringLiteral("test2")), true) 0067 SKGTESTERROR(QStringLiteral("UNIT.load"), unit.load(), true) 0068 SKGUnitValueObject UnitValue; 0069 SKGTESTERROR(QStringLiteral("UNIT.getLastUnitValue"), unit.getLastUnitValue(UnitValue), true) 0070 SKGTEST(QStringLiteral("UNIT:getQuantity"), SKGServices::doubleToString(UnitValue.getQuantity()), QStringLiteral("25.16")) 0071 } 0072 } 0073 0074 { 0075 // Test import SKGImportExportManager::CSV skrooge 0076 SKGDocumentBank document1; 0077 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) { 0078 // Scope of the transaction 0079 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err) { 0080 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsvunit/coma.csv")); 0081 QMap<QString, QString> parameters = imp1.getImportParameters(); 0082 parameters[QStringLiteral("mode_csv_unit")] = 'Y'; 0083 imp1.setImportParameters(parameters); 0084 SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), true) 0085 } 0086 } 0087 } 0088 // End test 0089 SKGENDTEST() 0090 }