2
* Copyright (C) 2014-2015 Canonical, Ltd.
4
* This program is free software: you can redistribute it and/or modify it under
5
* the terms of the GNU Lesser General Public License version 3, as published by
6
* the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but WITHOUT
9
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10
* SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
* Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
#define MIR_INCLUDE_DEPRECATED_EVENT_HEADER
19
#include <gtest/gtest.h>
21
#include <QLoggingCategory>
25
#include <Unity/Application/mirsurfaceitem.h>
28
#include <fake_mirsurface.h>
30
using namespace qtmir;
32
class MirSurfaceItemTest : public ::testing::Test
37
setenv("QT_QPA_PLATFORM", "minimal", 1);
39
char **argv = nullptr;
40
m_app = new QGuiApplication(argc, argv);
42
// We don't want the logging spam cluttering the test results
43
QLoggingCategory::setFilterRules(QStringLiteral("qtmir.surfaces=false"));
45
virtual ~MirSurfaceItemTest()
49
QGuiApplication *m_app;
53
Tests that even if Qt fails to finish a touch sequence, MirSurfaceItem will
54
properly finish it when forwarding it to its mir::input::surface. So
55
mir::input::surface will still consume a proper sequence of touch events
56
(comprised of a begin, zero or more updates and an end).
58
TEST_F(MirSurfaceItemTest, MissingTouchEnd)
60
MirSurfaceItem *surfaceItem = new MirSurfaceItem;
62
FakeMirSurface *fakeSurface = new FakeMirSurface;
64
surfaceItem->setSurface(fakeSurface);
65
surfaceItem->setConsumesInput(true);
67
ulong timestamp = 1234;
68
QList<QTouchEvent::TouchPoint> touchPoints;
69
touchPoints.append(QTouchEvent::TouchPoint());
71
touchPoints[0].setId(0);
72
touchPoints[0].setState(Qt::TouchPointPressed);
73
surfaceItem->processTouchEvent(QEvent::TouchBegin,
74
timestamp, Qt::NoModifier, touchPoints, touchPoints[0].state());
76
touchPoints[0].setState(Qt::TouchPointMoved);
77
surfaceItem->processTouchEvent(QEvent::TouchUpdate,
78
timestamp + 10, Qt::NoModifier, touchPoints, touchPoints[0].state());
80
// Starting a new touch sequence (with touch 1) without ending the current one
81
// (wich has touch 0).
82
touchPoints[0].setId(1);
83
touchPoints[0].setState(Qt::TouchPointPressed);
84
surfaceItem->processTouchEvent(QEvent::TouchBegin,
85
timestamp + 20, Qt::NoModifier, touchPoints, touchPoints[0].state());
88
auto touchesReceived = fakeSurface->touchesReceived();
90
// MirSurface should have received 4 events:
93
// 3 - (id=0,up) <- that's the one MirSurfaceItem should have synthesized to keep the event stream sane.
95
ASSERT_EQ(4, touchesReceived.count());
97
ASSERT_EQ(0, touchesReceived[0].touchPoints[0].id());
98
ASSERT_EQ(Qt::TouchPointPressed, touchesReceived[0].touchPoints[0].state());
100
ASSERT_EQ(0, touchesReceived[1].touchPoints[0].id());
101
ASSERT_EQ(Qt::TouchPointMoved, touchesReceived[1].touchPoints[0].state());
103
ASSERT_EQ(0, touchesReceived[2].touchPoints[0].id());
104
ASSERT_EQ(Qt::TouchPointReleased, touchesReceived[2].touchPoints[0].state());
106
ASSERT_EQ(1, touchesReceived[3].touchPoints[0].id());
107
ASSERT_EQ(Qt::TouchPointPressed, touchesReceived[3].touchPoints[0].state());
113
TEST_F(MirSurfaceItemTest, SetSurfaceInitializesVisiblity)
115
MirSurfaceItem *surfaceItem = new MirSurfaceItem;
116
surfaceItem->setVisible(false);
118
FakeMirSurface *fakeSurface = new FakeMirSurface;
119
surfaceItem->setSurface(fakeSurface);
121
EXPECT_FALSE(fakeSurface->visible());
127
TEST_F(MirSurfaceItemTest, AggregateSurfaceVisibility)
129
MirSurfaceItem *surfaceItem1 = new MirSurfaceItem;
130
surfaceItem1->setVisible(true);
131
MirSurfaceItem *surfaceItem2 = new MirSurfaceItem;
132
surfaceItem1->setVisible(true);
134
FakeMirSurface *fakeSurface = new FakeMirSurface;
135
surfaceItem1->setSurface(fakeSurface);
136
surfaceItem2->setSurface(fakeSurface);
138
EXPECT_TRUE(fakeSurface->visible());
140
surfaceItem1->setVisible(false);
141
EXPECT_TRUE(fakeSurface->visible());
143
surfaceItem2->setVisible(false);
144
EXPECT_FALSE(fakeSurface->visible());
146
surfaceItem1->setVisible(true);
147
EXPECT_TRUE(fakeSurface->visible());
150
EXPECT_FALSE(fakeSurface->visible());