2
* @file geis_backend_test_fixture.c
3
* @brief GEIS mock back end test fixture implementation
5
* Copyright 2010 Canonical Ltd.
7
* This library is free software; you can redistribute it and/or modify it under
8
* the terms of the GNU Lesser General Public License as published by the Free
9
* Software Foundation; either version 3 of the License, or (at your option) any
12
* This library is distributed in the hope that it will be useful, but WITHOUT
13
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#include "geis_config.h"
21
#include "geis_backend.h"
22
#include "geis_backend_protected.h"
24
#include "geis_attr.h"
25
#include "geis_class.h"
26
#include "geis_device.h"
27
#include "geis_event.h"
28
#include "geis_filter.h"
29
#include "geis_filter_term.h"
30
#include "geis_frame.h"
31
#include "geis_group.h"
32
#include "geis_logging.h"
33
#include "geis_private.h"
34
#include "geis_subscription.h"
35
#include "geis_test_api.h"
36
#include "geis_touch.h"
39
#include <sys/socket.h>
43
static inline GeisSize
44
_min(GeisSize a, GeisSize b)
46
return (a < b) ? a : b;
50
static inline GeisSize
51
_max(GeisSize a, GeisSize b)
53
return (a > b) ? a : b;
56
static GeisSize g_min_touches = 1;
57
static GeisSize g_max_touches = 5;
60
typedef struct GeisBackendTestFixture
63
} *GeisBackendTestFixture;
66
typedef struct TestBackendToken
68
struct GeisBackendToken base;
69
GeisBackendTestFixture be;
70
GeisInteger min_touches;
71
GeisInteger max_touches;
74
static inline TestBackendToken
75
_tbtoken_from_token(GeisBackendToken bet)
77
return (TestBackendToken)bet;
80
static GeisBackendToken _token_clone(GeisBackendToken);
81
static void _token_finalize(GeisBackendToken);
82
static void _token_compose(GeisBackendToken, GeisBackendToken);
83
static GeisStatus _token_activate(GeisBackendToken, GeisSubscription);
84
static GeisStatus _token_deactivate(GeisBackendToken, GeisSubscription);
86
static struct GeisBackendTokenVtable _token_vtbl = {
94
static GeisGestureClass g_poke_class = NULL;
97
_add_device_term(GeisBackendToken token GEIS_UNUSED,
98
void *context GEIS_UNUSED,
100
GeisFilterOperation op GEIS_UNUSED,
101
void *value GEIS_UNUSED)
103
GeisStatus status = GEIS_STATUS_SUCCESS;
104
geis_error("called: name=%s", name);
110
_create_test_devices(GeisBackendTestFixture tf)
112
GeisDevice device = geis_device_new("abs-test-device", 0);
113
struct GeisFilterableAttribute attrs[] = {
114
{ GEIS_DEVICE_ATTRIBUTE_NAME, GEIS_ATTR_TYPE_STRING, _add_device_term, NULL },
115
{ GEIS_DEVICE_ATTRIBUTE_ID, GEIS_ATTR_TYPE_INTEGER, _add_device_term, NULL },
116
{ GEIS_DEVICE_ATTRIBUTE_TOUCHES, GEIS_ATTR_TYPE_INTEGER, _add_device_term, NULL },
117
{ GEIS_DEVICE_ATTRIBUTE_DIRECT_TOUCH, GEIS_ATTR_TYPE_BOOLEAN, _add_device_term, NULL }
119
GeisSize attr_count = sizeof(attrs) / sizeof(struct GeisFilterableAttribute);
121
geis_register_device(tf->tf_geis, device, attr_count, attrs);
126
_add_class_term(GeisBackendToken gbtoken,
127
void *context GEIS_UNUSED,
129
GeisFilterOperation op,
132
GeisStatus status = GEIS_STATUS_SUCCESS;
133
TestBackendToken token = _tbtoken_from_token(gbtoken);
135
if (0 == strcmp(name, GEIS_CLASS_ATTRIBUTE_NAME)
136
&& op == GEIS_FILTER_OP_EQ)
138
GeisString class_name = (GeisString)value;
139
geis_debug("called: attr=%s name=\"%s\"", name, class_name);
141
else if (0 == strcmp(name, GEIS_GESTURE_ATTRIBUTE_TOUCHES))
143
GeisInteger touches = *(GeisInteger*)value;
146
case GEIS_FILTER_OP_GT:
147
token->min_touches = _max(token->min_touches, touches+1);
149
case GEIS_FILTER_OP_GE:
150
token->min_touches = _max(token->min_touches, touches);
152
case GEIS_FILTER_OP_LT:
153
token->max_touches = _min(touches-1, token->max_touches);
155
case GEIS_FILTER_OP_LE:
156
token->max_touches = _min(touches, token->max_touches);
158
case GEIS_FILTER_OP_EQ:
159
token->min_touches = _max(token->min_touches, touches);
160
token->max_touches = _min(touches, token->max_touches);
162
case GEIS_FILTER_OP_NE:
165
geis_debug("called: attr=%s touches=\"%d\" min=%d max=%d", name, touches, token->min_touches, token->max_touches);
172
_create_test_classes(GeisBackendTestFixture tf)
176
g_poke_class = geis_gesture_class_new("poke", 2100);
177
struct GeisFilterableAttribute attrs[] = {
178
{ GEIS_CLASS_ATTRIBUTE_NAME, GEIS_ATTR_TYPE_STRING, _add_class_term, g_poke_class },
179
{ GEIS_CLASS_ATTRIBUTE_ID, GEIS_ATTR_TYPE_INTEGER, _add_class_term, g_poke_class },
180
{ GEIS_GESTURE_ATTRIBUTE_TOUCHES, GEIS_ATTR_TYPE_INTEGER, _add_class_term, g_poke_class }
182
GeisSize attr_count = sizeof(attrs) / sizeof(struct GeisFilterableAttribute);
184
geis_register_gesture_class(tf->tf_geis, g_poke_class, attr_count, attrs);
190
_construct(void *mem, Geis geis)
192
GeisBackendTestFixture tf = (GeisBackendTestFixture)mem;
195
_create_test_devices(tf);
196
_create_test_classes(tf);
197
geis_post_event(tf->tf_geis, geis_event_new(GEIS_EVENT_INIT_COMPLETE));
202
_finalize(GeisBackend be)
204
GeisBackendTestFixture tf GEIS_UNUSED = (GeisBackendTestFixture)be;
208
static GeisBackendToken
209
_create_token(GeisBackend be, GeisBackendTokenInitState init_state)
211
TestBackendToken token = NULL;
212
token = calloc(1, sizeof(struct TestBackendToken));
215
token->base.vtbl = &_token_vtbl;
216
token->be = (GeisBackendTestFixture)be;
217
if (init_state == GEIS_BACKEND_TOKEN_INIT_ALL)
219
token->min_touches = g_min_touches;
220
token->max_touches = g_max_touches;
224
token->min_touches = g_max_touches;
225
token->max_touches = g_min_touches;
228
return (GeisBackendToken)token;
233
_gmock_accept_gesture(GeisBackend be GEIS_UNUSED,
234
GeisGroup group GEIS_UNUSED,
235
GeisGestureId gesture_ID GEIS_UNUSED)
237
return GEIS_STATUS_SUCCESS;
242
_gmock_reject_gesture(GeisBackend be GEIS_UNUSED,
243
GeisGroup group GEIS_UNUSED,
244
GeisGestureId gesture_ID GEIS_UNUSED)
246
return GEIS_STATUS_SUCCESS;
251
_gmock_get_configuration(GeisBackend be GEIS_UNUSED,
252
GeisSubscription subscription GEIS_UNUSED,
253
GeisString item_name GEIS_UNUSED,
254
GeisPointer item_value GEIS_UNUSED)
256
return GEIS_STATUS_NOT_SUPPORTED;
261
_gmock_set_configuration(GeisBackend be GEIS_UNUSED,
262
GeisSubscription subscription GEIS_UNUSED,
263
GeisString item_name GEIS_UNUSED,
264
GeisPointer item_value GEIS_UNUSED)
266
return GEIS_STATUS_NOT_SUPPORTED;
270
static struct GeisBackendVtable tf_vtbl = {
274
_gmock_accept_gesture,
275
_gmock_reject_gesture,
276
_gmock_get_configuration,
277
_gmock_set_configuration
282
* Generates a gesture event, the contets of which varies accoring to what's in
286
_create_gesture_events_for_token(TestBackendToken token)
290
GeisFloat attr_float;
291
GeisInteger attr_int;
292
GeisAttr attr = NULL;
294
GeisEvent event = geis_event_new(GEIS_EVENT_GESTURE_BEGIN);
295
GeisGroupSet groupset = geis_groupset_new();
296
GeisGroup group = geis_group_new(1);
297
GeisAttr group_attr = geis_attr_new(GEIS_EVENT_ATTRIBUTE_GROUPSET,
298
GEIS_ATTR_TYPE_POINTER,
300
GeisTouchSet touchset = geis_touchset_new();
301
GeisAttr touch_attr = geis_attr_new(GEIS_EVENT_ATTRIBUTE_TOUCHSET,
302
GEIS_ATTR_TYPE_POINTER,
305
GeisFrame frame = geis_frame_new(1);
306
geis_frame_set_is_class(frame, g_poke_class);
309
attr = geis_attr_new(GEIS_GESTURE_ATTRIBUTE_DEVICE_ID,
310
GEIS_ATTR_TYPE_INTEGER,
312
geis_frame_add_attr(frame, attr);
315
attr = geis_attr_new(GEIS_GESTURE_ATTRIBUTE_TIMESTAMP,
316
GEIS_ATTR_TYPE_INTEGER,
318
geis_frame_add_attr(frame, attr);
321
attr = geis_attr_new(GEIS_GESTURE_ATTRIBUTE_ROOT_WINDOW_ID,
322
GEIS_ATTR_TYPE_INTEGER,
324
geis_frame_add_attr(frame, attr);
327
attr = geis_attr_new(GEIS_GESTURE_ATTRIBUTE_EVENT_WINDOW_ID,
328
GEIS_ATTR_TYPE_INTEGER,
330
geis_frame_add_attr(frame, attr);
333
attr = geis_attr_new(GEIS_GESTURE_ATTRIBUTE_CHILD_WINDOW_ID,
334
GEIS_ATTR_TYPE_INTEGER,
336
geis_frame_add_attr(frame, attr);
338
attr_float = 123.456;
339
attr = geis_attr_new(GEIS_GESTURE_ATTRIBUTE_FOCUS_X,
340
GEIS_ATTR_TYPE_FLOAT,
342
geis_frame_add_attr(frame, attr);
344
attr_float = 987.654;
345
attr = geis_attr_new(GEIS_GESTURE_ATTRIBUTE_FOCUS_Y,
346
GEIS_ATTR_TYPE_FLOAT,
348
geis_frame_add_attr(frame, attr);
350
attr = geis_attr_new(GEIS_GESTURE_ATTRIBUTE_GESTURE_NAME,
351
GEIS_ATTR_TYPE_STRING,
353
geis_frame_add_attr(frame, attr);
355
attr = geis_attr_new(GEIS_GESTURE_ATTRIBUTE_TOUCHES,
356
GEIS_ATTR_TYPE_INTEGER,
357
&token->min_touches);
358
geis_frame_add_attr(frame, attr);
360
for (i = 0; i < token->min_touches; ++i)
362
GeisTouch touch = geis_touch_new(1);
363
geis_touchset_insert(touchset, touch);
364
geis_frame_add_touchid(frame, geis_touch_id(touch));
367
geis_group_insert_frame(group, frame);
369
geis_groupset_insert(groupset, group);
371
geis_event_add_attr(event, group_attr);
372
geis_event_add_attr(event, touch_attr);
374
geis_post_event(token->be->tf_geis, event);
378
static GeisBackendToken
379
_token_clone(GeisBackendToken gbtoken)
381
TestBackendToken token = _tbtoken_from_token(gbtoken);
382
TestBackendToken new_token = calloc(1, sizeof(struct TestBackendToken));
385
memcpy(new_token, token, sizeof(struct TestBackendToken));
386
return &new_token->base;
393
_token_finalize(GeisBackendToken gbtoken GEIS_UNUSED)
399
_token_compose(GeisBackendToken lhs, GeisBackendToken rhs)
401
TestBackendToken token1 = _tbtoken_from_token(lhs);
402
TestBackendToken token2 = _tbtoken_from_token(rhs);
403
token1->min_touches = _min(token1->min_touches, token2->min_touches);
404
token1->max_touches = _max(token1->max_touches, token2->max_touches);
409
_token_activate(GeisBackendToken gbtoken,
410
GeisSubscription subscription GEIS_UNUSED)
412
GeisStatus status = GEIS_STATUS_SUCCESS;
413
TestBackendToken token = _tbtoken_from_token(gbtoken);
414
_create_gesture_events_for_token(token);
420
_token_deactivate(GeisBackendToken gbtoken GEIS_UNUSED,
421
GeisSubscription subscription GEIS_UNUSED)
423
GeisStatus status = GEIS_STATUS_SUCCESS;
428
__attribute__((constructor))
429
static void _register_test_fixture()
431
geis_register_backend(GEIS_INIT_MOCK_BACKEND,
432
sizeof(struct GeisBackendTestFixture),
437
/* A dummy routine to force linkage of this module without dlopening it */
439
geis_include_backend_test_fixture()