~ubuntu-branches/ubuntu/vivid/qt3d-opensource-src/vivid-proposed

« back to all changes in this revision

Viewing changes to tests/auto/qml3d_cpp/picking/tst_picking.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-08-02 11:10:16 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130802111016-r3cjsz79ulbawpgv
Tags: 5.0~git20130731-0ubuntu1
* New upstream snapshot release
* Improve override_dh_auto_install, use --fail-missing
* Drop patches:
  - add_GPL_license_file.patch, merged upstream
  - add_module_version.patch, added upstream
  - disable_conflicting_examples.patch, not needed anymore
* Refresh link_against_system_zlib.patch
* Add bug link to workaround_zlib_linking_issue.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
**
 
3
** Copyright (C) 2011 - 2013 Research In Motion
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the Qt3D module of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
17
** GNU Lesser General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Lesser
 
19
** General Public License version 2.1 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#include <QtTest/QtTest>
 
43
#include <QtQuick/qquickview.h>
 
44
#include <QtQml/qqmlengine.h>
 
45
#include <QtQml/qqmlcontext.h>
 
46
#include <QQuickItem>
 
47
#include <qpa/qwindowsysteminterface.h>
 
48
 
 
49
class tst_Picking : public QObject
 
50
{
 
51
    Q_OBJECT
 
52
public:
 
53
    tst_Picking() {}
 
54
    ~tst_Picking() {}
 
55
 
 
56
private slots:
 
57
    void initTestCase();
 
58
    void cleanupTestCase();
 
59
    void testWithNavigation();
 
60
    void testWithoutNavigation();
 
61
    void testMove();
 
62
 
 
63
private:
 
64
    void testMouse();
 
65
 
 
66
private:
 
67
    QQuickItem *rootObject;
 
68
    QQuickView *window;
 
69
};
 
70
 
 
71
void tst_Picking::initTestCase()
 
72
{
 
73
    window = new QQuickView(0);
 
74
    window->setSource(QUrl::fromLocalFile(QFINDTESTDATA("data/tst_picking.qml")));
 
75
    window->setGeometry(0,0,480,480);
 
76
    window->show();
 
77
    QTest::qWaitForWindowExposed(window);
 
78
    rootObject = window->rootObject();
 
79
}
 
80
 
 
81
void tst_Picking::cleanupTestCase()
 
82
{
 
83
    delete window;
 
84
}
 
85
 
 
86
void tst_Picking::testWithNavigation()
 
87
{
 
88
    rootObject->setProperty("navigation", true);
 
89
    testMouse();
 
90
}
 
91
 
 
92
void tst_Picking::testWithoutNavigation()
 
93
{
 
94
    rootObject->setProperty("navigation", false);
 
95
    testMouse();
 
96
}
 
97
 
 
98
void tst_Picking::testMouse()
 
99
{
 
100
    QTest::mousePress(window, Qt::LeftButton, 0, QPoint(240, 90));
 
101
    QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(240, 90), 300);
 
102
 
 
103
    QTRY_COMPARE(rootObject->property("pickedObjectPressed").toString(), QString("first"));
 
104
    QTRY_COMPARE(rootObject->property("pickedObjectClicked").toString(), QString("first"));
 
105
    QTRY_COMPARE(rootObject->property("pickedObjectReleased").toString(), QString("first"));
 
106
 
 
107
    QTest::mousePress(window, Qt::LeftButton, 0, QPoint(240, 320));
 
108
    QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(240, 240),300);
 
109
 
 
110
    QTRY_COMPARE(rootObject->property("pickedObjectPressed").toString(), QString("second"));
 
111
    QTRY_COMPARE(rootObject->property("pickedObjectClicked").toString(), QString("first"));
 
112
    QTRY_COMPARE(rootObject->property("pickedObjectReleased").toString(), QString("second"));
 
113
 
 
114
    QTest::mousePress(window, Qt::LeftButton, 0, QPoint(20, 100));
 
115
    QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(20, 100), 300);
 
116
 
 
117
    QTRY_COMPARE(rootObject->property("pickedObjectPressed").toString(), QString("second"));
 
118
    QTRY_COMPARE(rootObject->property("pickedObjectClicked").toString(), QString("first"));
 
119
    QTRY_COMPARE(rootObject->property("pickedObjectReleased").toString(), QString("second"));
 
120
}
 
121
 
 
122
void tst_Picking::testMove()
 
123
{
 
124
    rootObject->setProperty("hoveredObject", "");
 
125
    QTest::mouseMove(window, QPoint(240, 90));
 
126
    QTRY_COMPARE(rootObject->property("hoveredObject").toString(), QString("first"));
 
127
 
 
128
    QTest::mouseMove(window, QPoint(240, 200));
 
129
    QTRY_COMPARE(rootObject->property("hoveredObject").toString(), QString(""));
 
130
}
 
131
 
 
132
QTEST_MAIN(tst_Picking)
 
133
 
 
134
#include "tst_picking.moc"