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

« back to all changes in this revision

Viewing changes to testsuite/geis1/check_gesture_attrs.c

  • 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
/**
 
2
 * @file check_gesture_attrs.c
 
3
 * @brief Unit tests for GEIS v1 gesture attrs
 
4
 *
 
5
 * Copyright 2011 Canonical Ltd.
 
6
 *
 
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
 
10
 * later version.
 
11
 *
 
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
 
15
 * details.
 
16
 *
 
17
 * You should have received a copy of the GNU Lesser General Public License
 
18
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 
19
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
20
 */
 
21
#include <check.h>
 
22
 
 
23
#include <geis/geis.h>
 
24
#include <math.h>
 
25
#include <stdio.h>
 
26
#include <string.h>
 
27
 
 
28
#define GEIS_TEST_WINDOW geis_win_type_str(Test)
 
29
 
 
30
static const char* s_gestures[] = {
 
31
  GEIS_GESTURE_TYPE_DRAG2, GEIS_GESTURE_TYPE_DRAG3,
 
32
  GEIS_GESTURE_TYPE_PINCH2, GEIS_GESTURE_TYPE_PINCH3,
 
33
  GEIS_GESTURE_TYPE_ROTATE2, GEIS_GESTURE_TYPE_ROTATE3,
 
34
  GEIS_GESTURE_TYPE_TAP2, GEIS_GESTURE_TYPE_TAP3, GEIS_GESTURE_TYPE_TAP4,
 
35
  NULL
 
36
};
 
37
 
 
38
struct test_data_t
 
39
{
 
40
  int count_728606;
 
41
  int count_732104;
 
42
};
 
43
 
 
44
static void
 
45
gesture_added(void            *cookie CK_ATTRIBUTE_UNUSED,
 
46
              GeisGestureType  gesture_type CK_ATTRIBUTE_UNUSED,
 
47
              GeisGestureId    gesture_id CK_ATTRIBUTE_UNUSED,
 
48
              GeisSize         attr_count CK_ATTRIBUTE_UNUSED,
 
49
              GeisGestureAttr *attrs CK_ATTRIBUTE_UNUSED)
 
50
{
 
51
}
 
52
 
 
53
static void
 
54
gesture_removed(void              *cookie CK_ATTRIBUTE_UNUSED,
 
55
                GeisGestureType    gesture_type CK_ATTRIBUTE_UNUSED,
 
56
                GeisGestureId      gesture_id CK_ATTRIBUTE_UNUSED,
 
57
                GeisSize           attr_count CK_ATTRIBUTE_UNUSED,
 
58
                GeisGestureAttr   *attrs CK_ATTRIBUTE_UNUSED)
 
59
{
 
60
}
 
61
 
 
62
/*
 
63
 * Checks for special values generated by the mock back end.
 
64
 */
 
65
static void
 
66
gesture_start(void              *cookie,
 
67
              GeisGestureType    gesture_type CK_ATTRIBUTE_UNUSED,
 
68
              GeisGestureId      gesture_id CK_ATTRIBUTE_UNUSED,
 
69
              GeisSize           attr_count,
 
70
              GeisGestureAttr   *attrs)
 
71
{
 
72
  GeisSize i;
 
73
  struct test_data_t *test_data = (struct test_data_t*)cookie;
 
74
 
 
75
  for (i = 0; i < attr_count; ++i)
 
76
  {
 
77
    if (0 == strcmp(attrs[i].name, GEIS_GESTURE_ATTRIBUTE_FOCUS_X)
 
78
     && fabs(attrs[i].float_val - 123.456) < 0.01)
 
79
    {
 
80
      ++test_data->count_728606;
 
81
    }
 
82
    else if (0 == strcmp(attrs[i].name, GEIS_GESTURE_ATTRIBUTE_FOCUS_Y)
 
83
     && fabs(attrs[i].float_val - 987.654) < 0.01)
 
84
    {
 
85
      ++test_data->count_728606;
 
86
    }
 
87
    else if (0 == strcmp(attrs[i].name, GEIS_GESTURE_ATTRIBUTE_TOUCHES)
 
88
     && attrs[i].integer_val == 1)
 
89
    {
 
90
      ++test_data->count_732104;
 
91
    }
 
92
  }
 
93
}
 
94
 
 
95
static void
 
96
gesture_update(void              *cookie CK_ATTRIBUTE_UNUSED,
 
97
               GeisGestureType    gesture_type CK_ATTRIBUTE_UNUSED,
 
98
               GeisGestureId      gesture_id CK_ATTRIBUTE_UNUSED,
 
99
               GeisSize           attr_count CK_ATTRIBUTE_UNUSED,
 
100
               GeisGestureAttr   *attrs CK_ATTRIBUTE_UNUSED)
 
101
{
 
102
}
 
103
 
 
104
static void
 
105
gesture_finish(void              *cookie CK_ATTRIBUTE_UNUSED,
 
106
               GeisGestureType    gesture_type CK_ATTRIBUTE_UNUSED,
 
107
               GeisGestureId      gesture_id CK_ATTRIBUTE_UNUSED,
 
108
               GeisSize           attr_count CK_ATTRIBUTE_UNUSED,
 
109
               GeisGestureAttr   *attrs CK_ATTRIBUTE_UNUSED)
 
110
{
 
111
}
 
112
 
 
113
 
 
114
GeisGestureFuncs gesture_funcs = {
 
115
  gesture_added,
 
116
  gesture_removed,
 
117
  gesture_start,
 
118
  gesture_update,
 
119
  gesture_finish
 
120
};
 
121
 
 
122
/* fixtures */
 
123
static GeisInstance g_instance;
 
124
 
 
125
/* fixture setup */
 
126
static void
 
127
construct_instance()
 
128
{
 
129
  GeisStatus   status;
 
130
  GeisXcbWinInfo x_win_info = {
 
131
    .display_name  = NULL,
 
132
    .screenp       = NULL,
 
133
    .window_id     = 1
 
134
  };
 
135
  GeisWinInfo  win_info = { GEIS_TEST_WINDOW, &x_win_info };
 
136
 
 
137
  status = geis_init(&win_info, &g_instance);
 
138
}
 
139
 
 
140
/* fixture teardown */
 
141
static void
 
142
destroy_instance()
 
143
{
 
144
  geis_finish(g_instance);
 
145
}
 
146
 
 
147
START_TEST(receive_events)
 
148
{
 
149
  GeisStatus status;
 
150
  struct test_data_t test_data;
 
151
  memset(&test_data, 0, sizeof(test_data));
 
152
 
 
153
  status = geis_subscribe(g_instance,
 
154
                          GEIS_ALL_INPUT_DEVICES,
 
155
                          s_gestures,
 
156
                          &gesture_funcs,
 
157
                          &test_data);
 
158
  fail_unless(status == GEIS_STATUS_SUCCESS, "subscription failed");
 
159
 
 
160
  while (GEIS_STATUS_CONTINUE == geis_event_dispatch(g_instance))
 
161
    ;
 
162
 
 
163
  /* Regression test for bug LP: #728606. */
 
164
  fail_unless(test_data.count_728606 == 2,
 
165
              "unexpected count for LP:728606: expected 2, got %d", test_data.count_728606);
 
166
  fail_unless(test_data.count_732104 == 0,
 
167
              "unexpected count for LP:732104: expected 0, got %d", test_data.count_732104);
 
168
}
 
169
END_TEST
 
170
 
 
171
 
 
172
Suite *
 
173
geis1_gesture_attrs_new()
 
174
{
 
175
  Suite *s = suite_create("geis1_gesture_attrs");
 
176
  TCase *test;
 
177
 
 
178
  test = tcase_create("lp728606");
 
179
  tcase_add_checked_fixture(test, construct_instance, destroy_instance);
 
180
  tcase_add_test(test, receive_events);
 
181
  suite_add_tcase(s, test);
 
182
 
 
183
  return s;
 
184
}
 
185