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
=== modified file '.bzrignore'
--- .bzrignore 2012-03-28 00:45:08 +0000
+++ .bzrignore 2012-07-18 13:01:21 +0000
@@ -26,9 +26,10 @@
26m4/lt~obsolete.m426m4/lt~obsolete.m4
27m4/pkg.m427m4/pkg.m4
28stamp-*28stamp-*
29test/check-c-compile29test/regular/check-c-compile
30test/check-cxx-compile30test/regular/check-cxx-compile
31test/check-frame31test/regular/check-regular
32test/integration/check-integration
32tools/utouch-frame-test-mtdev33tools/utouch-frame-test-mtdev
33tools/utouch-frame-test-mtdev.134tools/utouch-frame-test-mtdev.1
34tools/utouch-frame-test-xi235tools/utouch-frame-test-xi2
3536
=== modified file 'Makefile.am'
--- Makefile.am 2012-03-31 02:31:54 +0000
+++ Makefile.am 2012-07-18 13:01:21 +0000
@@ -9,8 +9,6 @@
9pkgconfigdir = $(libdir)/pkgconfig9pkgconfigdir = $(libdir)/pkgconfig
10pkgconfig_DATA = utouch-frame.pc10pkgconfig_DATA = utouch-frame.pc
1111
12INCLUDES = $(top_srcdir)/include/
13
14if HAVE_GCOV12if HAVE_GCOV
15 .PHONY: clean-gcda13 .PHONY: clean-gcda
16 clean-gcda:14 clean-gcda:
1715
=== modified file 'configure.ac'
--- configure.ac 2012-06-18 18:28:21 +0000
+++ configure.ac 2012-07-18 13:01:21 +0000
@@ -25,7 +25,8 @@
25AC_PROG_CXX25AC_PROG_CXX
26AC_PROG_INSTALL26AC_PROG_INSTALL
2727
28PKG_CHECK_MODULES([EVEMU], [utouch-evemu >= 1.0.5])28PKG_CHECK_MODULES([EVEMU], [utouch-evemu >= 1.0.5], [have_evemu=yes])
29AM_CONDITIONAL([HAVE_EVEMU], [test "x$have_evemu" = xyes])
2930
30PKG_CHECK_MODULES(XINPUT, x11 xext xorg-server [xi >= 1.5.99.1] [inputproto >= 2.1.99.6])31PKG_CHECK_MODULES(XINPUT, x11 xext xorg-server [xi >= 1.5.99.1] [inputproto >= 2.1.99.6])
3132
@@ -34,6 +35,11 @@
34AS_IF([test "x$ASCIIDOC" = "x"],35AS_IF([test "x$ASCIIDOC" = "x"],
35 [AC_MSG_WARN([asciidoc not installed, man pages will not be created])])36 [AC_MSG_WARN([asciidoc not installed, man pages will not be created])])
3637
38
39# Check for Google C++ Testing Framework
40CHECK_GTEST()
41AM_CONDITIONAL([HAVE_GTEST], [test "x$have_gtest" = xyes])
42
37# Check for TDD tools43# Check for TDD tools
38AC_ARG_ENABLE([integration-tests],44AC_ARG_ENABLE([integration-tests],
39 [AS_HELP_STRING([--enable-integration-tests],45 [AS_HELP_STRING([--enable-integration-tests],
@@ -43,13 +49,11 @@
4349
44AS_IF([test "x$enable_integration_tests" != xno],50AS_IF([test "x$enable_integration_tests" != xno],
45 [CHECK_XORG_GTEST(51 [CHECK_XORG_GTEST(
46 [AC_MSG_NOTICE([xorg-gtest is available, tests will be built])],52 [AC_MSG_NOTICE([xorg-gtest is available, integration tests will be built])],
47 [AC_MSG_WARN([xorg-gtest is not available, tests will not be built])])])53 [AC_MSG_WARN([xorg-gtest is not available, tests will not be built])])])
4854
49AM_CONDITIONAL([ENABLE_INTEGRATION_TESTS], [test "x$have_xorg_gtest" = xyes])55AM_CONDITIONAL([ENABLE_INTEGRATION_TESTS], [test "x$have_xorg_gtest" = xyes])
5056
51AM_CONDITIONAL([HAVE_GTEST], [test "x$have_xorg_gtest" = xyes])
52
53AC_SUBST([GTEST_LDFLAGS])57AC_SUBST([GTEST_LDFLAGS])
54AC_SUBST([GTEST_CXXFLAGS])58AC_SUBST([GTEST_CXXFLAGS])
5559
@@ -66,6 +70,10 @@
66 doc/Makefile70 doc/Makefile
67 src/Makefile71 src/Makefile
68 test/Makefile72 test/Makefile
73 test/gtest/Makefile
74 test/integration/Makefile
75 test/regular/Makefile
76 test/x11_mocks/Makefile
69 tools/Makefile77 tools/Makefile
70 utouch-frame.pc])78 utouch-frame.pc])
7179
7280
=== added file 'm4/gtest.m4'
--- m4/gtest.m4 1970-01-01 00:00:00 +0000
+++ m4/gtest.m4 2012-07-18 13:01:21 +0000
@@ -0,0 +1,51 @@
1# Copyright (C) 2012 Canonical, Ltd.
2#
3# Permission is hereby granted, free of charge, to any person obtaining a copy
4# of this software and associated documentation files (the "Software"), to deal
5# in the Software without restriction, including without limitation the rights
6# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7# copies of the Software, and to permit persons to whom the Software is
8# furnished to do so, subject to the following conditions:
9#
10# The above copyright notice and this permission notice (including the next
11# paragraph) shall be included in all copies or substantial portions of the
12# Software.
13#
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20# SOFTWARE.
21
22# Checks whether the gtest source is available on the system. Allows for
23# adjusting the include and source path. Sets have_gtest=yes if the source is
24# present. Sets GTEST_CPPFLAGS and GTEST_SOURCE to the preprocessor flags and
25# source location respectively.
26AC_DEFUN([CHECK_GTEST],
27[
28 AC_ARG_WITH([gtest-include-path],
29 [AS_HELP_STRING([--with-gtest-include-path],
30 [location of the Google test headers])],
31 [GTEST_CPPFLAGS="-I$withval"])
32
33 AC_ARG_WITH([gtest-source-path],
34 [AS_HELP_STRING([--with-gtest-source-path],
35 [location of the Google test sources, defaults to /usr/src/gtest])],
36 [GTEST_SOURCE="$withval"],
37 [GTEST_SOURCE="/usr/src/gtest"])
38
39 GTEST_CPPFLAGS="$GTEST_CPPFLAGS -I$GTEST_SOURCE"
40
41 AC_CHECK_FILES([$GTEST_SOURCE/src/gtest-all.cc]
42 [$GTEST_SOURCE/src/gtest_main.cc],
43 [have_gtest=yes],
44 [have_gtest=no])
45
46 AS_IF([test "x$have_gtest" = xyes],
47 [GTEST_LIBS=-lpthread
48 AC_SUBST(GTEST_CPPFLAGS)
49 AC_SUBST(GTEST_SOURCE)
50 AC_SUBST(GTEST_LIBS)])
51]) # CHECK_GTEST
052
=== modified file 'src/x11/window_x11.cpp'
--- src/x11/window_x11.cpp 2012-06-18 18:28:21 +0000
+++ src/x11/window_x11.cpp 2012-07-18 13:01:21 +0000
@@ -36,8 +36,6 @@
36 : window_(window),36 : window_(window),
37 display_(display),37 display_(display),
38 device_(static_cast<UFDeviceX11*>(device.get())),38 device_(static_cast<UFDeviceX11*>(device.get())),
39 touches_to_accept_(),
40 touches_to_reject_(),
41 unaccepted_unrejected_touches_() {39 unaccepted_unrejected_touches_() {
42}40}
4341
@@ -167,55 +165,37 @@
167165
168 current_frame_ = *frame;166 current_frame_ = *frame;
169167
170 if (touches_to_accept_.count(event->touchid)) {168 unaccepted_unrejected_touches_.insert(event->touchid);
171 XIAllowTouchEvents(display_, device_->master_id(), event->touchid, window_,
172 XIAcceptTouch);
173 touches_to_accept_.erase(event->touchid);
174 } else if (touches_to_reject_.count(event->touchid)) {
175 XIAllowTouchEvents(display_, device_->master_id(), event->touchid, window_,
176 XIRejectTouch);
177 touches_to_reject_.erase(event->touchid);
178 } else {
179 unaccepted_unrejected_touches_.insert(event->touchid);
180 }
181169
182 return true;170 return true;
183}171}
184172
185UFStatus WindowX11::AcceptTouch(UFTouchId touch_id) {173UFStatus WindowX11::AcceptTouch(UFTouchId touch_id) {
186 if (current_frame_->IsTouchOwned(touch_id)) {174 if (XIAllowTouchEvents(display_, device_->master_id(), touch_id, window_,
187 if (XIAllowTouchEvents(display_, device_->master_id(), touch_id, window_,175 XIAcceptTouch))
188 XIAcceptTouch))176 return UFStatusErrorGeneric;
189 return UFStatusErrorGeneric;177
190178 /* Flush output buffer so touches are actually accepted ASAP. The server
191 /* Flush output buffer so touches are actually accepted ASAP. The server179 * can't perform pointer emulation while the currently emulated touch is
192 * can't perform pointer emulation while the currently emulated touch is180 * still potentially active for pointer emulation. */
193 * still potentially active for pointer emulation. */181 XFlush(display_);
194 XFlush(display_);182
195183 unaccepted_unrejected_touches_.erase(touch_id);
196 unaccepted_unrejected_touches_.erase(touch_id);
197 } else {
198 touches_to_accept_.insert(touch_id);
199 }
200184
201 return UFStatusSuccess;185 return UFStatusSuccess;
202}186}
203187
204UFStatus WindowX11::RejectTouch(UFTouchId touch_id) {188UFStatus WindowX11::RejectTouch(UFTouchId touch_id) {
205 if (current_frame_->IsTouchOwned(touch_id)) {189 if (XIAllowTouchEvents(display_, device_->master_id(), touch_id, window_,
206 if (XIAllowTouchEvents(display_, device_->master_id(), touch_id, window_,190 XIRejectTouch))
207 XIRejectTouch))191 return UFStatusErrorGeneric;
208 return UFStatusErrorGeneric;192
209193 /* Flush output buffer so touches are actually rejected ASAP. The server
210 /* Flush output buffer so touches are actually rejected ASAP. The server194 * can't perform pointer emulation while the currently emulated touch is
211 * can't perform pointer emulation while the currently emulated touch is195 * still potentially active for pointer emulation. */
212 * still potentially active for pointer emulation. */196 XFlush(display_);
213 XFlush(display_);197
214198 unaccepted_unrejected_touches_.erase(touch_id);
215 unaccepted_unrejected_touches_.erase(touch_id);
216 } else {
217 touches_to_reject_.insert(touch_id);
218 }
219199
220 return UFStatusSuccess;200 return UFStatusSuccess;
221}201}
222202
=== modified file 'src/x11/window_x11.h'
--- src/x11/window_x11.h 2012-06-18 18:28:21 +0000
+++ src/x11/window_x11.h 2012-07-18 13:01:21 +0000
@@ -57,8 +57,6 @@
57 ::Window window_;57 ::Window window_;
58 Display* display_;58 Display* display_;
59 UFDeviceX11* device_;59 UFDeviceX11* device_;
60 std::set<UFTouchId> touches_to_accept_;
61 std::set<UFTouchId> touches_to_reject_;
62 std::set<UFTouchId> unaccepted_unrejected_touches_;60 std::set<UFTouchId> unaccepted_unrejected_touches_;
63};61};
6462
6563
=== removed file 'test/Makefile-xorg-gtest.am'
--- test/Makefile-xorg-gtest.am 2012-06-18 18:28:21 +0000
+++ test/Makefile-xorg-gtest.am 1970-01-01 00:00:00 +0000
@@ -1,63 +0,0 @@
1# Copyright (C) 2012 Canonical, Ltd.
2#
3# Permission is hereby granted, free of charge, to any person obtaining a copy
4# of this software and associated documentation files (the "Software"), to deal
5# in the Software without restriction, including without limitation the rights
6# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7# copies of the Software, and to permit persons to whom the Software is
8# furnished to do so, subject to the following conditions:
9#
10# The above copyright notice and this permission notice (including the next
11# paragraph) shall be included in all copies or substantial portions of the
12# Software.
13#
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20# SOFTWARE.
21#
22
23XORG_GTEST_BUILD_LIBS = \
24 libgtest.a \
25 libgtest_main.a \
26 libxorg-gtest.a \
27 libxorg-gtest_main.a
28
29nodist_libgtest_a_SOURCES = $(GTEST_SOURCE)/src/gtest-all.cc
30libgtest_a_CPPFLAGS = $(GTEST_CPPFLAGS) $(AM_CPPFLAGS) -w
31libgtest_a_CXXFLAGS = $(GTEST_CXXFLAGS) $(AM_CXXFLAGS)
32
33nodist_libgtest_main_a_SOURCES = $(GTEST_SOURCE)/src/gtest_main.cc
34libgtest_main_a_CPPFLAGS = $(GTEST_CPPFLAGS) $(AM_CPPFLAGS) -w
35libgtest_main_a_CXXFLAGS = $(GTEST_CXXFLAGS) $(AM_CXXFLAGS)
36
37nodist_libxorg_gtest_a_SOURCES = $(XORG_GTEST_SOURCE)/src/xorg-gtest-all.cpp
38libxorg_gtest_a_CPPFLAGS = \
39 $(XORG_GTEST_CPPFLAGS) \
40 $(GTEST_CPPFLAGS) \
41 $(AM_CPPFLAGS) \
42 -iquote$(XORG_GTEST_SOURCE) \
43 -w
44libxorg_gtest_a_CXXFLAGS = \
45 $(XORG_GTEST_CXXFLAGS) \
46 $(GTEST_CXXFLAGS) \
47 $(AM_CPPFLAGS)
48
49nodist_libxorg_gtest_main_a_SOURCES = \
50 $(XORG_GTEST_SOURCE)/src/xorg-gtest_main.cpp
51libxorg_gtest_main_a_CPPFLAGS = \
52 $(XORG_GTEST_CPPFLAGS) \
53 $(GTEST_CPPFLAGS) \
54 $(AM_CPPFLAGS) \
55 -iquote$(XORG_GTEST_SOURCE) \
56 -w
57libxorg_gtest_main_a_CXXFLAGS = \
58 $(XORG_GTEST_CXXFLAGS) \
59 $(GTEST_CXXFLAGS) \
60 $(AM_CXXFLAGS)
61
62XORG_GTEST_LIBS = libxorg-gtest.a libgtest.a -lpthread $(X11_LIBS)
63XORG_GTEST_MAIN_LIBS = libxorg-gtest_main.a
640
=== added file 'test/Makefile.am'
--- test/Makefile.am 1970-01-01 00:00:00 +0000
+++ test/Makefile.am 2012-07-18 13:01:21 +0000
@@ -0,0 +1,5 @@
1SUBDIRS = gtest x11_mocks regular
2
3if ENABLE_INTEGRATION_TESTS
4SUBDIRS += integration
5endif
06
=== added file 'test/README'
--- test/README 1970-01-01 00:00:00 +0000
+++ test/README 2012-07-18 13:01:21 +0000
@@ -0,0 +1,11 @@
1Directory structure
2===================
3
4- integration
5 Here goes all integration tests.
6 Those tests take time to run and rely on or interact with other processes
7 beyond the test program itself.
8
9- regular
10 Here goes tests that are fast to run and don't rely on the run-time
11 environment (such as other processes, files, etc).
012
=== added directory 'test/gtest'
=== added file 'test/gtest/Makefile-xorg-gtest.am'
--- test/gtest/Makefile-xorg-gtest.am 1970-01-01 00:00:00 +0000
+++ test/gtest/Makefile-xorg-gtest.am 2012-07-18 13:01:21 +0000
@@ -0,0 +1,68 @@
1# Copyright (C) 2012 Canonical, Ltd.
2#
3# Permission is hereby granted, free of charge, to any person obtaining a copy
4# of this software and associated documentation files (the "Software"), to deal
5# in the Software without restriction, including without limitation the rights
6# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7# copies of the Software, and to permit persons to whom the Software is
8# furnished to do so, subject to the following conditions:
9#
10# The above copyright notice and this permission notice (including the next
11# paragraph) shall be included in all copies or substantial portions of the
12# Software.
13#
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20# SOFTWARE.
21#
22
23XORG_GTEST_BUILD_LIBS = \
24 libgtest.a \
25 libgtest_main.a \
26 libxorg-gtest.a \
27 libxorg-gtest_main.a
28
29# Here and below we compile without warnings (-w) because the projects using
30# xorg-gtest will not want to see warnings or fail to build due to warnings in
31# gtest or xorg-gtest.
32nodist_libgtest_a_SOURCES = $(GTEST_SOURCE)/src/gtest-all.cc
33libgtest_a_CPPFLAGS = --std=c++0x $(GTEST_CPPFLAGS) $(AM_CPPFLAGS) -w
34libgtest_a_CXXFLAGS = $(GTEST_CXXFLAGS) $(AM_CXXFLAGS)
35
36nodist_libgtest_main_a_SOURCES = $(GTEST_SOURCE)/src/gtest_main.cc
37libgtest_main_a_CPPFLAGS = --std=c++0x $(GTEST_CPPFLAGS) $(AM_CPPFLAGS) -w
38libgtest_main_a_CXXFLAGS = $(GTEST_CXXFLAGS) $(AM_CXXFLAGS)
39
40nodist_libxorg_gtest_a_SOURCES = $(XORG_GTEST_SOURCE)/src/xorg-gtest-all.cpp
41libxorg_gtest_a_CPPFLAGS = \
42 --std=c++0x \
43 $(XORG_GTEST_CPPFLAGS) \
44 $(GTEST_CPPFLAGS) \
45 $(AM_CPPFLAGS) \
46 -iquote$(XORG_GTEST_SOURCE) \
47 -w
48libxorg_gtest_a_CXXFLAGS = \
49 $(XORG_GTEST_CXXFLAGS) \
50 $(GTEST_CXXFLAGS) \
51 $(AM_CPPFLAGS)
52
53nodist_libxorg_gtest_main_a_SOURCES = \
54 $(XORG_GTEST_SOURCE)/src/xorg-gtest_main.cpp
55libxorg_gtest_main_a_CPPFLAGS = \
56 --std=c++0x \
57 $(XORG_GTEST_CPPFLAGS) \
58 $(GTEST_CPPFLAGS) \
59 $(AM_CPPFLAGS) \
60 -iquote$(XORG_GTEST_SOURCE) \
61 -w
62libxorg_gtest_main_a_CXXFLAGS = \
63 $(XORG_GTEST_CXXFLAGS) \
64 $(GTEST_CXXFLAGS) \
65 $(AM_CXXFLAGS)
66
67XORG_GTEST_LIBS = libxorg-gtest.a libgtest.a -lpthread $(X11_LIBS)
68XORG_GTEST_MAIN_LIBS = libxorg-gtest_main.a
069
=== added file 'test/gtest/Makefile.am'
--- test/gtest/Makefile.am 1970-01-01 00:00:00 +0000
+++ test/gtest/Makefile.am 2012-07-18 13:01:21 +0000
@@ -0,0 +1,11 @@
1include $(top_srcdir)/test/gtest/Makefile-xorg-gtest.am
2
3check_LIBRARIES =
4
5if HAVE_GTEST
6 check_LIBRARIES += libgtest.a libgtest_main.a
7endif
8
9if ENABLE_INTEGRATION_TESTS
10 check_LIBRARIES += libxorg-gtest.a libxorg-gtest_main.a
11endif
012
=== added directory 'test/integration'
=== renamed file 'test/Makefile.am' => 'test/integration/Makefile.am'
--- test/Makefile.am 2012-06-18 18:28:21 +0000
+++ test/integration/Makefile.am 2012-07-18 13:01:21 +0000
@@ -1,18 +1,11 @@
1test_targets = check-c-compile check-cxx-compile1test_targets = check-integration
2
3if ENABLE_INTEGRATION_TESTS
4include $(top_srcdir)/test/Makefile-xorg-gtest.am
5check_LIBRARIES = $(XORG_GTEST_BUILD_LIBS)
6
7test_targets += check-frame
8endif
92
10TESTS = $(test_targets)3TESTS = $(test_targets)
11check_PROGRAMS = $(test_targets) check-static-type-checking4check_PROGRAMS = $(test_targets)
125
13x11dir = x116x11dir = x11
147
15check_frame_SOURCES = \8check_integration_SOURCES = \
16 events.cpp \9 events.cpp \
17 events.h \10 events.h \
18 x11/device.cpp \11 x11/device.cpp \
@@ -22,53 +15,43 @@
22 x11/ids.cpp \15 x11/ids.cpp \
23 x11/recording.cpp16 x11/recording.cpp
2417
25AM_CPPFLAGS = \18check_integration_CPPFLAGS = \
19 --std=c++0x \
20 -I$(top_srcdir) \
26 -I$(top_srcdir)/include \21 -I$(top_srcdir)/include \
22 -I../include \
23 -DTEST_ROOT_DIR=\"$(abs_top_srcdir)/test/integration/\"\
27 $(WARNING_CPPFLAGS) \24 $(WARNING_CPPFLAGS) \
28 $(GTEST_CPPFLAGS) \25 $(GTEST_CPPFLAGS) \
29 $(XORG_GTEST_CPPFLAGS)26 $(XORG_GTEST_CPPFLAGS)
3027
31AM_CFLAGS = $(C11_CFLAGS) $(COVERAGE_CFLAGS)28check_integration_CFLAGS = \
29 $(C11_CFLAGS) \
30 $(COVERAGE_CFLAGS) \
31 $(XORG_GTEST_CFLAGS)
3232
33AM_CXXFLAGS = \33check_integration_CXXFLAGS = \
34 $(CXX11_CXXFLAGS) \34 $(CXX11_CXXFLAGS) \
35 $(COVERAGE_CXXFLAGS) \
35 $(GTEST_CXXFLAGS) \36 $(GTEST_CXXFLAGS) \
36 $(COVERAGE_CXXFLAGS) \
37 $(XORG_GTEST_CXXFLAGS)37 $(XORG_GTEST_CXXFLAGS)
3838
39check_c_compile_SOURCES = check-c-compile.c39# check_integration_LDFLAGS = $(GTEST_LDFLAGS)
40check_c_compile_LDADD = \
41 $(top_builddir)/src/libutouch-frame.la \
42 $(COVERAGE_LIBS)
43
44check_cxx_compile_SOURCES = check-cxx-compile.cpp
45check_cxx_compile_LDADD = \
46 $(top_builddir)/src/libutouch-frame.la \
47 $(COVERAGE_LIBS)
48
49check_frame_LDFLAGS = $(GTEST_LDFLAGS)
5040
51#41#
52# Link against the (non-distributed) static lib to pick up the42# Link against the (non-distributed) static lib to pick up the
53# internal symbols.43# internal symbols.
54#44#
55check_frame_LDADD = \45check_integration_LDADD = \
56 $(top_builddir)/src/.libs/libutouch-frame.a \46 $(top_builddir)/src/.libs/libutouch-frame.a \
47 $(top_builddir)/test/gtest/libgtest.a \
48 $(top_builddir)/test/gtest/libxorg-gtest.a \
49 $(top_builddir)/test/gtest/libxorg-gtest_main.a \
50 $(GTEST_LIBS) \
57 $(XORG_GTEST_LIBS) \51 $(XORG_GTEST_LIBS) \
58 $(XORG_GTEST_MAIN_LIBS) \
59 $(XINPUT_LIBS) \52 $(XINPUT_LIBS) \
60 $(EVEMU_LIBS) \53 $(EVEMU_LIBS) \
61 $(COVERAGE_LIBS) \54 $(COVERAGE_LIBS) \
62 $(CXX_LIBS)55 $(CXX_LIBS)
6356
64check-static-type-checking$(EXEEXT):
65 @echo "Checking whether static type checking works..."
66 $(AM_V_at)if $(CC) -I../include -L../.libs check-static-type-checking.c -o check_static_type_checking; then \
67 echo "FAIL: Static type checking source compiled without error"; \
68 exit -1; \
69 else \
70 echo "SUCCESS: Static type checking source failed to compile"; \
71 exit 0; \
72 fi
73
74EXTRA_DIST = recordings57EXTRA_DIST = recordings
7558
=== renamed file 'test/events.cpp' => 'test/integration/events.cpp'
=== renamed file 'test/events.h' => 'test/integration/events.h'
=== renamed directory 'test/recordings' => 'test/integration/recordings'
=== renamed directory 'test/x11' => 'test/integration/x11'
=== added directory 'test/regular'
=== added file 'test/regular/Makefile.am'
--- test/regular/Makefile.am 1970-01-01 00:00:00 +0000
+++ test/regular/Makefile.am 2012-07-18 13:01:21 +0000
@@ -0,0 +1,57 @@
1test_targets = check-c-compile check-cxx-compile
2
3if HAVE_GTEST
4test_targets += check-regular
5endif
6
7TESTS = $(test_targets)
8check_PROGRAMS = $(test_targets) check-static-type-checking
9
10check_c_compile_SOURCES = check-c-compile.c
11check_c_compile_LDADD = \
12 $(top_builddir)/src/libutouch-frame.la \
13 $(COVERAGE_LIBS)
14
15check_cxx_compile_SOURCES = check-cxx-compile.cpp
16check_cxx_compile_LDADD = \
17 $(top_builddir)/src/libutouch-frame.la \
18 $(COVERAGE_LIBS)
19
20check-static-type-checking$(EXEEXT):
21 @echo "Checking whether static type checking works..."
22 $(AM_V_at)if $(CC) -I../../include -L../../.libs check-static-type-checking.c -o check_static_type_checking; then \
23 echo "FAIL: Static type checking source compiled without error"; \
24 exit -1; \
25 else \
26 echo "SUCCESS: Static type checking source failed to compile"; \
27 exit 0; \
28 fi
29
30### check-regular
31
32check_regular_SOURCES = \
33 accept-ended-touch.cpp \
34 frame-fixture.cpp
35
36#
37# Link against the (non-distributed) static lib to pick up the
38# internal symbols.
39#
40check_regular_LDADD = \
41 $(top_builddir)/src/.libs/libutouch-frame.a \
42 $(top_builddir)/test/gtest/libgtest.a \
43 $(top_builddir)/test/gtest/libgtest_main.a \
44 $(top_builddir)/test/x11_mocks/libx11_mocks.a \
45 $(COVERAGE_LIBS) \
46 $(GTEST_LIBS)
47
48check_regular_CPPFLAGS = \
49 --std=c++0x \
50 -I$(top_srcdir) \
51 -I$(top_srcdir)/include \
52 -I$(top_srcdir)/test/x11_mocks \
53 $(WARNING_CPPFLAGS) \
54 $(GTEST_CPPFLAGS)
55
56check_regular_CFLAGS = \
57 $(COVERAGE_CFLAGS)
058
=== added file 'test/regular/accept-ended-touch.cpp'
--- test/regular/accept-ended-touch.cpp 1970-01-01 00:00:00 +0000
+++ test/regular/accept-ended-touch.cpp 2012-07-18 13:01:21 +0000
@@ -0,0 +1,72 @@
1#include "frame-fixture.h"
2#include "x11_mocks.h"
3
4class AcceptEndedTouch : public FrameFixture
5{
6};
7
8/*
9 Regression test for https://bugs.launchpad.net/bugs/1025297
10
11 The bug is as follows:
12
13 frame lib fails to forward the accept/reject command to xserver for an owned
14 touch if it has already ended.
15
16 Steps to reproduce the issue:
17 1 - touch 1 begins and gets ownership
18 2 - touch 1 ends
19 3 - touch 2 begins and gets ownership
20 4 - frame client accepts touch 1
21
22 Expected outcome:
23 frame lib accepts the touch on the XInput backend.
24
25 Outcome of the bug:
26 Nothing happens. frame lib never accepts that touch.
27 */
28TEST_F(AcceptEndedTouch, Test)
29{
30 UFStatus status;
31 UFDevice device;
32
33 xmock_server_time = 1234;
34
35 CreateXMockTouchScreenDevice();
36
37 Display *display = XOpenDisplay(NULL);
38
39 status = frame_x11_new(display, &frame_handle);
40 ASSERT_EQ(UFStatusSuccess, status);
41
42 FetchDeviceAddedEvent(&device);
43 AssertNoMoreEvents();
44
45 SendTouchEvent(XI_TouchBegin, 1, 10.0f, 10.0f);
46 SendTouchOwnershipEvent(1);
47
48 xmock_server_time += 10;
49
50 SendTouchEvent(XI_TouchEnd, 1, 10.0f, 20.0f);
51
52 xmock_server_time += 3;
53
54 SendTouchEvent(XI_TouchBegin, 2, 10.0f, 21.0f);
55 SendTouchOwnershipEvent(2);
56
57 UFWindowId frame_window_id = frame_x11_create_window_id(DefaultRootWindow(display));
58 status = frame_x11_accept_touch(device, frame_window_id, 1);
59 ASSERT_EQ(UFStatusSuccess, status);
60
61 ASSERT_EQ(XIAcceptTouch,
62 xmock_get_touch_acceptance(xmock_devices[0].attachment /* device id */,
63 1 /* touch id */,
64 DefaultRootWindow(display)));
65
66 frame_x11_delete(frame_handle);
67 frame_handle = nullptr;
68
69 XCloseDisplay(display);
70
71 DestroyXMockDevices();
72}
073
=== renamed file 'test/check-c-compile.c' => 'test/regular/check-c-compile.c'
=== renamed file 'test/check-cxx-compile.cpp' => 'test/regular/check-cxx-compile.cpp'
=== renamed file 'test/check-static-type-checking.c' => 'test/regular/check-static-type-checking.c'
=== added file 'test/regular/frame-fixture.cpp'
--- test/regular/frame-fixture.cpp 1970-01-01 00:00:00 +0000
+++ test/regular/frame-fixture.cpp 2012-07-18 13:01:21 +0000
@@ -0,0 +1,161 @@
1#include "frame-fixture.h"
2#include "x11_mocks.h"
3
4FrameFixture::FrameFixture()
5 : frame_handle(nullptr),
6 _xevent_serial_number(1)
7{
8}
9
10void FrameFixture::SetUp()
11{
12 xmock_touch_acceptance.clear();
13}
14
15void FrameFixture::TearDown()
16{
17 ASSERT_EQ(nullptr, frame_handle);
18}
19
20void FrameFixture::CreateXMockTouchScreenDevice()
21{
22 xmock_devices_count = 1;
23 xmock_devices = (XIDeviceInfo*) calloc(xmock_devices_count,
24 sizeof(XIDeviceInfo));
25
26 XITouchClassInfo *touch_info = (XITouchClassInfo*) malloc(sizeof(XITouchClassInfo));
27 touch_info->type = XITouchClass;
28 touch_info->sourceid = 0;
29 touch_info->mode = XIDirectTouch;
30 touch_info->num_touches = 5;
31
32 XIValuatorClassInfo *x_axis_info = (XIValuatorClassInfo*) malloc(sizeof(XIValuatorClassInfo));
33 x_axis_info->type = XIValuatorClass;
34 x_axis_info->sourceid = 0;
35 x_axis_info->number = 0; /* identifies it as being the X axis */
36 x_axis_info->min = -500.0;
37 x_axis_info->max = 500.0;
38 x_axis_info->resolution = 3000; /* counts/meter */
39
40 XIValuatorClassInfo *y_axis_info = (XIValuatorClassInfo*) malloc(sizeof(XIValuatorClassInfo));
41 y_axis_info->type = XIValuatorClass;
42 y_axis_info->sourceid = 0;
43 y_axis_info->number = 1; /* identifies it as being the Y axis */
44 y_axis_info->min = -500.0;
45 y_axis_info->max = 500.0;
46 y_axis_info->resolution = 3000;
47
48 XIAnyClassInfo **classes = (XIAnyClassInfo**) malloc(sizeof(XIAnyClassInfo*)*3);
49 classes[0] = (XIAnyClassInfo*) touch_info;
50 classes[1] = (XIAnyClassInfo*) x_axis_info;
51 classes[2] = (XIAnyClassInfo*) y_axis_info;
52
53 xmock_devices[0].deviceid = 0;
54 xmock_devices[0].name = const_cast<char *>("Fake Touch Screen");
55 xmock_devices[0].use = XISlavePointer;
56 xmock_devices[0].attachment = 1;
57 xmock_devices[0].enabled = True;
58 xmock_devices[0].num_classes = 3;
59 xmock_devices[0].classes = classes;
60}
61
62void FrameFixture::DestroyXMockDevices()
63{
64 for (int i = 0; i < xmock_devices_count; ++i)
65 {
66 for (int j = 0; j < xmock_devices[i].num_classes; ++j)
67 free(xmock_devices[i].classes[j]);
68 free(xmock_devices[i].classes);
69 }
70 free(xmock_devices);
71}
72
73void FrameFixture::SendTouchEvent(
74 int event_type, int touch_id, float x, float y)
75{
76 UFStatus status;
77 XGenericEventCookie xcookie;
78 XIDeviceEvent *device_event = 0;
79
80 device_event = (XIDeviceEvent*)calloc(1, sizeof(XIDeviceEvent));
81 device_event->serial = _xevent_serial_number++;
82 device_event->display = xmock_display;
83 device_event->extension = xmock_xi2_opcode;
84 device_event->evtype = event_type;
85 device_event->time = xmock_server_time;
86 device_event->deviceid = 0;
87 device_event->sourceid = device_event->deviceid;
88 device_event->detail = touch_id;
89 device_event->root = DefaultRootWindow(xmock_display);
90 device_event->event = DefaultRootWindow(xmock_display);
91 device_event->child = 0;
92 device_event->root_x = x;
93 device_event->root_y = y;
94 device_event->event_x = device_event->root_x;
95 device_event->event_y = device_event->root_y;
96 device_event->valuators.mask_len = 2;
97 device_event->valuators.mask = (unsigned char*) malloc(2);
98 XISetMask(device_event->valuators.mask, 0);
99 XISetMask(device_event->valuators.mask, 1);
100 device_event->valuators.values = (double*) malloc(sizeof(double)*2);
101 device_event->valuators.values[0] = 0; /* just change the coordinate system */
102 device_event->valuators.values[1] = 0;
103 xcookie.extension = xmock_xi2_opcode;
104 xcookie.evtype = event_type;
105 xcookie.data = device_event;
106
107 status = frame_x11_process_event(frame_handle, &xcookie);
108 ASSERT_EQ(UFStatusSuccess, status);
109}
110
111void FrameFixture::SendTouchOwnershipEvent(int touch_id)
112{
113 UFStatus status;
114 XGenericEventCookie xcookie;
115 XITouchOwnershipEvent *ownership_event = 0;
116
117 ownership_event = (XITouchOwnershipEvent*)calloc(1, sizeof(XITouchOwnershipEvent));
118 ownership_event->type = GenericEvent;
119 ownership_event->serial = _xevent_serial_number++;
120 ownership_event->display = xmock_display;
121 ownership_event->extension = xmock_xi2_opcode;
122 ownership_event->evtype = XI_TouchOwnership;
123 ownership_event->time = xmock_server_time;
124 ownership_event->deviceid = 0;
125 ownership_event->sourceid = ownership_event->deviceid;
126 ownership_event->touchid = touch_id;
127 ownership_event->root = DefaultRootWindow(xmock_display);
128 ownership_event->event = DefaultRootWindow(xmock_display);
129 ownership_event->child = 0;
130 xcookie.extension = xmock_xi2_opcode;
131 xcookie.evtype = XI_TouchOwnership;
132 xcookie.data = ownership_event;
133
134 status = frame_x11_process_event(frame_handle, &xcookie);
135 ASSERT_EQ(UFStatusSuccess, status);
136}
137
138void FrameFixture::FetchDeviceAddedEvent(UFDevice *device)
139{
140 UFEvent event;
141 UFStatus status;
142
143 status = frame_get_event(frame_handle, &event);
144 ASSERT_EQ(UFStatusSuccess, status);
145
146 ASSERT_EQ(UFEventTypeDeviceAdded, frame_event_get_type(event));
147
148 status = frame_event_get_property(event, UFEventPropertyDevice, device);
149 ASSERT_EQ(UFStatusSuccess, status);
150
151 frame_event_unref(event);
152}
153
154void FrameFixture::AssertNoMoreEvents()
155{
156 UFEvent event;
157 UFStatus status;
158
159 status = frame_get_event(frame_handle, &event);
160 ASSERT_EQ(UFStatusErrorNoEvent, status);
161}
0162
=== added file 'test/regular/frame-fixture.h'
--- test/regular/frame-fixture.h 1970-01-01 00:00:00 +0000
+++ test/regular/frame-fixture.h 2012-07-18 13:01:21 +0000
@@ -0,0 +1,31 @@
1#ifndef GTEST_FRAME_FIXTURE_H
2#define GTEST_FRAME_FIXTURE_H
3
4#include <gtest/gtest.h>
5#include "utouch/frame.h"
6#include "utouch/frame_x11.h"
7
8class FrameFixture : public ::testing::Test
9{
10 protected:
11 FrameFixture();
12
13 virtual void SetUp();
14 virtual void TearDown();
15
16 void CreateXMockTouchScreenDevice();
17 void DestroyXMockDevices();
18
19 void SendTouchEvent(int event_type, int touch_id, float x, float y);
20 void SendTouchOwnershipEvent(int touch_id);
21
22 void FetchDeviceAddedEvent(UFDevice *device);
23 void AssertNoMoreEvents();
24
25 UFHandle frame_handle;
26 private:
27 /* holds the serial number to be used on the next synthetic XEvent */
28 int _xevent_serial_number;
29};
30
31#endif
032
=== added directory 'test/x11_mocks'
=== added file 'test/x11_mocks/Makefile.am'
--- test/x11_mocks/Makefile.am 1970-01-01 00:00:00 +0000
+++ test/x11_mocks/Makefile.am 2012-07-18 13:01:21 +0000
@@ -0,0 +1,14 @@
1#
2# @file testsuite/x11_mocks/Makefile.am
3# @brief automake recipe for the X11 mockups
4#
5
6check_LIBRARIES = libx11_mocks.a
7
8libx11_mocks_a_SOURCES = \
9 x11_mocks.h x11_mocks.cpp
10
11libx11_mocks_a_CPPFLAGS = \
12 --std=c++0x \
13 -Wno-unused-parameter
14
015
=== added file 'test/x11_mocks/x11_mocks.cpp'
--- test/x11_mocks/x11_mocks.cpp 1970-01-01 00:00:00 +0000
+++ test/x11_mocks/x11_mocks.cpp 2012-07-18 13:01:21 +0000
@@ -0,0 +1,435 @@
1/* needed to break into 'Display' struct internals. */
2#define XLIB_ILLEGAL_ACCESS
3#include <X11/Xlib.h>
4
5#include "x11_mocks.h"
6
7#include <sys/eventfd.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <unistd.h>
11
12int xmock_xi2_opcode = 42;
13int xmock_xi2_event_base = 40000;
14int xmock_xi2_error_base = 40000;
15int xmock_xsync_event_base = 50000;
16int xmock_xsync_error_base = 50000;
17Display *xmock_display = NULL;
18uint64_t xmock_server_time = 0;
19
20XIDeviceInfo *xmock_devices = NULL;
21int xmock_devices_count = 0;
22
23std::map<int, std::map<unsigned int, std::map<Window, int> > > xmock_touch_acceptance;
24
25/* id to be used for the next alarm that gets created */
26XSyncAlarm _xmock_next_alarm = 1;
27
28struct EventQueueItem
29{
30 XEvent event;
31 struct EventQueueItem *next;
32} *xmock_event_queue = NULL;
33
34#define XMOCK_PRINT_FUNCTION _xmock_print_function(__func__)
35void _xmock_print_function(const char *function)
36{
37 static int debug_enabled = -1;
38 if (debug_enabled == -1)
39 {
40 if (getenv("XMOCK_DEBUG"))
41 debug_enabled = 1;
42 else
43 debug_enabled = 0;
44 }
45
46 if (debug_enabled)
47 printf("XMOCK: %s mock called.\n", function);
48}
49
50void xmock_add_to_event_queue(const XEvent *event)
51{
52 struct EventQueueItem *new_item = reinterpret_cast<struct EventQueueItem *>(malloc(sizeof(struct EventQueueItem)));
53 new_item->event = *event;
54 new_item->next = NULL;
55
56 if (!xmock_event_queue)
57 {
58 xmock_event_queue = new_item;
59 }
60 else
61 {
62 struct EventQueueItem *last_item = xmock_event_queue;
63 while (last_item->next)
64 {
65 last_item = last_item->next;
66 }
67 last_item->next = new_item;
68 }
69
70 static const uint64_t num = 1;
71 if (write(xmock_display->fd, &num, sizeof(num)) != sizeof(num))
72 {
73 fprintf(stderr, "ERROR: failed to update eventfd instance,\n");
74 exit(1);
75 }
76}
77
78int xmock_get_touch_acceptance(int device_id, unsigned int touch_id, Window window)
79{
80 if (xmock_touch_acceptance.find(device_id) == xmock_touch_acceptance.end())
81 return -1;
82
83 std::map<unsigned int, std::map<Window, int> > &touch_map =
84 xmock_touch_acceptance[device_id];
85
86 if (touch_map.find(touch_id) == touch_map.end())
87 return -1;
88
89 std::map<Window, int> &window_map = touch_map[touch_id];
90
91 if (window_map.find(window) == window_map.end())
92 return -1;
93
94 return window_map[window];
95}
96
97Display *XOpenDisplay(_Xconst char *display_name)
98{
99 XMOCK_PRINT_FUNCTION;
100 (void)display_name;
101
102 Display *display = (Display*)calloc(1, sizeof(Display));
103 display->fd = eventfd(0, EFD_NONBLOCK);
104 display->default_screen = 0;
105 display->nscreens = 1;
106 display->screens = (Screen*)calloc(1, sizeof(Screen));
107 display->screens[0].root = 1;
108
109 xmock_display = display;
110
111 return display;
112}
113
114int XCloseDisplay(Display *display)
115{
116 XMOCK_PRINT_FUNCTION;
117
118 close(display->fd);
119 free(display->screens);
120 free(display);
121
122 xmock_display = NULL;
123
124 return 0;
125}
126
127int XSync(Display *display, Bool discard)
128{
129 (void)display;
130 (void)discard;
131 return 0;
132}
133
134int XFlush(Display *display)
135{
136 (void)display;
137 return 0;
138}
139
140Bool XQueryExtension(Display *display, const char *name,
141 int *major_opcode_return, int *first_event_return, int *first_error_return)
142{
143 XMOCK_PRINT_FUNCTION;
144 (void)display;
145 (void)name; /* assuming name == "XInputExtension" */
146
147 *major_opcode_return = xmock_xi2_opcode;
148 *first_event_return = xmock_xi2_event_base;
149 *first_error_return = xmock_xi2_error_base;
150
151 return True;
152}
153
154int XPending(Display *display)
155{
156 XMOCK_PRINT_FUNCTION;
157 (void)display;
158
159 int pending_events_count = 0;
160 struct EventQueueItem *item = xmock_event_queue;
161 while (item != NULL)
162 {
163 ++pending_events_count;
164 item = item->next;
165 }
166 return pending_events_count;
167}
168
169int XNextEvent(Display *display, XEvent *event_return)
170{
171 XMOCK_PRINT_FUNCTION;
172 (void)display;
173
174
175 if (xmock_event_queue)
176 {
177 uint64_t num = 1;
178 ssize_t bytes_read = read(xmock_display->fd, &num, sizeof(num));
179 (void)bytes_read;
180
181 *event_return = xmock_event_queue->event;
182
183 struct EventQueueItem *removed_item = xmock_event_queue;
184 xmock_event_queue = xmock_event_queue->next;
185 free(removed_item);
186 }
187 else
188 {
189 /* not going to block... */
190 }
191
192 return 0;
193}
194
195Bool XGetEventData(Display *display, XGenericEventCookie *cookie)
196{
197 XMOCK_PRINT_FUNCTION;
198 (void)display;
199 (void)cookie;
200 return True;
201}
202
203void XFreeEventData(Display *display, XGenericEventCookie *cookie)
204{
205 XMOCK_PRINT_FUNCTION;
206 (void)display;
207
208 if (cookie->data && cookie->extension == xmock_xi2_opcode)
209 {
210 if (cookie->evtype == XI_TouchBegin
211 || cookie->evtype == XI_TouchUpdate
212 || cookie->evtype == XI_TouchEnd)
213 {
214 XIDeviceEvent *device_event = (XIDeviceEvent*) cookie->data;
215 free(device_event->valuators.mask);
216 free(device_event->valuators.values);
217 }
218 free(cookie->data);
219 }
220}
221
222XIDeviceInfo* XIQueryDevice(Display * display,
223 int deviceid,
224 int * ndevices_return)
225{
226 XMOCK_PRINT_FUNCTION;
227 (void)display;
228 (void)deviceid; /* assuming XIAllDevices */
229
230 XIDeviceInfo *devices;
231
232 devices = reinterpret_cast<XIDeviceInfo*>(calloc(xmock_devices_count, sizeof(XIDeviceInfo)));
233
234 for (int i = 0; i < xmock_devices_count; ++i) {
235 devices[i] = xmock_devices[i];
236 }
237
238 *ndevices_return = xmock_devices_count;
239
240 return devices;
241}
242
243void XIFreeDeviceInfo(XIDeviceInfo *info)
244{
245 XMOCK_PRINT_FUNCTION;
246 free(info);
247}
248
249Status XIQueryVersion(Display *display,
250 int *major_version_inout,
251 int *minor_version_inout)
252{
253 XMOCK_PRINT_FUNCTION;
254 (void)display;
255 *major_version_inout = 2;
256 *minor_version_inout = 2;
257 return Success;
258}
259
260Status XISelectEvents(Display *display,
261 Window win,
262 XIEventMask *masks,
263 int num_masks)
264{
265 XMOCK_PRINT_FUNCTION;
266 (void)display;
267 (void)win;
268 (void)masks;
269 (void)num_masks;
270 return Success;
271}
272
273int XIGrabTouchBegin(
274 Display* display,
275 int deviceid,
276 Window grab_window,
277 int owner_events,
278 XIEventMask *mask,
279 int num_modifiers,
280 XIGrabModifiers *modifiers_inout)
281{
282 XMOCK_PRINT_FUNCTION;
283 (void)display;
284 (void)deviceid;
285 (void)grab_window;
286 (void)owner_events;
287 (void)mask;
288
289 for (int i = 0; i < num_modifiers; ++i)
290 {
291 modifiers_inout[i].status = XIGrabSuccess;
292 }
293
294 return 0;
295}
296
297Status XIUngrabTouchBegin(
298 Display* display,
299 int deviceid,
300 Window grab_window,
301 int num_modifiers,
302 XIGrabModifiers *modifiers)
303{
304 XMOCK_PRINT_FUNCTION;
305 (void)display;
306 (void)deviceid;
307 (void)grab_window;
308 (void)num_modifiers;
309 (void)modifiers;
310 return Success;
311}
312
313Status XIAllowTouchEvents(
314 Display* display,
315 int deviceid,
316 unsigned int touchid,
317 Window grab_window,
318 int event_mode)
319{
320 XMOCK_PRINT_FUNCTION;
321 (void)display;
322 xmock_touch_acceptance[deviceid][touchid][grab_window] = event_mode;
323 return Success;
324}
325
326Status XSyncQueryExtension(
327 Display* dpy,
328 int* event_base_return,
329 int* error_base_return)
330{
331 XMOCK_PRINT_FUNCTION;
332 (void)dpy;
333 *event_base_return = xmock_xsync_event_base;
334 *error_base_return = xmock_xsync_error_base;
335 return True;
336}
337
338Status XSyncInitialize(
339 Display* dpy,
340 int* major_version_return,
341 int* minor_version_return)
342{
343 XMOCK_PRINT_FUNCTION;
344 (void)dpy;
345 *major_version_return = 1;
346 *minor_version_return = 0;
347 return True;
348}
349
350XSyncSystemCounter *XSyncListSystemCounters(
351 Display* dpy,
352 int* n_counters_return)
353{
354 XMOCK_PRINT_FUNCTION;
355 (void)dpy;
356 *n_counters_return = 1;
357
358 XSyncSystemCounter *sys_counter = reinterpret_cast<XSyncSystemCounter*>(malloc(sizeof(XSyncSystemCounter)));
359 sys_counter->name = const_cast<char*>("SERVERTIME"); // I know it's technically dangerous, but it's simple.
360 sys_counter->counter = 1;
361 sys_counter->resolution.hi = 1;
362 sys_counter->resolution.lo = 0;
363 return sys_counter;
364}
365
366void XSyncFreeSystemCounterList(XSyncSystemCounter* list)
367{
368 XMOCK_PRINT_FUNCTION;
369 free(list);
370}
371
372XSyncAlarm XSyncCreateAlarm(
373 Display* dpy,
374 unsigned long values_mask,
375 XSyncAlarmAttributes* values)
376{
377 XMOCK_PRINT_FUNCTION;
378 (void)dpy;
379
380 XSyncAlarmNotifyEvent alarm_notify;
381 alarm_notify.type = xmock_xsync_event_base + XSyncAlarmNotify;
382 alarm_notify.alarm = _xmock_next_alarm;
383 alarm_notify.counter_value = values->trigger.wait_value;
384 xmock_add_to_event_queue((XEvent*)&alarm_notify);
385
386 XSyncValue time = values->trigger.wait_value;
387 uint64_t timeout = (uint64_t)XSyncValueHigh32(time) << 32
388 | (uint64_t)XSyncValueLow32(time);
389 xmock_server_time = timeout + 1;
390
391 return _xmock_next_alarm++;
392}
393
394Status XSyncDestroyAlarm(
395 Display* dpy,
396 XSyncAlarm alarm)
397{
398 XMOCK_PRINT_FUNCTION;
399 (void)dpy;
400 (void)alarm;
401 return Success;
402}
403
404void XSyncIntsToValue(
405 XSyncValue* pv,
406 unsigned int l,
407 int h)
408{
409 XMOCK_PRINT_FUNCTION;
410 pv->hi = h;
411 pv->lo = l;
412}
413
414int XSyncValueHigh32(XSyncValue v)
415{
416 XMOCK_PRINT_FUNCTION;
417 return v.hi;
418}
419
420unsigned int XSyncValueLow32(XSyncValue v)
421{
422 XMOCK_PRINT_FUNCTION;
423 return v.lo;
424}
425
426Atom XInternAtom(Display* display, _Xconst char* atom_name, Bool only_if_exists)
427{
428 XMOCK_PRINT_FUNCTION;
429 /* This function doesn't end up getting called when frame is run from tests yet.
430 It's here just to make the code compile. Add some minimal logic when needed. */
431 abort();
432 return 1;
433}
434
435
0436
=== added file 'test/x11_mocks/x11_mocks.h'
--- test/x11_mocks/x11_mocks.h 1970-01-01 00:00:00 +0000
+++ test/x11_mocks/x11_mocks.h 2012-07-18 13:01:21 +0000
@@ -0,0 +1,41 @@
1#ifndef X11_MOCKS_H
2#define X11_MOCKS_H
3
4#include <X11/Xlib.h>
5#include <X11/extensions/XInput2.h>
6#include <X11/extensions/sync.h>
7#include <stdint.h>
8#include <map>
9
10extern int xmock_xi2_opcode;
11extern int xmock_xi2_event_base;
12extern int xmock_xi2_error_base;
13extern int xmock_xsync_event_base;
14extern int xmock_xsync_error_base;
15extern Display *xmock_display;
16extern uint64_t xmock_server_time;
17
18/* to be filled by user. A copy of it will be returned by each
19 XIQueryDevice call */
20extern XIDeviceInfo *xmock_devices;
21extern int xmock_devices_count;
22
23/* Adds the given XEvent to the xmock event queue.
24 The Diplay connection will signal that there are
25 pending events */
26extern void xmock_add_to_event_queue(const XEvent* event);
27
28/*
29 Each call to:
30 XIAllowTouchEvents(display, device_id, touch_id, window_id, touch_acceptance)
31 Causes:
32 xmock_touch_acceptance[device_id][touch_id][window_id] = touch_acceptance;
33 */
34extern std::map<int, std::map<unsigned int, std::map<Window, int> > > xmock_touch_acceptance;
35
36/*
37 Returns -1 if XIAllowTouchEvents wasn't called with the given parameters.
38 */
39int xmock_get_touch_acceptance(int device_id, unsigned int touch_id, Window window);
40
41#endif

Subscribers

People subscribed via source and target branches