Commit 7053378f authored by Ulf Hermann's avatar Ulf Hermann Committed by Kai Koehne
Browse files

Timeline: Complete test coverage of TimelineModel.



Change-Id: If27c51b1189bc0bb0333837c58849bc79b779845
Reviewed-by: default avatarKai Koehne <kai.koehne@theqtcompany.com>
parent 0e267a55
......@@ -4,7 +4,7 @@ QtcAutotest {
Depends { name: "Timeline" }
Depends { name: "Qt.gui" }
name: "Timeline Model autotest"
name: "TimelineModel autotest"
Group {
name: "Test sources"
files: [
......
......@@ -30,27 +30,31 @@
#include <QtTest>
#include <QColor>
#include <timeline/timelinemodel.h>
#include <timeline/timelinemodel_p.h>
static const int DefaultRowHeight = 30;
static const int NumItems = 10;
static const int NumItems = 32;
static const qint64 ItemDuration = 1 << 19;
static const qint64 ItemSpacing = 1 << 20;
class DummyModelPrivate;
class DummyModelPrivate : public Timeline::TimelineModel::TimelineModelPrivate {
public:
DummyModelPrivate(int modelId) :
Timeline::TimelineModel::TimelineModelPrivate(modelId, QLatin1String("horst"))
{}
};
class DummyModel : public Timeline::TimelineModel
{
Q_OBJECT
friend class tst_TimelineModel;
public:
DummyModel(int modelId);
DummyModel(QString displayName = tr("dummy"), QObject *parent = 0);
int typeId(int index) const { return index; }
QColor color(int) const { return QColor(); }
QVariantList labels() const { return QVariantList(); }
QVariantMap details(int) const { return QVariantMap(); }
int expandedRow(int) const { return 1; }
int expandedRow(int) const { return 2; }
int collapsedRow(int) const { return 1; }
quint64 features() const { return 0; }
protected:
void loadData();
......@@ -60,31 +64,67 @@ class tst_TimelineModel : public QObject
{
Q_OBJECT
public:
const int DefaultRowHeight;
tst_TimelineModel();
private slots:
void privateModel();
void isEmpty();
void modelId();
void rowHeight();
void rowOffset();
void height();
void count();
void times();
void selectionId();
void firstLast();
void expand();
void hide();
void displayName();
void defaultValues();
void row();
void colorByHue();
void colorBySelectionId();
void colorByFraction();
void supportedRenderPasses();
void insertStartEnd();
void rowCount();
void prevNext();
};
DummyModel::DummyModel(int modelId) :
Timeline::TimelineModel(*new DummyModelPrivate(modelId), 0)
{
}
DummyModel::DummyModel(QString displayName, QObject *parent) :
TimelineModel(0, displayName, parent)
TimelineModel(12, displayName, parent)
{
}
void DummyModel::loadData()
{
for (int i = 0; i < NumItems; ++i)
insert(i * ItemSpacing, ItemDuration, 5);
for (int i = 0; i < NumItems / 4; ++i) {
insert((i / 3) * ItemSpacing, ItemDuration * (i + 1) + 2, 4);
insert((i / 3) * ItemSpacing + 1, ItemDuration * (i + 1), 5);
insert(i * ItemSpacing / 3 + 1, ItemDuration * (i + 1) + 3, 6);
insert(i * ItemSpacing / 3 + 2, 1, 7);
}
computeNesting();
setCollapsedRowCount(2);
setExpandedRowCount(2);
setExpandedRowCount(3);
}
tst_TimelineModel::tst_TimelineModel() :
DefaultRowHeight(Timeline::TimelineModel::defaultRowHeight())
{
}
void tst_TimelineModel::privateModel()
{
DummyModel dummy(15);
QCOMPARE(dummy.modelId(), 15);
}
void tst_TimelineModel::isEmpty()
......@@ -97,13 +137,23 @@ void tst_TimelineModel::isEmpty()
QVERIFY(dummy.isEmpty());
}
void tst_TimelineModel::modelId()
{
DummyModel dummy;
QCOMPARE(dummy.modelId(), 12);
}
void tst_TimelineModel::rowHeight()
{
DummyModel dummy;
QCOMPARE(dummy.rowHeight(0), DefaultRowHeight);
QCOMPARE(dummy.collapsedRowHeight(0), DefaultRowHeight);
QCOMPARE(dummy.expandedRowHeight(0), DefaultRowHeight);
dummy.setExpandedRowHeight(0, 100);
QCOMPARE(dummy.rowHeight(0), DefaultRowHeight);
QCOMPARE(dummy.collapsedRowHeight(0), DefaultRowHeight);
QCOMPARE(dummy.expandedRowHeight(0), 100);
dummy.setExpanded(true);
QCOMPARE(dummy.rowHeight(0), 100);
......@@ -129,6 +179,10 @@ void tst_TimelineModel::rowHeight()
dummy.setExpanded(true);
QCOMPARE(dummy.rowHeight(0), 100);
QCOMPARE(dummy.rowHeight(1), 50);
QSignalSpy expandedSpy(&dummy, SIGNAL(expandedRowHeightChanged(int,int)));
dummy.clear();
QCOMPARE(expandedSpy.count(), 1);
}
void tst_TimelineModel::rowOffset()
......@@ -140,10 +194,15 @@ void tst_TimelineModel::rowOffset()
dummy.setExpanded(true);
QCOMPARE(dummy.rowOffset(0), 0);
QCOMPARE(dummy.rowOffset(1), DefaultRowHeight);
QCOMPARE(dummy.collapsedRowOffset(1), DefaultRowHeight);
QCOMPARE(dummy.expandedRowOffset(1), DefaultRowHeight);
dummy.setExpandedRowHeight(0, 100);
QCOMPARE(dummy.rowOffset(0), 0);
QCOMPARE(dummy.rowOffset(1), 100);
QCOMPARE(dummy.collapsedRowOffset(1), DefaultRowHeight);
QCOMPARE(dummy.expandedRowOffset(1), 100);
QCOMPARE(dummy.expandedRowOffset(2), 100 + DefaultRowHeight);
dummy.setExpandedRowHeight(1, 50);
QCOMPARE(dummy.rowOffset(0), 0);
......@@ -153,6 +212,9 @@ void tst_TimelineModel::rowOffset()
dummy.setExpanded(false);
QCOMPARE(dummy.rowOffset(0), 0);
QCOMPARE(dummy.rowOffset(1), DefaultRowHeight);
QCOMPARE(dummy.collapsedRowOffset(1), DefaultRowHeight);
QCOMPARE(dummy.expandedRowOffset(1), 100);
QCOMPARE(dummy.expandedRowOffset(2), 150);
// ... but restored when re-expanding
dummy.setExpanded(true);
......@@ -167,9 +229,58 @@ void tst_TimelineModel::height()
dummy.loadData();
QCOMPARE(dummy.height(), 2 * DefaultRowHeight);
dummy.setExpanded(true);
QCOMPARE(dummy.height(), 2 * DefaultRowHeight);
QCOMPARE(dummy.height(), 3 * DefaultRowHeight);
dummy.setExpandedRowHeight(0, 80);
QCOMPARE(dummy.height(), DefaultRowHeight + 80);
QCOMPARE(dummy.height(), 2 * DefaultRowHeight + 80);
}
void tst_TimelineModel::count()
{
DummyModel dummy;
QCOMPARE(dummy.count(), 0);
dummy.loadData();
QCOMPARE(dummy.count(), NumItems);
QSignalSpy emptySpy(&dummy, SIGNAL(emptyChanged()));
dummy.clear();
QCOMPARE(emptySpy.count(), 1);
QCOMPARE(dummy.count(), 0);
}
void tst_TimelineModel::times()
{
DummyModel dummy;
dummy.loadData();
QCOMPARE(dummy.startTime(0), 0);
QCOMPARE(dummy.duration(0), ItemDuration + 2);
QCOMPARE(dummy.endTime(0), ItemDuration + 2);
}
void tst_TimelineModel::selectionId()
{
DummyModel dummy;
dummy.loadData();
QCOMPARE(dummy.selectionId(0), 4);
}
void tst_TimelineModel::firstLast()
{
DummyModel dummy;
QCOMPARE(dummy.firstIndex(0), -1);
QCOMPARE(dummy.firstIndex(ItemSpacing), -1);
QCOMPARE(dummy.lastIndex(0), -1);
QCOMPARE(dummy.lastIndex(ItemSpacing), -1);
dummy.insert(0, 10, 5); // test special case for only one item
QCOMPARE(dummy.firstIndex(5), 0);
QCOMPARE(dummy.lastIndex(5), 0);
dummy.clear();
dummy.loadData();
QCOMPARE(dummy.firstIndex(0), 2);
QCOMPARE(dummy.firstIndex(ItemSpacing + 1), 2);
QCOMPARE(dummy.lastIndex(0), -1);
QCOMPARE(dummy.lastIndex(ItemSpacing + 1), 14);
QCOMPARE(dummy.firstIndex(ItemDuration * 5000), -1);
QCOMPARE(dummy.lastIndex(ItemDuration * 5000), NumItems - 1);
}
void tst_TimelineModel::expand()
......@@ -227,6 +338,16 @@ void tst_TimelineModel::defaultValues()
QCOMPARE(dummy.relativeHeight(0), 1.0);
QCOMPARE(dummy.rowMinValue(0), 0);
QCOMPARE(dummy.rowMaxValue(0), 0);
QCOMPARE(dummy.typeId(0), -1);
}
void tst_TimelineModel::row()
{
DummyModel dummy;
dummy.loadData();
QCOMPARE(dummy.row(0), 1);
dummy.setExpanded(true);
QCOMPARE(dummy.row(0), 2);
}
void tst_TimelineModel::colorByHue()
......@@ -249,6 +370,66 @@ void tst_TimelineModel::colorByFraction()
QCOMPARE(dummy.colorByFraction(0.5), QColor::fromHsl(0.5 * 96 + 10, 150, 166));
}
void tst_TimelineModel::supportedRenderPasses()
{
DummyModel dummy;
QVERIFY(!dummy.supportedRenderPasses().isEmpty());
}
void tst_TimelineModel::insertStartEnd()
{
DummyModel dummy;
int id = dummy.insertStart(10, 0);
dummy.insertEnd(id, 10);
QCOMPARE(dummy.startTime(id), 10);
QCOMPARE(dummy.endTime(id), 20);
int id2 = dummy.insertStart(5, 3);
dummy.insertEnd(id2, 10);
QCOMPARE(dummy.startTime(id2), 5);
QCOMPARE(dummy.endTime(id2), 15);
}
void tst_TimelineModel::rowCount()
{
DummyModel dummy;
QSignalSpy expandedSpy(&dummy, SIGNAL(expandedRowCountChanged()));
QSignalSpy collapsedSpy(&dummy, SIGNAL(collapsedRowCountChanged()));
QCOMPARE(dummy.rowCount(), 1);
dummy.setExpanded(true);
QCOMPARE(dummy.rowCount(), 1);
dummy.loadData();
QCOMPARE(expandedSpy.count(), 1);
QCOMPARE(collapsedSpy.count(), 1);
QCOMPARE(dummy.rowCount(), 3);
dummy.setExpanded(false);
QCOMPARE(dummy.rowCount(), 2);
dummy.clear();
QCOMPARE(expandedSpy.count(), 2);
QCOMPARE(collapsedSpy.count(), 2);
QCOMPARE(dummy.rowCount(), 1);
}
void tst_TimelineModel::prevNext()
{
DummyModel dummy;
QCOMPARE(dummy.nextItemBySelectionId(5, 10, 5), -1);
QCOMPARE(dummy.prevItemBySelectionId(5, 10, 5), -1);
dummy.loadData();
QCOMPARE(dummy.nextItemBySelectionId(5, 5000 * ItemSpacing, -1), 3);
QCOMPARE(dummy.prevItemBySelectionId(5, 5000 * ItemSpacing, -1), 28);
QCOMPARE(dummy.nextItemBySelectionId(15, 10, -1), -1);
QCOMPARE(dummy.prevItemBySelectionId(15, 10, -1), -1);
QCOMPARE(dummy.nextItemBySelectionId(5, 10, -1), 15);
QCOMPARE(dummy.prevItemBySelectionId(5, 10, -1), 6);
QCOMPARE(dummy.nextItemBySelectionId(5, 10, 5), 6);
QCOMPARE(dummy.prevItemBySelectionId(5, 10, 5), 3);
QCOMPARE(dummy.nextItemByTypeId(-1, 10, 5), 6);
QCOMPARE(dummy.prevItemByTypeId(-1, 10, 5), 4);
}
QTEST_MAIN(tst_TimelineModel)
#include "tst_timelinemodel.moc"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment