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 "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     {
0030         // Import
0031         SKGDocumentBank document1;
0032         SKGTESTERROR(QStringLiteral("document1.load()"), document1.load(SKGTest::getTestPath(QStringLiteral("IN")) % "skgtestbudget/budget.skg"), true)
0033         SKGError err;
0034         {
0035             // Scope of the transaction
0036             SKGBEGINTRANSACTION(document1, QStringLiteral("BUDGET_CREATION"), err)
0037 
0038             SKGTESTERROR(QStringLiteral("BUDGET.createAutomaticBudget"), SKGBudgetObject::createAutomaticBudget(&document1, 2010, 2010, true, true), true)
0039             SKGTESTERROR(QStringLiteral("BUDGET.balanceBudget"), SKGBudgetObject::balanceBudget(&document1, 2010), true)
0040         }
0041         {
0042             // Scope of the transaction
0043             SKGBEGINTRANSACTION(document1, QStringLiteral("BUDGETRULE_CREATION"), err)
0044 
0045             SKGBudgetRuleObject br(&document1);
0046 
0047             SKGTESTERROR(QStringLiteral("BUDGETRULE.enableYearCondition"), br.enableYearCondition(true), true)
0048             SKGTESTBOOL("BUDGETRULE.isYearConditionEnabled", br.isYearConditionEnabled(), true)
0049             SKGTESTERROR(QStringLiteral("BUDGETRULE.enableYearCondition"), br.enableYearCondition(false), true)
0050             SKGTESTBOOL("BUDGETRULE.isYearConditionEnabled", br.isYearConditionEnabled(), false)
0051             SKGTESTERROR(QStringLiteral("BUDGETRULE.setBudgetYear"), br.setBudgetYear(2010), true)
0052             SKGTEST(QStringLiteral("BUDGETRULE.getBudgetYear"), br.getBudgetYear(), 2010)
0053 
0054             SKGTESTERROR(QStringLiteral("BUDGETRULE.enableMonthCondition"), br.enableMonthCondition(true), true)
0055             SKGTESTBOOL("BUDGETRULE.isMonthConditionEnabled", br.isMonthConditionEnabled(), true)
0056             SKGTESTERROR(QStringLiteral("BUDGETRULE.enableMonthCondition"), br.enableMonthCondition(false), true)
0057             SKGTESTBOOL("BUDGETRULE.isMonthConditionEnabled", br.isMonthConditionEnabled(), false)
0058             SKGTESTERROR(QStringLiteral("BUDGETRULE.setBudgetMonth"), br.setBudgetMonth(10), true)
0059             SKGTEST(QStringLiteral("BUDGETRULE.getBudgetMonth"), br.getBudgetMonth(), 10)
0060 
0061             SKGTESTERROR(QStringLiteral("BUDGETRULE.setOrder"), br.setOrder(1.0), true)
0062             SKGTEST(QStringLiteral("BUDGETRULE.getOrder"), br.getOrder(), 1.0)
0063             SKGTESTERROR(QStringLiteral("BUDGETRULE.setOrder"), br.setOrder(-1), true)
0064             SKGTEST(QStringLiteral("BUDGETRULE.getOrder"), br.getOrder(), 1.0)
0065 
0066             SKGTESTERROR(QStringLiteral("BUDGETRULE.enableCategoryCondition"), br.enableCategoryCondition(true), true)
0067             SKGTESTBOOL("BUDGETRULE.isCategoryConditionEnabled", br.isCategoryConditionEnabled(), true)
0068             SKGCategoryObject cat;
0069             SKGTESTERROR(QStringLiteral("BUDGETRULE.enableCategoryChange"), br.enableCategoryChange(br.isCategoryChangeEnabled()), true)
0070             SKGTESTERROR(QStringLiteral("BUDGETRULE.getBudgetCategory"), br.getBudgetCategory(cat), false)
0071             SKGTESTERROR(QStringLiteral("BUDGETRULE.createPathCategory"), SKGCategoryObject::createPathCategory(&document1, QStringLiteral("category_55 > category_57"), cat), true)
0072             SKGTESTERROR(QStringLiteral("BUDGETRULE.removeBudgetCategory"), br.removeBudgetCategory(), true)
0073             SKGTESTERROR(QStringLiteral("BUDGETRULE.setBudgetCategory"), br.setBudgetCategory(cat), true)
0074 
0075 
0076             SKGTESTERROR(QStringLiteral("BUDGETRULE.setCondition"), br.setCondition(SKGBudgetRuleObject::NEGATIVE), true)
0077             SKGTEST(QStringLiteral("BUDGETRULE.getCondition"), static_cast<unsigned int>(br.getCondition()), static_cast<unsigned int>(SKGBudgetRuleObject::NEGATIVE))
0078             SKGTESTERROR(QStringLiteral("BUDGETRULE.setCondition"), br.setCondition(SKGBudgetRuleObject::POSITIVE), true)
0079             SKGTEST(QStringLiteral("BUDGETRULE.getCondition"), static_cast<unsigned int>(br.getCondition()), static_cast<unsigned int>(SKGBudgetRuleObject::POSITIVE))
0080             SKGTESTERROR(QStringLiteral("BUDGETRULE.setCondition"), br.setCondition(SKGBudgetRuleObject::ALL), true)
0081             SKGTEST(QStringLiteral("BUDGETRULE.getCondition"), static_cast<unsigned int>(br.getCondition()), static_cast<unsigned int>(SKGBudgetRuleObject::ALL))
0082 
0083             SKGTESTERROR(QStringLiteral("BUDGETRULE.setQuantity"), br.setQuantity(100, false), true)
0084             SKGTEST(QStringLiteral("BUDGETRULE.getQuantity"), br.getQuantity(), 100)
0085             SKGTESTBOOL("BUDGETRULE.isAbolute", br.isAbolute(), false)
0086 
0087             SKGTESTERROR(QStringLiteral("BUDGETRULE.setTransfer"), br.setTransfer(SKGBudgetRuleObject::CURRENT), true)
0088             SKGTEST(QStringLiteral("BUDGETRULE.getTransferMode"), static_cast<unsigned int>(br.getTransferMode()), static_cast<unsigned int>(SKGBudgetRuleObject::CURRENT))
0089             SKGTESTERROR(QStringLiteral("BUDGETRULE.setTransfer"), br.setTransfer(SKGBudgetRuleObject::NEXT), true)
0090             SKGTEST(QStringLiteral("BUDGETRULE.getTransferMode"), static_cast<unsigned int>(br.getTransferMode()), static_cast<unsigned int>(SKGBudgetRuleObject::NEXT))
0091 
0092             SKGTESTERROR(QStringLiteral("BUDGETRULE.save"), br.save(), true)
0093 
0094             SKGBudgetRuleObject br2 = br;
0095             SKGBudgetRuleObject br3(br);
0096             SKGBudgetRuleObject br4(static_cast<SKGObjectBase>(br));
0097             SKGBudgetRuleObject br5(SKGObjectBase(&document1, QStringLiteral("xxx"), br.getID()));
0098 
0099             SKGTESTERROR(QStringLiteral("BUDGETRULE.processAllRules"), SKGBudgetRuleObject::processAllRules(&document1), true)
0100 
0101             SKGTESTERROR(QStringLiteral("BUDGETRULE.setTransfer"), br.setTransfer(SKGBudgetRuleObject::YEAR), true)
0102             SKGTEST(QStringLiteral("BUDGETRULE.getTransferMode"), static_cast<unsigned int>(br.getTransferMode()), static_cast<unsigned int>(SKGBudgetRuleObject::YEAR))
0103             SKGTESTERROR(QStringLiteral("BUDGETRULE.save"), br.save(), true)
0104 
0105             SKGTESTERROR(QStringLiteral("BUDGETRULE.processAllRules"), SKGBudgetRuleObject::processAllRules(&document1), true)
0106         }
0107         SKGTESTERROR(QStringLiteral("document1.saveAs()"), document1.saveAs(SKGTest::getTestPath(QStringLiteral("OUT")) % "skgtestbudget/budget.skg", true), true)
0108     }
0109 
0110     // ============================================================================
0111     {
0112         // Import
0113         SKGDocumentBank document1;
0114         SKGTESTERROR(QStringLiteral("document1.load()"), document1.load(SKGTest::getTestPath(QStringLiteral("IN")) % "skgtestbudget/320323.skg"), true)
0115         SKGError err;
0116         {
0117             // Scope of the transaction
0118             SKGBEGINTRANSACTION(document1, QStringLiteral("BUDGET_PROCESS"), err)
0119 
0120             SKGTESTERROR(QStringLiteral("BUDGETRULE.processAllRules"), SKGBudgetRuleObject::processAllRules(&document1), true)
0121         }
0122         document1.dump(DUMPBUDGET);
0123         bool check = false;
0124         document1.existObjects(QStringLiteral("v_budget_display"), QStringLiteral("t_PERIOD='2013-02' AND t_CATEGORY='Alimentation' AND f_budgeted_modified=300"), check);
0125         SKGTESTBOOL("BUDGETRULE.Alimentation 2013-02 300", check, true)
0126 
0127         document1.existObjects(QStringLiteral("v_budget_display"), QStringLiteral("t_PERIOD='2013-02' AND t_CATEGORY='Loisirs' AND f_budgeted_modified=2100"), check);
0128         SKGTESTBOOL("BUDGETRULE.Loisirs 2013-02 2100", check, true)
0129 
0130         SKGObjectBase bo;
0131         SKGTESTERROR(QStringLiteral("document1.getObject()"), document1.getObject(QStringLiteral("v_budget_display"), QStringLiteral("t_PERIOD='2013-02' AND t_CATEGORY='Loisirs' AND f_budgeted_modified=2100"), bo), true)
0132         SKGBudgetObject b(bo);
0133         SKGTEST(QStringLiteral("BUDGET.getBudgetedAmount"), b.getBudgetedAmount(), 300)
0134         SKGCategoryObject cat;
0135         SKGTESTERROR(QStringLiteral("BUDGET.getCategory"), b.getCategory(cat), true)
0136         SKGTEST(QStringLiteral("BUDGET.getModificationReasons"), b.getModificationReasons().remove(','), QStringLiteral("Transfer of -1800 from ' 2013-01 2000.0' to 'Loisirs 2013-02 300.0' due to the rule 'All 100.0% Next Loisirs'"))
0137         SKGTESTERROR(QStringLiteral("BUDGET.removeCategory"), b.removeCategory(), true)
0138         SKGTESTERROR(QStringLiteral("BUDGET.enableSubCategoriesInclusion"), b.enableSubCategoriesInclusion(true), true)
0139         SKGTESTBOOL(QStringLiteral("BUDGET.isSubCategoriesInclusionEnabled"), b.isSubCategoriesInclusionEnabled(), true)
0140         SKGTESTERROR(QStringLiteral("BUDGET.enableSubCategoriesInclusion"), b.enableSubCategoriesInclusion(false), true)
0141         SKGTESTBOOL(QStringLiteral("BUDGET.isSubCategoriesInclusionEnabled"), b.isSubCategoriesInclusionEnabled(), false)
0142 
0143         SKGBudgetObject bu;
0144     }
0145 
0146     // End test
0147     SKGENDTEST()
0148 }