File indexing completed on 2025-04-20 04:37:37
0001 /* 0002 SPDX-FileCopyrightText: 2011 Alvaro Soliverez asoliverez @kde.org 0003 0004 This file is part of libalkimia. 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 */ 0008 0009 #include "alkquoteitemtest.h" 0010 0011 #include "alkquoteitem.h" 0012 #include "test.h" 0013 0014 QTEST_GUILESS_MAIN(AlkQuoteItemTest) 0015 0016 void AlkQuoteItemTest::init() 0017 { 0018 } 0019 0020 void AlkQuoteItemTest::cleanup() 0021 { 0022 } 0023 0024 void AlkQuoteItemTest::emptyCtor() 0025 { 0026 AlkQuoteItem item; 0027 0028 QVERIFY(item.symbol().isEmpty()); 0029 QVERIFY(!item.dateTime().isValid()); 0030 QCOMPARE(item.currentValue(), AlkValue(0, 1)); 0031 QCOMPARE(item.openingValue(), AlkValue(0, 1)); 0032 QCOMPARE(item.lowValue(), AlkValue(0, 1)); 0033 QCOMPARE(item.highValue(), AlkValue(0, 1)); 0034 QCOMPARE(item.closingValue(), AlkValue(0, 1)); 0035 QCOMPARE(item.volume(), AlkValue(0, 1)); 0036 QCOMPARE(item.marketCap(), AlkValue(0, 1)); 0037 QCOMPARE(item.earningsPerShare(), AlkValue(0, 1)); 0038 QCOMPARE(item.changeToday(), AlkValue(0, 1)); 0039 QCOMPARE(item.ebitda(), AlkValue(0, 1)); 0040 QVERIFY(item.recordId().isEmpty()); 0041 } 0042 0043 void AlkQuoteItemTest::copyCtor() 0044 { 0045 AlkQuoteItem item; 0046 QString symbol = QString("TESTSYMBOL"); 0047 QDateTime dateTime = QDateTime::currentDateTime(); 0048 AlkValue currentValue(12, 1); 0049 AlkValue opening(1, 1); 0050 AlkValue lowValue(1, 2); 0051 AlkValue highValue(5, 1); 0052 AlkValue closing(4, 1); 0053 AlkValue volume(1000, 1); 0054 AlkValue marketCap(500, 1); 0055 AlkValue earnings(556, 1); 0056 AlkValue change(4, 1); 0057 AlkValue ebitda(67, 1); 0058 QString recordId("A1337"); 0059 0060 item.setSymbol(symbol); 0061 item.setDateTime(dateTime); 0062 item.setCurrentValue(currentValue); 0063 item.setOpeningValue(opening); 0064 item.setLowValue(lowValue); 0065 item.setHighValue(highValue); 0066 item.setClosingValue(closing); 0067 item.setVolume(volume); 0068 item.setMarketCap(marketCap); 0069 item.setEarningsPerShare(earnings); 0070 item.setChangeToday(change); 0071 item.setEbitda(ebitda); 0072 item.setRecordId(recordId); 0073 0074 AlkQuoteItem itemCopy(item); 0075 0076 QCOMPARE(itemCopy.symbol(), symbol); 0077 QCOMPARE(itemCopy.dateTime(), dateTime); 0078 QCOMPARE(itemCopy.currentValue(), currentValue); 0079 QCOMPARE(itemCopy.openingValue(), opening); 0080 QCOMPARE(itemCopy.lowValue(), lowValue); 0081 QCOMPARE(itemCopy.highValue(), highValue); 0082 QCOMPARE(itemCopy.closingValue(), closing); 0083 QCOMPARE(itemCopy.volume(), volume); 0084 QCOMPARE(itemCopy.marketCap(), marketCap); 0085 QCOMPARE(itemCopy.earningsPerShare(), earnings); 0086 QCOMPARE(itemCopy.changeToday(), change); 0087 QCOMPARE(itemCopy.ebitda(), ebitda); 0088 QCOMPARE(itemCopy.recordId(), recordId); 0089 } 0090 0091 void AlkQuoteItemTest::settersAndGetters() 0092 { 0093 AlkQuoteItem item; 0094 QString symbol("TESTSYMBOL"); 0095 QDateTime dateTime = QDateTime::currentDateTime(); 0096 AlkValue currentValue(12, 1); 0097 AlkValue opening(1, 1); 0098 AlkValue lowValue(1, 2); 0099 AlkValue highValue(5, 1); 0100 AlkValue closing(4, 1); 0101 AlkValue volume(1000, 1); 0102 AlkValue marketCap(500, 1); 0103 AlkValue earnings(556, 1); 0104 AlkValue change(4, 1); 0105 AlkValue ebitda(67, 1); 0106 QString recordId("A1337"); 0107 0108 item.setSymbol(symbol); 0109 item.setDateTime(dateTime); 0110 item.setCurrentValue(currentValue); 0111 item.setOpeningValue(opening); 0112 item.setLowValue(lowValue); 0113 item.setHighValue(highValue); 0114 item.setClosingValue(closing); 0115 item.setVolume(volume); 0116 item.setMarketCap(marketCap); 0117 item.setEarningsPerShare(earnings); 0118 item.setChangeToday(change); 0119 item.setEbitda(ebitda); 0120 item.setRecordId(recordId); 0121 0122 QCOMPARE(item.symbol(), symbol); 0123 QCOMPARE(item.dateTime(), dateTime); 0124 QCOMPARE(item.currentValue(), currentValue); 0125 QCOMPARE(item.openingValue(), opening); 0126 QCOMPARE(item.lowValue(), lowValue); 0127 QCOMPARE(item.highValue(), highValue); 0128 QCOMPARE(item.closingValue(), closing); 0129 QCOMPARE(item.volume(), volume); 0130 QCOMPARE(item.marketCap(), marketCap); 0131 QCOMPARE(item.earningsPerShare(), earnings); 0132 QCOMPARE(item.changeToday(), change); 0133 QCOMPARE(item.ebitda(), ebitda); 0134 QCOMPARE(item.recordId(), recordId); 0135 } 0136 0137 void AlkQuoteItemTest::qDbusArgument() 0138 { 0139 AlkQuoteItem item; 0140 QString symbol("TESTSYMBOL"); 0141 QDateTime dateTime = QDateTime::currentDateTime(); 0142 AlkValue opening(1, 1); 0143 AlkValue lowValue(1, 2); 0144 AlkValue highValue(5, 1); 0145 AlkValue closing(4, 1); 0146 AlkValue volume(1000, 1); 0147 AlkValue marketCap(500, 1); 0148 0149 item.setSymbol(symbol); 0150 item.setDateTime(dateTime); 0151 item.setOpeningValue(opening); 0152 item.setLowValue(lowValue); 0153 item.setHighValue(highValue); 0154 item.setClosingValue(closing); 0155 item.setVolume(volume); 0156 item.setMarketCap(marketCap); 0157 0158 QDBusArgument arg; 0159 0160 arg << item; 0161 0162 // FIXME: reading from endArg throws a write-only warning and the test fails 0163 /*const QDBusArgument endArg(arg); 0164 0165 AlkQuoteItem itemEnd; 0166 endArg >> itemEnd; 0167 0168 qDebug() << "symbol: " << itemEnd.symbol(); 0169 0170 QVERIFY(symbol == itemEnd.symbol()); 0171 QVERIFY(dateTime == itemEnd.dateTime()); 0172 QVERIFY(opening == itemEnd.openingValue()); 0173 QVERIFY(lowValue == itemEnd.lowValue()); 0174 QVERIFY(highValue == itemEnd.highValue()); 0175 QVERIFY(closing == itemEnd.closingValue()); 0176 QVERIFY(volume == itemEnd.volume()); 0177 QVERIFY(marketCap == itemEnd.marketCap());*/ 0178 }