Merge lp:~dandrader/frame/lp1025297 into lp:frame

Proposed by Daniel d'Andrada
Status: Merged
Merged at revision: 82
Proposed branch: lp:~dandrader/frame/lp1025297
Merge into: lp:frame
Diff against target: 1378 lines (+1014/-152)
19 files modified
.bzrignore (+4/-3)
Makefile.am (+0/-2)
configure.ac (+12/-4)
m4/gtest.m4 (+51/-0)
src/x11/window_x11.cpp (+21/-41)
src/x11/window_x11.h (+0/-2)
test/Makefile-xorg-gtest.am (+0/-63)
test/Makefile.am (+5/-0)
test/README (+11/-0)
test/gtest/Makefile-xorg-gtest.am (+68/-0)
test/gtest/Makefile.am (+11/-0)
test/integration/Makefile.am (+20/-37)
test/regular/Makefile.am (+57/-0)
test/regular/accept-ended-touch.cpp (+72/-0)
test/regular/frame-fixture.cpp (+161/-0)
test/regular/frame-fixture.h (+31/-0)
test/x11_mocks/Makefile.am (+14/-0)
test/x11_mocks/x11_mocks.cpp (+435/-0)
test/x11_mocks/x11_mocks.h (+41/-0)
To merge this branch: bzr merge lp:~dandrader/frame/lp1025297
Reviewer Review Type Date Requested Status
Chase Douglas (community) Approve
Review via email: mp+115357@code.launchpad.net

Description of the change

Fixes bug 1025297.

Patch is big because it's adding all the infrastructure needed for mocks-based tests.

To post a comment you must log in.
Revision history for this message
Chase Douglas (chasedouglas) wrote :

* The added gtest.m4 file shouldn't have a serial number since it's not distributed anywhere. The serial number implies that it was copied in from some other distribution.

* The Makefile-xorg-gtest.am removal should be reverted. I think you removed it because of issues with the wrong files being included when compiling xorg-gtest itself. This has been fixed in the Makefile-xorg-gtest.am shipped upstream. It has not been fixed in Ubuntu yet, but you can download the change from here:

http://cgit.freedesktop.org/xorg/test/xorg-gtest/commit/?id=3fefcde53f8b69b37baeec61265f2e0190713fe6

Everything else looks good!

review: Needs Fixing
lp:~dandrader/frame/lp1025297 updated
86. By Daniel d'Andrada

Remove serial number from m4/gtest.m4

The serial number implies that it was copied in from some other distribution,
but it's not the case here.

87. By Daniel d'Andrada

Use Makefile-xorg-gtest.am from latest upstream xorg-gtest

Revision history for this message
Daniel d'Andrada (dandrader) wrote :

> * The added gtest.m4 file shouldn't have a serial number since it's not
> distributed anywhere. The serial number implies that it was copied in from
> some other distribution.
>
> * The Makefile-xorg-gtest.am removal should be reverted. I think you removed
> it because of issues with the wrong files being included when compiling xorg-
> gtest itself. This has been fixed in the Makefile-xorg-gtest.am shipped
> upstream. It has not been fixed in Ubuntu yet, but you can download the change
> from here:

Done.

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

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2012-03-28 00:45:08 +0000
3+++ .bzrignore 2012-07-18 13:01:21 +0000
4@@ -26,9 +26,10 @@
5 m4/lt~obsolete.m4
6 m4/pkg.m4
7 stamp-*
8-test/check-c-compile
9-test/check-cxx-compile
10-test/check-frame
11+test/regular/check-c-compile
12+test/regular/check-cxx-compile
13+test/regular/check-regular
14+test/integration/check-integration
15 tools/utouch-frame-test-mtdev
16 tools/utouch-frame-test-mtdev.1
17 tools/utouch-frame-test-xi2
18
19=== modified file 'Makefile.am'
20--- Makefile.am 2012-03-31 02:31:54 +0000
21+++ Makefile.am 2012-07-18 13:01:21 +0000
22@@ -9,8 +9,6 @@
23 pkgconfigdir = $(libdir)/pkgconfig
24 pkgconfig_DATA = utouch-frame.pc
25
26-INCLUDES = $(top_srcdir)/include/
27-
28 if HAVE_GCOV
29 .PHONY: clean-gcda
30 clean-gcda:
31
32=== modified file 'configure.ac'
33--- configure.ac 2012-06-18 18:28:21 +0000
34+++ configure.ac 2012-07-18 13:01:21 +0000
35@@ -25,7 +25,8 @@
36 AC_PROG_CXX
37 AC_PROG_INSTALL
38
39-PKG_CHECK_MODULES([EVEMU], [utouch-evemu >= 1.0.5])
40+PKG_CHECK_MODULES([EVEMU], [utouch-evemu >= 1.0.5], [have_evemu=yes])
41+AM_CONDITIONAL([HAVE_EVEMU], [test "x$have_evemu" = xyes])
42
43 PKG_CHECK_MODULES(XINPUT, x11 xext xorg-server [xi >= 1.5.99.1] [inputproto >= 2.1.99.6])
44
45@@ -34,6 +35,11 @@
46 AS_IF([test "x$ASCIIDOC" = "x"],
47 [AC_MSG_WARN([asciidoc not installed, man pages will not be created])])
48
49+
50+# Check for Google C++ Testing Framework
51+CHECK_GTEST()
52+AM_CONDITIONAL([HAVE_GTEST], [test "x$have_gtest" = xyes])
53+
54 # Check for TDD tools
55 AC_ARG_ENABLE([integration-tests],
56 [AS_HELP_STRING([--enable-integration-tests],
57@@ -43,13 +49,11 @@
58
59 AS_IF([test "x$enable_integration_tests" != xno],
60 [CHECK_XORG_GTEST(
61- [AC_MSG_NOTICE([xorg-gtest is available, tests will be built])],
62+ [AC_MSG_NOTICE([xorg-gtest is available, integration tests will be built])],
63 [AC_MSG_WARN([xorg-gtest is not available, tests will not be built])])])
64
65 AM_CONDITIONAL([ENABLE_INTEGRATION_TESTS], [test "x$have_xorg_gtest" = xyes])
66
67-AM_CONDITIONAL([HAVE_GTEST], [test "x$have_xorg_gtest" = xyes])
68-
69 AC_SUBST([GTEST_LDFLAGS])
70 AC_SUBST([GTEST_CXXFLAGS])
71
72@@ -66,6 +70,10 @@
73 doc/Makefile
74 src/Makefile
75 test/Makefile
76+ test/gtest/Makefile
77+ test/integration/Makefile
78+ test/regular/Makefile
79+ test/x11_mocks/Makefile
80 tools/Makefile
81 utouch-frame.pc])
82
83
84=== added file 'm4/gtest.m4'
85--- m4/gtest.m4 1970-01-01 00:00:00 +0000
86+++ m4/gtest.m4 2012-07-18 13:01:21 +0000
87@@ -0,0 +1,51 @@
88+# Copyright (C) 2012 Canonical, Ltd.
89+#
90+# Permission is hereby granted, free of charge, to any person obtaining a copy
91+# of this software and associated documentation files (the "Software"), to deal
92+# in the Software without restriction, including without limitation the rights
93+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
94+# copies of the Software, and to permit persons to whom the Software is
95+# furnished to do so, subject to the following conditions:
96+#
97+# The above copyright notice and this permission notice (including the next
98+# paragraph) shall be included in all copies or substantial portions of the
99+# Software.
100+#
101+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
102+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
103+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
104+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
105+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
106+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
107+# SOFTWARE.
108+
109+# Checks whether the gtest source is available on the system. Allows for
110+# adjusting the include and source path. Sets have_gtest=yes if the source is
111+# present. Sets GTEST_CPPFLAGS and GTEST_SOURCE to the preprocessor flags and
112+# source location respectively.
113+AC_DEFUN([CHECK_GTEST],
114+[
115+ AC_ARG_WITH([gtest-include-path],
116+ [AS_HELP_STRING([--with-gtest-include-path],
117+ [location of the Google test headers])],
118+ [GTEST_CPPFLAGS="-I$withval"])
119+
120+ AC_ARG_WITH([gtest-source-path],
121+ [AS_HELP_STRING([--with-gtest-source-path],
122+ [location of the Google test sources, defaults to /usr/src/gtest])],
123+ [GTEST_SOURCE="$withval"],
124+ [GTEST_SOURCE="/usr/src/gtest"])
125+
126+ GTEST_CPPFLAGS="$GTEST_CPPFLAGS -I$GTEST_SOURCE"
127+
128+ AC_CHECK_FILES([$GTEST_SOURCE/src/gtest-all.cc]
129+ [$GTEST_SOURCE/src/gtest_main.cc],
130+ [have_gtest=yes],
131+ [have_gtest=no])
132+
133+ AS_IF([test "x$have_gtest" = xyes],
134+ [GTEST_LIBS=-lpthread
135+ AC_SUBST(GTEST_CPPFLAGS)
136+ AC_SUBST(GTEST_SOURCE)
137+ AC_SUBST(GTEST_LIBS)])
138+]) # CHECK_GTEST
139
140=== modified file 'src/x11/window_x11.cpp'
141--- src/x11/window_x11.cpp 2012-06-18 18:28:21 +0000
142+++ src/x11/window_x11.cpp 2012-07-18 13:01:21 +0000
143@@ -36,8 +36,6 @@
144 : window_(window),
145 display_(display),
146 device_(static_cast<UFDeviceX11*>(device.get())),
147- touches_to_accept_(),
148- touches_to_reject_(),
149 unaccepted_unrejected_touches_() {
150 }
151
152@@ -167,55 +165,37 @@
153
154 current_frame_ = *frame;
155
156- if (touches_to_accept_.count(event->touchid)) {
157- XIAllowTouchEvents(display_, device_->master_id(), event->touchid, window_,
158- XIAcceptTouch);
159- touches_to_accept_.erase(event->touchid);
160- } else if (touches_to_reject_.count(event->touchid)) {
161- XIAllowTouchEvents(display_, device_->master_id(), event->touchid, window_,
162- XIRejectTouch);
163- touches_to_reject_.erase(event->touchid);
164- } else {
165- unaccepted_unrejected_touches_.insert(event->touchid);
166- }
167+ unaccepted_unrejected_touches_.insert(event->touchid);
168
169 return true;
170 }
171
172 UFStatus WindowX11::AcceptTouch(UFTouchId touch_id) {
173- if (current_frame_->IsTouchOwned(touch_id)) {
174- if (XIAllowTouchEvents(display_, device_->master_id(), touch_id, window_,
175- XIAcceptTouch))
176- return UFStatusErrorGeneric;
177-
178- /* Flush output buffer so touches are actually accepted ASAP. The server
179- * can't perform pointer emulation while the currently emulated touch is
180- * still potentially active for pointer emulation. */
181- XFlush(display_);
182-
183- unaccepted_unrejected_touches_.erase(touch_id);
184- } else {
185- touches_to_accept_.insert(touch_id);
186- }
187+ if (XIAllowTouchEvents(display_, device_->master_id(), touch_id, window_,
188+ XIAcceptTouch))
189+ return UFStatusErrorGeneric;
190+
191+ /* Flush output buffer so touches are actually accepted ASAP. The server
192+ * can't perform pointer emulation while the currently emulated touch is
193+ * still potentially active for pointer emulation. */
194+ XFlush(display_);
195+
196+ unaccepted_unrejected_touches_.erase(touch_id);
197
198 return UFStatusSuccess;
199 }
200
201 UFStatus WindowX11::RejectTouch(UFTouchId touch_id) {
202- if (current_frame_->IsTouchOwned(touch_id)) {
203- if (XIAllowTouchEvents(display_, device_->master_id(), touch_id, window_,
204- XIRejectTouch))
205- return UFStatusErrorGeneric;
206-
207- /* Flush output buffer so touches are actually rejected ASAP. The server
208- * can't perform pointer emulation while the currently emulated touch is
209- * still potentially active for pointer emulation. */
210- XFlush(display_);
211-
212- unaccepted_unrejected_touches_.erase(touch_id);
213- } else {
214- touches_to_reject_.insert(touch_id);
215- }
216+ if (XIAllowTouchEvents(display_, device_->master_id(), touch_id, window_,
217+ XIRejectTouch))
218+ return UFStatusErrorGeneric;
219+
220+ /* Flush output buffer so touches are actually rejected ASAP. The server
221+ * can't perform pointer emulation while the currently emulated touch is
222+ * still potentially active for pointer emulation. */
223+ XFlush(display_);
224+
225+ unaccepted_unrejected_touches_.erase(touch_id);
226
227 return UFStatusSuccess;
228 }
229
230=== modified file 'src/x11/window_x11.h'
231--- src/x11/window_x11.h 2012-06-18 18:28:21 +0000
232+++ src/x11/window_x11.h 2012-07-18 13:01:21 +0000
233@@ -57,8 +57,6 @@
234 ::Window window_;
235 Display* display_;
236 UFDeviceX11* device_;
237- std::set<UFTouchId> touches_to_accept_;
238- std::set<UFTouchId> touches_to_reject_;
239 std::set<UFTouchId> unaccepted_unrejected_touches_;
240 };
241
242
243=== removed file 'test/Makefile-xorg-gtest.am'
244--- test/Makefile-xorg-gtest.am 2012-06-18 18:28:21 +0000
245+++ test/Makefile-xorg-gtest.am 1970-01-01 00:00:00 +0000
246@@ -1,63 +0,0 @@
247-# Copyright (C) 2012 Canonical, Ltd.
248-#
249-# Permission is hereby granted, free of charge, to any person obtaining a copy
250-# of this software and associated documentation files (the "Software"), to deal
251-# in the Software without restriction, including without limitation the rights
252-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
253-# copies of the Software, and to permit persons to whom the Software is
254-# furnished to do so, subject to the following conditions:
255-#
256-# The above copyright notice and this permission notice (including the next
257-# paragraph) shall be included in all copies or substantial portions of the
258-# Software.
259-#
260-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
261-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
262-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
263-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
264-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
265-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
266-# SOFTWARE.
267-#
268-
269-XORG_GTEST_BUILD_LIBS = \
270- libgtest.a \
271- libgtest_main.a \
272- libxorg-gtest.a \
273- libxorg-gtest_main.a
274-
275-nodist_libgtest_a_SOURCES = $(GTEST_SOURCE)/src/gtest-all.cc
276-libgtest_a_CPPFLAGS = $(GTEST_CPPFLAGS) $(AM_CPPFLAGS) -w
277-libgtest_a_CXXFLAGS = $(GTEST_CXXFLAGS) $(AM_CXXFLAGS)
278-
279-nodist_libgtest_main_a_SOURCES = $(GTEST_SOURCE)/src/gtest_main.cc
280-libgtest_main_a_CPPFLAGS = $(GTEST_CPPFLAGS) $(AM_CPPFLAGS) -w
281-libgtest_main_a_CXXFLAGS = $(GTEST_CXXFLAGS) $(AM_CXXFLAGS)
282-
283-nodist_libxorg_gtest_a_SOURCES = $(XORG_GTEST_SOURCE)/src/xorg-gtest-all.cpp
284-libxorg_gtest_a_CPPFLAGS = \
285- $(XORG_GTEST_CPPFLAGS) \
286- $(GTEST_CPPFLAGS) \
287- $(AM_CPPFLAGS) \
288- -iquote$(XORG_GTEST_SOURCE) \
289- -w
290-libxorg_gtest_a_CXXFLAGS = \
291- $(XORG_GTEST_CXXFLAGS) \
292- $(GTEST_CXXFLAGS) \
293- $(AM_CPPFLAGS)
294-
295-nodist_libxorg_gtest_main_a_SOURCES = \
296- $(XORG_GTEST_SOURCE)/src/xorg-gtest_main.cpp
297-libxorg_gtest_main_a_CPPFLAGS = \
298- $(XORG_GTEST_CPPFLAGS) \
299- $(GTEST_CPPFLAGS) \
300- $(AM_CPPFLAGS) \
301- -iquote$(XORG_GTEST_SOURCE) \
302- -w
303-libxorg_gtest_main_a_CXXFLAGS = \
304- $(XORG_GTEST_CXXFLAGS) \
305- $(GTEST_CXXFLAGS) \
306- $(AM_CXXFLAGS)
307-
308-XORG_GTEST_LIBS = libxorg-gtest.a libgtest.a -lpthread $(X11_LIBS)
309-XORG_GTEST_MAIN_LIBS = libxorg-gtest_main.a
310
311=== added file 'test/Makefile.am'
312--- test/Makefile.am 1970-01-01 00:00:00 +0000
313+++ test/Makefile.am 2012-07-18 13:01:21 +0000
314@@ -0,0 +1,5 @@
315+SUBDIRS = gtest x11_mocks regular
316+
317+if ENABLE_INTEGRATION_TESTS
318+SUBDIRS += integration
319+endif
320
321=== added file 'test/README'
322--- test/README 1970-01-01 00:00:00 +0000
323+++ test/README 2012-07-18 13:01:21 +0000
324@@ -0,0 +1,11 @@
325+Directory structure
326+===================
327+
328+- integration
329+ Here goes all integration tests.
330+ Those tests take time to run and rely on or interact with other processes
331+ beyond the test program itself.
332+
333+- regular
334+ Here goes tests that are fast to run and don't rely on the run-time
335+ environment (such as other processes, files, etc).
336
337=== added directory 'test/gtest'
338=== added file 'test/gtest/Makefile-xorg-gtest.am'
339--- test/gtest/Makefile-xorg-gtest.am 1970-01-01 00:00:00 +0000
340+++ test/gtest/Makefile-xorg-gtest.am 2012-07-18 13:01:21 +0000
341@@ -0,0 +1,68 @@
342+# Copyright (C) 2012 Canonical, Ltd.
343+#
344+# Permission is hereby granted, free of charge, to any person obtaining a copy
345+# of this software and associated documentation files (the "Software"), to deal
346+# in the Software without restriction, including without limitation the rights
347+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
348+# copies of the Software, and to permit persons to whom the Software is
349+# furnished to do so, subject to the following conditions:
350+#
351+# The above copyright notice and this permission notice (including the next
352+# paragraph) shall be included in all copies or substantial portions of the
353+# Software.
354+#
355+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
356+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
357+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
358+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
359+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
360+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
361+# SOFTWARE.
362+#
363+
364+XORG_GTEST_BUILD_LIBS = \
365+ libgtest.a \
366+ libgtest_main.a \
367+ libxorg-gtest.a \
368+ libxorg-gtest_main.a
369+
370+# Here and below we compile without warnings (-w) because the projects using
371+# xorg-gtest will not want to see warnings or fail to build due to warnings in
372+# gtest or xorg-gtest.
373+nodist_libgtest_a_SOURCES = $(GTEST_SOURCE)/src/gtest-all.cc
374+libgtest_a_CPPFLAGS = --std=c++0x $(GTEST_CPPFLAGS) $(AM_CPPFLAGS) -w
375+libgtest_a_CXXFLAGS = $(GTEST_CXXFLAGS) $(AM_CXXFLAGS)
376+
377+nodist_libgtest_main_a_SOURCES = $(GTEST_SOURCE)/src/gtest_main.cc
378+libgtest_main_a_CPPFLAGS = --std=c++0x $(GTEST_CPPFLAGS) $(AM_CPPFLAGS) -w
379+libgtest_main_a_CXXFLAGS = $(GTEST_CXXFLAGS) $(AM_CXXFLAGS)
380+
381+nodist_libxorg_gtest_a_SOURCES = $(XORG_GTEST_SOURCE)/src/xorg-gtest-all.cpp
382+libxorg_gtest_a_CPPFLAGS = \
383+ --std=c++0x \
384+ $(XORG_GTEST_CPPFLAGS) \
385+ $(GTEST_CPPFLAGS) \
386+ $(AM_CPPFLAGS) \
387+ -iquote$(XORG_GTEST_SOURCE) \
388+ -w
389+libxorg_gtest_a_CXXFLAGS = \
390+ $(XORG_GTEST_CXXFLAGS) \
391+ $(GTEST_CXXFLAGS) \
392+ $(AM_CPPFLAGS)
393+
394+nodist_libxorg_gtest_main_a_SOURCES = \
395+ $(XORG_GTEST_SOURCE)/src/xorg-gtest_main.cpp
396+libxorg_gtest_main_a_CPPFLAGS = \
397+ --std=c++0x \
398+ $(XORG_GTEST_CPPFLAGS) \
399+ $(GTEST_CPPFLAGS) \
400+ $(AM_CPPFLAGS) \
401+ -iquote$(XORG_GTEST_SOURCE) \
402+ -w
403+libxorg_gtest_main_a_CXXFLAGS = \
404+ $(XORG_GTEST_CXXFLAGS) \
405+ $(GTEST_CXXFLAGS) \
406+ $(AM_CXXFLAGS)
407+
408+XORG_GTEST_LIBS = libxorg-gtest.a libgtest.a -lpthread $(X11_LIBS)
409+XORG_GTEST_MAIN_LIBS = libxorg-gtest_main.a
410
411=== added file 'test/gtest/Makefile.am'
412--- test/gtest/Makefile.am 1970-01-01 00:00:00 +0000
413+++ test/gtest/Makefile.am 2012-07-18 13:01:21 +0000
414@@ -0,0 +1,11 @@
415+include $(top_srcdir)/test/gtest/Makefile-xorg-gtest.am
416+
417+check_LIBRARIES =
418+
419+if HAVE_GTEST
420+ check_LIBRARIES += libgtest.a libgtest_main.a
421+endif
422+
423+if ENABLE_INTEGRATION_TESTS
424+ check_LIBRARIES += libxorg-gtest.a libxorg-gtest_main.a
425+endif
426
427=== added directory 'test/integration'
428=== renamed file 'test/Makefile.am' => 'test/integration/Makefile.am'
429--- test/Makefile.am 2012-06-18 18:28:21 +0000
430+++ test/integration/Makefile.am 2012-07-18 13:01:21 +0000
431@@ -1,18 +1,11 @@
432-test_targets = check-c-compile check-cxx-compile
433-
434-if ENABLE_INTEGRATION_TESTS
435-include $(top_srcdir)/test/Makefile-xorg-gtest.am
436-check_LIBRARIES = $(XORG_GTEST_BUILD_LIBS)
437-
438-test_targets += check-frame
439-endif
440+test_targets = check-integration
441
442 TESTS = $(test_targets)
443-check_PROGRAMS = $(test_targets) check-static-type-checking
444+check_PROGRAMS = $(test_targets)
445
446 x11dir = x11
447
448-check_frame_SOURCES = \
449+check_integration_SOURCES = \
450 events.cpp \
451 events.h \
452 x11/device.cpp \
453@@ -22,53 +15,43 @@
454 x11/ids.cpp \
455 x11/recording.cpp
456
457-AM_CPPFLAGS = \
458+check_integration_CPPFLAGS = \
459+ --std=c++0x \
460+ -I$(top_srcdir) \
461 -I$(top_srcdir)/include \
462+ -I../include \
463+ -DTEST_ROOT_DIR=\"$(abs_top_srcdir)/test/integration/\"\
464 $(WARNING_CPPFLAGS) \
465 $(GTEST_CPPFLAGS) \
466 $(XORG_GTEST_CPPFLAGS)
467
468-AM_CFLAGS = $(C11_CFLAGS) $(COVERAGE_CFLAGS)
469+check_integration_CFLAGS = \
470+ $(C11_CFLAGS) \
471+ $(COVERAGE_CFLAGS) \
472+ $(XORG_GTEST_CFLAGS)
473
474-AM_CXXFLAGS = \
475+check_integration_CXXFLAGS = \
476 $(CXX11_CXXFLAGS) \
477+ $(COVERAGE_CXXFLAGS) \
478 $(GTEST_CXXFLAGS) \
479- $(COVERAGE_CXXFLAGS) \
480 $(XORG_GTEST_CXXFLAGS)
481
482-check_c_compile_SOURCES = check-c-compile.c
483-check_c_compile_LDADD = \
484- $(top_builddir)/src/libutouch-frame.la \
485- $(COVERAGE_LIBS)
486-
487-check_cxx_compile_SOURCES = check-cxx-compile.cpp
488-check_cxx_compile_LDADD = \
489- $(top_builddir)/src/libutouch-frame.la \
490- $(COVERAGE_LIBS)
491-
492-check_frame_LDFLAGS = $(GTEST_LDFLAGS)
493+# check_integration_LDFLAGS = $(GTEST_LDFLAGS)
494
495 #
496 # Link against the (non-distributed) static lib to pick up the
497 # internal symbols.
498 #
499-check_frame_LDADD = \
500+check_integration_LDADD = \
501 $(top_builddir)/src/.libs/libutouch-frame.a \
502+ $(top_builddir)/test/gtest/libgtest.a \
503+ $(top_builddir)/test/gtest/libxorg-gtest.a \
504+ $(top_builddir)/test/gtest/libxorg-gtest_main.a \
505+ $(GTEST_LIBS) \
506 $(XORG_GTEST_LIBS) \
507- $(XORG_GTEST_MAIN_LIBS) \
508 $(XINPUT_LIBS) \
509 $(EVEMU_LIBS) \
510 $(COVERAGE_LIBS) \
511 $(CXX_LIBS)
512
513-check-static-type-checking$(EXEEXT):
514- @echo "Checking whether static type checking works..."
515- $(AM_V_at)if $(CC) -I../include -L../.libs check-static-type-checking.c -o check_static_type_checking; then \
516- echo "FAIL: Static type checking source compiled without error"; \
517- exit -1; \
518- else \
519- echo "SUCCESS: Static type checking source failed to compile"; \
520- exit 0; \
521- fi
522-
523 EXTRA_DIST = recordings
524
525=== renamed file 'test/events.cpp' => 'test/integration/events.cpp'
526=== renamed file 'test/events.h' => 'test/integration/events.h'
527=== renamed directory 'test/recordings' => 'test/integration/recordings'
528=== renamed directory 'test/x11' => 'test/integration/x11'
529=== added directory 'test/regular'
530=== added file 'test/regular/Makefile.am'
531--- test/regular/Makefile.am 1970-01-01 00:00:00 +0000
532+++ test/regular/Makefile.am 2012-07-18 13:01:21 +0000
533@@ -0,0 +1,57 @@
534+test_targets = check-c-compile check-cxx-compile
535+
536+if HAVE_GTEST
537+test_targets += check-regular
538+endif
539+
540+TESTS = $(test_targets)
541+check_PROGRAMS = $(test_targets) check-static-type-checking
542+
543+check_c_compile_SOURCES = check-c-compile.c
544+check_c_compile_LDADD = \
545+ $(top_builddir)/src/libutouch-frame.la \
546+ $(COVERAGE_LIBS)
547+
548+check_cxx_compile_SOURCES = check-cxx-compile.cpp
549+check_cxx_compile_LDADD = \
550+ $(top_builddir)/src/libutouch-frame.la \
551+ $(COVERAGE_LIBS)
552+
553+check-static-type-checking$(EXEEXT):
554+ @echo "Checking whether static type checking works..."
555+ $(AM_V_at)if $(CC) -I../../include -L../../.libs check-static-type-checking.c -o check_static_type_checking; then \
556+ echo "FAIL: Static type checking source compiled without error"; \
557+ exit -1; \
558+ else \
559+ echo "SUCCESS: Static type checking source failed to compile"; \
560+ exit 0; \
561+ fi
562+
563+### check-regular
564+
565+check_regular_SOURCES = \
566+ accept-ended-touch.cpp \
567+ frame-fixture.cpp
568+
569+#
570+# Link against the (non-distributed) static lib to pick up the
571+# internal symbols.
572+#
573+check_regular_LDADD = \
574+ $(top_builddir)/src/.libs/libutouch-frame.a \
575+ $(top_builddir)/test/gtest/libgtest.a \
576+ $(top_builddir)/test/gtest/libgtest_main.a \
577+ $(top_builddir)/test/x11_mocks/libx11_mocks.a \
578+ $(COVERAGE_LIBS) \
579+ $(GTEST_LIBS)
580+
581+check_regular_CPPFLAGS = \
582+ --std=c++0x \
583+ -I$(top_srcdir) \
584+ -I$(top_srcdir)/include \
585+ -I$(top_srcdir)/test/x11_mocks \
586+ $(WARNING_CPPFLAGS) \
587+ $(GTEST_CPPFLAGS)
588+
589+check_regular_CFLAGS = \
590+ $(COVERAGE_CFLAGS)
591
592=== added file 'test/regular/accept-ended-touch.cpp'
593--- test/regular/accept-ended-touch.cpp 1970-01-01 00:00:00 +0000
594+++ test/regular/accept-ended-touch.cpp 2012-07-18 13:01:21 +0000
595@@ -0,0 +1,72 @@
596+#include "frame-fixture.h"
597+#include "x11_mocks.h"
598+
599+class AcceptEndedTouch : public FrameFixture
600+{
601+};
602+
603+/*
604+ Regression test for https://bugs.launchpad.net/bugs/1025297
605+
606+ The bug is as follows:
607+
608+ frame lib fails to forward the accept/reject command to xserver for an owned
609+ touch if it has already ended.
610+
611+ Steps to reproduce the issue:
612+ 1 - touch 1 begins and gets ownership
613+ 2 - touch 1 ends
614+ 3 - touch 2 begins and gets ownership
615+ 4 - frame client accepts touch 1
616+
617+ Expected outcome:
618+ frame lib accepts the touch on the XInput backend.
619+
620+ Outcome of the bug:
621+ Nothing happens. frame lib never accepts that touch.
622+ */
623+TEST_F(AcceptEndedTouch, Test)
624+{
625+ UFStatus status;
626+ UFDevice device;
627+
628+ xmock_server_time = 1234;
629+
630+ CreateXMockTouchScreenDevice();
631+
632+ Display *display = XOpenDisplay(NULL);
633+
634+ status = frame_x11_new(display, &frame_handle);
635+ ASSERT_EQ(UFStatusSuccess, status);
636+
637+ FetchDeviceAddedEvent(&device);
638+ AssertNoMoreEvents();
639+
640+ SendTouchEvent(XI_TouchBegin, 1, 10.0f, 10.0f);
641+ SendTouchOwnershipEvent(1);
642+
643+ xmock_server_time += 10;
644+
645+ SendTouchEvent(XI_TouchEnd, 1, 10.0f, 20.0f);
646+
647+ xmock_server_time += 3;
648+
649+ SendTouchEvent(XI_TouchBegin, 2, 10.0f, 21.0f);
650+ SendTouchOwnershipEvent(2);
651+
652+ UFWindowId frame_window_id = frame_x11_create_window_id(DefaultRootWindow(display));
653+ status = frame_x11_accept_touch(device, frame_window_id, 1);
654+ ASSERT_EQ(UFStatusSuccess, status);
655+
656+ ASSERT_EQ(XIAcceptTouch,
657+ xmock_get_touch_acceptance(xmock_devices[0].attachment /* device id */,
658+ 1 /* touch id */,
659+ DefaultRootWindow(display)));
660+
661+ frame_x11_delete(frame_handle);
662+ frame_handle = nullptr;
663+
664+ XCloseDisplay(display);
665+
666+ DestroyXMockDevices();
667+}
668
669=== renamed file 'test/check-c-compile.c' => 'test/regular/check-c-compile.c'
670=== renamed file 'test/check-cxx-compile.cpp' => 'test/regular/check-cxx-compile.cpp'
671=== renamed file 'test/check-static-type-checking.c' => 'test/regular/check-static-type-checking.c'
672=== added file 'test/regular/frame-fixture.cpp'
673--- test/regular/frame-fixture.cpp 1970-01-01 00:00:00 +0000
674+++ test/regular/frame-fixture.cpp 2012-07-18 13:01:21 +0000
675@@ -0,0 +1,161 @@
676+#include "frame-fixture.h"
677+#include "x11_mocks.h"
678+
679+FrameFixture::FrameFixture()
680+ : frame_handle(nullptr),
681+ _xevent_serial_number(1)
682+{
683+}
684+
685+void FrameFixture::SetUp()
686+{
687+ xmock_touch_acceptance.clear();
688+}
689+
690+void FrameFixture::TearDown()
691+{
692+ ASSERT_EQ(nullptr, frame_handle);
693+}
694+
695+void FrameFixture::CreateXMockTouchScreenDevice()
696+{
697+ xmock_devices_count = 1;
698+ xmock_devices = (XIDeviceInfo*) calloc(xmock_devices_count,
699+ sizeof(XIDeviceInfo));
700+
701+ XITouchClassInfo *touch_info = (XITouchClassInfo*) malloc(sizeof(XITouchClassInfo));
702+ touch_info->type = XITouchClass;
703+ touch_info->sourceid = 0;
704+ touch_info->mode = XIDirectTouch;
705+ touch_info->num_touches = 5;
706+
707+ XIValuatorClassInfo *x_axis_info = (XIValuatorClassInfo*) malloc(sizeof(XIValuatorClassInfo));
708+ x_axis_info->type = XIValuatorClass;
709+ x_axis_info->sourceid = 0;
710+ x_axis_info->number = 0; /* identifies it as being the X axis */
711+ x_axis_info->min = -500.0;
712+ x_axis_info->max = 500.0;
713+ x_axis_info->resolution = 3000; /* counts/meter */
714+
715+ XIValuatorClassInfo *y_axis_info = (XIValuatorClassInfo*) malloc(sizeof(XIValuatorClassInfo));
716+ y_axis_info->type = XIValuatorClass;
717+ y_axis_info->sourceid = 0;
718+ y_axis_info->number = 1; /* identifies it as being the Y axis */
719+ y_axis_info->min = -500.0;
720+ y_axis_info->max = 500.0;
721+ y_axis_info->resolution = 3000;
722+
723+ XIAnyClassInfo **classes = (XIAnyClassInfo**) malloc(sizeof(XIAnyClassInfo*)*3);
724+ classes[0] = (XIAnyClassInfo*) touch_info;
725+ classes[1] = (XIAnyClassInfo*) x_axis_info;
726+ classes[2] = (XIAnyClassInfo*) y_axis_info;
727+
728+ xmock_devices[0].deviceid = 0;
729+ xmock_devices[0].name = const_cast<char *>("Fake Touch Screen");
730+ xmock_devices[0].use = XISlavePointer;
731+ xmock_devices[0].attachment = 1;
732+ xmock_devices[0].enabled = True;
733+ xmock_devices[0].num_classes = 3;
734+ xmock_devices[0].classes = classes;
735+}
736+
737+void FrameFixture::DestroyXMockDevices()
738+{
739+ for (int i = 0; i < xmock_devices_count; ++i)
740+ {
741+ for (int j = 0; j < xmock_devices[i].num_classes; ++j)
742+ free(xmock_devices[i].classes[j]);
743+ free(xmock_devices[i].classes);
744+ }
745+ free(xmock_devices);
746+}
747+
748+void FrameFixture::SendTouchEvent(
749+ int event_type, int touch_id, float x, float y)
750+{
751+ UFStatus status;
752+ XGenericEventCookie xcookie;
753+ XIDeviceEvent *device_event = 0;
754+
755+ device_event = (XIDeviceEvent*)calloc(1, sizeof(XIDeviceEvent));
756+ device_event->serial = _xevent_serial_number++;
757+ device_event->display = xmock_display;
758+ device_event->extension = xmock_xi2_opcode;
759+ device_event->evtype = event_type;
760+ device_event->time = xmock_server_time;
761+ device_event->deviceid = 0;
762+ device_event->sourceid = device_event->deviceid;
763+ device_event->detail = touch_id;
764+ device_event->root = DefaultRootWindow(xmock_display);
765+ device_event->event = DefaultRootWindow(xmock_display);
766+ device_event->child = 0;
767+ device_event->root_x = x;
768+ device_event->root_y = y;
769+ device_event->event_x = device_event->root_x;
770+ device_event->event_y = device_event->root_y;
771+ device_event->valuators.mask_len = 2;
772+ device_event->valuators.mask = (unsigned char*) malloc(2);
773+ XISetMask(device_event->valuators.mask, 0);
774+ XISetMask(device_event->valuators.mask, 1);
775+ device_event->valuators.values = (double*) malloc(sizeof(double)*2);
776+ device_event->valuators.values[0] = 0; /* just change the coordinate system */
777+ device_event->valuators.values[1] = 0;
778+ xcookie.extension = xmock_xi2_opcode;
779+ xcookie.evtype = event_type;
780+ xcookie.data = device_event;
781+
782+ status = frame_x11_process_event(frame_handle, &xcookie);
783+ ASSERT_EQ(UFStatusSuccess, status);
784+}
785+
786+void FrameFixture::SendTouchOwnershipEvent(int touch_id)
787+{
788+ UFStatus status;
789+ XGenericEventCookie xcookie;
790+ XITouchOwnershipEvent *ownership_event = 0;
791+
792+ ownership_event = (XITouchOwnershipEvent*)calloc(1, sizeof(XITouchOwnershipEvent));
793+ ownership_event->type = GenericEvent;
794+ ownership_event->serial = _xevent_serial_number++;
795+ ownership_event->display = xmock_display;
796+ ownership_event->extension = xmock_xi2_opcode;
797+ ownership_event->evtype = XI_TouchOwnership;
798+ ownership_event->time = xmock_server_time;
799+ ownership_event->deviceid = 0;
800+ ownership_event->sourceid = ownership_event->deviceid;
801+ ownership_event->touchid = touch_id;
802+ ownership_event->root = DefaultRootWindow(xmock_display);
803+ ownership_event->event = DefaultRootWindow(xmock_display);
804+ ownership_event->child = 0;
805+ xcookie.extension = xmock_xi2_opcode;
806+ xcookie.evtype = XI_TouchOwnership;
807+ xcookie.data = ownership_event;
808+
809+ status = frame_x11_process_event(frame_handle, &xcookie);
810+ ASSERT_EQ(UFStatusSuccess, status);
811+}
812+
813+void FrameFixture::FetchDeviceAddedEvent(UFDevice *device)
814+{
815+ UFEvent event;
816+ UFStatus status;
817+
818+ status = frame_get_event(frame_handle, &event);
819+ ASSERT_EQ(UFStatusSuccess, status);
820+
821+ ASSERT_EQ(UFEventTypeDeviceAdded, frame_event_get_type(event));
822+
823+ status = frame_event_get_property(event, UFEventPropertyDevice, device);
824+ ASSERT_EQ(UFStatusSuccess, status);
825+
826+ frame_event_unref(event);
827+}
828+
829+void FrameFixture::AssertNoMoreEvents()
830+{
831+ UFEvent event;
832+ UFStatus status;
833+
834+ status = frame_get_event(frame_handle, &event);
835+ ASSERT_EQ(UFStatusErrorNoEvent, status);
836+}
837
838=== added file 'test/regular/frame-fixture.h'
839--- test/regular/frame-fixture.h 1970-01-01 00:00:00 +0000
840+++ test/regular/frame-fixture.h 2012-07-18 13:01:21 +0000
841@@ -0,0 +1,31 @@
842+#ifndef GTEST_FRAME_FIXTURE_H
843+#define GTEST_FRAME_FIXTURE_H
844+
845+#include <gtest/gtest.h>
846+#include "utouch/frame.h"
847+#include "utouch/frame_x11.h"
848+
849+class FrameFixture : public ::testing::Test
850+{
851+ protected:
852+ FrameFixture();
853+
854+ virtual void SetUp();
855+ virtual void TearDown();
856+
857+ void CreateXMockTouchScreenDevice();
858+ void DestroyXMockDevices();
859+
860+ void SendTouchEvent(int event_type, int touch_id, float x, float y);
861+ void SendTouchOwnershipEvent(int touch_id);
862+
863+ void FetchDeviceAddedEvent(UFDevice *device);
864+ void AssertNoMoreEvents();
865+
866+ UFHandle frame_handle;
867+ private:
868+ /* holds the serial number to be used on the next synthetic XEvent */
869+ int _xevent_serial_number;
870+};
871+
872+#endif
873
874=== added directory 'test/x11_mocks'
875=== added file 'test/x11_mocks/Makefile.am'
876--- test/x11_mocks/Makefile.am 1970-01-01 00:00:00 +0000
877+++ test/x11_mocks/Makefile.am 2012-07-18 13:01:21 +0000
878@@ -0,0 +1,14 @@
879+#
880+# @file testsuite/x11_mocks/Makefile.am
881+# @brief automake recipe for the X11 mockups
882+#
883+
884+check_LIBRARIES = libx11_mocks.a
885+
886+libx11_mocks_a_SOURCES = \
887+ x11_mocks.h x11_mocks.cpp
888+
889+libx11_mocks_a_CPPFLAGS = \
890+ --std=c++0x \
891+ -Wno-unused-parameter
892+
893
894=== added file 'test/x11_mocks/x11_mocks.cpp'
895--- test/x11_mocks/x11_mocks.cpp 1970-01-01 00:00:00 +0000
896+++ test/x11_mocks/x11_mocks.cpp 2012-07-18 13:01:21 +0000
897@@ -0,0 +1,435 @@
898+/* needed to break into 'Display' struct internals. */
899+#define XLIB_ILLEGAL_ACCESS
900+#include <X11/Xlib.h>
901+
902+#include "x11_mocks.h"
903+
904+#include <sys/eventfd.h>
905+#include <stdio.h>
906+#include <stdlib.h>
907+#include <unistd.h>
908+
909+int xmock_xi2_opcode = 42;
910+int xmock_xi2_event_base = 40000;
911+int xmock_xi2_error_base = 40000;
912+int xmock_xsync_event_base = 50000;
913+int xmock_xsync_error_base = 50000;
914+Display *xmock_display = NULL;
915+uint64_t xmock_server_time = 0;
916+
917+XIDeviceInfo *xmock_devices = NULL;
918+int xmock_devices_count = 0;
919+
920+std::map<int, std::map<unsigned int, std::map<Window, int> > > xmock_touch_acceptance;
921+
922+/* id to be used for the next alarm that gets created */
923+XSyncAlarm _xmock_next_alarm = 1;
924+
925+struct EventQueueItem
926+{
927+ XEvent event;
928+ struct EventQueueItem *next;
929+} *xmock_event_queue = NULL;
930+
931+#define XMOCK_PRINT_FUNCTION _xmock_print_function(__func__)
932+void _xmock_print_function(const char *function)
933+{
934+ static int debug_enabled = -1;
935+ if (debug_enabled == -1)
936+ {
937+ if (getenv("XMOCK_DEBUG"))
938+ debug_enabled = 1;
939+ else
940+ debug_enabled = 0;
941+ }
942+
943+ if (debug_enabled)
944+ printf("XMOCK: %s mock called.\n", function);
945+}
946+
947+void xmock_add_to_event_queue(const XEvent *event)
948+{
949+ struct EventQueueItem *new_item = reinterpret_cast<struct EventQueueItem *>(malloc(sizeof(struct EventQueueItem)));
950+ new_item->event = *event;
951+ new_item->next = NULL;
952+
953+ if (!xmock_event_queue)
954+ {
955+ xmock_event_queue = new_item;
956+ }
957+ else
958+ {
959+ struct EventQueueItem *last_item = xmock_event_queue;
960+ while (last_item->next)
961+ {
962+ last_item = last_item->next;
963+ }
964+ last_item->next = new_item;
965+ }
966+
967+ static const uint64_t num = 1;
968+ if (write(xmock_display->fd, &num, sizeof(num)) != sizeof(num))
969+ {
970+ fprintf(stderr, "ERROR: failed to update eventfd instance,\n");
971+ exit(1);
972+ }
973+}
974+
975+int xmock_get_touch_acceptance(int device_id, unsigned int touch_id, Window window)
976+{
977+ if (xmock_touch_acceptance.find(device_id) == xmock_touch_acceptance.end())
978+ return -1;
979+
980+ std::map<unsigned int, std::map<Window, int> > &touch_map =
981+ xmock_touch_acceptance[device_id];
982+
983+ if (touch_map.find(touch_id) == touch_map.end())
984+ return -1;
985+
986+ std::map<Window, int> &window_map = touch_map[touch_id];
987+
988+ if (window_map.find(window) == window_map.end())
989+ return -1;
990+
991+ return window_map[window];
992+}
993+
994+Display *XOpenDisplay(_Xconst char *display_name)
995+{
996+ XMOCK_PRINT_FUNCTION;
997+ (void)display_name;
998+
999+ Display *display = (Display*)calloc(1, sizeof(Display));
1000+ display->fd = eventfd(0, EFD_NONBLOCK);
1001+ display->default_screen = 0;
1002+ display->nscreens = 1;
1003+ display->screens = (Screen*)calloc(1, sizeof(Screen));
1004+ display->screens[0].root = 1;
1005+
1006+ xmock_display = display;
1007+
1008+ return display;
1009+}
1010+
1011+int XCloseDisplay(Display *display)
1012+{
1013+ XMOCK_PRINT_FUNCTION;
1014+
1015+ close(display->fd);
1016+ free(display->screens);
1017+ free(display);
1018+
1019+ xmock_display = NULL;
1020+
1021+ return 0;
1022+}
1023+
1024+int XSync(Display *display, Bool discard)
1025+{
1026+ (void)display;
1027+ (void)discard;
1028+ return 0;
1029+}
1030+
1031+int XFlush(Display *display)
1032+{
1033+ (void)display;
1034+ return 0;
1035+}
1036+
1037+Bool XQueryExtension(Display *display, const char *name,
1038+ int *major_opcode_return, int *first_event_return, int *first_error_return)
1039+{
1040+ XMOCK_PRINT_FUNCTION;
1041+ (void)display;
1042+ (void)name; /* assuming name == "XInputExtension" */
1043+
1044+ *major_opcode_return = xmock_xi2_opcode;
1045+ *first_event_return = xmock_xi2_event_base;
1046+ *first_error_return = xmock_xi2_error_base;
1047+
1048+ return True;
1049+}
1050+
1051+int XPending(Display *display)
1052+{
1053+ XMOCK_PRINT_FUNCTION;
1054+ (void)display;
1055+
1056+ int pending_events_count = 0;
1057+ struct EventQueueItem *item = xmock_event_queue;
1058+ while (item != NULL)
1059+ {
1060+ ++pending_events_count;
1061+ item = item->next;
1062+ }
1063+ return pending_events_count;
1064+}
1065+
1066+int XNextEvent(Display *display, XEvent *event_return)
1067+{
1068+ XMOCK_PRINT_FUNCTION;
1069+ (void)display;
1070+
1071+
1072+ if (xmock_event_queue)
1073+ {
1074+ uint64_t num = 1;
1075+ ssize_t bytes_read = read(xmock_display->fd, &num, sizeof(num));
1076+ (void)bytes_read;
1077+
1078+ *event_return = xmock_event_queue->event;
1079+
1080+ struct EventQueueItem *removed_item = xmock_event_queue;
1081+ xmock_event_queue = xmock_event_queue->next;
1082+ free(removed_item);
1083+ }
1084+ else
1085+ {
1086+ /* not going to block... */
1087+ }
1088+
1089+ return 0;
1090+}
1091+
1092+Bool XGetEventData(Display *display, XGenericEventCookie *cookie)
1093+{
1094+ XMOCK_PRINT_FUNCTION;
1095+ (void)display;
1096+ (void)cookie;
1097+ return True;
1098+}
1099+
1100+void XFreeEventData(Display *display, XGenericEventCookie *cookie)
1101+{
1102+ XMOCK_PRINT_FUNCTION;
1103+ (void)display;
1104+
1105+ if (cookie->data && cookie->extension == xmock_xi2_opcode)
1106+ {
1107+ if (cookie->evtype == XI_TouchBegin
1108+ || cookie->evtype == XI_TouchUpdate
1109+ || cookie->evtype == XI_TouchEnd)
1110+ {
1111+ XIDeviceEvent *device_event = (XIDeviceEvent*) cookie->data;
1112+ free(device_event->valuators.mask);
1113+ free(device_event->valuators.values);
1114+ }
1115+ free(cookie->data);
1116+ }
1117+}
1118+
1119+XIDeviceInfo* XIQueryDevice(Display * display,
1120+ int deviceid,
1121+ int * ndevices_return)
1122+{
1123+ XMOCK_PRINT_FUNCTION;
1124+ (void)display;
1125+ (void)deviceid; /* assuming XIAllDevices */
1126+
1127+ XIDeviceInfo *devices;
1128+
1129+ devices = reinterpret_cast<XIDeviceInfo*>(calloc(xmock_devices_count, sizeof(XIDeviceInfo)));
1130+
1131+ for (int i = 0; i < xmock_devices_count; ++i) {
1132+ devices[i] = xmock_devices[i];
1133+ }
1134+
1135+ *ndevices_return = xmock_devices_count;
1136+
1137+ return devices;
1138+}
1139+
1140+void XIFreeDeviceInfo(XIDeviceInfo *info)
1141+{
1142+ XMOCK_PRINT_FUNCTION;
1143+ free(info);
1144+}
1145+
1146+Status XIQueryVersion(Display *display,
1147+ int *major_version_inout,
1148+ int *minor_version_inout)
1149+{
1150+ XMOCK_PRINT_FUNCTION;
1151+ (void)display;
1152+ *major_version_inout = 2;
1153+ *minor_version_inout = 2;
1154+ return Success;
1155+}
1156+
1157+Status XISelectEvents(Display *display,
1158+ Window win,
1159+ XIEventMask *masks,
1160+ int num_masks)
1161+{
1162+ XMOCK_PRINT_FUNCTION;
1163+ (void)display;
1164+ (void)win;
1165+ (void)masks;
1166+ (void)num_masks;
1167+ return Success;
1168+}
1169+
1170+int XIGrabTouchBegin(
1171+ Display* display,
1172+ int deviceid,
1173+ Window grab_window,
1174+ int owner_events,
1175+ XIEventMask *mask,
1176+ int num_modifiers,
1177+ XIGrabModifiers *modifiers_inout)
1178+{
1179+ XMOCK_PRINT_FUNCTION;
1180+ (void)display;
1181+ (void)deviceid;
1182+ (void)grab_window;
1183+ (void)owner_events;
1184+ (void)mask;
1185+
1186+ for (int i = 0; i < num_modifiers; ++i)
1187+ {
1188+ modifiers_inout[i].status = XIGrabSuccess;
1189+ }
1190+
1191+ return 0;
1192+}
1193+
1194+Status XIUngrabTouchBegin(
1195+ Display* display,
1196+ int deviceid,
1197+ Window grab_window,
1198+ int num_modifiers,
1199+ XIGrabModifiers *modifiers)
1200+{
1201+ XMOCK_PRINT_FUNCTION;
1202+ (void)display;
1203+ (void)deviceid;
1204+ (void)grab_window;
1205+ (void)num_modifiers;
1206+ (void)modifiers;
1207+ return Success;
1208+}
1209+
1210+Status XIAllowTouchEvents(
1211+ Display* display,
1212+ int deviceid,
1213+ unsigned int touchid,
1214+ Window grab_window,
1215+ int event_mode)
1216+{
1217+ XMOCK_PRINT_FUNCTION;
1218+ (void)display;
1219+ xmock_touch_acceptance[deviceid][touchid][grab_window] = event_mode;
1220+ return Success;
1221+}
1222+
1223+Status XSyncQueryExtension(
1224+ Display* dpy,
1225+ int* event_base_return,
1226+ int* error_base_return)
1227+{
1228+ XMOCK_PRINT_FUNCTION;
1229+ (void)dpy;
1230+ *event_base_return = xmock_xsync_event_base;
1231+ *error_base_return = xmock_xsync_error_base;
1232+ return True;
1233+}
1234+
1235+Status XSyncInitialize(
1236+ Display* dpy,
1237+ int* major_version_return,
1238+ int* minor_version_return)
1239+{
1240+ XMOCK_PRINT_FUNCTION;
1241+ (void)dpy;
1242+ *major_version_return = 1;
1243+ *minor_version_return = 0;
1244+ return True;
1245+}
1246+
1247+XSyncSystemCounter *XSyncListSystemCounters(
1248+ Display* dpy,
1249+ int* n_counters_return)
1250+{
1251+ XMOCK_PRINT_FUNCTION;
1252+ (void)dpy;
1253+ *n_counters_return = 1;
1254+
1255+ XSyncSystemCounter *sys_counter = reinterpret_cast<XSyncSystemCounter*>(malloc(sizeof(XSyncSystemCounter)));
1256+ sys_counter->name = const_cast<char*>("SERVERTIME"); // I know it's technically dangerous, but it's simple.
1257+ sys_counter->counter = 1;
1258+ sys_counter->resolution.hi = 1;
1259+ sys_counter->resolution.lo = 0;
1260+ return sys_counter;
1261+}
1262+
1263+void XSyncFreeSystemCounterList(XSyncSystemCounter* list)
1264+{
1265+ XMOCK_PRINT_FUNCTION;
1266+ free(list);
1267+}
1268+
1269+XSyncAlarm XSyncCreateAlarm(
1270+ Display* dpy,
1271+ unsigned long values_mask,
1272+ XSyncAlarmAttributes* values)
1273+{
1274+ XMOCK_PRINT_FUNCTION;
1275+ (void)dpy;
1276+
1277+ XSyncAlarmNotifyEvent alarm_notify;
1278+ alarm_notify.type = xmock_xsync_event_base + XSyncAlarmNotify;
1279+ alarm_notify.alarm = _xmock_next_alarm;
1280+ alarm_notify.counter_value = values->trigger.wait_value;
1281+ xmock_add_to_event_queue((XEvent*)&alarm_notify);
1282+
1283+ XSyncValue time = values->trigger.wait_value;
1284+ uint64_t timeout = (uint64_t)XSyncValueHigh32(time) << 32
1285+ | (uint64_t)XSyncValueLow32(time);
1286+ xmock_server_time = timeout + 1;
1287+
1288+ return _xmock_next_alarm++;
1289+}
1290+
1291+Status XSyncDestroyAlarm(
1292+ Display* dpy,
1293+ XSyncAlarm alarm)
1294+{
1295+ XMOCK_PRINT_FUNCTION;
1296+ (void)dpy;
1297+ (void)alarm;
1298+ return Success;
1299+}
1300+
1301+void XSyncIntsToValue(
1302+ XSyncValue* pv,
1303+ unsigned int l,
1304+ int h)
1305+{
1306+ XMOCK_PRINT_FUNCTION;
1307+ pv->hi = h;
1308+ pv->lo = l;
1309+}
1310+
1311+int XSyncValueHigh32(XSyncValue v)
1312+{
1313+ XMOCK_PRINT_FUNCTION;
1314+ return v.hi;
1315+}
1316+
1317+unsigned int XSyncValueLow32(XSyncValue v)
1318+{
1319+ XMOCK_PRINT_FUNCTION;
1320+ return v.lo;
1321+}
1322+
1323+Atom XInternAtom(Display* display, _Xconst char* atom_name, Bool only_if_exists)
1324+{
1325+ XMOCK_PRINT_FUNCTION;
1326+ /* This function doesn't end up getting called when frame is run from tests yet.
1327+ It's here just to make the code compile. Add some minimal logic when needed. */
1328+ abort();
1329+ return 1;
1330+}
1331+
1332+
1333
1334=== added file 'test/x11_mocks/x11_mocks.h'
1335--- test/x11_mocks/x11_mocks.h 1970-01-01 00:00:00 +0000
1336+++ test/x11_mocks/x11_mocks.h 2012-07-18 13:01:21 +0000
1337@@ -0,0 +1,41 @@
1338+#ifndef X11_MOCKS_H
1339+#define X11_MOCKS_H
1340+
1341+#include <X11/Xlib.h>
1342+#include <X11/extensions/XInput2.h>
1343+#include <X11/extensions/sync.h>
1344+#include <stdint.h>
1345+#include <map>
1346+
1347+extern int xmock_xi2_opcode;
1348+extern int xmock_xi2_event_base;
1349+extern int xmock_xi2_error_base;
1350+extern int xmock_xsync_event_base;
1351+extern int xmock_xsync_error_base;
1352+extern Display *xmock_display;
1353+extern uint64_t xmock_server_time;
1354+
1355+/* to be filled by user. A copy of it will be returned by each
1356+ XIQueryDevice call */
1357+extern XIDeviceInfo *xmock_devices;
1358+extern int xmock_devices_count;
1359+
1360+/* Adds the given XEvent to the xmock event queue.
1361+ The Diplay connection will signal that there are
1362+ pending events */
1363+extern void xmock_add_to_event_queue(const XEvent* event);
1364+
1365+/*
1366+ Each call to:
1367+ XIAllowTouchEvents(display, device_id, touch_id, window_id, touch_acceptance)
1368+ Causes:
1369+ xmock_touch_acceptance[device_id][touch_id][window_id] = touch_acceptance;
1370+ */
1371+extern std::map<int, std::map<unsigned int, std::map<Window, int> > > xmock_touch_acceptance;
1372+
1373+/*
1374+ Returns -1 if XIAllowTouchEvents wasn't called with the given parameters.
1375+ */
1376+int xmock_get_touch_acceptance(int device_id, unsigned int touch_id, Window window);
1377+
1378+#endif

Subscribers

People subscribed via source and target branches