diff options
| author | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:03 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:03 +0200 |
| commit | 059831534c7e884f0a607ed86b582fd00d821731 (patch) | |
| tree | 76bcb67a78f8aa2654fd34c2ad801a62136b0170 /tests/unit/common/test_active_station_list.cpp | |
| parent | d83a420f0517d7fc47aeb288a6a0cf4891784fcc (diff) | |
New upstream version 3.2.0~rc1+dfsgupstream/3.2.0_rc1+dfsg
Diffstat (limited to 'tests/unit/common/test_active_station_list.cpp')
| -rw-r--r-- | tests/unit/common/test_active_station_list.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/unit/common/test_active_station_list.cpp b/tests/unit/common/test_active_station_list.cpp new file mode 100644 index 00000000..b07933fe --- /dev/null +++ b/tests/unit/common/test_active_station_list.cpp @@ -0,0 +1,67 @@ +#include <QtTest> + +#include "ActiveStationList.hpp" + +class TestActiveStationList : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void limitsAscendingRows(); + void limitsDescendingRows(); + void preservesEqualKeyOrder(); + void handlesEmptyAndZeroLimit(); +}; + +void TestActiveStationList::limitsAscendingRows() +{ + QVector<ActiveStationListItem> rows; + for(int i=59; i>=0; --i) rows.append({float(i), QString::number(i)}); + + auto const limited=sorted_limited_active_station_items(rows, 50, false); + + QCOMPARE(limited.size(), 50); + QCOMPARE(limited.front().text, QString {"0"}); + QCOMPARE(limited.back().text, QString {"49"}); +} + +void TestActiveStationList::limitsDescendingRows() +{ + QVector<ActiveStationListItem> rows; + for(int i=0; i<60; ++i) rows.append({float(i), QString::number(i)}); + + auto const limited=sorted_limited_active_station_items(rows, 50, true); + + QCOMPARE(limited.size(), 50); + QCOMPARE(limited.front().text, QString {"59"}); + QCOMPARE(limited.back().text, QString {"10"}); +} + +void TestActiveStationList::preservesEqualKeyOrder() +{ + QVector<ActiveStationListItem> rows { + {2.0f, "first"}, + {1.0f, "low"}, + {2.0f, "second"}, + {2.0f, "third"} + }; + + auto const limited=sorted_limited_active_station_items(rows, 4, true); + + QCOMPARE(limited[0].text, QString {"first"}); + QCOMPARE(limited[1].text, QString {"second"}); + QCOMPARE(limited[2].text, QString {"third"}); + QCOMPARE(limited[3].text, QString {"low"}); +} + +void TestActiveStationList::handlesEmptyAndZeroLimit() +{ + QVERIFY(sorted_limited_active_station_items({}, 50, false).isEmpty()); + + QVector<ActiveStationListItem> rows {{1.0f, "row"}}; + QVERIFY(sorted_limited_active_station_items(rows, 0, false).isEmpty()); +} + +QTEST_MAIN(TestActiveStationList) + +#include "test_active_station_list.moc" |
