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

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 
0012 #include <qdesktopservices.h>
0013 
0014 #include "skgbankincludes.h"
0015 #include "skgtestmacro.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     {
0031         QStringList sources = SKGUnitObject::downloadSources();
0032         SKGTESTBOOL("UNIT:downloadSources", (sources.count() >= 4), true)
0033         for (const QString& source : qAsConst(sources)) {
0034             SKGUnitObject::getCommentFromSource(source);
0035         }
0036 
0037         // Test unit et unitvalue
0038         SKGDocumentBank document1;
0039         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0040         SKGError err;
0041         SKGTEST(QStringLiteral("UNIT:getNbTransaction"), document1.getNbTransaction(), 0)
0042         // Scope of the transaction
0043         SKGBEGINTRANSACTION(document1, QStringLiteral("BANK_T1"), err)
0044 
0045         // Create unit
0046         SKGUnitObject unit1(&document1);
0047         SKGTESTERROR(QStringLiteral("UNIT:setName"), unit1.setName(QStringLiteral("UNIT1")), true)
0048         SKGTESTERROR(QStringLiteral("UNIT:setSymbol"), unit1.setSymbol(QStringLiteral("F")), true)
0049         SKGTEST(QStringLiteral("UNIT:getSymbol"), unit1.getSymbol(), QStringLiteral("F"))
0050         SKGTESTERROR(QStringLiteral("UNIT:setCountry"), unit1.setCountry(QStringLiteral("France")), true)
0051         SKGTEST(QStringLiteral("UNIT:getSymbol"), unit1.getCountry(), QStringLiteral("France"))
0052         SKGTESTERROR(QStringLiteral("UNIT:setInternetCode"), unit1.setInternetCode(QStringLiteral("code Internet")), true)
0053         SKGTEST(QStringLiteral("UNIT:getInternetCode"), unit1.getInternetCode(), QStringLiteral("code Internet"))
0054         SKGTESTERROR(QStringLiteral("UNIT:setType"), unit1.setType(SKGUnitObject::OBJECT), true)
0055         SKGTEST(QStringLiteral("UNIT:getType"), static_cast<unsigned int>(unit1.getType()), static_cast<unsigned int>(SKGUnitObject::OBJECT))
0056         SKGTESTERROR(QStringLiteral("UNIT:setNumberDecimal"), unit1.setNumberDecimal(4), true)
0057         SKGTEST(QStringLiteral("UNIT:getNumberDecimal"), unit1.getNumberDecimal(), 4)
0058 
0059         SKGUnitValueObject unitvalue1;
0060         SKGTESTERROR(QStringLiteral("UNIT:addUnitValue"), unit1.addUnitValue(unitvalue1), false)
0061 
0062         SKGTESTERROR(QStringLiteral("UNIT:save"), unit1.save(), true)
0063 
0064         // Create unit value
0065         SKGTESTERROR(QStringLiteral("UNIT:addUnitValue"), unit1.addUnitValue(unitvalue1), true)
0066 
0067         SKGTESTERROR(QStringLiteral("UNITVALUE:setQuantity"), unitvalue1.setQuantity(119999.11), true)
0068         SKGTESTERROR(QStringLiteral("UNITVALUE:setDate"), unitvalue1.setDate(SKGServices::stringToTime(QStringLiteral("1970-07-16")).date()), true)
0069         SKGTESTERROR(QStringLiteral("UNITVALUE:save"), unitvalue1.save(), true)
0070 
0071         SKGUnitValueObject unitvalue1bis = SKGUnitValueObject(unitvalue1);
0072         SKGUnitValueObject unitvalue1ter = SKGUnitValueObject(static_cast<SKGObjectBase>(unitvalue1));
0073         SKGUnitValueObject unitvalue14(SKGNamedObject(&document1, QStringLiteral("xxx"), unitvalue1.getID()));
0074 
0075         SKGUnitObject unit_get;
0076         SKGTESTERROR(QStringLiteral("UNITVALUE:getUnit"), unitvalue1.getUnit(unit_get), true)
0077         SKGTESTBOOL("UNIT:comparison", (unit_get == unit1), true)
0078 
0079         SKGUnitValueObject unitvalue2;
0080         SKGTESTERROR(QStringLiteral("UNIT:addUnitValue"), unit1.addUnitValue(unitvalue2), true)
0081 
0082         SKGTESTERROR(QStringLiteral("UNITVALUE:setQuantity"), unitvalue2.setQuantity(34.12), true)
0083         SKGTESTERROR(QStringLiteral("UNITVALUE:setDate"), unitvalue2.setDate(SKGServices::stringToTime(QStringLiteral("1973-02-04")).date()), true)
0084         SKGTESTERROR(QStringLiteral("UNITVALUE:save"), unitvalue2.save(), true)
0085 
0086         // Retrieve unit
0087         SKGNamedObject unit2Named;
0088         SKGTESTERROR(QStringLiteral("UNIT:getObjectByName"), SKGNamedObject::getObjectByName(&document1, QStringLiteral("unit"), QStringLiteral("UNIT1"), unit2Named), true)
0089         SKGUnitObject unit2(unit2Named);
0090 
0091         // Retrieve unit value
0092         SKGUnitValueObject unitvalue3;
0093         SKGTESTERROR(QStringLiteral("UNIT:getLastUnitValue"), unit2.getLastUnitValue(unitvalue3), true)
0094 
0095         SKGUnitValueObject unitvalue19700101;
0096         SKGTESTERROR(QStringLiteral("UNIT:getUnitValue"), unit2.getUnitValue(SKGServices::stringToTime(QStringLiteral("1970-01-01")).date(), unitvalue19700101), true)
0097         SKGUnitValueObject unitvalue19700716;
0098         SKGTESTERROR(QStringLiteral("UNIT:getUnitValue"), unit2.getUnitValue(SKGServices::stringToTime(QStringLiteral("1970-07-16")).date(), unitvalue19700716), true)
0099         SKGUnitValueObject unitvalue19720716;
0100         SKGTESTERROR(QStringLiteral("UNIT:getUnitValue"), unit2.getUnitValue(SKGServices::stringToTime(QStringLiteral("1972-07-16")).date(), unitvalue19720716), true)
0101         SKGUnitValueObject unitvalue19730204;
0102         SKGTESTERROR(QStringLiteral("UNIT:getUnitValue"), unit2.getUnitValue(SKGServices::stringToTime(QStringLiteral("1973-02-04")).date(), unitvalue19730204), true)
0103         SKGUnitValueObject unitvalue19750204;
0104         SKGTESTERROR(QStringLiteral("UNIT:getUnitValue"), unit2.getUnitValue(SKGServices::stringToTime(QStringLiteral("1975-02-04")).date(), unitvalue19750204), true)
0105 
0106         // Check unit value
0107         SKGTESTBOOL("UNITVALUE:==", (unitvalue3 == unitvalue2), true)
0108         SKGTESTBOOL("UNITVALUE:==", (unitvalue19700101 == unitvalue1), true)
0109         SKGTESTBOOL("UNITVALUE:==", (unitvalue19700716 == unitvalue1), true)
0110         SKGTESTBOOL("UNITVALUE:==", (unitvalue19720716 == unitvalue1), true)
0111         SKGTESTBOOL("UNITVALUE:==", (unitvalue19730204 == unitvalue2), true)
0112         SKGTESTBOOL("UNITVALUE:==", (unitvalue19750204 == unitvalue2), true)
0113 
0114         SKGTEST(QStringLiteral("UNITVALUE:getQuantity"), unitvalue1.getQuantity() - 119999.11, 0)
0115         SKGTEST(QStringLiteral("UNITVALUE:getQuantity"), unitvalue3.getQuantity() - 34.12, 0)
0116         SKGTEST(QStringLiteral("UNITVALUE:getDate"), SKGServices::dateToSqlString(unitvalue3.getDate()), QStringLiteral("1973-02-04"))
0117 
0118         // Check cascading delete
0119         SKGTESTERROR(QStringLiteral("UNIT:delete"), unit2.remove(), true)
0120 
0121         QStringList oResult;
0122         SKGTESTERROR(QStringLiteral("UNIT:getDistinctValues"), document1.getDistinctValues(QStringLiteral("unit"), QStringLiteral("id"), oResult), true)
0123         SKGTEST(QStringLiteral("UNIT:oResult.size"), oResult.size(), 0)
0124 
0125         SKGTESTERROR(QStringLiteral("UNITVALUE:getDistinctValues"), document1.getDistinctValues(QStringLiteral("unitvalue"), QStringLiteral("rd_unit_id"), oResult), true)
0126         SKGTEST(QStringLiteral("UNITVALUE:oResult.size"), oResult.size(), 0)
0127 
0128         // Merge
0129         SKGTESTERROR(QStringLiteral("UNIT:merge"), unit1.merge(unit2), true)
0130     }
0131 
0132     {
0133         // Test unit et unitvalue
0134         SKGDocumentBank document1;
0135         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0136         SKGError err;
0137         SKGTEST(QStringLiteral("DOC:getPrimaryUnit"), document1.getPrimaryUnit().Symbol, QLatin1String(""))
0138         SKGTEST(QStringLiteral("DOC:getSecondaryUnit"), document1.getSecondaryUnit().Symbol, QLatin1String(""))
0139         SKGUnitObject franc(&document1);
0140         {
0141             SKGBEGINTRANSACTION(document1, QStringLiteral("UNIT_1"), err)
0142 
0143             // Create unit
0144             SKGTESTERROR(QStringLiteral("FRANC:setName"), franc.setName(QStringLiteral("F")), true)
0145             SKGTESTERROR(QStringLiteral("FRANC:setSymbol"), franc.setSymbol(QStringLiteral("F")), true)
0146             SKGTESTERROR(QStringLiteral("FRANC:setType"), franc.setType(SKGUnitObject::PRIMARY), true)
0147             SKGTEST(QStringLiteral("FRANC:getType"), static_cast<unsigned int>(franc.getType()), static_cast<unsigned int>(SKGUnitObject::PRIMARY))
0148             SKGTESTERROR(QStringLiteral("FRANC:save"), franc.save(), true)
0149 
0150             SKGTEST(QStringLiteral("DOC:getPrimaryUnit"), document1.getPrimaryUnit().Symbol, QStringLiteral("F"))
0151         }
0152 
0153         SKGTEST(QStringLiteral("DOC:getPrimaryUnit"), document1.getPrimaryUnit().Symbol, QStringLiteral("F"))
0154         SKGTEST(QStringLiteral("DOC:getSecondaryUnit"), document1.getSecondaryUnit().Symbol, QLatin1String(""))
0155         SKGTEST(QStringLiteral("DOC:getSecondaryUnit"), document1.getSecondaryUnit().Value, 1)
0156 
0157         {
0158             SKGBEGINTRANSACTION(document1, QStringLiteral("UNIT_2"), err)
0159 
0160             SKGUnitObject euro(&document1);
0161             SKGTESTERROR(QStringLiteral("EURO:setName"), euro.setName(QStringLiteral("E")), true)
0162             SKGTESTERROR(QStringLiteral("EURO:setSymbol"), euro.setSymbol(QStringLiteral("E")), true)
0163             SKGTESTERROR(QStringLiteral("EURO:setType"), euro.setType(SKGUnitObject::PRIMARY), true)
0164             SKGTEST(QStringLiteral("EURO:getType"), static_cast<unsigned int>(euro.getType()), static_cast<unsigned int>(SKGUnitObject::PRIMARY))
0165             SKGTESTERROR(QStringLiteral("EURO:save"), euro.save(), true)
0166 
0167             SKGTESTERROR(QStringLiteral("FRANC:load"), franc.load(), true)
0168             SKGTEST(QStringLiteral("FRANC:getType"), static_cast<unsigned int>(franc.getType()), static_cast<unsigned int>(SKGUnitObject::SECONDARY))
0169 
0170             SKGTEST(QStringLiteral("EURO:getType"), static_cast<unsigned int>(euro.getType()), static_cast<unsigned int>(SKGUnitObject::PRIMARY))
0171             SKGTESTERROR(QStringLiteral("EURO:save"), euro.save(), true)
0172         }
0173 
0174         SKGTEST(QStringLiteral("DOC:getPrimaryUnit"), document1.getPrimaryUnit().Symbol, QStringLiteral("E"))
0175         SKGTEST(QStringLiteral("DOC:getSecondaryUnit"), document1.getSecondaryUnit().Symbol, QStringLiteral("F"))
0176     }
0177 
0178     {
0179         // Test unit et unitvalue
0180         SKGDocumentBank document1;
0181         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0182         SKGError err;
0183         {
0184             QStringList units = SKGUnitObject::getListofKnownCurrencies(false);
0185             SKGTEST(QStringLiteral("UNIT:getListofKnownCurrencies"), units.count(), 276)
0186             units = SKGUnitObject::getListofKnownCurrencies(true);
0187             SKGTEST(QStringLiteral("UNIT:getListofKnownCurrencies"), units.count(), 316)
0188             for (const auto& unit : qAsConst(units)) {
0189                 SKGBEGINTRANSACTION(document1, QStringLiteral("UNIT_1"), err)
0190                 SKGUnitObject unitObj;
0191                 SKGTESTERROR(QStringLiteral("UNIT:createCurrencyUnit-") % unit, SKGUnitObject::createCurrencyUnit(&document1, unit, unitObj), true)
0192                 unitObj.getUnitInfo();
0193             }
0194             SKGBEGINTRANSACTION(document1, QStringLiteral("UNIT_1"), err)
0195             SKGUnitObject unitObj;
0196             SKGTESTERROR(QStringLiteral("UNIT:createCurrencyUnit"), SKGUnitObject::createCurrencyUnit(&document1, QStringLiteral("ZZZZZZZ"), unitObj), false)
0197         }
0198     }
0199 
0200     {
0201         // Compute unit amount at a date
0202         SKGDocumentBank document1;
0203         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0204         SKGError err;
0205         SKGUnitObject unit1(&document1);
0206         SKGUnitObject unit2(&document1);
0207         {
0208             SKGBEGINTRANSACTION(document1, QStringLiteral("UNIT"), err)
0209             SKGTESTERROR(QStringLiteral("UNIT:setName"), unit1.setName(QStringLiteral("U1")), true)
0210             SKGTESTERROR(QStringLiteral("UNIT:setSymbol"), unit1.setSymbol(QStringLiteral("U1")), true)
0211             SKGTESTERROR(QStringLiteral("UNIT:save"), unit1.save(), true)
0212             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), SKGServices::stringToTime(QStringLiteral("2001-01-01")).date(), 1), true)
0213             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), SKGServices::stringToTime(QStringLiteral("2006-01-01")).date(), 6), true)
0214             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), SKGServices::stringToTime(QStringLiteral("2007-01-01")).date(), 7), true)
0215             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), SKGServices::stringToTime(QStringLiteral("2008-01-01")).date(), 8), true)
0216 
0217             SKGTESTERROR(QStringLiteral("UNIT:setName"), unit2.setName(QStringLiteral("U2")), true)
0218             SKGTESTERROR(QStringLiteral("UNIT:setSymbol"), unit2.setSymbol(QStringLiteral("U2")), true)
0219             SKGTESTERROR(QStringLiteral("UNIT:removeUnit"), unit2.removeUnit(), true)
0220             SKGTESTERROR(QStringLiteral("UNIT:save"), unit2.save(), true)
0221             SKGTESTERROR(QStringLiteral("UNIT:setUnit"), unit2.setUnit(unit2), false)
0222             SKGTESTERROR(QStringLiteral("UNIT:setUnit"), unit2.setUnit(unit1), true)
0223             SKGTESTERROR(QStringLiteral("UNIT:save"), unit2.save(), true)
0224             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U2"), SKGServices::stringToTime(QStringLiteral("2001-02-01")).date(), 10), true)
0225             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U2"), SKGServices::stringToTime(QStringLiteral("2006-01-01")).date(), 60), true)
0226             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U2"), SKGServices::stringToTime(QStringLiteral("2007-02-01")).date(), 70), true)
0227             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U2"), SKGServices::stringToTime(QStringLiteral("2008-01-01")).date(), 80), true)
0228         }
0229 
0230         SKGTEST(QStringLiteral("DOC:getAmount"), unit1.getAmount(SKGServices::stringToTime(QStringLiteral("2001-01-01")).date()), 1)
0231         SKGTEST(QStringLiteral("DOC:getAmount"), unit1.getAmount(SKGServices::stringToTime(QStringLiteral("2001-02-01")).date()), 1)
0232         SKGTEST(QStringLiteral("DOC:getAmount"), unit1.getAmount(SKGServices::stringToTime(QStringLiteral("2006-01-01")).date()), 6)
0233         SKGTEST(QStringLiteral("DOC:getAmount"), unit1.getAmount(SKGServices::stringToTime(QStringLiteral("2006-02-01")).date()), 6)
0234         SKGTEST(QStringLiteral("DOC:getAmount"), unit1.getAmount(SKGServices::stringToTime(QStringLiteral("2007-01-01")).date()), 7)
0235         SKGTEST(QStringLiteral("DOC:getAmount"), unit1.getAmount(SKGServices::stringToTime(QStringLiteral("2007-02-01")).date()), 7)
0236         SKGTEST(QStringLiteral("DOC:getAmount"), unit1.getAmount(SKGServices::stringToTime(QStringLiteral("2008-01-01")).date()), 8)
0237         SKGTEST(QStringLiteral("DOC:getAmount"), unit1.getAmount(SKGServices::stringToTime(QStringLiteral("2008-02-01")).date()), 8)
0238 
0239         SKGTEST(QStringLiteral("DOC:getAmount"), unit2.getAmount(SKGServices::stringToTime(QStringLiteral("2001-01-01")).date()), 1 * 10)
0240         SKGTEST(QStringLiteral("DOC:getAmount"), unit2.getAmount(SKGServices::stringToTime(QStringLiteral("2001-02-01")).date()), 1 * 10)
0241         SKGTEST(QStringLiteral("DOC:getAmount"), unit2.getAmount(SKGServices::stringToTime(QStringLiteral("2006-01-01")).date()), 6 * 60)
0242         SKGTEST(QStringLiteral("DOC:getAmount"), unit2.getAmount(SKGServices::stringToTime(QStringLiteral("2006-02-01")).date()), 6 * 60)
0243         SKGTEST(QStringLiteral("DOC:getAmount"), unit2.getAmount(SKGServices::stringToTime(QStringLiteral("2007-01-01")).date()), 7 * 60)
0244         SKGTEST(QStringLiteral("DOC:getAmount"), unit2.getAmount(SKGServices::stringToTime(QStringLiteral("2007-02-01")).date()), 7 * 70)
0245         SKGTEST(QStringLiteral("DOC:getAmount"), unit2.getAmount(SKGServices::stringToTime(QStringLiteral("2008-01-01")).date()), 8 * 80)
0246         SKGTEST(QStringLiteral("DOC:getAmount"), unit2.getAmount(SKGServices::stringToTime(QStringLiteral("2008-02-01")).date()), 8 * 80)
0247 
0248         SKGTESTERROR(QStringLiteral("UNIT:load"), unit1.load(), true)
0249         SKGTESTERROR(QStringLiteral("UNIT:load"), unit2.load(), true)
0250         SKGTEST(QStringLiteral("DOC:convert"), SKGUnitObject::convert(100, unit1, unit1), 100)
0251         SKGTEST(QStringLiteral("DOC:convert"), SKGUnitObject::convert(100, unit1, unit2), 1.25)
0252     }
0253 
0254     {
0255         // Split unit
0256         SKGDocumentBank document1;
0257         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0258         SKGError err;
0259         SKGUnitObject unit1(&document1);
0260         {
0261             SKGBEGINTRANSACTION(document1, QStringLiteral("UNIT"), err)
0262             SKGTESTERROR(QStringLiteral("UNIT:setName"), unit1.setName(QStringLiteral("U1")), true)
0263             SKGTESTERROR(QStringLiteral("UNIT:setSymbol"), unit1.setSymbol(QStringLiteral("U1")), true)
0264             SKGTESTERROR(QStringLiteral("UNIT:save"), unit1.save(), true)
0265             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), SKGServices::stringToTime(QStringLiteral("2001-01-01")).date(), 100), true)
0266         }
0267         {
0268             SKGBEGINTRANSACTION(document1, QStringLiteral("UNIT-SPLIT"), err)
0269             SKGTESTERROR(QStringLiteral("DOC:getAmount"), unit1.split(-2), false)
0270             SKGTESTERROR(QStringLiteral("DOC:getAmount"), unit1.split(2), true)
0271         }
0272 
0273         SKGTESTERROR(QStringLiteral("UNIT:load"), unit1.load(), true)
0274         SKGTEST(QStringLiteral("UNIT:getAmount"), unit1.getAmount(SKGServices::stringToTime(QStringLiteral("2001-01-01")).date()), 50)
0275     }
0276 
0277     {
0278         // Unit Daily change
0279         SKGDocumentBank document1;
0280         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0281         SKGError err;
0282         SKGUnitObject unit1(&document1);
0283         {
0284             SKGBEGINTRANSACTION(document1, QStringLiteral("UNIT"), err)
0285             SKGTESTERROR(QStringLiteral("UNIT:setName"), unit1.setName(QStringLiteral("U1")), true)
0286             SKGTESTERROR(QStringLiteral("UNIT:setSymbol"), unit1.setSymbol(QStringLiteral("U1")), true)
0287             SKGTESTERROR(QStringLiteral("UNIT:save"), unit1.save(), true)
0288             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), SKGServices::stringToTime(QStringLiteral("2009-01-01")).date(), 100), true)
0289             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), SKGServices::stringToTime(QStringLiteral("2009-01-02")).date(), 105), true)
0290             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), SKGServices::stringToTime(QStringLiteral("2009-02-01")).date(), 110), true)
0291         }
0292 
0293         SKGTEST(QStringLiteral("UNIT:getDailyChange"), SKGServices::intToString(365 * unit1.getDailyChange(SKGServices::stringToTime(QStringLiteral("2009-01-02")).date())), QStringLiteral("1825"))
0294         SKGTEST(QStringLiteral("UNIT:getDailyChange"), SKGServices::intToString(365 * unit1.getDailyChange(SKGServices::stringToTime(QStringLiteral("2009-02-01")).date())), QStringLiteral("80"))
0295     }
0296 
0297     {
0298         // Unit download with internet code = " " (see https://forum.kde.org/viewtopic.php?f=210&t=163184&p=424630&hilit=skrooge#p424630)
0299         SKGDocumentBank document1;
0300         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0301         SKGError err;
0302         SKGUnitObject unit1(&document1);
0303         {
0304             SKGBEGINTRANSACTION(document1, QStringLiteral("UNIT"), err)
0305             SKGTESTERROR(QStringLiteral("UNIT:setName"), unit1.setName(QStringLiteral("DS")), true)
0306             SKGTESTERROR(QStringLiteral("UNIT:setSymbol"), unit1.setSymbol(QStringLiteral("DS")), true)
0307             SKGTESTERROR(QStringLiteral("UNIT:setInternetCode"), unit1.setInternetCode(QStringLiteral(" ")), true)
0308             SKGTESTERROR(QStringLiteral("UNIT:save"), unit1.save(), true)
0309             SKGTESTERROR(QStringLiteral("UNIT:downloadUnitValue"), unit1.downloadUnitValue(SKGUnitObject::ALL_DAILY, 20), true)
0310         }
0311     }
0312 
0313     {
0314         // Unit download
0315         SKGDocumentBank document1;
0316         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0317         SKGError err;
0318         SKGUnitObject unit1(&document1);
0319         {
0320             SKGBEGINTRANSACTION(document1, QStringLiteral("UNIT"), err)
0321             SKGTESTERROR(QStringLiteral("UNIT:setName"), unit1.setName(QStringLiteral("DS")), true)
0322             SKGTESTERROR(QStringLiteral("UNIT:setSymbol"), unit1.setSymbol(QStringLiteral("DS")), true)
0323             SKGTESTERROR(QStringLiteral("UNIT:setDownloadSource"), unit1.setDownloadSource(QStringLiteral("Yahoo")), true)
0324             SKGTESTERROR(QStringLiteral("UNIT:setInternetCode"), unit1.setInternetCode(QStringLiteral("DSY.PA")), true)
0325             SKGTESTERROR(QStringLiteral("UNIT:save"), unit1.save(), true)
0326             SKGTESTERROR(QStringLiteral("UNIT:downloadUnitValue"), unit1.downloadUnitValue(SKGUnitObject::ALL_DAILY, 20), true)
0327 
0328             SKGObjectBase::SKGListSKGObjectBase values;
0329             SKGTESTERROR(QStringLiteral("UNIT:getUnitValues"), unit1.getUnitValues(values), true)
0330             SKGTESTBOOL("UNIT:getUnitValues", (!values.isEmpty()), true)
0331 
0332             // All download modes
0333             SKGTESTERROR(QStringLiteral("UNIT:downloadUnitValue"), unit1.downloadUnitValue(SKGUnitObject::LAST_WEEKLY, 20), true)
0334             SKGTESTERROR(QStringLiteral("UNIT:downloadUnitValue"), unit1.downloadUnitValue(SKGUnitObject::LAST_DAILY, 20), true)
0335             SKGTESTERROR(QStringLiteral("UNIT:downloadUnitValue"), unit1.downloadUnitValue(SKGUnitObject::LAST_MONTHLY, 20), true)
0336             SKGTESTERROR(QStringLiteral("UNIT:downloadUnitValue"), unit1.downloadUnitValue(SKGUnitObject::ALL_MONTHLY, 20), true)
0337             SKGTESTERROR(QStringLiteral("UNIT:downloadUnitValue"), unit1.downloadUnitValue(SKGUnitObject::ALL_WEEKLY, 20), true)
0338 
0339             SKGTESTERROR(QStringLiteral("UNIT:getUnitValues"), unit1.getUnitValues(values), true)
0340             SKGTESTBOOL("UNIT:getUnitValues", static_cast<unsigned int>(values.count() > 1), static_cast<unsigned int>(true))
0341 
0342             QUrl url;
0343             unit1.getUrl(url);  // For coverage
0344         }
0345     }
0346     {
0347         // Unit download
0348         SKGDocumentBank document1;
0349         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0350         SKGError err;
0351         SKGUnitObject unit1(&document1);
0352         {
0353             SKGBEGINTRANSACTION(document1, QStringLiteral("UNIT"), err)
0354             SKGTESTERROR(QStringLiteral("UNIT:setName"), unit1.setName(QStringLiteral("FORMULA")), true)
0355             SKGTESTERROR(QStringLiteral("UNIT:setSymbol"), unit1.setSymbol(QStringLiteral("FORMULA")), true)
0356             SKGTESTERROR(QStringLiteral("UNIT:setInternetCode"), unit1.setInternetCode(QStringLiteral("=5")), true)
0357             SKGTESTERROR(QStringLiteral("UNIT:save"), unit1.save(), true)
0358             SKGTESTERROR(QStringLiteral("UNIT:downloadUnitValue"), unit1.downloadUnitValue(SKGUnitObject::ALL_DAILY, 20), true)
0359 
0360             SKGObjectBase::SKGListSKGObjectBase values;
0361             SKGTESTERROR(QStringLiteral("UNIT:getUnitValues"), unit1.getUnitValues(values), true)
0362             SKGTESTBOOL("UNIT:getUnitValues.isEmpty", values.isEmpty(), false)
0363         }
0364     }
0365     {
0366         // Unit download
0367         SKGDocumentBank document1;
0368         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0369         SKGError err;
0370 
0371         {
0372             SKGBEGINTRANSACTION(document1, QStringLiteral("UNIT"), err)
0373             SKGUnitObject euro;
0374             SKGTESTERROR(QStringLiteral("UNIT:createCurrencyUnit"), SKGUnitObject::createCurrencyUnit(&document1, QStringLiteral("EUR"), euro), true)
0375             SKGUnitObject fr;
0376             SKGTESTERROR(QStringLiteral("UNIT:createCurrencyUnit"), SKGUnitObject::createCurrencyUnit(&document1, QStringLiteral("GBP"), fr), true)
0377             SKGTESTERROR(QStringLiteral("UNIT:downloadUnitValue"), fr.downloadUnitValue(SKGUnitObject::LAST), true)
0378 
0379             SKGObjectBase::SKGListSKGObjectBase values;
0380             SKGTESTERROR(QStringLiteral("UNIT:getUnitValues"), fr.getUnitValues(values), true)
0381             SKGTESTBOOL("UNIT:getUnitValues", values.isEmpty(), false)
0382         }
0383     }
0384     {
0385         // Unit simplify
0386         SKGDocumentBank document1;
0387         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0388         SKGError err;
0389         SKGUnitObject unit1(&document1);
0390         {
0391             SKGBEGINTRANSACTION(document1, QStringLiteral("UNIT"), err)
0392             SKGTESTERROR(QStringLiteral("UNIT:setName"), unit1.setName(QStringLiteral("U1")), true)
0393             SKGTESTERROR(QStringLiteral("UNIT:setSymbol"), unit1.setSymbol(QStringLiteral("U1")), true)
0394             SKGTESTERROR(QStringLiteral("UNIT:save"), unit1.save(), true)
0395 
0396             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), QDate::currentDate().addDays(-7), 1), true)
0397             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), QDate::currentDate().addDays(-6), 2), true)
0398             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), QDate::currentDate().addDays(-5), 3), true)
0399 
0400             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), QDate::currentDate().addMonths(-3).addDays(-7), 1), true)
0401             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), QDate::currentDate().addMonths(-3).addDays(-6), 2), true)
0402             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), QDate::currentDate().addMonths(-3).addDays(-5), 3), true)
0403 
0404             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), QDate::currentDate().addYears(-1).addDays(-7), 1), true)
0405             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), QDate::currentDate().addMonths(-1).addDays(-6), 2), true)
0406             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), QDate::currentDate().addMonths(-1).addDays(-5), 3), true)
0407 
0408             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), SKGServices::stringToTime(QStringLiteral("2009-01-01")).date(), 1), true)
0409             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), SKGServices::stringToTime(QStringLiteral("2009-01-02")).date(), 2), true)
0410             SKGTESTERROR(QStringLiteral("UNIT:addOrModifyUnitValue"), document1.addOrModifyUnitValue(QStringLiteral("U1"), SKGServices::stringToTime(QStringLiteral("2009-01-03")).date(), 3), true)
0411         }
0412 
0413         {
0414             SKGBEGINTRANSACTION(document1, QStringLiteral("SYMPLIFY"), err)
0415             SKGTESTERROR(QStringLiteral("UNIT:setName"), unit1.simplify(), true)
0416         }
0417         SKGObjectBase::SKGListSKGObjectBase oUnitValueList;
0418         SKGTESTERROR(QStringLiteral("UNIT:getUnitValues"), unit1.getUnitValues(oUnitValueList), true)
0419         SKGTESTBOOL("UNIT:oUnitValueList", (oUnitValueList.count() == 10 || oUnitValueList.count() == 11), true)
0420     }
0421 
0422     {
0423         SKGTESTERROR(QStringLiteral("UNIT:addSource"), SKGUnitObject::addSource(QStringLiteral("test"), false), true)
0424         SKGTESTBOOL("UNIT:isWritable", SKGUnitObject::isWritable(QStringLiteral("test")), true)
0425         SKGTESTERROR(QStringLiteral("UNIT:deleteSource"), SKGUnitObject::deleteSource(QStringLiteral("test")), true)
0426         SKGTESTERROR(QStringLiteral("UNIT:deleteSource"), SKGUnitObject::deleteSource(QStringLiteral("notfound")), false)
0427     }
0428     // End test
0429     SKGENDTEST()
0430 }