File indexing completed on 2024-05-12 16:45:19
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 <qfile.h> 0012 0013 #include "skgbankincludes.h" 0014 #include "skgtestmacro.h" 0015 #include "skgtraces.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 0030 QDate now = QDate::currentDate(); 0031 0032 // ============================================================================ 0033 // Init 0034 QString filename = SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestbigdocument/skgtestbigdocument.skg"; 0035 0036 { 0037 // Test bank document 0038 SKGDocumentBank document1; 0039 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0040 SKGUnitValueObject unit_euro_val1; 0041 SKGBankObject bank(&document1); 0042 SKGAccountObject account; 0043 SKGError err; 0044 { 0045 // Scope of the transaction 0046 SKGBEGINTRANSACTION(document1, QStringLiteral("BANK_T1"), err) 0047 0048 // Creation bank 0049 SKGTESTERROR(QStringLiteral("BANK:setName"), bank.setName(QStringLiteral("CREDIT COOP")), true) 0050 SKGTESTERROR(QStringLiteral("BANK:save"), bank.save(), true) 0051 0052 // Creation account 0053 SKGTESTERROR(QStringLiteral("BANK:addAccount"), bank.addAccount(account), true) 0054 SKGTESTERROR(QStringLiteral("ACCOUNT:setName"), account.setName(QStringLiteral("Courant steph")), true) 0055 SKGTESTERROR(QStringLiteral("ACCOUNT:setNumber"), account.setNumber(QStringLiteral("12345P")), true) 0056 SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account.save(), true) 0057 0058 // Creation unit 0059 SKGUnitObject unit_euro(&document1); 0060 SKGTESTERROR(QStringLiteral("UNIT:setName"), unit_euro.setName(QStringLiteral("euro")), true) 0061 SKGTESTERROR(QStringLiteral("UNIT:save"), unit_euro.save(), true) 0062 0063 // Creation unitvalue 0064 SKGTESTERROR(QStringLiteral("UNIT:addUnitValue"), unit_euro.addUnitValue(unit_euro_val1), true) 0065 SKGTESTERROR(QStringLiteral("UNITVALUE:setQuantity"), unit_euro_val1.setQuantity(1), true) 0066 SKGTESTERROR(QStringLiteral("UNITVALUE:setDate"), unit_euro_val1.setDate(now), true) 0067 SKGTESTERROR(QStringLiteral("UNITVALUE:save"), unit_euro_val1.save(), true) 0068 0069 // Creation categories 0070 auto cats = new SKGCategoryObject[30]; 0071 for (int i = 0; i < 10; ++i) { 0072 cats[i] = SKGCategoryObject(&document1); 0073 SKGTESTERROR(QStringLiteral("CAT:setName"), cats[i].setName("cat_" % SKGServices::intToString(i)), true) 0074 SKGTESTERROR(QStringLiteral("CAT:save"), cats[i].save(), true) 0075 0076 for (int j = 0; j < 2; ++j) { 0077 int indexSubCat = 10 * (j + 1) + i; 0078 SKGTESTERROR(QStringLiteral("CAT:addCategory"), cats[i].addCategory(cats[indexSubCat]), true) 0079 SKGTESTERROR(QStringLiteral("CAT:setName"), cats[indexSubCat].setName("cat_" % SKGServices::intToString(i) % '_' % SKGServices::intToString(j)), true) 0080 SKGTESTERROR(QStringLiteral("CAT:save"), cats[indexSubCat].save(), true) 0081 } 0082 } 0083 0084 // Creation payees 0085 auto payees = new SKGPayeeObject[10]; 0086 for (int i = 0; i < 10; ++i) { 0087 payees[i] = SKGPayeeObject(&document1); 0088 SKGTESTERROR(QStringLiteral("PAY:setName"), payees[i].setName("pay_" % SKGServices::intToString(i)), true) 0089 SKGTESTERROR(QStringLiteral("PAY:save"), payees[i].save(), true) 0090 } 0091 0092 // Mode 0093 auto modes = new QString[5]; 0094 modes[0] = QStringLiteral("cheque"); 0095 modes[1] = QStringLiteral("carte"); 0096 modes[2] = QStringLiteral("tip"); 0097 modes[3] = QStringLiteral("virement"); 0098 modes[4] = QStringLiteral("espece"); 0099 0100 // Comments 0101 auto comments = new QString[3]; 0102 comments[0] = QStringLiteral("bla bla"); 0103 comments[1] = QStringLiteral("hello world"); 0104 comments[2] = QStringLiteral("youpi"); 0105 0106 // Creation operation 0107 SKGOperationObject mainOperation; 0108 for (int i = 1; i <= 365 * 10; ++i) { 0109 SKGOperationObject op_1; 0110 SKGTESTERROR(QStringLiteral("ACCOUNT:addOperation"), account.addOperation(op_1), true) 0111 SKGTESTERROR(QStringLiteral("OPE:setNumber"), op_1.setNumber(SKGServices::intToString(1000 + i)), true) 0112 SKGTESTERROR(QStringLiteral("OPE:setMode"), op_1.setMode(modes[i % 5]), true) 0113 SKGTESTERROR(QStringLiteral("OPE:setComment"), op_1.setComment(comments[i % 3]), true) 0114 SKGTESTERROR(QStringLiteral("OPE:setDate"), op_1.setDate(now.addDays(-i)), true) 0115 SKGTESTERROR(QStringLiteral("OPE:setUnit"), op_1.setUnit(unit_euro), true) 0116 SKGTESTERROR(QStringLiteral("OPE:setStatus"), op_1.setStatus((i < 20 ? SKGOperationObject::NONE : (i < 40 ? SKGOperationObject::MARKED : SKGOperationObject::CHECKED))), true) 0117 SKGTESTERROR(QStringLiteral("OPE:bookmark"), op_1.bookmark(i % 2 == 0), true) 0118 SKGTESTERROR(QStringLiteral("OPE:save"), op_1.save(), true) 0119 if (i == 1) { 0120 mainOperation = op_1; 0121 mainOperation.setGroupOperation(mainOperation); 0122 SKGTESTERROR(QStringLiteral("OPE:save"), mainOperation.save(), true) 0123 } else { 0124 if (!op_1.isBookmarked()) { 0125 op_1.setGroupOperation(mainOperation); 0126 } 0127 SKGTESTERROR(QStringLiteral("OPE:save"), op_1.save(), true) 0128 } 0129 0130 // Creation suboperation 0131 for (int j = 1; j <= 2; ++j) { 0132 SKGSubOperationObject subop_1; 0133 SKGTESTERROR(QStringLiteral("OPE:addSubOperation"), op_1.addSubOperation(subop_1), true) 0134 SKGTESTERROR(QStringLiteral("SUBOPE:setCategory"), subop_1.setCategory(cats[i % 30]), true) 0135 SKGTESTERROR(QStringLiteral("SUBOPE:setQuantity"), subop_1.setQuantity(((i * j) % 60) - 10), true) 0136 SKGTESTERROR(QStringLiteral("SUBOPE:setOrder"), subop_1.setOrder(i), true) 0137 SKGTEST(QStringLiteral("SUBOPE:getOrder"), subop_1.getOrder(), i) 0138 SKGTESTERROR(QStringLiteral("SUBOPE:save"), subop_1.save(), true) 0139 } 0140 } 0141 0142 cats[0].merge(cats[1]); 0143 payees[0].merge(payees[1]); 0144 0145 // Delete 0146 delete [] cats; 0147 delete [] modes; 0148 delete [] comments; 0149 delete [] payees; 0150 } // A commit is done here because the scope is close 0151 0152 SKGTESTERROR(QStringLiteral("ACCOUNT:getCurrentAmount"), account.load(), true) 0153 SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), account.getCurrentAmount(), 140165) 0154 0155 QFile(filename).remove(); 0156 SKGTESTERROR(QStringLiteral("DOC:saveAs"), document1.saveAs(filename), true) 0157 } 0158 0159 // ============================================================================ 0160 { 0161 SKGTraces::SKGPerfo = true; 0162 SKGTRACEIN(0, "openTest") 0163 0164 // Test bank document 0165 SKGDocumentBank document1; 0166 { 0167 SKGTRACEIN(0, "openTest-Load") 0168 SKGTESTERROR(QStringLiteral("document1.load"), document1.load(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestbigdocument/skgtestbigdocument.skg"), true) 0169 } 0170 0171 { 0172 SKGTRACEIN(0, "openTest-Get") 0173 SKGAccountObject account; 0174 SKGTESTERROR(QStringLiteral("SKGAccountObject::getObjectByName"), SKGAccountObject::getObjectByName(&document1, QStringLiteral("v_account"), QStringLiteral("Courant steph"), account), true) 0175 SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), account.getCurrentAmount(), 140165) 0176 0177 SKGAccountObject::SKGListSKGObjectBase objects; 0178 SKGTESTERROR(QStringLiteral("SKGAccountObject::getObjects"), document1.getObjects(QStringLiteral("v_operation"), QLatin1String(""), objects), true) 0179 0180 int nbobj = 0; 0181 SKGTESTERROR(QStringLiteral("SKGAccountObject::getNbObjects"), document1.getNbObjects(QStringLiteral("v_operation"), QLatin1String(""), nbobj), true) 0182 } 0183 0184 { 0185 SKGTRACEIN(0, "openTest-Save") 0186 SKGTESTERROR(QStringLiteral("document1.save"), document1.save(), true) 0187 } 0188 } 0189 0190 // End test 0191 SKGENDTEST() 0192 }