Refactor using Fable
This commit is contained in:
90 files changed
+2080
-2267
No files matched your search
@@ -0,0 +1,124 @@
|
||||
#include <QtTest>
|
||||
|
||||
#include "backend/reading/MangaPagination.h"
|
||||
|
||||
static QSize portrait() { return {800, 1200}; }
|
||||
static QSize landscape() { return {1600, 1200}; }
|
||||
|
||||
class MangaPaginationTest : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void portraitViewportAllSolo()
|
||||
{
|
||||
MangaPagination p;
|
||||
p.rebuild({portrait(), portrait(), portrait()}, /*landscape=*/false, /*shift=*/true);
|
||||
QCOMPARE(p.count(), 3);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
QCOMPARE(p.at(i).first, i);
|
||||
QCOMPARE(p.at(i).second, -1);
|
||||
}
|
||||
}
|
||||
|
||||
void landscapeCoverSoloThenPairs()
|
||||
{
|
||||
MangaPagination p;
|
||||
// cover + 4 portrait pages, shift off: cover solo, (1,2), (3,4)
|
||||
p.rebuild({portrait(), portrait(), portrait(), portrait(), portrait()},
|
||||
true, /*shift=*/false);
|
||||
QCOMPARE(p.count(), 3);
|
||||
QCOMPARE(p.at(0).first, 0);
|
||||
QCOMPARE(p.at(0).second, -1);
|
||||
QCOMPARE(p.at(1).first, 1);
|
||||
QCOMPARE(p.at(1).second, 2);
|
||||
QCOMPARE(p.at(2).first, 3);
|
||||
QCOMPARE(p.at(2).second, 4);
|
||||
}
|
||||
|
||||
void shiftMakesFirstPageSolo()
|
||||
{
|
||||
MangaPagination p;
|
||||
// shift on: cover solo, page 1 solo, (2,3), 4 solo
|
||||
p.rebuild({portrait(), portrait(), portrait(), portrait(), portrait()},
|
||||
true, /*shift=*/true);
|
||||
QCOMPARE(p.count(), 4);
|
||||
QCOMPARE(p.at(1).first, 1);
|
||||
QCOMPARE(p.at(1).second, -1);
|
||||
QCOMPARE(p.at(2).first, 2);
|
||||
QCOMPARE(p.at(2).second, 3);
|
||||
QCOMPARE(p.at(3).first, 4);
|
||||
QCOMPARE(p.at(3).second, -1);
|
||||
}
|
||||
|
||||
void widePagesStaySolo()
|
||||
{
|
||||
MangaPagination p;
|
||||
// cover, portrait, WIDE, portrait, portrait — wide page must not pair
|
||||
p.rebuild({portrait(), portrait(), landscape(), portrait(), portrait()},
|
||||
true, /*shift=*/false);
|
||||
QCOMPARE(p.count(), 4);
|
||||
QCOMPARE(p.at(1).first, 1);
|
||||
QCOMPARE(p.at(1).second, -1); // can't pair: next is wide
|
||||
QCOMPARE(p.at(2).first, 2);
|
||||
QCOMPARE(p.at(2).second, -1); // wide page solo
|
||||
QCOMPARE(p.at(3).first, 3);
|
||||
QCOMPARE(p.at(3).second, 4);
|
||||
}
|
||||
|
||||
void invalidSizesTreatedAsPortrait()
|
||||
{
|
||||
MangaPagination p;
|
||||
p.rebuild({QSize(), QSize(), QSize()}, true, /*shift=*/false);
|
||||
QCOMPARE(p.count(), 2);
|
||||
QCOMPARE(p.at(1).first, 1);
|
||||
QCOMPARE(p.at(1).second, 2);
|
||||
}
|
||||
|
||||
void pairIndexForChunkFindsBothSlots()
|
||||
{
|
||||
MangaPagination p;
|
||||
p.rebuild({portrait(), portrait(), portrait(), portrait(), portrait()},
|
||||
true, /*shift=*/false);
|
||||
QCOMPARE(p.pairIndexForChunk(0), 0);
|
||||
QCOMPARE(p.pairIndexForChunk(1), 1);
|
||||
QCOMPARE(p.pairIndexForChunk(2), 1);
|
||||
QCOMPARE(p.pairIndexForChunk(3), 2);
|
||||
QCOMPARE(p.pairIndexForChunk(4), 2);
|
||||
QCOMPARE(p.pairIndexForChunk(99), 0); // not found falls back to 0
|
||||
}
|
||||
|
||||
void anchorStableAcrossDoubleToggle()
|
||||
{
|
||||
const QVector<QSize> sizes = {portrait(), portrait(), portrait(),
|
||||
portrait(), portrait()};
|
||||
MangaPagination p;
|
||||
p.rebuild(sizes, true, /*shift=*/false); // pairs: [0], (1,2), (3,4)
|
||||
|
||||
// Viewing pair (1,2); toggle shift ON → anchor on .second (chunk 2)
|
||||
const int anchorOn = p.anchorChunkForShiftToggle(1, /*shiftTurningOn=*/true);
|
||||
QCOMPARE(anchorOn, 2);
|
||||
|
||||
p.rebuild(sizes, true, /*shift=*/true); // pairs: [0], [1], (2,3), [4]
|
||||
const int pairOn = p.pairIndexForChunk(anchorOn);
|
||||
QCOMPARE(pairOn, 2);
|
||||
|
||||
// Toggle back OFF → anchor on .first (chunk 2), land on (1,2) again
|
||||
const int anchorOff = p.anchorChunkForShiftToggle(pairOn, /*shiftTurningOn=*/false);
|
||||
QCOMPARE(anchorOff, 2);
|
||||
p.rebuild(sizes, true, /*shift=*/false);
|
||||
QCOMPARE(p.pairIndexForChunk(anchorOff), 1);
|
||||
}
|
||||
|
||||
void clearEmpties()
|
||||
{
|
||||
MangaPagination p;
|
||||
p.rebuild({portrait()}, false, false);
|
||||
QCOMPARE(p.count(), 1);
|
||||
p.clear();
|
||||
QCOMPARE(p.count(), 0);
|
||||
QCOMPARE(p.at(0).first, -1); // out of range is safe
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(MangaPaginationTest)
|
||||
#include "MangaPaginationTest.moc"
|
||||
Reference in new issue
Block a user