File indexing completed on 2024-05-12 16:45:26
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 #include "skgimportplugin.h" 0015 #include "skgreportbank.h" 0016 0017 /** 0018 * The main function of the unit test 0019 * @param argc the number of arguments 0020 * @param argv the list of arguments 0021 */ 0022 int main(int argc, char** argv) 0023 { 0024 Q_UNUSED(argc) 0025 Q_UNUSED(argv) 0026 0027 // Init test 0028 SKGINITTEST(true) { 0029 // Test bug 324649 0030 SKGDocumentBank document1; 0031 SKGTESTERROR(QStringLiteral("document1.load()"), document1.load(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestvariousbugs/324649.skg"), true) 0032 0033 // Check 0034 { 0035 auto* report = qobject_cast<SKGReportBank*>(document1.getReport()); 0036 report->setPeriod(QStringLiteral("2013-09")); 0037 0038 QVariantList values = report->getBankTable(); 0039 SKGTEST(QStringLiteral("324649:getCurrentAmount"), values.count(), 4) 0040 SKGTEST(QStringLiteral("324649:title"), values[0].toList()[0].toString(), QStringLiteral("sum")) 0041 SKGTEST(QStringLiteral("324649:10"), values[1].toList()[2].toString(), QStringLiteral("20")) 0042 SKGTEST(QStringLiteral("324649:20"), values[2].toList()[2].toString(), QStringLiteral("10")) 0043 SKGTEST(QStringLiteral("324649:30"), values[3].toList()[2].toString(), QStringLiteral("30")) 0044 } 0045 } 0046 0047 { 0048 // Test bug 324972 0049 SKGDocumentBank document1; 0050 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0051 SKGError err; 0052 { 0053 // Scope of the transaction 0054 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_CSV"), err) 0055 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestvariousbugs/324972_1.csv")); 0056 SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), true) 0057 } 0058 0059 { 0060 // Scope of the transaction 0061 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_CSV"), err) 0062 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestvariousbugs/324972_2.csv")); 0063 SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), true) 0064 0065 SKGDocument::SKGMessageList messages; 0066 SKGTESTERROR(QStringLiteral("DOC.getMessages"), document1.getMessages(document1.getCurrentTransaction(), messages, true), true) 0067 bool test = false; 0068 for (const auto& msg : qAsConst(messages)) { 0069 SKGTRACE << "Message:" << msg.Text << SKGENDL; 0070 if (msg.Text.contains(QStringLiteral("last imported one"))) { 0071 test = true; 0072 } 0073 } 0074 SKGTEST(QStringLiteral("message.last imported one"), static_cast<unsigned int>(test), 1) 0075 } 0076 0077 0078 SKGAccountObject account; 0079 SKGTESTERROR(QStringLiteral("ACCOUNT.getObjectByName"), SKGNamedObject::getObjectByName(&document1, QStringLiteral("v_account"), QStringLiteral("My account"), account), true) 0080 SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true) 0081 SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("1000")) 0082 } 0083 0084 0085 { 0086 // Test import Weboob 0087 SKGDocumentBank document1; 0088 SKGTESTERROR(QStringLiteral("document1.load()"), document1.load(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestvariousbugs/interests_and_shares.skg"), true) 0089 0090 // Check 0091 { 0092 SKGAccountObject act(&document1); 0093 SKGTESTERROR(QStringLiteral("account.setName()"), act.setName(QStringLiteral("TEST")), true) 0094 SKGTESTERROR(QStringLiteral("account.load()"), act.load(), true) 0095 0096 SKGAccountObject::SKGInterestItemList oInterestList; 0097 double oInterests; 0098 SKGTESTERROR(QStringLiteral("account.getInterestItems()"), act.getInterestItems(oInterestList, oInterests, 2013), true) 0099 SKGTEST(QStringLiteral("oInterestList"), oInterestList.count(), 4) 0100 SKGTEST(QStringLiteral("oInterests"), static_cast<unsigned int>(oInterests > 3.20 && oInterests < 3.22), 1) 0101 0102 SKGTESTERROR(QStringLiteral("account.getInterestItems()"), act.getInterestItems(oInterestList, oInterests, 2014), true) 0103 } 0104 } 0105 0106 { 0107 // Test open invalid files 0108 SKGDocumentBank document1; 0109 SKGTEST(QStringLiteral("document1.load(interests_and_shares.skg,notneededpassword)"), document1.load(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestvariousbugs/interests_and_shares.skg", QStringLiteral("notneededpassword")).getReturnCode(), 0) 0110 SKGTEST(QStringLiteral("document1.load(invalid.skg)"), document1.load(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestvariousbugs/invalid.skg").getReturnCode(), ERR_CORRUPTION) 0111 SKGTEST(QStringLiteral("document1.load(invalid_protected.skg)"), document1.load(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestvariousbugs/invalid_protected.skg").getReturnCode(), ERR_ENCRYPTION) 0112 SKGTEST(QStringLiteral("document1.load(protected.skg)"), document1.load(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestvariousbugs/protected.skg").getReturnCode(), ERR_ENCRYPTION) 0113 SKGTEST(QStringLiteral("document1.load(protected.skg, pwd)"), document1.load(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestvariousbugs/protected.skg", QStringLiteral("pwd")).getReturnCode(), 0) 0114 0115 SKGTEST(QStringLiteral("document1.load(forrecovery.skg)"), document1.load(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestvariousbugs/forrecovery.skg").getReturnCode(), ERR_CORRUPTION) 0116 QString recoveredFile; 0117 SKGTESTERROR(QStringLiteral("document1.recover(forrecovery.skg)"), document1.recover(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestvariousbugs/forrecovery.skg", QLatin1String(""), recoveredFile), true) 0118 SKGTEST(QStringLiteral("document1.load(forrecovery_recovered.skg)"), document1.load(recoveredFile).getReturnCode(), 0) 0119 } 0120 0121 { 0122 // Test 329568 0123 SKGDocumentBank document1; 0124 SKGTESTERROR(QStringLiteral("document1.load()"), document1.load(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestvariousbugs/329568.skg"), true) 0125 0126 // Check 0127 { 0128 SKGAccountObject act(&document1); 0129 SKGTESTERROR(QStringLiteral("account.setName()"), act.setName(QStringLiteral("T")), true) 0130 SKGTESTERROR(QStringLiteral("account.load()"), act.load(), true) 0131 0132 SKGAccountObject::SKGInterestItemList oInterestList; 0133 double oInterests; 0134 SKGTESTERROR(QStringLiteral("account.getInterestItems()"), act.getInterestItems(oInterestList, oInterests, 2014), true) 0135 SKGTEST(QStringLiteral("oInterestList"), oInterestList.count(), 4) 0136 SKGTEST(QStringLiteral("oInterests"), static_cast<unsigned int>(oInterests > 8.20 && oInterests < 8.22), 1) 0137 } 0138 0139 { 0140 auto imp1 = new SKGImportPlugin(); 0141 SKGTESTERROR(QStringLiteral("SKGImportPlugin.importFile"), imp1->importFile(), false) 0142 SKGTESTERROR(QStringLiteral("SKGImportPlugin.exportFile"), imp1->exportFile(), false) 0143 imp1->getMimeTypeFilter(); 0144 delete imp1; 0145 } 0146 } 0147 // End test 0148 SKGENDTEST() 0149 }