File indexing completed on 2024-06-16 04:47:56
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 { 0029 // Test import KMY 0030 SKGDocumentBank document1; 0031 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0032 SKGError err; 0033 { 0034 // Scope of the transaction 0035 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_KMY"), err) 0036 SKGImportExportManager impmissing(&document1, QUrl::fromLocalFile(QStringLiteral("missingfile.kmy"))); 0037 SKGTESTERROR(QStringLiteral("imp1.importFile"), impmissing.importFile(), false) 0038 0039 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportkmy/rapprochement-incorrect.kmy")); 0040 SKGTESTERROR(QStringLiteral("KMY.importFile"), imp1.importFile(), true) 0041 } 0042 0043 { 0044 SKGAccountObject account(&document1); 0045 SKGTESTERROR(QStringLiteral("KMY.setName"), account.setName(QStringLiteral("CCP")), true) 0046 SKGTESTERROR(QStringLiteral("KMY.load"), account.load(), true) 0047 SKGTEST(QStringLiteral("KMY:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("750")) 0048 } 0049 0050 { 0051 SKGAccountObject account(&document1); 0052 SKGTESTERROR(QStringLiteral("KMY.setName"), account.setName(QStringLiteral("CEL Donald")), true) 0053 SKGTESTERROR(QStringLiteral("KMY.load"), account.load(), true) 0054 SKGTEST(QStringLiteral("KMY:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("150")) 0055 } 0056 0057 { 0058 SKGAccountObject account(&document1); 0059 SKGTESTERROR(QStringLiteral("KMY.setName"), account.setName(QStringLiteral("PEEs")), true) 0060 SKGTESTERROR(QStringLiteral("KMY.load"), account.load(), true) 0061 SKGTEST(QStringLiteral("KMY:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("640")) 0062 } 0063 0064 { 0065 // Scope of the transaction 0066 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportkmy1/rapprochement-incorrect.kmy")); 0067 SKGTESTERROR(QStringLiteral("KMY.exportFile"), imp1.exportFile(), true) 0068 } 0069 } 0070 0071 { 0072 // Test import KMY 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_KMY"), err) 0079 0080 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportkmy/mytest.kmy")); 0081 SKGTESTERROR(QStringLiteral("KMY.importFile"), imp1.importFile(), true) 0082 } 0083 0084 int nb = 0; 0085 SKGTESTERROR(QStringLiteral("KMY:getNbObjects(recurrentoperation)"), document1.getNbObjects(QStringLiteral("recurrentoperation"), QLatin1String(""), nb), true) 0086 SKGTEST(QStringLiteral("KMY:getNbObjects(recurrentoperation)"), nb, 8) 0087 } 0088 0089 { 0090 // Test import KMY 0091 SKGDocumentBank document1; 0092 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0093 SKGError err; 0094 { 0095 // Scope of the transaction 0096 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_KMY"), err) 0097 0098 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportkmy/action.kmy")); 0099 SKGTESTERROR(QStringLiteral("KMY.importFile"), imp1.importFile(), true) 0100 } 0101 0102 { 0103 SKGAccountObject account(&document1); 0104 SKGTESTERROR(QStringLiteral("KMY.setName"), account.setName(QStringLiteral("courant")), true) 0105 SKGTESTERROR(QStringLiteral("KMY.load"), account.load(), true) 0106 SKGTEST(QStringLiteral("KMY:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-600")) 0107 } 0108 0109 { 0110 SKGAccountObject account(&document1); 0111 SKGTESTERROR(QStringLiteral("KMY.setName"), account.setName(QStringLiteral("actions")), true) 0112 SKGTESTERROR(QStringLiteral("KMY.load"), account.load(), true) 0113 SKGTEST(QStringLiteral("KMY:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("100")) 0114 } 0115 0116 // test multi import 0117 { 0118 // Scope of the transaction 0119 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_KMY"), err) 0120 0121 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportkmy/action.kmy")); 0122 SKGTESTERROR(QStringLiteral("KMY.importFile"), imp1.importFile(), true) 0123 } 0124 } 0125 0126 { 0127 // Test import KMY 0128 SKGDocumentBank document1; 0129 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0130 SKGError err; 0131 { 0132 // Scope of the transaction 0133 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_KMY"), err) 0134 0135 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportkmy/252869.kmy")); 0136 SKGTESTERROR(QStringLiteral("KMY.importFile"), imp1.importFile(), true) 0137 } 0138 0139 int nb = 0; 0140 SKGTESTERROR(QStringLiteral("KMY:getNbObjects(recurrentoperation)"), document1.getNbObjects(QStringLiteral("bank"), QStringLiteral("t_name='Test Bank'"), nb), true) 0141 SKGTEST(QStringLiteral("KMY:getNbObjects(recurrentoperation)"), nb, 1) 0142 } 0143 0144 { 0145 // 384119 0146 SKGDocumentBank document1; 0147 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0148 SKGError err; 0149 { 0150 // Scope of the transaction 0151 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_KMY"), err) 0152 0153 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportkmy/384119.kmy")); 0154 SKGTESTERROR(QStringLiteral("KMY.importFile"), imp1.importFile(), true) 0155 } 0156 0157 int nb = 0; 0158 SKGTESTERROR(QStringLiteral("KMY:getNbObjects(transactions without suboperation)"), document1.getNbObjects(QStringLiteral("operation"), QStringLiteral("NOT EXISTS (SELECT 1 FROM suboperation where rd_operation_id=operation.id)"), nb), true) 0159 SKGTEST(QStringLiteral("KMY:getNbObjects(transactions without suboperation)"), nb, 0) 0160 } 0161 0162 { 0163 // Non utf8 0164 SKGDocumentBank document1; 0165 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0166 SKGError err; 0167 { 0168 // Scope of the transaction 0169 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_KMY"), err) 0170 0171 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportkmy/non_utf8.kmy")); 0172 SKGTESTERROR(QStringLiteral("KMY.importFile"), imp1.importFile(), true) 0173 } 0174 } 0175 // End test 0176 SKGENDTEST() 0177 }