~matttbe/ubuntu/raring/geis/lp1077376

« back to all changes in this revision

Viewing changes to testsuite/geis1/gtest_attrs.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
/**
 
2
 * Gtest test suite for GEIS v1 attributes.
 
3
 *
 
4
 * Copyright 2012 Canonical Ltd.
 
5
 */
 
6
 
 
7
#include <functional>
 
8
#include "geis/geis.h"
 
9
#include "gtest_evemu_device.h"
 
10
#include "gtest_geis1_fixture.h"
 
11
#include <gtest/gtest.h>
 
12
#include <mutex>
 
13
#include <sys/select.h>
 
14
#include <sys/time.h>
 
15
 
 
16
 
 
17
namespace
 
18
{
 
19
 
 
20
const std::string TEST_DEVICE_PROP_FILE(TEST_ROOT_DIR "recordings/apple_magic_trackpad/device.prop");
 
21
const std::string TEST_DEVICE_EVENTS_FILE(TEST_ROOT_DIR "recordings/apple_magic_trackpad/four_tap.record");
 
22
 
 
23
/**
 
24
 * Fixture for testing expected attributes.  This has to be a separate class
 
25
 * because of the way Java reflection is used in jUnit.
 
26
 */
 
27
class Geis1AttributeTests
 
28
: public GTestGeis1Fixture
 
29
{
 
30
public:
 
31
  Geis1AttributeTests()
 
32
  : evemu_device_(TEST_DEVICE_PROP_FILE),
 
33
    saw_four_tap(false)
 
34
  { }
 
35
 
 
36
  void GestureUpdate(GeisGestureType type, GeisGestureId id, GeisSize count,
 
37
                     GeisGestureAttr* attrs);
 
38
 
 
39
protected:
 
40
  Testsuite::EvemuDevice evemu_device_;
 
41
  bool saw_four_tap;
 
42
};
 
43
 
 
44
void gesture_begin(void* cookie, GeisGestureType type, GeisGestureId id,
 
45
                   GeisSize count, GeisGestureAttr* attrs) {
 
46
  FAIL() << "received unexpected gesture begin event";
 
47
}
 
48
 
 
49
void gesture_update(void* cookie, GeisGestureType type, GeisGestureId id,
 
50
                    GeisSize count, GeisGestureAttr* attrs) {
 
51
  Geis1AttributeTests* fixture = reinterpret_cast<Geis1AttributeTests*>(cookie);
 
52
  fixture->GestureUpdate(type, id, count, attrs);
 
53
}
 
54
 
 
55
void gesture_end(void* cookie, GeisGestureType type, GeisGestureId id,
 
56
                 GeisSize count, GeisGestureAttr* attrs) {
 
57
  FAIL() << "received unexpected gesture end event";
 
58
}
 
59
 
 
60
void gesture_null_func(void* cookie, GeisGestureType type, GeisGestureId id,
 
61
                       GeisSize count, GeisGestureAttr* attrs) {
 
62
}
 
63
 
 
64
void Geis1AttributeTests::GestureUpdate(GeisGestureType type, GeisGestureId id,
 
65
                                        GeisSize count,
 
66
                                        GeisGestureAttr* attrs) {
 
67
  EXPECT_EQ(GEIS_GESTURE_PRIMITIVE_TAP, type);
 
68
 
 
69
  EXPECT_FALSE(saw_four_tap);
 
70
 
 
71
  for (int i = 0; i < count; i++) {
 
72
    GeisGestureAttr attr = attrs[i];
 
73
    if (strcmp(attr.name, GEIS_GESTURE_ATTRIBUTE_TOUCHES) == 0) {
 
74
      ASSERT_EQ(4, attr.integer_val);
 
75
      saw_four_tap = true;
 
76
      return;
 
77
    }
 
78
  }
 
79
}
 
80
 
 
81
/*
 
82
 * Regression test for lp:957331, lp:957334, and lp:957344: geis v1 tap handling
 
83
 *
 
84
 * A geis v1 four tap system subscription is created, and a four tap gesture is
 
85
 * replayed on a touchpad device.
 
86
 *
 
87
 * Expected: One four touch tap gesture update event is received. No other
 
88
 * events should be seen.
 
89
 */
 
90
TEST_F(Geis1AttributeTests, tap_touch_count)
 
91
{
 
92
  static const char* gestures[] = {
 
93
    GEIS_GESTURE_TYPE_TAP4,
 
94
    GEIS_GESTURE_TYPE_SYSTEM,
 
95
  };
 
96
 
 
97
  static GeisGestureFuncs callbacks = {
 
98
    &gesture_null_func,
 
99
    &gesture_null_func,
 
100
    &gesture_begin,
 
101
    &gesture_update,
 
102
    &gesture_update,
 
103
  };
 
104
 
 
105
  ASSERT_EQ(GEIS_STATUS_SUCCESS,
 
106
            geis_subscribe(geis(), GEIS_ALL_INPUT_DEVICES, gestures, &callbacks,
 
107
                           this));
 
108
 
 
109
  evemu_device_.play(TEST_DEVICE_EVENTS_FILE);
 
110
 
 
111
  while (1) {
 
112
    fd_set read_fds;
 
113
    FD_ZERO(&read_fds);
 
114
    FD_SET(geis_fd(), &read_fds);
 
115
    timeval tmo = { 1, 0 };
 
116
    int sstat = select(geis_fd() + 1, &read_fds, NULL, NULL, &tmo);
 
117
    EXPECT_GT(sstat, -1) << "error in select";
 
118
    if (sstat == 0)
 
119
      break;
 
120
    ASSERT_EQ(GEIS_STATUS_SUCCESS, geis_event_dispatch(geis()));
 
121
  }
 
122
 
 
123
  EXPECT_TRUE(saw_four_tap);
 
124
}
 
125
 
 
126
} // anonymous namespace