File indexing completed on 2024-05-19 16:18: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 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 interest 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 bank1 0038 SKGBankObject bank1(&document1); 0039 SKGTESTERROR(QStringLiteral("BANK:setName"), bank1.setName(QStringLiteral("CREDIT COOP")), true) 0040 SKGTESTERROR(QStringLiteral("BANK:save"), bank1.save(), true) 0041 0042 // Creation account1 0043 SKGAccountObject account1; 0044 SKGTESTERROR(QStringLiteral("BANK:addAccount"), bank1.addAccount(account1), true) 0045 SKGTESTERROR(QStringLiteral("ACCOUNT:setName"), account1.setName(QStringLiteral("Livre A")), true) 0046 SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account1.save(), true) 0047 0048 // Add interest parameters 0049 SKGInterestObject interest1; 0050 SKGTESTERROR(QStringLiteral("ACCOUNT:addInterest"), account1.addInterest(interest1), true) 0051 SKGTESTERROR(QStringLiteral("INTEREST:setDate"), interest1.setDate(QDate::currentDate()), true) 0052 SKGTESTERROR(QStringLiteral("INTEREST:setRate"), interest1.setRate(1.25), true) 0053 SKGTESTERROR(QStringLiteral("INTEREST:setIncomeValueDateMode"), interest1.setIncomeValueDateMode(SKGInterestObject::J1), true) 0054 SKGTESTERROR(QStringLiteral("INTEREST:setExpenditueValueDateMode"), interest1.setExpenditueValueDateMode(SKGInterestObject::J2), true) 0055 SKGTESTERROR(QStringLiteral("INTEREST:setInterestComputationMode"), interest1.setInterestComputationMode(SKGInterestObject::DAYS360), true) 0056 0057 SKGTEST(QStringLiteral("INTEREST:getRate"), interest1.getRate(), 1.25) 0058 SKGTEST(QStringLiteral("INTEREST:getIncomeValueDateMode"), static_cast<unsigned int>(interest1.getIncomeValueDateMode()), static_cast<unsigned int>(SKGInterestObject::J1)) 0059 SKGTEST(QStringLiteral("INTEREST:getExpenditueValueDateMode"), static_cast<unsigned int>(interest1.getExpenditueValueDateMode()), static_cast<unsigned int>(SKGInterestObject::J2)) 0060 SKGTEST(QStringLiteral("INTEREST:getInterestComputationMode"), static_cast<unsigned int>(interest1.getInterestComputationMode()), static_cast<unsigned int>(SKGInterestObject::DAYS360)) 0061 SKGTESTERROR(QStringLiteral("INTEREST:save"), interest1.save(), true) 0062 0063 0064 SKGInterestObject interest11(static_cast<SKGObjectBase>(interest1)); 0065 SKGInterestObject interest12 = interest1; 0066 SKGInterestObject interest13(SKGObjectBase(&document1, QStringLiteral("xxx"), interest1.getID())); 0067 SKGInterestObject interest14; 0068 interest14 = static_cast<SKGObjectBase>(interest1); 0069 } 0070 0071 // Test interest computation 0072 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) { 0073 QDate firstday = QDate::currentDate(); 0074 firstday = firstday.addMonths(1 - firstday.month()); 0075 firstday = firstday.addDays(1 - firstday.day()); 0076 0077 // Scope of the transaction 0078 SKGBEGINTRANSACTION(document1, QStringLiteral("BANK_T1"), err) 0079 0080 // Creation bank1 0081 SKGBankObject bank1(&document1); 0082 SKGTESTERROR(QStringLiteral("BANK:setName"), bank1.setName(QStringLiteral("CREDIT COOP")), true) 0083 SKGTESTERROR(QStringLiteral("BANK:save"), bank1.save(), true) 0084 0085 // Creation account1 0086 SKGAccountObject account1; 0087 SKGTESTERROR(QStringLiteral("BANK:addAccount"), bank1.addAccount(account1), true) 0088 SKGTESTERROR(QStringLiteral("ACCOUNT:setName"), account1.setName(QStringLiteral("Livre A")), true) 0089 SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account1.save(), true) 0090 0091 // Creation unit 0092 SKGUnitObject unit_euro(&document1); 0093 SKGTESTERROR(QStringLiteral("UNIT:setName"), unit_euro.setName(QStringLiteral("euro")), true) 0094 SKGTESTERROR(QStringLiteral("UNIT:save"), unit_euro.save(), true) 0095 0096 // Creation unitvalue 0097 SKGUnitValueObject unit_euro_val1; 0098 SKGTESTERROR(QStringLiteral("UNIT:addUnitValue"), unit_euro.addUnitValue(unit_euro_val1), true) 0099 SKGTESTERROR(QStringLiteral("UNITVALUE:setQuantity"), unit_euro_val1.setQuantity(1), true) 0100 SKGTESTERROR(QStringLiteral("UNITVALUE:setDate"), unit_euro_val1.setDate(firstday), true) 0101 SKGTESTERROR(QStringLiteral("UNITVALUE:save"), unit_euro_val1.save(), true) 0102 0103 // Add interest parameters 0104 SKGInterestObject interest1; 0105 SKGTESTERROR(QStringLiteral("ACCOUNT:addInterest"), account1.addInterest(interest1), true) 0106 SKGTESTERROR(QStringLiteral("INTEREST:setDate"), interest1.setDate(firstday.addDays(-10)), true) 0107 SKGTESTERROR(QStringLiteral("INTEREST:setRate"), interest1.setRate(4), true) 0108 SKGTESTERROR(QStringLiteral("INTEREST:save"), interest1.save(), true) 0109 0110 SKGInterestObject interest2; 0111 SKGTESTERROR(QStringLiteral("ACCOUNT:addInterest"), account1.addInterest(interest2), true) 0112 SKGTESTERROR(QStringLiteral("INTEREST:setDate"), interest2.setDate(firstday.addMonths(1)), true) 0113 SKGTESTERROR(QStringLiteral("INTEREST:setRate"), interest2.setRate(2.5), true) 0114 SKGTESTERROR(QStringLiteral("INTEREST:save"), interest2.save(), true) 0115 0116 SKGInterestObject interest3; 0117 SKGTESTERROR(QStringLiteral("ACCOUNT:addInterest"), account1.addInterest(interest3), true) 0118 SKGTESTERROR(QStringLiteral("INTEREST:setDate"), interest3.setDate(firstday.addMonths(4)), true) 0119 SKGTESTERROR(QStringLiteral("INTEREST:setRate"), interest3.setRate(1.75), true) 0120 SKGTESTERROR(QStringLiteral("INTEREST:save"), interest3.save(), true) 0121 0122 // Add transactions 0123 { 0124 SKGOperationObject op_1; 0125 SKGTESTERROR(QStringLiteral("ACCOUNT:addOperation"), account1.addOperation(op_1), true) 0126 SKGTESTERROR(QStringLiteral("OPE:setDate"), op_1.setDate(firstday.addDays(-1)), true) 0127 SKGTESTERROR(QStringLiteral("OPE:setUnit"), op_1.setUnit(unit_euro), true) 0128 SKGTESTERROR(QStringLiteral("OPE:save"), op_1.save(), true) 0129 SKGSubOperationObject subop_1; 0130 SKGTESTERROR(QStringLiteral("OPE:addSubOperation"), op_1.addSubOperation(subop_1), true) 0131 SKGTESTERROR(QStringLiteral("SUBOPE:setQuantity"), subop_1.setQuantity(100), true) 0132 SKGTESTERROR(QStringLiteral("SUBOPE:save"), subop_1.save(), true) 0133 } 0134 { 0135 SKGOperationObject op_1; 0136 SKGTESTERROR(QStringLiteral("ACCOUNT:addOperation"), account1.addOperation(op_1), true) 0137 SKGTESTERROR(QStringLiteral("OPE:setDate"), op_1.setDate(firstday.addDays(14)), true) 0138 SKGTESTERROR(QStringLiteral("OPE:setUnit"), op_1.setUnit(unit_euro), true) 0139 SKGTESTERROR(QStringLiteral("OPE:save"), op_1.save(), true) 0140 SKGSubOperationObject subop_1; 0141 SKGTESTERROR(QStringLiteral("OPE:addSubOperation"), op_1.addSubOperation(subop_1), true) 0142 SKGTESTERROR(QStringLiteral("SUBOPE:setQuantity"), subop_1.setQuantity(100), true) 0143 SKGTESTERROR(QStringLiteral("SUBOPE:save"), subop_1.save(), true) 0144 } 0145 { 0146 SKGOperationObject op_1; 0147 SKGTESTERROR(QStringLiteral("ACCOUNT:addOperation"), account1.addOperation(op_1), true) 0148 SKGTESTERROR(QStringLiteral("OPE:setDate"), op_1.setDate(firstday.addMonths(5).addDays(28)), true) 0149 SKGTESTERROR(QStringLiteral("OPE:setUnit"), op_1.setUnit(unit_euro), true) 0150 SKGTESTERROR(QStringLiteral("OPE:save"), op_1.save(), true) 0151 SKGSubOperationObject subop_1; 0152 SKGTESTERROR(QStringLiteral("OPE:addSubOperation"), op_1.addSubOperation(subop_1), true) 0153 SKGTESTERROR(QStringLiteral("SUBOPE:setQuantity"), subop_1.setQuantity(-100), true) 0154 SKGTESTERROR(QStringLiteral("SUBOPE:save"), subop_1.save(), true) 0155 } 0156 0157 SKGAccountObject::SKGInterestItemList oInterestList; 0158 double oInterests = 0; 0159 SKGTESTERROR(QStringLiteral("ACCOUNT:getInterestItems"), account1.getInterestItems(oInterestList, oInterests), true) 0160 0161 int nb = oInterestList.count(); 0162 for (int i = 0; i < nb; ++i) { 0163 SKGAccountObject::SKGInterestItem item = oInterestList.at(i); 0164 SKGTRACE << "[" << item.object.getDisplayName() << "]: " 0165 << SKGServices::dateToSqlString(item.date) 0166 << " " << SKGServices::dateToSqlString(item.valueDate) 0167 << " " << item.amount 0168 << " " << item.coef 0169 << " " << item.rate 0170 << " " << item.annualInterest 0171 << " " << item.accruedInterest 0172 << SKGENDL; 0173 } 0174 SKGTEST(QStringLiteral("INTEREST:oInterestList.count"), oInterestList.count(), 5) 0175 SKGTESTBOOL("INTEREST:oInterestList.at(1).date", (oInterestList.at(0).date == firstday), true) 0176 SKGTESTBOOL("INTEREST:oInterestList.at(2).date", (oInterestList.at(1).date == firstday.addDays(14)), true) 0177 SKGTESTBOOL("INTEREST:oInterestList.at(3).date", (oInterestList.at(2).date == firstday.addMonths(1)), true) 0178 SKGTESTBOOL("INTEREST:oInterestList.at(6).date", (oInterestList.at(3).date == firstday.addMonths(4)), true) 0179 SKGTESTBOOL("INTEREST:oInterestList.at(7).date", (oInterestList.at(4).date == firstday.addMonths(5).addDays(28)), true) 0180 SKGTEST(QStringLiteral("INTEREST:oInterests"), SKGServices::doubleToString(oInterests), QStringLiteral("3.135416667")) 0181 } 0182 } 0183 0184 // End test 0185 SKGENDTEST() 0186 }