~ubuntu-branches/ubuntu/trusty/geis/trusty

« back to all changes in this revision

Viewing changes to testsuite/geis2/gtest_gbe_direct_touch_coords.cpp

  • Committer: Package Import Robot
  • Author(s): Chase Douglas
  • Date: 2012-07-30 08:51:42 UTC
  • Revision ID: package-import@ubuntu.com-20120730085142-jrc33ygjvt0ob1wl
Tags: upstream-2.2.11
ImportĀ upstreamĀ versionĀ 2.2.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "gtest_grail_backend.h"
 
2
#include "x11_mocks.h"
 
3
 
 
4
/*
 
5
  Check that when a direct device (e.g. a touchscreen) is being used, the
 
6
  position of a GeisTouch will be in window coordinates instead of input
 
7
  device coordinates.
 
8
 
 
9
  This means that the x an y values of a GeisTouch should come from
 
10
  XIDeviceEvent::event_x and XIDeviceEvent::event_y and not from
 
11
  XIDeviceEvent::valuators.values[0] and XIDeviceEvent::valuators.values[1],
 
12
  like it's the case for indirect devices (such as trackpads).
 
13
 
 
14
  Regression test for https://bugs.launchpad.net/bugs/984069
 
15
 */
 
16
 
 
17
class Geis2GrailBackend : public Geis2GrailBackendBase
 
18
{
 
19
 protected:
 
20
  Geis2GrailBackend() : _subscription(nullptr) {}
 
21
 
 
22
  void SendXInput2Events();
 
23
 
 
24
  virtual void OnEventInitComplete(GeisEvent event);
 
25
  virtual void OnEventGestureBegin(GeisEvent event);
 
26
 
 
27
  GeisSubscription _subscription;
 
28
};
 
29
 
 
30
void Geis2GrailBackend::SendXInput2Events()
 
31
{
 
32
  XEvent event;
 
33
  XGenericEventCookie *xcookie = 0;
 
34
  XIDeviceEvent *device_event = 0;
 
35
  XITouchOwnershipEvent *ownership_event = 0;
 
36
  int serial = 0;
 
37
 
 
38
  event.type = GenericEvent;
 
39
  device_event = (XIDeviceEvent*)calloc(1, sizeof(XIDeviceEvent));
 
40
  device_event->serial = serial++;
 
41
  device_event->display = xmock_display;
 
42
  device_event->extension = xmock_xi2_opcode;
 
43
  device_event->evtype = XI_TouchBegin;
 
44
  device_event->time = xmock_server_time;
 
45
  device_event->deviceid = 0;
 
46
  /* The source device that originally generated the event. */
 
47
  device_event->sourceid = device_event->deviceid;
 
48
  device_event->detail = 0; /* touch id */
 
49
  device_event->root = DefaultRootWindow(xmock_display);
 
50
  device_event->event = DefaultRootWindow(xmock_display);
 
51
  device_event->child = 0;
 
52
  device_event->root_x = 123.0f;
 
53
  device_event->root_y = 456.0f;
 
54
  device_event->event_x = device_event->root_x;
 
55
  device_event->event_y = device_event->root_y;
 
56
  device_event->valuators.mask_len = 2; /* two bytes */
 
57
  device_event->valuators.mask = (unsigned char*) malloc(2);
 
58
  XISetMask(device_event->valuators.mask, 0); /* X axis is present */
 
59
  XISetMask(device_event->valuators.mask, 1); /* Y axis is present */
 
60
  device_event->valuators.values = (double*) malloc(sizeof(double)*2);
 
61
  device_event->valuators.values[0] = -200.0;
 
62
  device_event->valuators.values[1] = -100.0;
 
63
  xcookie = &event.xcookie;
 
64
  xcookie->extension = xmock_xi2_opcode;
 
65
  xcookie->evtype = XI_TouchBegin;
 
66
  xcookie->data = device_event;
 
67
  xmock_add_to_event_queue(&event);
 
68
 
 
69
  event.type = GenericEvent;
 
70
  device_event = (XIDeviceEvent*)calloc(1, sizeof(XIDeviceEvent));
 
71
  device_event->serial = serial++;
 
72
  device_event->display = xmock_display;
 
73
  device_event->extension = xmock_xi2_opcode;
 
74
  device_event->evtype = XI_TouchBegin;
 
75
  device_event->time = xmock_server_time;
 
76
  device_event->deviceid = 0;
 
77
  device_event->sourceid = device_event->deviceid;
 
78
  device_event->detail = 1; /* touch id */
 
79
  device_event->root = DefaultRootWindow(xmock_display);
 
80
  device_event->event = DefaultRootWindow(xmock_display);
 
81
  device_event->child = 0;
 
82
  device_event->root_x = 222.0f;
 
83
  device_event->root_y = 456.0f;
 
84
  device_event->event_x = device_event->root_x;
 
85
  device_event->event_y = device_event->root_y;
 
86
  device_event->valuators.mask_len = 2;
 
87
  device_event->valuators.mask = (unsigned char*) malloc(2);
 
88
  XISetMask(device_event->valuators.mask, 0);
 
89
  XISetMask(device_event->valuators.mask, 1);
 
90
  device_event->valuators.values = (double*) malloc(sizeof(double)*2);
 
91
  device_event->valuators.values[0] = -150.0;
 
92
  device_event->valuators.values[1] = -100.0;
 
93
  xcookie = &event.xcookie;
 
94
  xcookie->extension = xmock_xi2_opcode;
 
95
  xcookie->evtype = XI_TouchBegin;
 
96
  xcookie->data = device_event;
 
97
  xmock_add_to_event_queue(&event);
 
98
 
 
99
  xmock_server_time += 5;
 
100
 
 
101
  event.type = GenericEvent;
 
102
  ownership_event = (XITouchOwnershipEvent*)calloc(1, sizeof(XITouchOwnershipEvent));
 
103
  ownership_event->type = GenericEvent;
 
104
  ownership_event->serial = serial++;
 
105
  ownership_event->display = xmock_display;
 
106
  ownership_event->extension = xmock_xi2_opcode;
 
107
  ownership_event->evtype = XI_TouchOwnership;
 
108
  ownership_event->time = xmock_server_time;
 
109
  ownership_event->deviceid = 0;
 
110
  ownership_event->sourceid = ownership_event->deviceid;
 
111
  ownership_event->touchid = 0;
 
112
  ownership_event->root = DefaultRootWindow(xmock_display);
 
113
  ownership_event->event = DefaultRootWindow(xmock_display);
 
114
  ownership_event->child = 0;
 
115
  xcookie = &event.xcookie;
 
116
  xcookie->extension = xmock_xi2_opcode;
 
117
  xcookie->evtype = XI_TouchOwnership;
 
118
  xcookie->data = ownership_event;
 
119
  xmock_add_to_event_queue(&event);
 
120
 
 
121
  event.type = GenericEvent;
 
122
  ownership_event = (XITouchOwnershipEvent*)calloc(1, sizeof(XITouchOwnershipEvent));
 
123
  ownership_event->type = GenericEvent;
 
124
  ownership_event->serial = serial++;
 
125
  ownership_event->display = xmock_display;
 
126
  ownership_event->extension = xmock_xi2_opcode;
 
127
  ownership_event->evtype = XI_TouchOwnership;
 
128
  ownership_event->time = xmock_server_time;
 
129
  ownership_event->deviceid = 0;
 
130
  ownership_event->sourceid = ownership_event->deviceid;
 
131
  ownership_event->touchid = 1;
 
132
  ownership_event->root = DefaultRootWindow(xmock_display);
 
133
  ownership_event->event = DefaultRootWindow(xmock_display);
 
134
  ownership_event->child = 0;
 
135
  xcookie = &event.xcookie;
 
136
  xcookie->extension = xmock_xi2_opcode;
 
137
  xcookie->evtype = XI_TouchOwnership;
 
138
  xcookie->data = ownership_event;
 
139
  xmock_add_to_event_queue(&event);
 
140
 
 
141
  event.type = GenericEvent;
 
142
  device_event = (XIDeviceEvent*)calloc(1, sizeof(XIDeviceEvent));
 
143
  device_event->serial = serial++;
 
144
  device_event->display = xmock_display;
 
145
  device_event->extension = xmock_xi2_opcode;
 
146
  device_event->evtype = XI_TouchUpdate;
 
147
  device_event->time = xmock_server_time;
 
148
  device_event->deviceid = 0;
 
149
  device_event->sourceid = device_event->deviceid;
 
150
  device_event->detail = 0;
 
151
  device_event->root = DefaultRootWindow(xmock_display);
 
152
  device_event->event = DefaultRootWindow(xmock_display);
 
153
  device_event->child = 0;
 
154
  device_event->root_x = 123.0f;
 
155
  device_event->root_y = 466.0f;
 
156
  device_event->event_x = device_event->root_x;
 
157
  device_event->event_y = device_event->root_y;
 
158
  device_event->valuators.mask_len = 2; /* two bytes */
 
159
  device_event->valuators.mask = (unsigned char*) malloc(2);
 
160
  XISetMask(device_event->valuators.mask, 0);
 
161
  XISetMask(device_event->valuators.mask, 1);
 
162
  device_event->valuators.values = (double*) malloc(sizeof(double)*2);
 
163
  device_event->valuators.values[0] = -200.0;
 
164
  device_event->valuators.values[1] = -90.0;
 
165
  xcookie = &event.xcookie;
 
166
  xcookie->extension = xmock_xi2_opcode;
 
167
  xcookie->evtype = XI_TouchUpdate;
 
168
  xcookie->data = device_event;
 
169
  xmock_add_to_event_queue(&event);
 
170
 
 
171
  event.type = GenericEvent;
 
172
  device_event = (XIDeviceEvent*)calloc(1, sizeof(XIDeviceEvent));
 
173
  device_event->serial = serial++;
 
174
  device_event->display = xmock_display;
 
175
  device_event->extension = xmock_xi2_opcode;
 
176
  device_event->evtype = XI_TouchUpdate;
 
177
  device_event->time = xmock_server_time;
 
178
  device_event->deviceid = 0;
 
179
  device_event->sourceid = device_event->deviceid;
 
180
  device_event->detail = 1; /* touch id */
 
181
  device_event->root = DefaultRootWindow(xmock_display);
 
182
  device_event->event = DefaultRootWindow(xmock_display);
 
183
  device_event->child = 0;
 
184
  device_event->root_x = 222.0f;
 
185
  device_event->root_y = 466.0f;
 
186
  device_event->event_x = device_event->root_x;
 
187
  device_event->event_y = device_event->root_y;
 
188
  device_event->valuators.mask_len = 2;
 
189
  device_event->valuators.mask = (unsigned char*) malloc(2);
 
190
  XISetMask(device_event->valuators.mask, 0);
 
191
  XISetMask(device_event->valuators.mask, 1);
 
192
  device_event->valuators.values = (double*) malloc(sizeof(double)*2);
 
193
  device_event->valuators.values[0] = -150.0;
 
194
  device_event->valuators.values[1] = -90.0;
 
195
  xcookie = &event.xcookie;
 
196
  xcookie->extension = xmock_xi2_opcode;
 
197
  xcookie->evtype = XI_TouchUpdate;
 
198
  xcookie->data = device_event;
 
199
  xmock_add_to_event_queue(&event);
 
200
}
 
201
 
 
202
void Geis2GrailBackend::OnEventInitComplete(GeisEvent event)
 
203
{
 
204
  _subscription = CreateFilteredSubscription(
 
205
      "My 2-touches Touch", 2, GEIS_GESTURE_TOUCH);
 
206
  ASSERT_NE(nullptr, _subscription);
 
207
 
 
208
  SendXInput2Events();
 
209
}
 
210
 
 
211
void Geis2GrailBackend::OnEventGestureBegin(GeisEvent event)
 
212
{
 
213
  GeisAttr attr = geis_event_attr_by_name(event, GEIS_EVENT_ATTRIBUTE_TOUCHSET);
 
214
  GeisTouchSet geis_touch_set = (GeisTouchSet) geis_attr_value_to_pointer(attr);
 
215
 
 
216
  TouchSet touch_set(geis_touch_set);
 
217
 
 
218
  /* check that there are two touch points and that they are in window coordinates
 
219
     (instead of input device coordinates) */
 
220
  ASSERT_EQ(2, touch_set.size());
 
221
  ASSERT_TRUE(touch_set.contains(123.0f, 456.0f));
 
222
  ASSERT_TRUE(touch_set.contains(222.0f, 456.0f));
 
223
}
 
224
 
 
225
TEST_F(Geis2GrailBackend, DirectDeviceTouchCoords)
 
226
{
 
227
  CreateXMockTouchScreenDevice();
 
228
 
 
229
  _geis = geis_new(GEIS_INIT_GRAIL_BACKEND,
 
230
                       nullptr);
 
231
  ASSERT_NE(nullptr, _geis);
 
232
 
 
233
  Run();
 
234
 
 
235
  if (_subscription)
 
236
    geis_subscription_delete(_subscription);
 
237
  geis_delete(_geis);
 
238
 
 
239
  DestroyXMockDevices();
 
240
}