a bit of refactor
This commit is contained in:
19 files changed
+546
-232
No files matched your search
@@ -0,0 +1,53 @@
|
||||
#include <QtTest>
|
||||
#include "backend/QDocumentChunkMeasurer.h"
|
||||
|
||||
class QDocumentChunkMeasurerTest : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void returnsOneHeightPerChunk()
|
||||
{
|
||||
QDocumentChunkMeasurer measurer;
|
||||
QStringList chunks = {"<p>First</p>", "<p>Second</p>", "<p>Third</p>"};
|
||||
QVector<qreal> heights = measurer.measure(chunks, 800);
|
||||
QCOMPARE(heights.size(), 3);
|
||||
}
|
||||
|
||||
void heightsArePositive()
|
||||
{
|
||||
QDocumentChunkMeasurer measurer;
|
||||
QStringList chunks = {"<p>Hello world</p>", "<p>Another paragraph</p>"};
|
||||
QVector<qreal> heights = measurer.measure(chunks, 800);
|
||||
for (qreal h : heights)
|
||||
QVERIFY(h > 0.0);
|
||||
}
|
||||
|
||||
void emptyChunkListReturnsEmpty()
|
||||
{
|
||||
QDocumentChunkMeasurer measurer;
|
||||
QVector<qreal> heights = measurer.measure({}, 800);
|
||||
QVERIFY(heights.isEmpty());
|
||||
}
|
||||
|
||||
void zeroWidthClampedToOne()
|
||||
{
|
||||
// Must not crash and must return positive heights
|
||||
QDocumentChunkMeasurer measurer;
|
||||
QStringList chunks = {"<p>text</p>"};
|
||||
QVector<qreal> heights = measurer.measure(chunks, 0);
|
||||
QCOMPARE(heights.size(), 1);
|
||||
QVERIFY(heights.first() > 0.0);
|
||||
}
|
||||
|
||||
void narrowerWidthGivesGreaterOrEqualHeight()
|
||||
{
|
||||
QDocumentChunkMeasurer measurer;
|
||||
QStringList chunks = {"<p>A long paragraph that should wrap when the width is very narrow.</p>"};
|
||||
qreal height800 = measurer.measure(chunks, 800).first();
|
||||
qreal height200 = measurer.measure(chunks, 200).first();
|
||||
QVERIFY(height200 >= height800);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(QDocumentChunkMeasurerTest)
|
||||
#include "QDocumentChunkMeasurerTest.moc"
|
||||
Reference in new issue
Block a user