File indexing completed on 2024-12-29 04:52:27
0001 /* 0002 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org> 0003 SPDX-License-Identifier: GPL-2.0-only 0004 */ 0005 0006 #include "historyclosedreadermanagertest.h" 0007 #include "historyclosedreader/historyclosedreadermanager.h" 0008 #include <QSignalSpy> 0009 #include <QTest> 0010 QTEST_GUILESS_MAIN(HistoryClosedReaderManagerTest) 0011 HistoryClosedReaderManagerTest::HistoryClosedReaderManagerTest(QObject *parent) 0012 : QObject{parent} 0013 { 0014 } 0015 0016 void HistoryClosedReaderManagerTest::shouldHaveDefaultValues() 0017 { 0018 HistoryClosedReaderManager w; 0019 QVERIFY(w.isEmpty()); 0020 QVERIFY(w.closedReaderInfos().isEmpty()); 0021 } 0022 0023 void HistoryClosedReaderManagerTest::shouldAddValues() 0024 { 0025 HistoryClosedReaderManager w; 0026 { 0027 HistoryClosedReaderInfo info; 0028 info.setItem(2); 0029 info.setSubject(QStringLiteral("sub")); 0030 w.addInfo(std::move(info)); 0031 } 0032 QVERIFY(!w.isEmpty()); 0033 QCOMPARE(w.count(), 1); 0034 { 0035 HistoryClosedReaderInfo info; 0036 info.setItem(5); 0037 info.setSubject(QStringLiteral("sub2")); 0038 w.addInfo(std::move(info)); 0039 } 0040 QCOMPARE(w.count(), 2); 0041 } 0042 0043 void HistoryClosedReaderManagerTest::shouldClear() 0044 { 0045 HistoryClosedReaderManager w; 0046 { 0047 HistoryClosedReaderInfo info; 0048 info.setItem(2); 0049 info.setSubject(QStringLiteral("sub")); 0050 w.addInfo(std::move(info)); 0051 } 0052 QVERIFY(!w.isEmpty()); 0053 { 0054 HistoryClosedReaderInfo info; 0055 info.setItem(5); 0056 info.setSubject(QStringLiteral("sub2")); 0057 w.addInfo(std::move(info)); 0058 } 0059 QCOMPARE(w.count(), 2); 0060 w.clear(); 0061 QVERIFY(w.isEmpty()); 0062 } 0063 0064 void HistoryClosedReaderManagerTest::shouldRemoveValue() 0065 { 0066 HistoryClosedReaderManager w; 0067 { 0068 HistoryClosedReaderInfo info; 0069 info.setItem(2); 0070 info.setSubject(QStringLiteral("sub")); 0071 w.addInfo(std::move(info)); 0072 } 0073 QVERIFY(!w.isEmpty()); 0074 { 0075 HistoryClosedReaderInfo info; 0076 info.setItem(5); 0077 info.setSubject(QStringLiteral("sub2")); 0078 w.addInfo(std::move(info)); 0079 } 0080 QCOMPARE(w.count(), 2); 0081 // Don't compare value 0082 (void)w.lastInfo(); 0083 QCOMPARE(w.count(), 1); 0084 (void)w.lastInfo(); 0085 QCOMPARE(w.count(), 0); 0086 QVERIFY(w.isEmpty()); 0087 } 0088 0089 void HistoryClosedReaderManagerTest::shouldEmitSignal() 0090 { 0091 HistoryClosedReaderManager w; 0092 QSignalSpy spyHistoryClosedReaderChanged(&w, &HistoryClosedReaderManager::historyClosedReaderChanged); 0093 // List is empty => clearing will not emit signal. 0094 w.clear(); 0095 QCOMPARE(spyHistoryClosedReaderChanged.count(), 0); 0096 0097 { 0098 HistoryClosedReaderInfo info; 0099 info.setItem(2); 0100 info.setSubject(QStringLiteral("sub")); 0101 w.addInfo(std::move(info)); 0102 QCOMPARE(spyHistoryClosedReaderChanged.count(), 1); 0103 w.clear(); 0104 QCOMPARE(spyHistoryClosedReaderChanged.count(), 2); 0105 } 0106 w.clear(); 0107 spyHistoryClosedReaderChanged.clear(); 0108 0109 { 0110 HistoryClosedReaderInfo info; 0111 info.setItem(2); 0112 info.setSubject(QStringLiteral("sub")); 0113 w.addInfo(std::move(info)); 0114 0115 HistoryClosedReaderInfo info2; 0116 info2.setItem(3); 0117 info2.setSubject(QStringLiteral("sub2")); 0118 w.addInfo(std::move(info2)); 0119 spyHistoryClosedReaderChanged.clear(); 0120 0121 (void)w.lastInfo(); 0122 QCOMPARE(spyHistoryClosedReaderChanged.count(), 0); 0123 0124 (void)w.lastInfo(); 0125 QCOMPARE(spyHistoryClosedReaderChanged.count(), 1); 0126 } 0127 // TODO 0128 } 0129 0130 void HistoryClosedReaderManagerTest::shouldAssignMaxValues() 0131 { 0132 HistoryClosedReaderManager w; 0133 for (int i = 0; i < 15; i++) { 0134 HistoryClosedReaderInfo info; 0135 info.setItem(2); 0136 info.setSubject(QStringLiteral("sub")); 0137 w.addInfo(std::move(info)); 0138 } 0139 QCOMPARE(w.count(), 10); 0140 } 0141 0142 #include "moc_historyclosedreadermanagertest.cpp"