File indexing completed on 2024-11-17 04:39:06
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 0014 /** 0015 * The main function of the unit test 0016 * @param argc the number of arguments 0017 * @param argv the list of arguments 0018 */ 0019 int main(int argc, char** argv) 0020 { 0021 Q_UNUSED(argc) 0022 Q_UNUSED(argv) 0023 0024 // Init test 0025 SKGINITTEST(true) 0026 // ============================================================================ 0027 // Init 0028 { 0029 // Test bank1 document 0030 SKGDocumentBank document1; 0031 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0032 SKGError err; 0033 { 0034 // Scope of the transaction 0035 SKGBEGINTRANSACTION(document1, QStringLiteral("BANK_T1"), err) 0036 0037 // Creation unit 0038 SKGUnitObject unit_euro(&document1); 0039 SKGTESTERROR(QStringLiteral("BANK:setName"), unit_euro.setName(QStringLiteral("euro")), true) 0040 SKGTESTERROR(QStringLiteral("BANK:setSymbol"), unit_euro.setSymbol(QStringLiteral("euro")), true) 0041 SKGTESTERROR(QStringLiteral("BANK:save"), unit_euro.save(), true) 0042 0043 // Creation unitvalue 0044 SKGUnitValueObject unit_euro_val1; 0045 SKGTESTERROR(QStringLiteral("BANK:addUnitValue"), unit_euro.addUnitValue(unit_euro_val1), true) 0046 SKGTESTERROR(QStringLiteral("BANK:setQuantity"), unit_euro_val1.setQuantity(1), true) 0047 SKGTESTERROR(QStringLiteral("BANK:setDate"), unit_euro_val1.setDate(QDate::currentDate()), true) 0048 SKGTESTERROR(QStringLiteral("BANK:save"), unit_euro_val1.save(), true) 0049 0050 // Creation bank1 0051 SKGBankObject bank1(&document1); 0052 SKGAccountObject account1; 0053 SKGTESTERROR(QStringLiteral("BANK:addAccount"), bank1.addAccount(account1), false) 0054 0055 SKGTESTERROR(QStringLiteral("BANK:setName"), bank1.setName(QStringLiteral("CREDIT COOP")), true) 0056 SKGTESTERROR(QStringLiteral("BANK:setIcon"), bank1.setIcon(QStringLiteral("credit cooperatif")), true) 0057 SKGTESTERROR(QStringLiteral("BANK:setNumber"), bank1.setNumber(QStringLiteral("111111")), true) 0058 SKGTESTERROR(QStringLiteral("BANK:save"), bank1.save(), true) 0059 SKGTEST(QStringLiteral("BANK:getIcon"), bank1.getIcon(), QStringLiteral("credit cooperatif")) 0060 SKGTEST(QStringLiteral("BANK:getNumber"), bank1.getNumber(), QStringLiteral("111111")) 0061 0062 SKGBankObject bank11(bank1); // For coverage 0063 SKGTESTBOOL("BANK:comparison", (bank11 == bank1), true) 0064 SKGBankObject bank12 = bank1; // For coverage 0065 SKGTESTBOOL("BANK:comparison", (bank12 == bank1), true) 0066 SKGBankObject bank13((SKGNamedObject(bank1))); // For coverage 0067 SKGTESTBOOL("BANK:comparison", (bank12 == SKGNamedObject(bank1)), true) 0068 SKGNamedObject bank1n(bank1); 0069 SKGBankObject bank14(bank1n); // For coverage 0070 0071 SKGBankObject bank15(SKGObjectBase(bank1.getDocument(), QStringLiteral("xxx"), bank1.getID())); // For coverage 0072 SKGBankObject bank16(SKGNamedObject(bank1.getDocument(), QStringLiteral("xxx"), bank1.getID())); // For coverage 0073 0074 // Creation account1 0075 SKGTESTERROR(QStringLiteral("BANK:addAccount"), bank1.addAccount(account1), true) 0076 0077 SKGOperationObject op; 0078 SKGTESTERROR(QStringLiteral("ACCOUNT:addOperation"), account1.addOperation(op), false) 0079 0080 SKGInterestObject it; 0081 SKGTESTERROR(QStringLiteral("ACCOUNT:addOperation"), account1.addInterest(it), false) 0082 0083 SKGTESTERROR(QStringLiteral("ACCOUNT:setName"), account1.setName(QStringLiteral("Courant steph")), true) 0084 SKGTESTERROR(QStringLiteral("ACCOUNT:setNumber"), account1.setNumber(QStringLiteral("12345P")), true) 0085 SKGTESTERROR(QStringLiteral("ACCOUNT:setAgencyNumber"), account1.setAgencyNumber(QStringLiteral("99999")), true) 0086 SKGTESTERROR(QStringLiteral("ACCOUNT:setAgencyAddress"), account1.setAgencyAddress(QStringLiteral("10 rue Albert CAMUS\n31000 TOULOUSE")), true) 0087 SKGTESTERROR(QStringLiteral("ACCOUNT:setType"), account1.setType(SKGAccountObject::CURRENT), true) 0088 SKGTESTERROR(QStringLiteral("ACCOUNT:setComment"), account1.setComment(QStringLiteral("bla bla")), true) 0089 SKGTESTERROR(QStringLiteral("ACCOUNT:setMaxLimitAmount"), account1.setMaxLimitAmount(15000.0), true) 0090 SKGTESTERROR(QStringLiteral("ACCOUNT:setMinLimitAmount"), account1.setMinLimitAmount(-500.0), true) 0091 SKGTESTERROR(QStringLiteral("ACCOUNT:maxLimitAmountEnabled"), account1.maxLimitAmountEnabled(true), true) 0092 SKGTESTERROR(QStringLiteral("ACCOUNT:minLimitAmountEnabled"), account1.minLimitAmountEnabled(false), true) 0093 SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account1.save(), true) 0094 SKGTEST(QStringLiteral("ACCOUNT:getNumber"), account1.getNumber(), QStringLiteral("12345P")) 0095 SKGTEST(QStringLiteral("ACCOUNT:getAgencyNumber"), account1.getAgencyNumber(), QStringLiteral("99999")) 0096 SKGTEST(QStringLiteral("ACCOUNT:getAgencyAddress"), account1.getAgencyAddress(), QStringLiteral("10 rue Albert CAMUS\n31000 TOULOUSE")) 0097 SKGTEST(QStringLiteral("ACCOUNT:getMaxLimitAmount"), account1.getMaxLimitAmount(), 15000.0) 0098 SKGTEST(QStringLiteral("ACCOUNT:getMinLimitAmount"), account1.getMinLimitAmount(), -500.0) 0099 0100 SKGTESTERROR(QStringLiteral("ACCOUNT:setMaxLimitAmount"), account1.setMaxLimitAmount(-1000.0), true) 0101 SKGTEST(QStringLiteral("ACCOUNT:getMaxLimitAmount"), account1.getMaxLimitAmount(), -1000.0) 0102 SKGTEST(QStringLiteral("ACCOUNT:getMinLimitAmount"), account1.getMinLimitAmount(), -1000.0) 0103 0104 SKGTESTBOOL("ACCOUNT:isMaxLimitAmountEnabled", account1.isMaxLimitAmountEnabled(), true) 0105 SKGTESTBOOL("ACCOUNT:isMinLimitAmountEnabled", account1.isMinLimitAmountEnabled(), false) 0106 0107 SKGTEST(QStringLiteral("ACCOUNT:getType"), static_cast<unsigned int>(account1.getType()), static_cast<unsigned int>(SKGAccountObject::CURRENT)) 0108 0109 SKGTESTERROR(QStringLiteral("ACCOUNT:setType"), account1.setType(SKGAccountObject::CREDITCARD), true) 0110 SKGTEST(QStringLiteral("ACCOUNT:getType"), static_cast<unsigned int>(account1.getType()), static_cast<unsigned int>(SKGAccountObject::CREDITCARD)) 0111 0112 SKGTESTERROR(QStringLiteral("ACCOUNT:setType"), account1.setType(SKGAccountObject::ASSETS), true) 0113 SKGTEST(QStringLiteral("ACCOUNT:getType"), static_cast<unsigned int>(account1.getType()), static_cast<unsigned int>(SKGAccountObject::ASSETS)) 0114 0115 SKGTESTERROR(QStringLiteral("ACCOUNT:setType"), account1.setType(SKGAccountObject::INVESTMENT), true) 0116 SKGTEST(QStringLiteral("ACCOUNT:getType"), static_cast<unsigned int>(account1.getType()), static_cast<unsigned int>(SKGAccountObject::INVESTMENT)) 0117 0118 SKGTESTERROR(QStringLiteral("ACCOUNT:setType"), account1.setType(SKGAccountObject::WALLET), true) 0119 SKGTEST(QStringLiteral("ACCOUNT:getType"), static_cast<unsigned int>(account1.getType()), static_cast<unsigned int>(SKGAccountObject::WALLET)) 0120 0121 SKGTESTERROR(QStringLiteral("ACCOUNT:setType"), account1.setType(SKGAccountObject::LOAN), true) 0122 SKGTEST(QStringLiteral("ACCOUNT:getType"), static_cast<unsigned int>(account1.getType()), static_cast<unsigned int>(SKGAccountObject::LOAN)) 0123 0124 SKGTESTERROR(QStringLiteral("ACCOUNT:setType"), account1.setType(SKGAccountObject::SAVING), true) 0125 SKGTEST(QStringLiteral("ACCOUNT:getType"), static_cast<unsigned int>(account1.getType()), static_cast<unsigned int>(SKGAccountObject::SAVING)) 0126 0127 SKGTESTERROR(QStringLiteral("ACCOUNT:setType"), account1.setType(SKGAccountObject::OTHER), true) 0128 SKGTEST(QStringLiteral("ACCOUNT:getType"), static_cast<unsigned int>(account1.getType()), static_cast<unsigned int>(SKGAccountObject::OTHER)) 0129 0130 SKGTESTERROR(QStringLiteral("ACCOUNT:setType"), account1.setType(SKGAccountObject::PENSION), true) 0131 SKGTEST(QStringLiteral("ACCOUNT:getType"), static_cast<unsigned int>(account1.getType()), static_cast<unsigned int>(SKGAccountObject::PENSION)) 0132 0133 SKGTEST(QStringLiteral("ACCOUNT:getComment"), account1.getComment(), QStringLiteral("bla bla")) 0134 0135 QDate n = QDate::currentDate(); 0136 SKGTESTERROR(QStringLiteral("ACCOUNT:setReconciliationDate"), account1.setReconciliationDate(n), true) 0137 SKGTEST(QStringLiteral("ACCOUNT:getReconciliationDate"), SKGServices::dateToSqlString(account1.getReconciliationDate()), SKGServices::dateToSqlString(n)) 0138 SKGTESTERROR(QStringLiteral("ACCOUNT:setReconciliationBalance"), account1.setReconciliationBalance(125), true) 0139 SKGTEST(QStringLiteral("ACCOUNT:getReconciliationBalance"), SKGServices::doubleToString(account1.getReconciliationBalance()), SKGServices::doubleToString(125)) 0140 0141 SKGTESTERROR(QStringLiteral("ACCOUNT:setInitialBalance"), account1.setInitialBalance(125, unit_euro), true) 0142 double init = 0; 0143 SKGUnitObject unit; 0144 SKGTESTERROR(QStringLiteral("ACCOUNT:getInitialBalance"), account1.getInitialBalance(init, unit), true) 0145 SKGTESTBOOL("ACCOUNT:getInitialBalance", (unit == unit_euro), true) 0146 SKGTEST(QStringLiteral("ACCOUNT:getInitialBalance"), init, 125) 0147 0148 SKGAccountObject account11(account1); // For coverage 0149 SKGTESTBOOL("BANK:comparison", (account11 == account1), true) 0150 SKGAccountObject account12(static_cast<SKGNamedObject>(account1)); // For coverage 0151 SKGTESTBOOL("BANK:comparison", (account12 == account1), true) 0152 SKGAccountObject account13(static_cast<SKGObjectBase>(account1)); // For coverage 0153 SKGTESTBOOL("BANK:comparison", (account13 == account1), true) 0154 0155 SKGAccountObject account14(SKGObjectBase(account1.getDocument(), QStringLiteral("xxx"), account1.getID())); // For coverage 0156 SKGAccountObject account15(SKGNamedObject(account1.getDocument(), QStringLiteral("xxx"), account1.getID())); // For coverage 0157 0158 // Creation bank2 0159 SKGBankObject bank2(&document1); 0160 SKGTESTERROR(QStringLiteral("BANK:setName"), bank2.setName(QStringLiteral("NEF")), true) 0161 SKGTESTERROR(QStringLiteral("BANK:save"), bank2.save(), true) 0162 0163 // Creation account2 0164 SKGAccountObject account2; 0165 SKGTESTERROR(QStringLiteral("BANK:addAccount"), bank2.addAccount(account2), true) 0166 SKGTESTERROR(QStringLiteral("ACCOUNT:setName"), account2.setName(QStringLiteral("Courant steph")), true) 0167 SKGTESTERROR(QStringLiteral("ACCOUNT:setNumber"), account2.setNumber(QStringLiteral("98765A")), true) 0168 SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account2.save(false), false) 0169 0170 SKGAccountObject account3; 0171 SKGTESTERROR(QStringLiteral("BANK:addAccount"), bank2.addAccount(account3), true) 0172 SKGTESTERROR(QStringLiteral("ACCOUNT:setName"), account3.setName(QStringLiteral("Courant vero")), true) 0173 SKGTESTERROR(QStringLiteral("ACCOUNT:setNumber"), account3.setNumber(QStringLiteral("98765A")), true) 0174 SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account3.save(), true) 0175 0176 QStringList oResult; 0177 SKGTESTERROR(QStringLiteral("BANK:getDistinctValues"), document1.getDistinctValues(QStringLiteral("bank"), QStringLiteral("t_name"), oResult), true) 0178 SKGTEST(QStringLiteral("BANK:oResult.size"), oResult.size(), 2) 0179 0180 SKGTESTERROR(QStringLiteral("BANK:getDistinctValues"), document1.getDistinctValues(QStringLiteral("account"), QStringLiteral("t_name"), oResult), true) 0181 SKGTEST(QStringLiteral("BANK:oResult.size"), oResult.size(), 2) 0182 0183 SKGObjectBase::SKGListSKGObjectBase oAccountList; 0184 SKGTESTERROR(QStringLiteral("BANK:getAccounts"), bank1.getAccounts(oAccountList), true) 0185 SKGTEST(QStringLiteral("ACCOUNT:count"), oAccountList.count(), 1) 0186 0187 SKGTESTERROR(QStringLiteral("BANK:getAccounts"), bank2.getAccounts(oAccountList), true) 0188 SKGTEST(QStringLiteral("ACCOUNT:count"), oAccountList.count(), 1) 0189 0190 // Modification account1 0191 SKGBankObject tmpBank; 0192 SKGTESTERROR(QStringLiteral("ACCOUNT:getBank"), account3.getBank(tmpBank), true) 0193 SKGTESTBOOL("BANK:tmpBank==bank2", (tmpBank == bank2), true) 0194 SKGTESTERROR(QStringLiteral("ACCOUNT:setBank"), account3.setBank(bank1), true) 0195 SKGTESTERROR(QStringLiteral("ACCOUNT:getBank"), account3.getBank(tmpBank), true) 0196 SKGTESTBOOL("BANK:tmpBank==bank2", (tmpBank == bank1), true) 0197 SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account3.save(), true) 0198 0199 SKGTESTERROR(QStringLiteral("BANK:getAccounts"), bank1.getAccounts(oAccountList), true) 0200 SKGTEST(QStringLiteral("ACCOUNT:count"), oAccountList.count(), 2) 0201 0202 SKGTESTERROR(QStringLiteral("BANK:getAccounts"), bank2.getAccounts(oAccountList), true) 0203 SKGTEST(QStringLiteral("ACCOUNT:count"), oAccountList.count(), 0) 0204 0205 SKGTESTBOOL("ACCOUNT:isBookmarked", account3.isBookmarked(), false) 0206 SKGTESTERROR(QStringLiteral("ACCOUNT:bookmark"), account3.bookmark(true), true) 0207 SKGTESTBOOL("ACCOUNT:isBookmarked", account3.isBookmarked(), true) 0208 0209 SKGTESTBOOL("ACCOUNT:isClosed", account3.isClosed(), false) 0210 SKGTESTERROR(QStringLiteral("ACCOUNT:setClosed"), account3.setClosed(true), true) 0211 SKGTESTBOOL("ACCOUNT:isClosed", account3.isClosed(), true) 0212 0213 SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account3.save(), true) 0214 0215 // Merge 0216 SKGTESTERROR(QStringLiteral("ACCOUNT:merge"), account2.merge(account3, true), true) 0217 0218 // interest 0219 SKGObjectBase::SKGListSKGObjectBase oInterestList; 0220 SKGTESTERROR(QStringLiteral("ACCOUNT:getInterests"), account2.getInterests(oInterestList), true) 0221 0222 SKGInterestObject oInterest; 0223 SKGTESTERROR(QStringLiteral("ACCOUNT:getInterests"), account2.getInterest(QDate::currentDate(), oInterest), false) 0224 0225 SKGObjectBase account4(&document1, QStringLiteral("account"), account1.getID()); 0226 SKGTESTERROR(QStringLiteral("ACCOUNT:load"), account4.load(), true) 0227 SKGTESTERROR(QStringLiteral("ACCOUNT:setAttribute"), account4.setAttribute(QStringLiteral("t_BANK"), QStringLiteral("bankname")), true) 0228 SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account4.save(), true) 0229 SKGTESTERROR(QStringLiteral("BANK:load"), bank1.load(), true) 0230 SKGTEST(QStringLiteral("BANK:getName"), bank1.getName(), QStringLiteral("bankname")) 0231 0232 SKGTESTERROR(QStringLiteral("DOC:dump"), document1.dump(DUMPACCOUNT), true) 0233 } 0234 } 0235 0236 // End test 0237 SKGENDTEST() 0238 }