File indexing completed on 2024-05-12 16:45:25

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 
0016 /**
0017  * The main function of the unit test
0018  * @param argc the number of arguments
0019  * @param argv the list of arguments
0020  */
0021 int main(int argc, char** argv)
0022 {
0023     Q_UNUSED(argc)
0024     Q_UNUSED(argv)
0025 
0026     // Init test
0027     SKGINITTEST(true)
0028 
0029     QString filename = SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestoperation.skg";
0030     QDate now = QDate::currentDate();
0031     QDate tomorrow = QDate::currentDate().addDays(+1);
0032     // ============================================================================
0033     {
0034         // Test bank document
0035         SKGDocumentBank document1;
0036         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0037         SKGUnitValueObject unit_euro_val1;
0038         SKGBankObject bank(&document1);
0039         SKGUnitObject unit_euro(&document1);
0040         SKGAccountObject account;
0041         SKGError err;
0042         {
0043             // Scope of the transaction
0044             SKGBEGINTRANSACTION(document1, QStringLiteral("BANK_T1"), err)
0045 
0046             // Creation bank
0047             SKGTESTERROR(QStringLiteral("BANK:setName"), bank.setName(QStringLiteral("CREDIT COOP")), true)
0048             SKGTESTERROR(QStringLiteral("BANK:save"), bank.save(), true)
0049 
0050             // Creation account
0051             SKGTESTERROR(QStringLiteral("BANK:addAccount"), bank.addAccount(account), true)
0052             SKGTESTERROR(QStringLiteral("ACCOUNT:setName"), account.setName(QStringLiteral("Courant steph")), true)
0053 
0054             SKGOperationObject op_1;
0055             SKGTESTERROR(QStringLiteral("ACCOUNT:addOperation"), account.addOperation(op_1), false)
0056             SKGTESTERROR(QStringLiteral("OP:setParentAccount"), op_1.setParentAccount(account), false)
0057 
0058             SKGTESTERROR(QStringLiteral("ACCOUNT:setClosed"), account.setClosed(true), true)
0059             SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account.save(), true)
0060 
0061             // Creation transaction ==> failed
0062             SKGTESTERROR(QStringLiteral("ACCOUNT:addOperation"), account.addOperation(op_1), false)
0063 
0064             // Reopen account
0065             SKGTESTERROR(QStringLiteral("ACCOUNT:setClosed"), account.setClosed(false), true)
0066             SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account.save(), true)
0067 
0068             // Creation unit
0069             SKGTESTERROR(QStringLiteral("UNIT:setName"), unit_euro.setName(QStringLiteral("euro")), true)
0070             SKGTESTERROR(QStringLiteral("UNIT:save"), unit_euro.save(), true)
0071 
0072             // Creation unitvalue
0073             SKGTESTERROR(QStringLiteral("UNIT:addUnitValue"), unit_euro.addUnitValue(unit_euro_val1), true)
0074             SKGTESTERROR(QStringLiteral("UNITVALUE:setQuantity"), unit_euro_val1.setQuantity(1), true)
0075             SKGTESTERROR(QStringLiteral("UNITVALUE:setDate"), unit_euro_val1.setDate(now), true)
0076             SKGTESTERROR(QStringLiteral("UNITVALUE:save"), unit_euro_val1.save(), true)
0077 
0078             // Creation transaction ==> OK
0079             SKGTESTERROR(QStringLiteral("ACCOUNT:addOperation"), account.addOperation(op_1), true)
0080 
0081             SKGSubOperationObject subop_1;
0082             SKGTESTERROR(QStringLiteral("OPE:addSubOperation"), op_1.addSubOperation(subop_1), false)
0083 
0084             SKGTESTERROR(QStringLiteral("OPE:setDate"), op_1.setDate(now), true)
0085             SKGTESTERROR(QStringLiteral("OPE:setUnit"), op_1.setUnit(unit_euro), true)
0086             SKGTESTERROR(QStringLiteral("OPE:save"), op_1.save(), true)
0087 
0088             SKGTESTERROR(QStringLiteral("OPE:addSubOperation"), op_1.addSubOperation(subop_1), true)
0089             SKGTESTERROR(QStringLiteral("SUBOPE:save"), subop_1.save(), true)
0090 
0091             SKGTESTERROR(QStringLiteral("OPE:setDate"), op_1.setDate(now), true)
0092             SKGTESTERROR(QStringLiteral("OPE:save"), op_1.save(), true)
0093 
0094             SKGTEST(QStringLiteral("OPE:getDate"), SKGServices::dateToSqlString(op_1.getDate()), SKGServices::dateToSqlString(now))
0095             SKGTEST(QStringLiteral("SUBOPE:getDate"), SKGServices::dateToSqlString(subop_1.getDate()), SKGServices::dateToSqlString(now))
0096 
0097             SKGTESTERROR(QStringLiteral("SUBOPE:setDate"), subop_1.setDate(tomorrow), true)
0098             SKGTESTERROR(QStringLiteral("SUBOPE:save"), subop_1.save(), true)
0099 
0100             SKGTEST(QStringLiteral("SUBOPE:getDate"), SKGServices::dateToSqlString(subop_1.getDate()), SKGServices::dateToSqlString(tomorrow))
0101 
0102             SKGTESTERROR(QStringLiteral("OPE:setDate"), op_1.setDate(tomorrow), true)
0103             SKGTESTERROR(QStringLiteral("OPE:save"), op_1.save(), true)
0104             SKGTESTERROR(QStringLiteral("SUBOPE:load"), subop_1.load(), true)
0105 
0106             SKGTEST(QStringLiteral("OPE:getDate"), SKGServices::dateToSqlString(op_1.getDate()), SKGServices::dateToSqlString(tomorrow))
0107             SKGTEST(QStringLiteral("SUBOPE:getDate"), SKGServices::dateToSqlString(subop_1.getDate()), SKGServices::dateToSqlString(tomorrow.addDays(+1)))
0108         }
0109     }
0110 
0111     // ============================================================================
0112     {
0113         // Test bank document
0114         SKGDocumentBank document1;
0115         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0116         SKGUnitValueObject unit_euro_val1;
0117         SKGBankObject bank(&document1);
0118         SKGUnitObject unit_euro(&document1);
0119         SKGAccountObject account;
0120         SKGError err;
0121         {
0122             // Scope of the transaction
0123             SKGBEGINTRANSACTION(document1, QStringLiteral("BANK_T1"), err)
0124 
0125             // Creation bank
0126             SKGTESTERROR(QStringLiteral("BANK:setName"), bank.setName(QStringLiteral("CREDIT COOP")), true)
0127             SKGTESTERROR(QStringLiteral("BANK:save"), bank.save(), true)
0128 
0129             // Creation account
0130             SKGTESTERROR(QStringLiteral("BANK:addAccount"), bank.addAccount(account), true)
0131             SKGTESTERROR(QStringLiteral("ACCOUNT:setName"), account.setName(QStringLiteral("Courant steph")), true)
0132             SKGTESTERROR(QStringLiteral("ACCOUNT:setNumber"), account.setNumber(QStringLiteral("12345P")), true)
0133             SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account.save(), true)
0134 
0135             // Creation unit
0136             SKGTESTERROR(QStringLiteral("UNIT:setName"), unit_euro.setName(QStringLiteral("euro")), true)
0137             SKGTESTERROR(QStringLiteral("UNIT:save"), unit_euro.save(), true)
0138 
0139             // Creation unitvalue
0140             SKGTESTERROR(QStringLiteral("UNIT:addUnitValue"), unit_euro.addUnitValue(unit_euro_val1), true)
0141             SKGTESTERROR(QStringLiteral("UNITVALUE:setQuantity"), unit_euro_val1.setQuantity(1), true)
0142             SKGTESTERROR(QStringLiteral("UNITVALUE:setDate"), unit_euro_val1.setDate(now), true)
0143             SKGTESTERROR(QStringLiteral("UNITVALUE:save"), unit_euro_val1.save(), true)
0144 
0145             // Creation categories
0146             SKGCategoryObject cat_1(&document1);
0147             SKGTESTERROR(QStringLiteral("CAT:setName"), cat_1.setName(QStringLiteral("transport")), true)
0148             SKGTESTERROR(QStringLiteral("CAT:save"), cat_1.save(), true)
0149 
0150             SKGCategoryObject cat_2;
0151             SKGTESTERROR(QStringLiteral("CAT:addCategory"), cat_1.addCategory(cat_2), true)
0152             SKGTESTERROR(QStringLiteral("CAT:setName"), cat_2.setName(QStringLiteral("train")), true)
0153             SKGTESTERROR(QStringLiteral("CAT:save"), cat_2.save(), true)
0154 
0155             // Creation operation
0156             SKGOperationObject mainOperation;
0157             double balance = 0;
0158             for (int i = 1; i <= 10; ++i) {
0159                 SKGOperationObject op_1;
0160                 SKGTESTERROR(QStringLiteral("ACCOUNT:addOperation"), account.addOperation(op_1), true)
0161                 SKGTESTERROR(QStringLiteral("OPE:setTemplate"), op_1.setTemplate(true), true)
0162                 SKGTESTBOOL("OPE:isTemplate", op_1.isTemplate(), true)
0163                 SKGTESTERROR(QStringLiteral("OPE:setTemplate"), op_1.setTemplate(false), true)
0164                 SKGTESTBOOL("OPE:isTemplate", op_1.isTemplate(), false)
0165                 SKGTESTERROR(QStringLiteral("OPE:setNumber"), op_1.setNumber(SKGServices::intToString(1000 + i)), true)
0166                 SKGTESTERROR(QStringLiteral("OPE:setMode"), op_1.setMode(QStringLiteral("cheque")), true)
0167                 SKGTESTERROR(QStringLiteral("OPE:setComment"), op_1.setComment(QStringLiteral("10 tickets")), true)
0168                 SKGTESTERROR(QStringLiteral("OPE:setDate"), op_1.setDate(now), true)
0169                 SKGTESTERROR(QStringLiteral("OPE:setUnit"), op_1.setUnit(unit_euro), true)
0170                 SKGUnitObject u;
0171                 SKGTESTERROR(QStringLiteral("OPE:setUnit"), op_1.getUnit(u), true)
0172                 SKGTESTERROR(QStringLiteral("OPE:bookmark"), op_1.bookmark(i % 2 == 0), true)
0173                 SKGTESTERROR(QStringLiteral("OPE:save"), op_1.save(), true)
0174                 if (i == 1) {
0175                     mainOperation = op_1;
0176                     SKGTESTERROR(QStringLiteral("OPE:setGroupOperation"), mainOperation.setGroupOperation(mainOperation), true)
0177                     SKGTESTERROR(QStringLiteral("OPE:save"), mainOperation.save(), true)
0178                 } else {
0179                     if (!op_1.isBookmarked()) {
0180                         SKGTESTERROR(QStringLiteral("OPE:setGroupOperation"), op_1.setGroupOperation(mainOperation), true)
0181                     }
0182                     SKGTESTERROR(QStringLiteral("OPE:save"), op_1.save(), true)
0183                 }
0184 
0185                 // Creation suboperation
0186                 for (int j = 1; j <= 5; ++j) {
0187                     SKGSubOperationObject subop_1;
0188                     SKGTESTERROR(QStringLiteral("OPE:addSubOperation"), op_1.addSubOperation(subop_1), true)
0189                     SKGTESTERROR(QStringLiteral("SUBOPE:setCategory"), subop_1.setCategory(cat_2), true)
0190                     SKGTESTERROR(QStringLiteral("SUBOPE:setComment"), subop_1.setComment(QStringLiteral("subop")), true)
0191                     SKGTEST(QStringLiteral("SUBOPE:getComment"), subop_1.getComment(), QStringLiteral("subop"))
0192                     SKGTESTERROR(QStringLiteral("OPE:setFormula"), subop_1.setFormula(QStringLiteral("total*0.196")), true)
0193                     SKGTEST(QStringLiteral("SUBOPE:getFormula"), subop_1.getFormula(), QStringLiteral("total*0.196"))
0194                     SKGTESTERROR(QStringLiteral("SUBOPE:setQuantity"), subop_1.setQuantity(i * j), true)
0195                     SKGTESTERROR(QStringLiteral("SUBOPE:save"), subop_1.save(), true)
0196 
0197                     SKGTESTERROR(QStringLiteral("SUBOPE:load"), subop_1.load(), true)
0198                     SKGOperationObject opget;
0199                     SKGTESTERROR(QStringLiteral("SUBOPE:getParentOperation"), subop_1.getParentOperation(opget), true)
0200                     SKGTESTBOOL("OPE:comparison", (opget == op_1), true)
0201 
0202                     SKGSubOperationObject subop_12 = subop_1;
0203                     SKGSubOperationObject subop_13((SKGObjectBase(subop_1)));
0204                     SKGSubOperationObject subop_14 = SKGSubOperationObject(subop_1);
0205 
0206                     SKGObjectBase subop_base = subop_1;
0207                     SKGSubOperationObject subop_15;
0208                     subop_15 = subop_base;
0209                 }
0210 
0211                 // Checks
0212                 SKGTESTERROR(QStringLiteral("OPE:load"), op_1.load(), true)
0213                 SKGTEST(QStringLiteral("OPE:getCurrentAmount"), op_1.getCurrentAmount(), i * 15)
0214                 balance += i * 15;
0215                 SKGTEST(QStringLiteral("OPE:getNbSubOperations"), op_1.getNbSubOperations(), 5)
0216                 SKGTEST(QStringLiteral("OPE:getBalance"), op_1.getBalance(), balance)
0217             }
0218 
0219             SKGTESTERROR(QStringLiteral("ACCOUNT:load"), account.load(), true)
0220             SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), account.getCurrentAmount(), 55 * 15)
0221             SKGTEST(QStringLiteral("ACCOUNT:getAmount"), account.getAmount(QDate::currentDate()), 55 * 15)
0222 
0223             SKGUnitObject getUnit;
0224             SKGTESTERROR(QStringLiteral("ACCOUNT:getUnit"), account.getUnit(getUnit), true)
0225             SKGTESTBOOL("ACCOUNT:unit", (getUnit == unit_euro), true)
0226 
0227             SKGTESTERROR(QStringLiteral("OPE:load"), mainOperation.load(), true)
0228             SKGObjectBase::SKGListSKGObjectBase oGroupedOperations;
0229             SKGTESTERROR(QStringLiteral("OPE:getGroupedOperations"), mainOperation.getGroupedOperations(oGroupedOperations), true)
0230             SKGTEST(QStringLiteral("OPE:oGroupedOperations"), oGroupedOperations.size(), 2)  // Normal
0231             SKGTESTBOOL("OPE:isInGroup", mainOperation.isInGroup(), true)  // Normal
0232             SKGOperationObject mainOpe;
0233             SKGTESTERROR(QStringLiteral("OPE:getGroupedOperations"), mainOperation.getGroupOperation(mainOpe), true)
0234             SKGTESTBOOL("OPE:isImported", mainOperation.isImported(), false)
0235             SKGTESTBOOL("OPE:isTransfer", mainOperation.isTransfer(mainOpe), false)
0236 
0237             SKGTEST(QStringLiteral("OPE:getAmount"), mainOpe.getAmount(QDate::currentDate()), 135)
0238 
0239             SKGAccountObject acc;
0240             SKGTESTERROR(QStringLiteral("OPE:getParentAccount"), mainOperation.getParentAccount(acc), true)
0241             SKGTESTBOOL("OPE:account==acc", (account == acc), true)
0242             SKGTEST(QStringLiteral("OPE:getImportID"), mainOperation.getImportID(), QLatin1String(""))
0243 
0244             SKGObjectBase::SKGListSKGObjectBase oSubOperations;
0245             SKGTESTERROR(QStringLiteral("OPE:getSubOperations"), mainOperation.getSubOperations(oSubOperations), true)
0246             SKGTEST(QStringLiteral("OPE:oSubOperations"), oSubOperations.size(), 5)
0247 
0248             SKGTESTERROR(QStringLiteral("BANK:load"), bank.load(), true)
0249         }  // A commit is done here because the scope is close
0250 
0251         {
0252             // Scope of the transaction
0253             SKGBEGINTRANSACTION(document1, QStringLiteral("BANK_T2"), err)
0254 
0255             SKGTESTERROR(QStringLiteral("UNITVALUE:setQuantity"), unit_euro_val1.setQuantity(2.5), true)
0256             SKGTESTERROR(QStringLiteral("UNITVALUE:save"), unit_euro_val1.save(), true)
0257 
0258             SKGTESTERROR(QStringLiteral("ACCOUNT:load"), account.load(), true)
0259             SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), account.getCurrentAmount(), 55 * 15 * 2.5)
0260 
0261             SKGTESTERROR(QStringLiteral("BANK:load"), bank.load(), true)
0262             SKGTEST(QStringLiteral("BANK:getCurrentAmount"), bank.getCurrentAmount(), 55 * 15 * 2.5)
0263         }
0264 
0265         QFile(filename).remove();
0266         SKGTESTERROR(QStringLiteral("DOC:saveAs"), document1.saveAs(filename), true)
0267 
0268         {
0269             // Scope of the transaction
0270             SKGBEGINTRANSACTION(document1, QStringLiteral("BANK_T3"), err)
0271 
0272             // Test foreign key constrain
0273             SKGTESTERROR(QStringLiteral("UNIT:remove"), unit_euro.remove(), false)
0274         }
0275     }
0276 
0277     // ============================================================================
0278     {
0279         // Test bank document
0280         SKGDocumentBank document1;
0281         SKGTESTERROR(QStringLiteral("document1.load"), document1.load(filename), true)
0282 
0283         SKGAccountObject account;
0284         SKGTESTERROR(QStringLiteral("SKGAccountObject::getObjectByName"), SKGAccountObject::getObjectByName(&document1, QStringLiteral("v_account"), QStringLiteral("Courant steph"), account), true)
0285 
0286         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), account.getCurrentAmount(), 55 * 15 * 2.5)
0287 
0288         SKGBankObject bank;
0289         SKGTESTERROR(QStringLiteral("SKGBankObject::getObjectByName"), SKGBankObject::getObjectByName(&document1, QStringLiteral("v_bank"), QStringLiteral("CREDIT COOP"), bank), true)
0290 
0291         SKGTEST(QStringLiteral("BANK:getCurrentAmount"), bank.getCurrentAmount(), 55 * 15 * 2.5)
0292 
0293         SKGTESTERROR(QStringLiteral("BANK:undoRedoTransaction"), document1.undoRedoTransaction(), true)
0294 
0295         SKGTESTERROR(QStringLiteral("ACCOUNT:load"), account.load(), true)
0296         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), account.getCurrentAmount(), 55 * 15)
0297         SKGTESTERROR(QStringLiteral("BANK:load"), bank.load(), true)
0298         SKGTEST(QStringLiteral("BANK:getCurrentAmount"), bank.getCurrentAmount(), 55 * 15)
0299 
0300         // delete cascade
0301         SKGError err;
0302         {
0303             // Scope of the transaction
0304             SKGBEGINTRANSACTION(document1, QStringLiteral("BANK_T2"), err)
0305 
0306             SKGTESTERROR(QStringLiteral("BANK:delete"), bank.remove(), true)
0307         }
0308         QStringList oResult;
0309         SKGTESTERROR(QStringLiteral("BANK:getDistinctValues"), document1.getDistinctValues(QStringLiteral("bank"), QStringLiteral("id"), oResult), true)
0310         SKGTEST(QStringLiteral("BANK:oResult.size"), oResult.size(), 0)
0311         SKGTESTERROR(QStringLiteral("ACCOUNT:getDistinctValues"), document1.getDistinctValues(QStringLiteral("account"), QStringLiteral("id"), oResult), true)
0312         SKGTEST(QStringLiteral("ACCOUNT:oResult.size"), oResult.size(), 0)
0313         SKGTESTERROR(QStringLiteral("OPE:getDistinctValues"), document1.getDistinctValues(QStringLiteral("operation"), QStringLiteral("id"), oResult), true)
0314         SKGTEST(QStringLiteral("OPE:oResult.size"), oResult.size(), 0)
0315         SKGTESTERROR(QStringLiteral("SUBOPE:getDistinctValues"), document1.getDistinctValues(QStringLiteral("suboperation"), QStringLiteral("id"), oResult), true)
0316         SKGTEST(QStringLiteral("SUBOPE:oResult.size"), oResult.size(), 0)
0317 
0318         SKGTESTERROR(QStringLiteral("BANK:undoRedoTransaction"), document1.undoRedoTransaction(), true)
0319         SKGTESTERROR(QStringLiteral("BANK:undoRedoTransaction(SKGDocument::REDO)"), document1.undoRedoTransaction(SKGDocument::REDO), true)
0320 
0321 
0322         QFile(filename).remove();
0323     }
0324 
0325     // ============================================================================
0326     {
0327         // Test bank document
0328         SKGDocumentBank document1;
0329         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0330         SKGUnitValueObject unit_euro_val1;
0331         SKGBankObject bank(&document1);
0332         SKGUnitObject unit_euro(&document1);
0333         SKGAccountObject account1;
0334         SKGAccountObject account2;
0335         SKGError err;
0336         {
0337             // Scope of the transaction
0338             SKGBEGINTRANSACTION(document1, QStringLiteral("BANK_T1"), err)
0339 
0340             // Creation bank
0341             SKGTESTERROR(QStringLiteral("BANK:setName"), bank.setName(QStringLiteral("CREDIT COOP")), true)
0342             SKGTESTERROR(QStringLiteral("BANK:save"), bank.save(), true)
0343 
0344             // Creation account
0345             SKGTESTERROR(QStringLiteral("BANK:addAccount"), bank.addAccount(account1), true)
0346             SKGTESTERROR(QStringLiteral("ACCOUNT:setName"), account1.setName(QStringLiteral("Courant steph")), true)
0347             SKGTESTERROR(QStringLiteral("ACCOUNT:setType"), account1.setType(SKGAccountObject::CURRENT), true)
0348             SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account1.save(), true)
0349 
0350             SKGTESTERROR(QStringLiteral("BANK:addAccount"), bank.addAccount(account2), true)
0351             SKGTESTERROR(QStringLiteral("ACCOUNT:setName"), account2.setName(QStringLiteral("Loan")), true)
0352             SKGTESTERROR(QStringLiteral("ACCOUNT:setType"), account2.setType(SKGAccountObject::CURRENT), true)
0353             SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account2.save(), true)
0354 
0355             // Creation unit
0356             SKGTESTERROR(QStringLiteral("UNIT:setName"), unit_euro.setName(QStringLiteral("euro")), true)
0357             SKGTESTERROR(QStringLiteral("UNIT:save"), unit_euro.save(), true)
0358 
0359             // Creation unitvalue
0360             SKGTESTERROR(QStringLiteral("UNIT:addUnitValue"), unit_euro.addUnitValue(unit_euro_val1), true)
0361             SKGTESTERROR(QStringLiteral("UNITVALUE:setQuantity"), unit_euro_val1.setQuantity(1), true)
0362             SKGTESTERROR(QStringLiteral("UNITVALUE:setDate"), unit_euro_val1.setDate(now), true)
0363             SKGTESTERROR(QStringLiteral("UNITVALUE:save"), unit_euro_val1.save(), true)
0364 
0365             // Creation transactions
0366             SKGOperationObject op_1;
0367             SKGTESTERROR(QStringLiteral("ACCOUNT:addOperation"), account1.addOperation(op_1), true)
0368             SKGTESTERROR(QStringLiteral("OPE:setDate"), op_1.setDate(now), true)
0369             SKGTESTERROR(QStringLiteral("OPE:setUnit"), op_1.setUnit(unit_euro), true)
0370             SKGTESTERROR(QStringLiteral("OPE:setNumber"), op_1.setNumber(QStringLiteral("5490990004")), true)
0371             SKGTESTERROR(QStringLiteral("OPE:save"), op_1.save(), true)
0372             SKGTEST(QStringLiteral("OPE:getNumber"), op_1.getNumber(), QStringLiteral("5490990004"))
0373 
0374             SKGSubOperationObject subop_1;
0375             SKGTESTERROR(QStringLiteral("OPE:addSubOperation"), op_1.addSubOperation(subop_1), true)
0376             SKGTESTERROR(QStringLiteral("SUBOPE:setQuantity"), subop_1.setQuantity(10), true)
0377             SKGTESTERROR(QStringLiteral("SUBOPE:save"), subop_1.save(), true)
0378 
0379             SKGOperationObject op_2;
0380             SKGTESTERROR(QStringLiteral("ACCOUNT:addOperation"), account2.addOperation(op_2), true)
0381             SKGTESTERROR(QStringLiteral("OPE:setDate"), op_2.setDate(now), true)
0382             SKGTESTERROR(QStringLiteral("OPE:setUnit"), op_2.setUnit(unit_euro), true)
0383             SKGTESTERROR(QStringLiteral("OPE:save"), op_2.save(), true)
0384 
0385             SKGSubOperationObject subop_2;
0386             SKGTESTERROR(QStringLiteral("OPE:addSubOperation"), op_2.addSubOperation(subop_2), true)
0387             SKGTESTERROR(QStringLiteral("SUBOPE:setQuantity"), subop_2.setQuantity(-10), true)
0388             SKGTESTERROR(QStringLiteral("SUBOPE:save"), subop_2.save(), true)
0389 
0390 
0391             SKGTESTERROR(QStringLiteral("OPE:setGroupOperation"), op_1.setGroupOperation(op_2), true)
0392             SKGTESTERROR(QStringLiteral("OPE:setStatus"), op_1.setStatus(SKGOperationObject::MARKED), true)
0393             SKGTESTERROR(QStringLiteral("OPE:save"), op_1.save(), true)
0394 
0395             SKGOperationObject tmp;
0396             SKGOperationObject tmp2;
0397             SKGTESTBOOL("OPE:isTransfer", op_1.isTransfer(tmp), true)
0398             SKGTESTBOOL("OPE:isTransfer", tmp.isTransfer(tmp2), true)
0399             SKGTESTBOOL("OPE:equal", (tmp == op_2), true)
0400 
0401             SKGTESTERROR(QStringLiteral("ACCOUNT:setType"), account2.setType(SKGAccountObject::LOAN), true)
0402             SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account2.save(), true)
0403 
0404             SKGTESTERROR(QStringLiteral("OPE:load"), op_1.load(), true)
0405             SKGTESTBOOL("OPE:isTransfer", op_1.isTransfer(tmp), false)
0406             SKGTESTBOOL("OPE:isTransfer", tmp.isTransfer(tmp2), false)
0407             SKGTESTBOOL("OPE:equal", (tmp == op_2), true)
0408 
0409             SKGTESTERROR(QStringLiteral("OPE:mergeSuboperations"), op_1.mergeSuboperations(op_2), true)
0410 
0411             SKGTESTERROR(QStringLiteral("ACCOUNT:setLinkedAccount"), account1.setLinkedAccount(account2), true)
0412             SKGAccountObject account2_2;
0413             SKGTESTERROR(QStringLiteral("ACCOUNT:getLinkedAccount"), account1.getLinkedAccount(account2_2), true)
0414             SKGTESTBOOL("OPE:equal", (account2 == account2_2), true)
0415 
0416             SKGObjectBase::SKGListSKGObjectBase accounts;
0417             SKGTESTERROR(QStringLiteral("ACCOUNT:getLinkedByAccounts"), account2.getLinkedByAccounts(accounts), true)
0418 
0419             SKGTESTERROR(QStringLiteral("ACCOUNT:transferDeferredOperations"), account1.transferDeferredOperations(account2), true)
0420 
0421             // Creation template
0422             SKGOperationObject template1;
0423             SKGTESTERROR(QStringLiteral("ACCOUNT:addOperation"), account1.addOperation(template1), true)
0424             SKGTESTERROR(QStringLiteral("OPE:setDate"), template1.setDate(now.addDays(-5)), true)
0425             SKGTESTERROR(QStringLiteral("OPE:setUnit"), template1.setUnit(unit_euro), true)
0426             SKGTESTERROR(QStringLiteral("OPE:setComment"), template1.setComment(QStringLiteral("Comment op")), true)
0427             SKGTESTERROR(QStringLiteral("OPE:setTemplate"), template1.setTemplate(true), true)
0428             SKGTESTERROR(QStringLiteral("OPE:save"), template1.save(), true)
0429 
0430             SKGSubOperationObject template1_1;
0431             SKGTESTERROR(QStringLiteral("OPE:addSubOperation"), template1.addSubOperation(template1_1), true)
0432             SKGTESTERROR(QStringLiteral("SUBOPE:setDate"), template1_1.setDate(now.addDays(-4)), true)
0433             SKGTESTERROR(QStringLiteral("SUBOPE:setQuantity"), template1_1.setQuantity(10), true)
0434             SKGTESTERROR(QStringLiteral("SUBOPE:setComment"), template1.setComment(QStringLiteral("Comment sub op 1")), true)
0435             SKGTESTERROR(QStringLiteral("SUBOPE:save"), template1_1.save(), true)
0436 
0437             SKGSubOperationObject template1_2;
0438             SKGTESTERROR(QStringLiteral("OPE:addSubOperation"), template1.addSubOperation(template1_2), true)
0439             SKGTESTERROR(QStringLiteral("SUBOPE:setDate"), template1_2.setDate(now.addDays(-3)), true)
0440             SKGTESTERROR(QStringLiteral("SUBOPE:setQuantity"), template1_2.setQuantity(90), true)
0441             SKGTESTERROR(QStringLiteral("SUBOPE:setComment"), template1_2.setComment(QStringLiteral("Comment sub op 2")), true)
0442             SKGTESTERROR(QStringLiteral("SUBOPE:save"), template1_2.save(), true)
0443 
0444             // Creation op
0445             SKGOperationObject opbasic;
0446             SKGTESTERROR(QStringLiteral("ACCOUNT:addOperation"), account1.addOperation(opbasic), true)
0447             SKGTESTERROR(QStringLiteral("OPE:setDate"), opbasic.setDate(now), true)
0448             SKGTESTERROR(QStringLiteral("OPE:setUnit"), opbasic.setUnit(unit_euro), true)
0449             SKGTESTERROR(QStringLiteral("OPE:setComment"), opbasic.setComment(QStringLiteral("Comment op2")), true)
0450             SKGTESTERROR(QStringLiteral("OPE:save"), opbasic.save(), true)
0451 
0452             SKGSubOperationObject opbasic_1;
0453             SKGTESTERROR(QStringLiteral("OPE:addSubOperation"), opbasic.addSubOperation(opbasic_1), true)
0454             SKGTESTERROR(QStringLiteral("SUBOPE:setQuantity"), opbasic_1.setQuantity(200), true)
0455             SKGTESTERROR(QStringLiteral("SUBOPE:save"), opbasic_1.save(), true)
0456 
0457             document1.dump(DUMPOPERATION);
0458 
0459             SKGTESTERROR(QStringLiteral("SUBOPE:load"), template1.load(), true)
0460             SKGTEST(QStringLiteral("OPE:getCurrentAmount"), template1.getCurrentAmount(), 100)
0461             SKGTEST(QStringLiteral("OPE:getNbSubOperations"), template1.getNbSubOperations(), 2)
0462 
0463             SKGTESTERROR(QStringLiteral("SUBOPE:load"), opbasic.load(), true)
0464             SKGTEST(QStringLiteral("OPE:getCurrentAmount"), opbasic.getCurrentAmount(), 200)
0465             SKGTEST(QStringLiteral("OPE:getNbSubOperations"), opbasic.getNbSubOperations(), 1)
0466 
0467             // Apply the template
0468             SKGOperationObject op;
0469             SKGTESTERROR(QStringLiteral("OPE:duplicate"), template1.duplicate(op), true)
0470             SKGTESTERROR(QStringLiteral("OPE:load"), op.load(), true)
0471             SKGTEST(QStringLiteral("OPE:d_createdate"), static_cast<unsigned int>(op.getAttribute(QStringLiteral("d_createdate")) != QLatin1String("")), static_cast<unsigned int>(true))
0472 
0473             SKGTESTERROR(QStringLiteral("OPE:setProperty"), op.setProperty("a", "1"), true)
0474             SKGTESTERROR(QStringLiteral("OPE:setProperty"), opbasic.setProperty("a", "2"), true)
0475 
0476             SKGTESTERROR(QStringLiteral("OPE:mergeAttribute"), op.mergeAttribute(opbasic, SKGOperationObject::PROPORTIONAL), true)
0477             document1.dump(DUMPOPERATION);
0478 
0479             SKGTEST(QStringLiteral("OPE:getCurrentAmount"), template1.getCurrentAmount(), 100)
0480             SKGTEST(QStringLiteral("OPE:getNbSubOperations"), template1.getNbSubOperations(), 2)
0481 
0482             SKGTEST(QStringLiteral("OPE:getCurrentAmount"), op.getCurrentAmount(), 200)
0483             SKGTEST(QStringLiteral("OPE:getNbSubOperations"), op.getNbSubOperations(), 2)
0484         }
0485     }
0486 
0487     // End test
0488     SKGENDTEST()
0489 }