File indexing completed on 2024-11-24 04:37:55
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 bankperfect 0030 SKGError err; 0031 SKGDocumentBank document1; 0032 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) { 0033 // Scope of the transaction 0034 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_BP_CSV"), err) 0035 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/bankperfect.csv")); 0036 SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), true) 0037 } 0038 0039 { 0040 SKGBEGINTRANSACTION(document1, QStringLiteral("AUTORECONCILE"), err) 0041 SKGAccountObject account1(&document1); 0042 SKGTESTERROR(QStringLiteral("ACCOUNT.setName"), account1.setName(QStringLiteral("bankperfect")), true) 0043 SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account1.load(), true) 0044 auto soluces = account1.getPossibleReconciliations(3547.14); 0045 SKGTEST(QStringLiteral("ACCOUNT.getPossibleReconciliations"), soluces.count(), 1) 0046 SKGTESTERROR(QStringLiteral("ACCOUNT.autoReconcile"), account1.autoReconcile(3547.14), true) 0047 } 0048 } 0049 0050 { 0051 // Test import bankperfect 0052 SKGError err; 0053 SKGDocumentBank document1; 0054 SKGTESTERROR(QStringLiteral("document1.load()"), document1.load(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestautoreconcile/complex.skg"), true) { 0055 SKGBEGINTRANSACTION(document1, QStringLiteral("AUTORECONCILE"), err) { 0056 SKGAccountObject account1(&document1); 0057 SKGTESTERROR(QStringLiteral("ACCOUNT.setName"), account1.setName(QStringLiteral("EURO")), true) 0058 SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account1.load(), true) 0059 auto soluces = account1.getPossibleReconciliations(3699.67); 0060 SKGTEST(QStringLiteral("ACCOUNT.getPossibleReconciliations"), soluces.count(), 1) 0061 SKGTESTERROR(QStringLiteral("ACCOUNT.autoReconcile"), account1.autoReconcile(3699.67), true) 0062 0063 soluces = account1.getPossibleReconciliations(3699.67); 0064 SKGTEST(QStringLiteral("ACCOUNT.getPossibleReconciliations"), soluces.count(), 1) 0065 SKGTESTERROR(QStringLiteral("ACCOUNT.autoReconcile"), account1.autoReconcile(3699.67), true) 0066 } 0067 0068 { 0069 SKGAccountObject account1(&document1); 0070 SKGTESTERROR(QStringLiteral("ACCOUNT.setName"), account1.setName(QStringLiteral("DOLLAR")), true) 0071 SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account1.load(), true) 0072 auto soluces = account1.getPossibleReconciliations(3699.67); 0073 SKGTEST(QStringLiteral("ACCOUNT.getPossibleReconciliations"), soluces.count(), 1) 0074 SKGTESTERROR(QStringLiteral("ACCOUNT.autoReconcile"), account1.autoReconcile(3699.67), true) 0075 0076 SKGTESTERROR(QStringLiteral("ACCOUNT.autoReconcile"), account1.autoReconcile(3699.67), true) 0077 } 0078 } 0079 } 0080 0081 { 0082 // Test many combinations 0083 SKGDocumentBank document1; 0084 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0085 SKGError err; 0086 { 0087 // Scope of the transaction 0088 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err) 0089 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestautoreconcile/many_combinations.csv")); 0090 SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true) 0091 document1.dump(DUMPOPERATION | DUMPACCOUNT); 0092 } 0093 0094 { 0095 SKGAccountObject account1(&document1); 0096 SKGTESTERROR(QStringLiteral("ACCOUNT.setName"), account1.setName(QStringLiteral("many combinations")), true) 0097 SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account1.load(), true) 0098 auto soluces = account1.getPossibleReconciliations(53, true); 0099 SKGTEST(QStringLiteral("ACCOUNT.getPossibleReconciliations"), soluces.count(), 1) 0100 0101 SKGBEGINTRANSACTION(document1, QStringLiteral("CREATE OPERATIONS"), err) 0102 double oBalance; 0103 SKGUnitObject oUnit; 0104 QDate now = QDate::currentDate(); 0105 account1.getInitialBalance(oBalance, oUnit); 0106 int nb = 38; 0107 for (int i = 1; i <= nb; ++i) { 0108 SKGOperationObject op; 0109 SKGTESTERROR(QStringLiteral("ACCOUNT:addOperation"), account1.addOperation(op), true) 0110 SKGTESTERROR(QStringLiteral("OPE:setDate"), op.setDate(now), true) 0111 SKGTESTERROR(QStringLiteral("OPE:setUnit"), op.setUnit(oUnit), true) 0112 SKGTESTERROR(QStringLiteral("OPE:setImported"), op.setImported(true), true) 0113 SKGTESTERROR(QStringLiteral("OPE:save"), op.save(), true) 0114 0115 SKGSubOperationObject subop; 0116 SKGTESTERROR(QStringLiteral("OPE:addSubOperation"), op.addSubOperation(subop), true) 0117 SKGTESTERROR(QStringLiteral("OPE:setQuantity"), subop.setQuantity(10), true) 0118 SKGTESTERROR(QStringLiteral("SUBOPE:save"), subop.save(), true) 0119 } 0120 0121 // Test performance 0122 soluces = account1.getPossibleReconciliations(-23 + 10 * nb, true); 0123 } 0124 } 0125 // End test 0126 SKGENDTEST() 0127 }