summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2015-04-16 18:05:46 +0200
committerUlf Hermann <ulf.hermann@theqtcompany.com>2015-05-18 12:38:33 +0000
commitf356aae5f9c435e1d69156d11b709e1ee41909f4 (patch)
tree6add9969ae552d0527dc3932c74239c50f0504bf /tests
parent445c7f0014df37c078ca44439bdbe180a3900af7 (diff)
downloadqt-creator-f356aae5f9c435e1d69156d11b709e1ee41909f4.tar.gz
Timeline: Test TimelineZoomControl
Change-Id: I7053848aa5c77228ef2ce760899f411cf35c3c25 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/timeline/timeline.pro3
-rw-r--r--tests/auto/timeline/timeline.qbs3
-rw-r--r--tests/auto/timeline/timelinezoomcontrol/timelinezoomcontrol.pro4
-rw-r--r--tests/auto/timeline/timelinezoomcontrol/timelinezoomcontrol.qbs12
-rw-r--r--tests/auto/timeline/timelinezoomcontrol/tst_timelinezoomcontrol.cpp227
5 files changed, 247 insertions, 2 deletions
diff --git a/tests/auto/timeline/timeline.pro b/tests/auto/timeline/timeline.pro
index fc52112964..e493845a57 100644
--- a/tests/auto/timeline/timeline.pro
+++ b/tests/auto/timeline/timeline.pro
@@ -9,7 +9,8 @@ SUBDIRS = \
timelineoverviewrenderer \
timelinerenderer \
timelinerenderpass \
- timelinerenderstate
+ timelinerenderstate \
+ timelinezoomcontrol
minQtVersion(5,4,0) {
SUBDIRS += \
diff --git a/tests/auto/timeline/timeline.qbs b/tests/auto/timeline/timeline.qbs
index b3b67a7182..27cf27bc79 100644
--- a/tests/auto/timeline/timeline.qbs
+++ b/tests/auto/timeline/timeline.qbs
@@ -16,6 +16,7 @@ Project {
"timelinerenderer/timelinerenderer.qbs",
"timelinerenderpass/timelinerenderpass.qbs",
"timelinerenderstate/timelinerenderstate.qbs",
- "timelineselectionrenderpass/timelineselectionrenderpass.qbs"
+ "timelineselectionrenderpass/timelineselectionrenderpass.qbs",
+ "timelinezoomcontrol/timelinezoomcontrol.qbs"
]
}
diff --git a/tests/auto/timeline/timelinezoomcontrol/timelinezoomcontrol.pro b/tests/auto/timeline/timelinezoomcontrol/timelinezoomcontrol.pro
new file mode 100644
index 0000000000..41b11637e0
--- /dev/null
+++ b/tests/auto/timeline/timelinezoomcontrol/timelinezoomcontrol.pro
@@ -0,0 +1,4 @@
+include(../shared/shared.pri)
+
+SOURCES += \
+ tst_timelinezoomcontrol.cpp
diff --git a/tests/auto/timeline/timelinezoomcontrol/timelinezoomcontrol.qbs b/tests/auto/timeline/timelinezoomcontrol/timelinezoomcontrol.qbs
new file mode 100644
index 0000000000..6f189d16b9
--- /dev/null
+++ b/tests/auto/timeline/timelinezoomcontrol/timelinezoomcontrol.qbs
@@ -0,0 +1,12 @@
+import qbs
+import "../timelineautotest.qbs" as TimelineAutotest
+
+TimelineAutotest {
+ name: "TimelineZoomcontrol autotest"
+ Group {
+ name: "Test sources"
+ files: [
+ "tst_timelinezoomcontrol.cpp"
+ ]
+ }
+}
diff --git a/tests/auto/timeline/timelinezoomcontrol/tst_timelinezoomcontrol.cpp b/tests/auto/timeline/timelinezoomcontrol/tst_timelinezoomcontrol.cpp
new file mode 100644
index 0000000000..8e3ec78308
--- /dev/null
+++ b/tests/auto/timeline/timelinezoomcontrol/tst_timelinezoomcontrol.cpp
@@ -0,0 +1,227 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include <QtTest>
+#include <QColor>
+#include <timeline/timelinezoomcontrol.h>
+
+class tst_TimelineZoomControl : public QObject
+{
+ Q_OBJECT
+private:
+ void verifyWindow(const Timeline::TimelineZoomControl &zoomControl);
+
+private slots:
+ void trace();
+ void window();
+ void range();
+ void selection();
+};
+
+void tst_TimelineZoomControl::verifyWindow(const Timeline::TimelineZoomControl &zoomControl)
+{
+ QVERIFY(zoomControl.windowStart() <= zoomControl.rangeStart());
+ QVERIFY(zoomControl.windowEnd() >= zoomControl.rangeEnd());
+ QVERIFY(zoomControl.traceStart() <= zoomControl.windowStart());
+ QVERIFY(zoomControl.traceEnd() >= zoomControl.windowEnd());
+}
+
+void tst_TimelineZoomControl::trace()
+{
+ Timeline::TimelineZoomControl zoomControl;
+ QSignalSpy spy(&zoomControl, SIGNAL(traceChanged(qint64,qint64)));
+ QCOMPARE(zoomControl.traceStart(), -1);
+ QCOMPARE(zoomControl.traceEnd(), -1);
+ QCOMPARE(zoomControl.traceDuration(), 0);
+
+ zoomControl.setTrace(100, 200);
+ QCOMPARE(zoomControl.traceStart(), 100);
+ QCOMPARE(zoomControl.traceEnd(), 200);
+ QCOMPARE(zoomControl.traceDuration(), 100);
+ QCOMPARE(spy.count(), 1);
+
+ zoomControl.clear();
+ QCOMPARE(zoomControl.traceStart(), -1);
+ QCOMPARE(zoomControl.traceEnd(), -1);
+ QCOMPARE(zoomControl.traceDuration(), 0);
+ QCOMPARE(spy.count(), 2);
+}
+
+void tst_TimelineZoomControl::window()
+{
+ Timeline::TimelineZoomControl zoomControl;
+
+ QTimer timer;
+ timer.setSingleShot(true);
+ connect(&timer, &QTimer::timeout, [&](){
+ QVERIFY(zoomControl.windowLocked());
+ zoomControl.setWindowLocked(false);
+ });
+
+ int numWindowChanges = 0;
+
+ connect(&zoomControl, &Timeline::TimelineZoomControl::windowChanged,
+ [&](qint64, qint64) {
+ verifyWindow(zoomControl);
+
+ QVERIFY(!timer.isActive());
+ if (++numWindowChanges == 9) { // delay a bit during a move
+ zoomControl.setWindowLocked(true);
+ timer.start(300);
+ }
+ });
+
+ QCOMPARE(zoomControl.windowStart(), -1);
+ QCOMPARE(zoomControl.windowEnd(), -1);
+ QCOMPARE(zoomControl.windowDuration(), 0);
+
+ zoomControl.setTrace(100, 200);
+ QCOMPARE(zoomControl.windowStart(), 100);
+ QCOMPARE(zoomControl.windowEnd(), 200);
+ QCOMPARE(zoomControl.windowDuration(), 100);
+
+ zoomControl.clear();
+ QCOMPARE(zoomControl.windowStart(), -1);
+ QCOMPARE(zoomControl.windowEnd(), -1);
+ QCOMPARE(zoomControl.windowDuration(), 0);
+
+ zoomControl.setTrace(100000, 200000);
+ QCOMPARE(zoomControl.windowStart(), 100000);
+ QVERIFY(zoomControl.windowEnd() < 110000);
+
+ zoomControl.setRange(199995, 200000); // jump to end
+ verifyWindow(zoomControl);
+ zoomControl.setRange(100000, 100005); // jump to start
+ verifyWindow(zoomControl);
+
+ zoomControl.setRange(150000, 150005);
+ zoomControl.setRange(152000, 152005); // move right
+
+ QMetaObject::Connection connection = connect(
+ &zoomControl, &Timeline::TimelineZoomControl::windowMovingChanged,
+ [&](bool moving) {
+ if (moving)
+ return;
+
+ verifyWindow(zoomControl);
+ if (zoomControl.windowEnd() == zoomControl.traceEnd()) {
+ zoomControl.setRange(104005, 104010); // jump left
+ verifyWindow(zoomControl);
+ zoomControl.setRange(102005, 102010); // make sure it doesn't overrun trace start
+ } else if (zoomControl.windowStart() == zoomControl.traceStart()) {
+ qApp->exit();
+ } else {
+ QVERIFY(zoomControl.rangeStart() - zoomControl.windowStart() ==
+ zoomControl.windowEnd() - zoomControl.rangeEnd());
+ if (zoomControl.rangeStart() == 152000) {
+ zoomControl.setRange(150000, 150005); // move left
+ } else if (zoomControl.rangeStart() == 150000) {
+ zoomControl.setRange(196990, 196995); // jump right
+ verifyWindow(zoomControl);
+ zoomControl.setRange(198990, 198995); // make sure it doesn't overrun trace end
+ }
+ }
+ verifyWindow(zoomControl);
+ });
+
+ qApp->exec();
+
+ disconnect(connection);
+
+ bool stopDetected = false;
+ connect(&zoomControl, &Timeline::TimelineZoomControl::windowMovingChanged, [&](bool moving) {
+ if (!moving) {
+ QCOMPARE(stopDetected, false);
+ stopDetected = true;
+ } else {
+ zoomControl.clear();
+ QCOMPARE(zoomControl.windowStart(), -1);
+ QCOMPARE(zoomControl.windowEnd(), -1);
+ QCOMPARE(zoomControl.rangeStart(), -1);
+ QCOMPARE(zoomControl.rangeEnd(), -1);
+ zoomControl.clear(); // no second windowMovingChanged(false), please
+ }
+ });
+
+ zoomControl.setRange(180010, 180015);
+}
+
+void tst_TimelineZoomControl::range()
+{
+ Timeline::TimelineZoomControl zoomControl;
+ QSignalSpy spy(&zoomControl, SIGNAL(rangeChanged(qint64,qint64)));
+ QCOMPARE(zoomControl.rangeStart(), -1);
+ QCOMPARE(zoomControl.rangeEnd(), -1);
+ QCOMPARE(zoomControl.rangeDuration(), 0);
+
+ zoomControl.setTrace(10, 500);
+ QCOMPARE(zoomControl.rangeStart(), 10);
+ QCOMPARE(zoomControl.rangeEnd(), 10);
+ QCOMPARE(zoomControl.rangeDuration(), 0);
+ QCOMPARE(spy.count(), 1);
+
+ zoomControl.setRange(100, 200);
+ QCOMPARE(zoomControl.rangeStart(), 100);
+ QCOMPARE(zoomControl.rangeEnd(), 200);
+ QCOMPARE(zoomControl.rangeDuration(), 100);
+ QCOMPARE(spy.count(), 2);
+
+ zoomControl.clear();
+ QCOMPARE(zoomControl.rangeStart(), -1);
+ QCOMPARE(zoomControl.rangeEnd(), -1);
+ QCOMPARE(zoomControl.rangeDuration(), 0);
+ QCOMPARE(spy.count(), 3);
+}
+
+void tst_TimelineZoomControl::selection()
+{
+ Timeline::TimelineZoomControl zoomControl;
+ QSignalSpy spy(&zoomControl, SIGNAL(selectionChanged(qint64,qint64)));
+ QCOMPARE(zoomControl.selectionStart(), -1);
+ QCOMPARE(zoomControl.selectionEnd(), -1);
+ QCOMPARE(zoomControl.selectionDuration(), 0);
+
+ zoomControl.setTrace(10, 500);
+ zoomControl.setSelection(100, 200);
+ QCOMPARE(zoomControl.selectionStart(), 100);
+ QCOMPARE(zoomControl.selectionEnd(), 200);
+ QCOMPARE(zoomControl.selectionDuration(), 100);
+ QCOMPARE(spy.count(), 1);
+
+ zoomControl.clear();
+ QCOMPARE(zoomControl.selectionStart(), -1);
+ QCOMPARE(zoomControl.selectionEnd(), -1);
+ QCOMPARE(zoomControl.selectionDuration(), 0);
+ QCOMPARE(spy.count(), 2);
+}
+
+QTEST_MAIN(tst_TimelineZoomControl)
+
+#include "tst_timelinezoomcontrol.moc"