2024-06-28 09:25:03 +00:00
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
#include <StatusQ/modelcount.h>
|
|
|
|
|
|
|
|
#include <TestHelpers/testmodel.h>
|
|
|
|
|
|
|
|
|
|
|
|
class TestModelCount : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void modelCountTest()
|
|
|
|
{
|
|
|
|
TestModel model({
|
|
|
|
{ "name", { "a", "b", "c", "d" }}
|
|
|
|
});
|
|
|
|
|
|
|
|
ModelCount modelCount(&model);
|
|
|
|
|
|
|
|
QCOMPARE(modelCount.count(), 4);
|
2024-10-17 10:40:02 +00:00
|
|
|
QCOMPARE(modelCount.empty(), false);
|
2024-06-28 09:25:03 +00:00
|
|
|
|
2024-10-17 10:40:02 +00:00
|
|
|
QSignalSpy countSpy(&modelCount, &ModelCount::countChanged);
|
|
|
|
QSignalSpy emptySpy(&modelCount, &ModelCount::emptyChanged);
|
2024-06-28 09:25:03 +00:00
|
|
|
|
|
|
|
model.insert(1, { "e" });
|
|
|
|
|
2024-10-17 10:40:02 +00:00
|
|
|
QCOMPARE(countSpy.count(), 1);
|
|
|
|
QCOMPARE(emptySpy.count(), 0);
|
2024-06-28 09:25:03 +00:00
|
|
|
QCOMPARE(modelCount.count(), 5);
|
2024-10-17 10:40:02 +00:00
|
|
|
QCOMPARE(modelCount.empty(), false);
|
2024-06-28 09:25:03 +00:00
|
|
|
|
|
|
|
model.remove(0);
|
|
|
|
|
2024-10-17 10:40:02 +00:00
|
|
|
QCOMPARE(countSpy.count(), 2);
|
|
|
|
QCOMPARE(emptySpy.count(), 0);
|
2024-06-28 09:25:03 +00:00
|
|
|
QCOMPARE(modelCount.count(), 4);
|
2024-10-17 10:40:02 +00:00
|
|
|
QCOMPARE(modelCount.empty(), false);
|
2024-06-28 09:25:03 +00:00
|
|
|
|
|
|
|
model.update(0, 0, "aa");
|
|
|
|
|
2024-10-17 10:40:02 +00:00
|
|
|
QCOMPARE(countSpy.count(), 2);
|
|
|
|
QCOMPARE(emptySpy.count(), 0);
|
2024-06-28 09:25:03 +00:00
|
|
|
QCOMPARE(modelCount.count(), 4);
|
2024-10-17 10:40:02 +00:00
|
|
|
QCOMPARE(modelCount.empty(), false);
|
2024-06-28 09:25:03 +00:00
|
|
|
|
|
|
|
model.invert();
|
|
|
|
|
2024-10-17 10:40:02 +00:00
|
|
|
QCOMPARE(countSpy.count(), 2);
|
|
|
|
QCOMPARE(emptySpy.count(), 0);
|
2024-06-28 09:25:03 +00:00
|
|
|
QCOMPARE(modelCount.count(), 4);
|
2024-10-17 10:40:02 +00:00
|
|
|
QCOMPARE(modelCount.empty(), false);
|
2024-06-28 09:25:03 +00:00
|
|
|
|
|
|
|
model.removeEverySecond();
|
|
|
|
|
2024-10-17 10:40:02 +00:00
|
|
|
QCOMPARE(countSpy.count(), 3);
|
|
|
|
QCOMPARE(emptySpy.count(), 0);
|
2024-06-28 09:25:03 +00:00
|
|
|
QCOMPARE(modelCount.count(), 2);
|
2024-10-17 10:40:02 +00:00
|
|
|
QCOMPARE(modelCount.empty(), false);
|
2024-06-28 09:25:03 +00:00
|
|
|
|
|
|
|
model.reset();
|
|
|
|
|
2024-10-17 10:40:02 +00:00
|
|
|
QCOMPARE(countSpy.count(), 3);
|
|
|
|
QCOMPARE(emptySpy.count(), 0);
|
2024-06-28 09:25:03 +00:00
|
|
|
QCOMPARE(modelCount.count(), 2);
|
2024-10-17 10:40:02 +00:00
|
|
|
QCOMPARE(modelCount.empty(), false);
|
2024-06-28 09:25:03 +00:00
|
|
|
|
|
|
|
model.resetAndClear();
|
|
|
|
|
2024-10-17 10:40:02 +00:00
|
|
|
QCOMPARE(countSpy.count(), 4);
|
|
|
|
QCOMPARE(emptySpy.count(), 1);
|
2024-06-28 09:25:03 +00:00
|
|
|
QCOMPARE(modelCount.count(), 0);
|
2024-10-17 10:40:02 +00:00
|
|
|
QCOMPARE(modelCount.empty(), true);
|
2024-06-28 09:25:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
QTEST_MAIN(TestModelCount)
|
|
|
|
#include "tst_ModelCount.moc"
|