~fginther/geis/geis-2.2.9.1-precise

« back to all changes in this revision

Viewing changes to testsuite/geis2/gtest_devices.cpp

  • Committer: Francis Ginther
  • Date: 2012-08-16 13:43:15 UTC
  • mfrom: (49.1.37)
  • Revision ID: francis.ginther@canonical.com-20120816134315-ex9m75nqcv0uryim
* New upstream release.
  - fixes pinch radius and drag delta calculations (lp: #985916)
    (lp: #986215)
  - changes type of geisSubscriptionFlags (lp: #813819)
  - changes direct devices to use window coordinates (lp: #984069)
  - reports device axis extents, if available (lp: #987539)
  - removes XCB back end
  - removes overlapping events when a gesture is accepted (lp: #1001365)
  - avoids trying to start a DBus session if there is none already
    (lp: #997630)
  - detect added devices properly (LP: #1009270)
  - fix crash when accepting a gesture (LP: #1015775)
  - fix result value of geis_subscription_deactivate() (LP: #1021448)
  - upstream project renamed to just 'geis'

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
#include "geis/geis.h"
7
7
#include "gtest_evemu_device.h"
8
8
#include "gtest_geis_fixture.h"
9
 
#include "libutouch-geis/geis_test_api.h"
 
9
#include "libgeis/geis_test_api.h"
10
10
#include <memory>
11
 
#include <sys/select.h>
12
 
#include <sys/time.h>
13
11
 
14
12
 
15
13
namespace
87
85
  fs = geis_subscription_add_filter(sub, filter);
88
86
  EXPECT_EQ(fs, GEIS_STATUS_SUCCESS) << "can not add device term";
89
87
 
90
 
  GeisStatus dispatch_status= geis_dispatch_events(geis_);
91
 
  while (dispatch_status == GEIS_STATUS_CONTINUE
92
 
      || dispatch_status == GEIS_STATUS_SUCCESS)
 
88
  set_geis_event_handler([&](Geis, GeisEvent event)
93
89
  {
94
 
   GeisEvent  event;
95
 
    GeisStatus event_status = geis_next_event(geis_, &event);
96
 
    while (event_status == GEIS_STATUS_CONTINUE
97
 
        || event_status == GEIS_STATUS_SUCCESS)
 
90
    switch (geis_event_type(event))
98
91
    {
99
 
      switch (geis_event_type(event))
 
92
      case GEIS_EVENT_INIT_COMPLETE:
100
93
      {
101
 
        case GEIS_EVENT_INIT_COMPLETE:
102
 
        {
103
 
          EXPECT_EQ(GEIS_STATUS_SUCCESS, geis_subscription_activate(sub))
104
 
                      << "can not activate subscription";
105
 
 
106
 
          GeisBoolean off = GEIS_FALSE;
107
 
          geis_set_configuration(geis_,
108
 
                                 GEIS_CONFIG_DISCARD_DEVICE_MESSAGES,
109
 
                                 &off);
110
 
          new_device.reset(new Testsuite::EvemuDevice(TEST_DEVICE_PROP_FILE));
111
 
          device_has_been_created = GEIS_TRUE;
112
 
          break;
113
 
        }
114
 
 
115
 
       case GEIS_EVENT_DEVICE_AVAILABLE:
116
 
         new_device->play(TEST_DEVICE_EVENTS_FILE);
117
 
         break;
118
 
 
119
 
       case GEIS_EVENT_GESTURE_BEGIN:
120
 
       case GEIS_EVENT_GESTURE_UPDATE:
121
 
       {
122
 
         EXPECT_EQ(device_has_been_created, GEIS_TRUE)
123
 
           << "gesture events without device";
124
 
         gesture_events_received = device_has_been_created;
125
 
       }
126
 
 
127
 
       default:
128
 
          break;
 
94
        EXPECT_EQ(GEIS_STATUS_SUCCESS, geis_subscription_activate(sub))
 
95
                    << "can not activate subscription";
 
96
 
 
97
        GeisBoolean off = GEIS_FALSE;
 
98
        geis_set_configuration(geis_,
 
99
                               GEIS_CONFIG_DISCARD_DEVICE_MESSAGES,
 
100
                               &off);
 
101
        new_device.reset(new Testsuite::EvemuDevice(TEST_DEVICE_PROP_FILE));
 
102
        device_has_been_created = GEIS_TRUE;
 
103
        break;
129
104
      }
130
105
 
131
 
      geis_event_delete(event);
132
 
      event_status = geis_next_event(geis_, &event);
 
106
     case GEIS_EVENT_DEVICE_AVAILABLE:
 
107
       new_device->play(TEST_DEVICE_EVENTS_FILE);
 
108
       break;
 
109
 
 
110
     case GEIS_EVENT_GESTURE_BEGIN:
 
111
     case GEIS_EVENT_GESTURE_UPDATE:
 
112
     {
 
113
       EXPECT_EQ(device_has_been_created, GEIS_TRUE)
 
114
         << "gesture events without device";
 
115
       gesture_events_received = device_has_been_created;
 
116
     }
 
117
 
 
118
     default:
 
119
        break;
133
120
    }
134
 
 
135
 
    fd_set read_fds;
136
 
    FD_ZERO(&read_fds);
137
 
    FD_SET(geis_fd(), &read_fds);
138
 
    timeval tmo = { 5, 0 };
139
 
    int sstat = select(geis_fd() + 1, &read_fds, NULL, NULL, &tmo);
140
 
    EXPECT_GT(sstat, -1) << "error in select";
141
 
    if (sstat == 0)
142
 
      break;
143
 
    dispatch_status = geis_dispatch_events(geis_);
144
 
  }
145
 
 
 
121
  });
 
122
 
 
123
  geis_dispatch_loop();
146
124
  EXPECT_TRUE(gesture_events_received) << "no gesture events received";
147
125
  EXPECT_TRUE(device_has_been_created) << "no device created";
148
126
  geis_filter_delete(filter);
173
151
  fs = geis_subscription_add_filter(sub, filter);
174
152
  EXPECT_EQ(fs, GEIS_STATUS_SUCCESS) << "can not add device term";
175
153
 
176
 
  GeisStatus dispatch_status= geis_dispatch_events(geis_);
177
 
  while (dispatch_status == GEIS_STATUS_CONTINUE
178
 
      || dispatch_status == GEIS_STATUS_SUCCESS)
 
154
  set_geis_event_handler([&](Geis, GeisEvent event)
179
155
  {
180
 
   GeisEvent  event;
181
 
    GeisStatus event_status = geis_next_event(geis_, &event);
182
 
    while (event_status == GEIS_STATUS_CONTINUE
183
 
        || event_status == GEIS_STATUS_SUCCESS)
184
 
    {
185
 
      switch (geis_event_type(event))
186
 
      {
187
 
        case GEIS_EVENT_INIT_COMPLETE:
188
 
        {
189
 
          GeisBoolean off = GEIS_FALSE;
190
 
          geis_set_configuration(geis_,
191
 
                                 GEIS_CONFIG_DISCARD_DEVICE_MESSAGES,
192
 
                                 &off);
193
 
          new_device.reset(new Testsuite::EvemuDevice(TEST_DEVICE_PROP_FILE));
194
 
          break;
195
 
        }
196
 
 
197
 
       case GEIS_EVENT_DEVICE_AVAILABLE:
198
 
       {
199
 
         EXPECT_EQ(GEIS_STATUS_SUCCESS, geis_subscription_activate(sub))
200
 
                      << "can not activate subscription";
201
 
         new_device.reset();
202
 
         break;
203
 
       }
204
 
 
205
 
       case GEIS_EVENT_GESTURE_BEGIN:
206
 
       case GEIS_EVENT_GESTURE_UPDATE:
207
 
       {
208
 
       }
209
 
 
210
 
       default:
211
 
          break;
212
 
      }
213
 
 
214
 
      geis_event_delete(event);
215
 
      event_status = geis_next_event(geis_, &event);
216
 
    }
217
 
 
218
 
    fd_set read_fds;
219
 
    FD_ZERO(&read_fds);
220
 
    FD_SET(geis_fd(), &read_fds);
221
 
    timeval tmo = { 5, 0 };
222
 
    int sstat = select(geis_fd() + 1, &read_fds, NULL, NULL, &tmo);
223
 
    EXPECT_GT(sstat, -1) << "error in select";
224
 
    if (sstat == 0)
225
 
      break;
226
 
    dispatch_status = geis_dispatch_events(geis_);
227
 
  }
 
156
    if (geis_event_type(event) == GEIS_EVENT_INIT_COMPLETE)
 
157
    {
 
158
      GeisBoolean off = GEIS_FALSE;
 
159
      geis_set_configuration(geis_,
 
160
                             GEIS_CONFIG_DISCARD_DEVICE_MESSAGES,
 
161
                             &off);
 
162
      new_device.reset(new Testsuite::EvemuDevice(TEST_DEVICE_PROP_FILE));
 
163
    }
 
164
    else if (geis_event_type(event) == GEIS_EVENT_DEVICE_AVAILABLE)
 
165
    {
 
166
      EXPECT_EQ(GEIS_STATUS_SUCCESS, geis_subscription_activate(sub))
 
167
                    << "can not activate subscription";
 
168
      new_device.reset();
 
169
    }
 
170
    else if (geis_event_type(event) == GEIS_EVENT_DEVICE_UNAVAILABLE)
 
171
    {
 
172
      geis_dispatch_stop(true);
 
173
    }
 
174
  });
 
175
 
 
176
  geis_dispatch_loop();
228
177
  geis_filter_delete(filter);
229
178
  geis_subscription_delete(sub);
230
179
}
231
180
 
232
181
 
 
182
/*
 
183
 * Test case for lp:987539: report X and Y axis extents.
 
184
 *
 
185
 * This test creates a devicve with known X and Y extents and verifies the
 
186
 * extent attributes are reported with the expected values.
 
187
 */
 
188
TEST_F(GeisDeviceTests, deviceAttrs)
 
189
{
 
190
  GeisBoolean off = GEIS_FALSE;
 
191
  geis_set_configuration(geis_, GEIS_CONFIG_DISCARD_DEVICE_MESSAGES, &off);
 
192
 
 
193
  Testsuite::EvemuDevice test_device(TEST_DEVICE_PROP_FILE);
 
194
  set_geis_event_handler([&](Geis, GeisEvent event)
 
195
  {
 
196
    if (geis_event_type(event) == GEIS_EVENT_DEVICE_AVAILABLE)
 
197
    {
 
198
      GeisAttr attr = geis_event_attr_by_name(event, GEIS_EVENT_ATTRIBUTE_DEVICE);
 
199
      EXPECT_TRUE(attr != NULL);
 
200
      GeisDevice device = (GeisDevice)geis_attr_value_to_pointer(attr);
 
201
      ASSERT_TRUE(test_device.name() == geis_device_name(device));
 
202
 
 
203
      attr = geis_device_attr_by_name(device, GEIS_DEVICE_ATTRIBUTE_MIN_X);
 
204
      ASSERT_TRUE(attr != NULL);
 
205
      EXPECT_FLOAT_EQ(0.0f, geis_attr_value_to_float(attr));
 
206
      attr = geis_device_attr_by_name(device, GEIS_DEVICE_ATTRIBUTE_MAX_X);
 
207
      ASSERT_TRUE(attr != NULL);
 
208
      EXPECT_FLOAT_EQ(9600.0f, geis_attr_value_to_float(attr));
 
209
      attr = geis_device_attr_by_name(device, GEIS_DEVICE_ATTRIBUTE_RES_X);
 
210
      ASSERT_TRUE(attr != NULL);
 
211
      EXPECT_FLOAT_EQ(0.0f, geis_attr_value_to_float(attr));
 
212
      attr = geis_device_attr_by_name(device, GEIS_DEVICE_ATTRIBUTE_MIN_Y);
 
213
      ASSERT_TRUE(attr != NULL);
 
214
      EXPECT_FLOAT_EQ(0.0f, geis_attr_value_to_float(attr));
 
215
      attr = geis_device_attr_by_name(device, GEIS_DEVICE_ATTRIBUTE_MAX_Y);
 
216
      ASSERT_TRUE(attr != NULL);
 
217
      EXPECT_FLOAT_EQ(7200.0f, geis_attr_value_to_float(attr));
 
218
      attr = geis_device_attr_by_name(device, GEIS_DEVICE_ATTRIBUTE_RES_Y);
 
219
      ASSERT_TRUE(attr != NULL);
 
220
      EXPECT_FLOAT_EQ(0.0f, geis_attr_value_to_float(attr));
 
221
    }
 
222
  });
 
223
  geis_dispatch_loop();
 
224
}
 
225
 
 
226
 
233
227
} // anonymous namespace