Merge lp:~chasedouglas/geis/v1-device-add-subscribe-test into lp:geis

Proposed by Chase Douglas
Status: Merged
Merged at revision: 273
Proposed branch: lp:~chasedouglas/geis/v1-device-add-subscribe-test
Merge into: lp:geis
Prerequisite: lp:~chasedouglas/geis/misc-updates
Diff against target: 140 lines (+125/-0)
2 files modified
testsuite/geis1/Makefile.am (+1/-0)
testsuite/geis1/gtest_devices.cpp (+124/-0)
To merge this branch: bzr merge lp:~chasedouglas/geis/v1-device-add-subscribe-test
Reviewer Review Type Date Requested Status
Stephen M. Webb (community) Approve
Chase Douglas (community) Needs Resubmitting
Review via email: mp+109413@code.launchpad.net

Description of the change

Add test for lp:1009270: Unity fails to use multitouch gestures if magic touchpad is connected after Unity has launched.

To post a comment you must log in.
Revision history for this message
Stephen M. Webb (bregma) wrote :

Code looks OK, test fails as expected.

review: Approve
273. By Chase Douglas

Merged utouch-geis into v1-device-add-subscribe-test.

274. By Chase Douglas

Update new device subscription test to use device added callback

Revision history for this message
Chase Douglas (chasedouglas) wrote :

Test rebased and fixed up based on comments in the next merge proposal: https://code.launchpad.net/~chasedouglas/utouch-geis/v1-device-add-subscribe-fix/+merge/109414. Please review.

review: Needs Resubmitting
Revision history for this message
Stephen M. Webb (bregma) wrote :

Excellent.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'testsuite/geis1/Makefile.am'
2--- testsuite/geis1/Makefile.am 2012-04-11 19:29:52 +0000
3+++ testsuite/geis1/Makefile.am 2012-06-15 17:33:29 +0000
4@@ -35,6 +35,7 @@
5
6 gtest_geis1_api_SOURCES = \
7 gtest_attrs.cpp \
8+ gtest_devices.cpp \
9 gtest_subscription.cpp
10
11 nodist_gtest_geis1_api_SOURCES = \
12
13=== added file 'testsuite/geis1/gtest_devices.cpp'
14--- testsuite/geis1/gtest_devices.cpp 1970-01-01 00:00:00 +0000
15+++ testsuite/geis1/gtest_devices.cpp 2012-06-15 17:33:29 +0000
16@@ -0,0 +1,124 @@
17+/**
18+ * GTest test suite for GEIS v1 device handling.
19+ *
20+ * Copyright 2012 Canonical Ltd.
21+ */
22+#include "geis/geis.h"
23+#include "gtest_evemu_device.h"
24+#include "gtest_geis1_fixture.h"
25+#include "libutouch-geis/geis_test_api.h"
26+#include <memory>
27+
28+static const std::string TEST_DEVICE_PROP_FILE(
29+ TEST_ROOT_DIR "recordings/touchscreen_a/device.prop");
30+static const std::string TEST_DEVICE_EVENTS_FILE(
31+ TEST_ROOT_DIR "recordings/touchscreen_a/drag_2.record");
32+
33+/**
34+ * Fixture for testing device handling.
35+ * This is a separate class because gtest uses Java reflection.
36+ */
37+class Geis1DeviceTests : public GTestGeis1Fixture
38+{
39+public:
40+ Geis1DeviceTests() : saw_events_(false) {}
41+ void GestureUpdate(GeisGestureType type, GeisGestureId id, GeisSize count,
42+ GeisGestureAttr* attrs);
43+
44+ void UseNewDevice();
45+
46+protected:
47+ void CreateNewDevice();
48+
49+ std::unique_ptr<Testsuite::EvemuDevice> new_device_;
50+ bool saw_events_;
51+};
52+
53+namespace
54+{
55+
56+void gesture_update_func(void* cookie, GeisGestureType type, GeisGestureId id,
57+ GeisSize count, GeisGestureAttr* attrs) {
58+ Geis1DeviceTests* fixture = reinterpret_cast<Geis1DeviceTests*>(cookie);
59+ fixture->GestureUpdate(type, id, count, attrs);
60+}
61+
62+void gesture_null_func(void* cookie, GeisGestureType type, GeisGestureId id,
63+ GeisSize count, GeisGestureAttr* attrs) {
64+}
65+
66+void device_added_func(void* cookie, GeisInputDeviceId deviceId, void* attrs) {
67+ Geis1DeviceTests* fixture = reinterpret_cast<Geis1DeviceTests*>(cookie);
68+ fixture->UseNewDevice();
69+}
70+
71+void device_null_func(void* cookie, GeisInputDeviceId deviceId, void* attrs) {
72+}
73+
74+} // namespace
75+
76+void Geis1DeviceTests::GestureUpdate(GeisGestureType type, GeisGestureId id,
77+ GeisSize count, GeisGestureAttr* attrs)
78+{
79+ saw_events_ = true;
80+}
81+
82+void Geis1DeviceTests::CreateNewDevice() {
83+ new_device_.reset(new Testsuite::EvemuDevice(TEST_DEVICE_PROP_FILE));
84+}
85+
86+void Geis1DeviceTests::UseNewDevice() {
87+ new_device_->play(TEST_DEVICE_EVENTS_FILE);
88+}
89+
90+/*
91+ * Test case for lp:1009270 -- Geis v1 does not report gestures for new devices
92+ *
93+ * Creates a subscription before a device is present. A device is added, and
94+ * then events are played. Gesture events should be detected.
95+ */
96+TEST_F(Geis1DeviceTests, addDeviceSubscription)
97+{
98+
99+ static const char* gestures[] =
100+ {
101+ GEIS_GESTURE_TYPE_DRAG2,
102+ NULL
103+ };
104+
105+ static GeisGestureFuncs callbacks = {
106+ &gesture_null_func,
107+ &gesture_null_func,
108+ &gesture_null_func,
109+ &gesture_update_func,
110+ &gesture_null_func,
111+ };
112+
113+ static GeisInputFuncs inputfuncs = {
114+ &device_added_func,
115+ &device_null_func,
116+ &device_null_func,
117+ };
118+
119+ ASSERT_EQ(GEIS_STATUS_SUCCESS, geis_input_devices(geis(), &inputfuncs, this));
120+
121+ ASSERT_EQ(GEIS_STATUS_SUCCESS,
122+ geis_subscribe(geis(), GEIS_ALL_INPUT_DEVICES, gestures, &callbacks,
123+ this));
124+
125+ CreateNewDevice();
126+
127+ while (1) {
128+ fd_set read_fds;
129+ FD_ZERO(&read_fds);
130+ FD_SET(geis_fd(), &read_fds);
131+ timeval tmo = { 1, 0 };
132+ int sstat = select(geis_fd() + 1, &read_fds, NULL, NULL, &tmo);
133+ EXPECT_GT(sstat, -1) << "error in select";
134+ if (sstat == 0)
135+ break;
136+ ASSERT_EQ(GEIS_STATUS_SUCCESS, geis_event_dispatch(geis()));
137+ }
138+
139+ EXPECT_TRUE(saw_events_);
140+}

Subscribers

People subscribed via source and target branches