2 * Copyright (C) 2015 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24// Ubuntu.Gestures plugin
25#include <AxisVelocityCalculator.h>
27#include <UbuntuGestures/private/timer_p.h>
33class tst_EdgeDragEvaluator: public QObject
37 tst_EdgeDragEvaluator() {}
39 void initTestCase(); // will be called before the first test function is executed
40 void cleanupTestCase(); // will be called after the last test function was executed.
42 void init(); // called right before each and every test function is executed
43 void cleanup(); // called right after each and every test function is executed
45 void horizontalDirection();
46 void horizontalDirection_data();
49 void drag(qreal &pos, qreal distance, qreal speed);
51 QQuickView *createView();
53 FakeTimer *m_fakeTimer;
54 QSharedPointer<FakeTimeSource> m_fakeTimeSource;
55 AxisVelocityCalculator *m_dragEvaluator;
59void tst_EdgeDragEvaluator::initTestCase()
64void tst_EdgeDragEvaluator::cleanupTestCase()
68void tst_EdgeDragEvaluator::init()
71 m_view = createView();
72 m_view->setSource(QUrl::fromLocalFile(testDataDir() + "/" TEST_DIR "/tst_EdgeDragEvaluator.qml"));
74 QVERIFY(QTest::qWaitForWindowExposed(m_view));
75 QVERIFY(m_view->rootObject() != 0);
76 qApp->processEvents();
78 m_fakeTimeSource.reset(new FakeTimeSource);
79 m_fakeTimer = new FakeTimer(m_fakeTimeSource);
82 m_view->rootObject()->findChild<AxisVelocityCalculator*>("edgeDragEvaluator");
83 QVERIFY(m_dragEvaluator);
84 m_dragEvaluator->setTimeSource(m_fakeTimeSource);
87void tst_EdgeDragEvaluator::cleanup()
89 m_dragEvaluator = nullptr;
97 m_fakeTimeSource.reset();
100QQuickView *tst_EdgeDragEvaluator::createView()
102 QQuickView *window = new QQuickView(0);
103 window->setResizeMode(QQuickView::SizeRootObjectToView);
104 window->engine()->addImportPath(testDataDir() + "/" TEST_DIR);
109void tst_EdgeDragEvaluator::drag(qreal &pos, qreal distance, qreal speed)
112 qreal distanceStep = distance / ((qreal)numSteps);
113 int timeStep = qAbs(distanceStep / speed);
115 for (int i = 0; i < numSteps; ++i) {
116 m_fakeTimeSource->m_msecsSinceReference += timeStep;
118 m_dragEvaluator->setTrackedPosition(pos);
122void tst_EdgeDragEvaluator::horizontalDirection()
124 qreal maxDragDistance = 100.;
125 qreal speedThreshold = 100.;
126 qreal speedThresholdMs = speedThreshold / 1000.;
127 QFETCH(qreal, dragDirection);
129 m_dragEvaluator->setProperty("maxDragDistance", QVariant::fromValue(maxDragDistance));
130 m_dragEvaluator->setProperty("dragThreshold", QVariant::fromValue(maxDragDistance * 0.5));
131 m_dragEvaluator->setProperty("speedThreshold", QVariant::fromValue(speedThreshold));
133 // If direction is "Horizontal" it means it can drag leftwards or rightwards
134 m_dragEvaluator->setProperty("direction", QVariant::fromValue((int)Direction::Horizontal));
137 m_dragEvaluator->setTrackedPosition(pos);
139 // Go far beyond dragThreshold
140 drag(pos, maxDragDistance * 0.75 * dragDirection /*distance*/, speedThresholdMs * 0.5 /*speed*/);
142 // Then come back a bit, getting close to dragThreshold
143 drag(pos, -maxDragDistance * 0.20 * dragDirection /*distance*/, speedThresholdMs * 0.5 /*speed*/);
145 QVariant shouldAutoComplete;
146 bool ok = QMetaObject::invokeMethod(m_dragEvaluator, "shouldAutoComplete", Qt::DirectConnection,
147 Q_RETURN_ARG(QVariant, shouldAutoComplete));
150 // It should not autocomplete because the current negative velocity (speedThresholdMs * 0.5)
151 // is bigger (in absolute terms) than the minimum negative velocity at this position needed to
152 // cancel autocompletion (speedThreshold * 0.1)
153 QCOMPARE(shouldAutoComplete.toBool(), false);
156void tst_EdgeDragEvaluator::horizontalDirection_data()
158 QTest::addColumn<qreal>("dragDirection");
160 QTest::newRow("right") << 1.;
161 QTest::newRow("left") << -1.;
164QTEST_MAIN(tst_EdgeDragEvaluator)
166#include "tst_EdgeDragEvaluator.moc"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list