File indexing completed on 2024-05-12 16:45:22
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 class SKGTestImportMny2 0016 { 0017 public: 0018 /** 0019 * To check the progress 0020 */ 0021 static QString previousProgress; 0022 0023 /** 0024 * To test progress 0025 * @param iPos the current position 0026 * @return 0 0027 */ 0028 static int progress1(int iPos, qint64 iTime, const QString& iName, void* /*iData*/) 0029 { 0030 if (SKGTestImportMny2::previousProgress != iName) { 0031 SKGTRACE << iPos << "-" << iTime << ":" << iName << SKGENDL; 0032 SKGTestImportMny2::previousProgress = iName; 0033 } 0034 return 0; 0035 } 0036 }; 0037 0038 QString SKGTestImportMny2::previousProgress = QLatin1String(""); 0039 0040 struct test { 0041 QString fileName; 0042 QString password; 0043 QMap<QString, double> expectedAccountAmount; 0044 }; 0045 0046 /** 0047 * The main function of the unit test 0048 * @param argc the number of arguments 0049 * @param argv the list of arguments 0050 */ 0051 int main(int argc, char** argv) 0052 { 0053 Q_UNUSED(argc) 0054 Q_UNUSED(argv) 0055 0056 // Init test 0057 SKGINITTEST(true) 0058 0059 QVector<test> listTests; 0060 { 0061 test t1; 0062 t1.fileName = QStringLiteral("sunset-sample-5-pwd-12@a!.mny"); 0063 t1.password = QStringLiteral("12@a!"); 0064 0065 QMap<QString, double> accounts; 0066 // TODO(Stephane MANKOWSKI): accounts["Charlie & May’s Joint Inv (Cash)"] = -10004.15; 0067 accounts[QStringLiteral("Charlie's 401(k)")] = 24749.18; 0068 accounts[QStringLiteral("Charlie's 401(k) (Contributions)")] = 13192.68; 0069 accounts[QStringLiteral("Commodities")] = 8745.0000; 0070 accounts[QStringLiteral("Commodities (Cash)")] = 255.0; 0071 accounts[QStringLiteral("ETF Brokerage Account")] = 690.0; 0072 accounts[QStringLiteral("ETF Brokerage Account (Cash)")] = 2310.0; 0073 accounts[QStringLiteral("Escrow Account")] = 28100.0; 0074 accounts[QStringLiteral("Home Loan")] = -149122.08; 0075 accounts[QStringLiteral("Investments to Watch")] = 0.0; 0076 accounts[QStringLiteral("Previous card (No longer used)")] = -984.25; 0077 accounts[QStringLiteral("Primary Residence")] = 355000.0; 0078 accounts[QStringLiteral("WoodGrove Finance Stock Options")] = 0.0; 0079 accounts[QStringLiteral("WoodGrove Finance Stock Options (Cash)")] = 0.0; 0080 accounts[QStringLiteral("Woodgrove Bank Checking")] = 22871.06; 0081 accounts[QStringLiteral("Woodgrove Bank Credit Card")] = 19305.74; 0082 accounts[QStringLiteral("Woodgrove Bank Savings")] = 22946.30; 0083 accounts[QStringLiteral("Woodgrove Bond Account")] = 57916.20; 0084 accounts[QStringLiteral("Woodgrove Bond Account (Cash)")] = -57916.20; 0085 accounts[QStringLiteral("Woodgrove Investments")] = 1574.62; 0086 accounts[QStringLiteral("Woodgrove Investments (Cash)")] = -1594.62; 0087 accounts[QStringLiteral("Woodgrove Platinum Card")] = -836.0; 0088 t1.expectedAccountAmount = accounts; 0089 listTests << t1; 0090 } 0091 0092 for (const auto& t : qAsConst(listTests)) { 0093 // Test import MNY 0094 SKGTRACE << "Filename:" << t.fileName << SKGENDL; 0095 SKGDocumentBank document1; 0096 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0097 SKGTRACE << "SKG_SQLITE_LAST_VERSION:" << document1.getParameter(QStringLiteral("SKG_SQLITE_LAST_VERSION")) << SKGENDL; 0098 SKGTESTERROR(QStringLiteral("document1.setProgressCallback"), document1.setProgressCallback(&SKGTestImportMny2::progress1, nullptr), true) 0099 SKGError err; 0100 { 0101 // Scope of the transaction 0102 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_MNY"), err) 0103 0104 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportmny2/" % t.fileName)); 0105 QMap<QString, QString> params = imp1.getImportParameters(); 0106 params[QStringLiteral("password")] = t.password; 0107 params[QStringLiteral("install_sunriise")] = 'Y'; 0108 imp1.setImportParameters(params); 0109 SKGTESTERROR(t.fileName % ".importFile", imp1.importFile(), true) 0110 } 0111 0112 QStringList keys = t.expectedAccountAmount.keys(); 0113 for (const auto& k : qAsConst(keys)) { 0114 SKGAccountObject account(&document1); 0115 SKGTESTERROR(t.fileName % ".setName(QStringLiteral(" % k % "))", account.setName(k), true) 0116 SKGTESTERROR(t.fileName % ".load(QStringLiteral(" % k % "))", account.load(), true) 0117 SKGTEST(t.fileName % ".getCurrentAmount(" % k % ")", SKGServices::doubleToString(account.getCurrentAmount()), SKGServices::doubleToString(t.expectedAccountAmount[k])) 0118 } 0119 } 0120 // End test 0121 SKGENDTEST() 0122 }