Merge lp:~dandrader/geis/lp984069 into lp:geis
- lp984069
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 258 |
Proposed branch: | lp:~dandrader/geis/lp984069 |
Merge into: | lp:geis |
Diff against target: |
1242 lines (+1068/-27) 14 files modified
.bzrignore (+1/-0) configure.ac (+5/-0) include/geis/geis.h (+5/-0) libutouch-geis/backend/grail/geis_grail_backend.c (+18/-8) m4/gtest.m4 (+51/-0) testsuite/Makefile.am (+1/-1) testsuite/geis2/Makefile.am (+39/-9) testsuite/geis2/gtest_gbe_direct_touch_coords.cpp (+295/-0) testsuite/geis2/gtest_grail_backend.cpp (+134/-0) testsuite/geis2/gtest_grail_backend.h (+52/-0) testsuite/gtest/Makefile.am (+14/-9) testsuite/x11_mocks/Makefile.am (+13/-0) testsuite/x11_mocks/x11_mocks.c (+406/-0) testsuite/x11_mocks/x11_mocks.h (+34/-0) |
To merge this branch: | bzr merge lp:~dandrader/geis/lp984069 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chase Douglas (community) | Approve | ||
Stephen M. Webb (community) | Needs Fixing | ||
Review via email: mp+102337@code.launchpad.net |
Commit message
Description of the change
GeisTouches from direct devices should be in window coordinates. Have this also documented in geis.h
The fix for bug #978378 in Unity depends on it.
This should be tested by someone with a touchscreen device along with the fix for bug #978378 (lp:~dandrader/unity/direct_device) to verify that those modifications indeed get bug #978378 fixed.
Stephen M. Webb (bregma) wrote : | # |
Chase Douglas (chasedouglas) wrote : | # |
I tested the branch and everything seems to work appropriately. In the unity branch, the unity bug #978378 seems to be fixed.
We just need tests in geis now.
- 253. By Stephen M. Webb
-
Added an API for setting and getting grail tuning properties.
- 254. By Stephen M. Webb
-
Added a compile-time sentinel check to variadic calls in the API.
Daniel d'Andrada (dandrader) wrote : | # |
It now has a unit test.
Daniel d'Andrada (dandrader) wrote : | # |
I would make it use Google Test istead of Check Framework but in utouch-geis GTest is quite entangled with xorg-gtest and integration tests (ENABLE_
Chase Douglas (chasedouglas) wrote : | # |
As far as I understand, the gtest issue is merely that we need to make the autotools stuff know about gtest for unit testing. I would prefer to fix that issue now and continue to use gtest.
Otherwise, I'm ok with this for now. I think we may want to split the mock out into a separate project in the future, maybe using a mock framework like google-mock to make things easier.
- 255. By Chase Douglas
-
Merge fixes for radius and position delta calculations
- 256. By Chase Douglas
-
Merge fix for GeisSubscriptio
nFlags usage when compiling with g++
Daniel d'Andrada (dandrader) wrote : | # |
Took libgtest.a out of libgtest_geis.a and made the regression test of this bug GTest based instead of Check based.
Ready for a new review.
Chase Douglas (chasedouglas) wrote : | # |
* xorg-gtest.m4 shouldn't be modified. It comes from upstream xorg-gtest and may be replaced by a newer version from an updated xorg-gtest automatically by aclocal --install. IIRC, I think it may also be always replaced by our packaging since it uses aclocal --install --force.
Since _CHECK_GTEST is meant to be an internal implementation detail of xorg-gtest.m4, I suggest copying it to a new file m4/gtest.m4 and removing the leading underscore.
* libgtest_
* libgtest_
* libgtest doesn't need to be built with --std=c++0x. xorg-gtest doesn't need to built with it either. I also don't know why TEST_ROOT_DIR is defined for both gtest libs. I think it was a copy/paste error.
* PRINT_FAILURE_
* I like the idea of MOCK_PRINT. I think it duplicates the geis logging, though. Why not use geis_debug()? I know this means you can't enable mock printouts without geis debug printouts, but I think that's ok. If you're debugging at this level you might be setting GEIS_DEBUG=3 anyway. If you have a standard format where something like "XMOCK: " is prepended to the message, it will be easy to grep or grep -v on it.
Stephen M. Webb (bregma) wrote : | # |
(1) m4/xorg-gtest.m4 is actually a convenience copy of a source file belonging to another package and will likely be overwritten at build time. I would suggest the CHECK_GTEST macro be hoisted into its own .m4 file so it doesn't get trampled: it's already renamed so there shouldn't be a conflict.
(2) Not sure why you did all the fancy wrangling in testsuite/
(3) Why reorganize testsuite/
(4) If you're changing testsuite libraries around anyway, would it be possible to consolidate all support libraries used in the testsuite (gtest, mocks) into a single subdirectory? It would simplify the Makefile.ams used in the various test suites. Feel free to argue this.
Stephen M. Webb (bregma) wrote : | # |
* I like the idea of MOCK_PRINT. I think it duplicates the geis logging, though. Why not use geis_debug()? I know this means you can't enable mock printouts without geis debug printouts, but I think that's ok. If you're debugging at this level you might be setting GEIS_DEBUG=3 anyway. If you have a standard format where something like "XMOCK: " is prepended to the message, it will be easy to grep or grep -v on it.
geis_debug() is not a public symbol exported from libutouch-geis.so. It is not available for any part of the testsuite except the libutouch tests (which are internal unit tests).
Chase Douglas (chasedouglas) wrote : | # |
On 04/23/2012 02:17 PM, Stephen M. Webb wrote:
> * I like the idea of MOCK_PRINT. I think it duplicates the geis logging, though. Why not use geis_debug()? I know this means you can't enable mock printouts without geis debug printouts, but I think that's ok. If you're debugging at this level you might be setting GEIS_DEBUG=3 anyway. If you have a standard format where something like "XMOCK: " is prepended to the message, it will be easy to grep or grep -v on it.
>
> geis_debug() is not a public symbol exported from libutouch-geis.so. It is not available for any part of the testsuite except the libutouch tests (which are internal unit tests).
Ok. What about printing if an env var is set, like MOCK_DEBUG? I'm not a
big fan of preprocessor macros enabling optional functionality. It's not
easy to figure out whether something has been compiled with the
functionality or not.
Stephen M. Webb (bregma) wrote : | # |
> Ok. What about printing if an env var is set, like MOCK_DEBUG? I'm not a
> big fan of preprocessor macros enabling optional functionality. It's not
> easy to figure out whether something has been compiled with the
> functionality or not.
+1
Daniel d'Andrada (dandrader) wrote : | # |
> On 04/23/2012 02:17 PM, Stephen M. Webb wrote:
> > * I like the idea of MOCK_PRINT. I think it duplicates the geis logging,
> though. Why not use geis_debug()? I know this means you can't enable mock
> printouts without geis debug printouts, but I think that's ok. If you're
> debugging at this level you might be setting GEIS_DEBUG=3 anyway. If you have
> a standard format where something like "XMOCK: " is prepended to the message,
> it will be easy to grep or grep -v on it.
> >
> > geis_debug() is not a public symbol exported from libutouch-geis.so. It is
> not available for any part of the testsuite except the libutouch tests (which
> are internal unit tests).
>
> Ok. What about printing if an env var is set, like MOCK_DEBUG? I'm not a
> big fan of preprocessor macros enabling optional functionality. It's not
> easy to figure out whether something has been compiled with the
> functionality or not.
Me neither, but that was the easiest way and I didn't think it was worth to invest time into making a fully fledged solution.
Daniel d'Andrada (dandrader) wrote : | # |
> (3) Why reorganize testsuite/
> targets go at the top (eg. *_PROGRAMS) and the detailed rules for building
> them come later, rather than the other way around. Granted, that tradition
> started because automake required it, but following convention makes it easier
> from someone who sees a lot of Makefile.ams to follow unfamiliar code. Could
> you make your reasoning for this explicit?
I like when all code regarding a library/program is together in a single block instead of intertwined with code for other libraries/programs. I find that arrangement easier to read and maintain. But as with coding style, it's mostly a matter of personal taste.
Daniel d'Andrada (dandrader) wrote : | # |
> (2) Not sure why you did all the fancy wrangling in
> testsuite/
> including the xorg-gtest sources conditionally on ENABLE_
> Could you make your reasoning explicit?
That's another way of doing it. But I prefer the separation method since "That way we can have tests that depend on gtest but not on xorg-gtest" and therefore tests can link against only what they are going to use. Tests that use xmock will use gtest but never xorg-gtest, evemu or the fixtures included in libgtest_geis.
Daniel d'Andrada (dandrader) wrote : | # |
> (4) If you're changing testsuite libraries around anyway, would it be possible
> to consolidate all support libraries used in the testsuite (gtest, mocks) into
> a single subdirectory? It would simplify the Makefile.ams used in the various
> test suites. Feel free to argue this.
I personally find it a bit messy to have the sources of several separate, independent, binaries (programs of libraries) living together in the same directory. It can easily result in a cluttered directory listing and Makefile.am.
Stephen M. Webb (bregma) wrote : | # |
On 04/24/2012 09:52 AM, Daniel d'Andrada wrote:
>> (2) Not sure why you did all the fancy wrangling in
>> testsuite/
>> including the xorg-gtest sources conditionally on ENABLE_
>> Could you make your reasoning explicit?
>
> That's another way of doing it. But I prefer the separation method since "That way we can have tests that depend on gtest but not on xorg-gtest" and therefore tests can link against only what they are going to use. Tests that use xmock will use gtest but never xorg-gtest, evemu or the fixtures included in libgtest_geis.
But you know that for the last 40 years or so linkers only pull objects out of archives if they're used, so the only
difference between using a single library and using multiple libraries is one of increased maintenance cost and
confusion about which library to use?
Daniel d'Andrada (dandrader) wrote : | # |
> On 04/24/2012 09:52 AM, Daniel d'Andrada wrote:
> >> (2) Not sure why you did all the fancy wrangling in
> >> testsuite/
> >> including the xorg-gtest sources conditionally on ENABLE_
> >> Could you make your reasoning explicit?
> >
> > That's another way of doing it. But I prefer the separation method since
> "That way we can have tests that depend on gtest but not on xorg-gtest" and
> therefore tests can link against only what they are going to use. Tests that
> use xmock will use gtest but never xorg-gtest, evemu or the fixtures included
> in libgtest_geis.
>
> But you know that for the last 40 years or so linkers only pull objects out of
> archives if they're used, so the only
> difference between using a single library and using multiple libraries is one
> of increased maintenance cost and
> confusion about which library to use?
I can do single library approach, no problem.
Daniel d'Andrada (dandrader) wrote : | # |
Updated according to comments.
Ready for a new review round.
- 257. By Daniel d'Andrada
-
GeisTouches from direct devices should be in window coordinates
GeisTouches provided by gesture events (GEIS_EVENT_
GESTURE_ BEGIN,
GEIS_EVENT_GESTURE_ UPDATE and GEIS_EVENT_ GESTURE_ END) should be in window
coordinates if they come from a direct device (e.g. touchscreens) and in
input device coordinates when from indirect devices (e.g. touchpads/trackpads) . Have this also documented in geis.h
They were coming always in device coordinates.
- 258. By Daniel d'Andrada
-
Make it possible to have gtest without integration tests and xorg-gtest
That way we can have unit and functional tests using gtest independently
of whether integration tests will be built or whether xorg-gtest is present. - 259. By Daniel d'Andrada
-
Adding X11 mockups
- 260. By Daniel d'Andrada
-
Organize the Makefile a bit
Bring together the code for each binary in blocks instead of having them intertwined
- 261. By Daniel d'Andrada
-
Regression test for lp984069
Chase Douglas (chasedouglas) wrote : | # |
* The --std=c++0x flags are still used.
* PRINT_FAILURE_
I think everything else I commented on has been addressed.
Daniel d'Andrada (dandrader) wrote : | # |
> * The --std=c++0x flags are still used.
>
> * PRINT_FAILURE_
>
> I think everything else I commented on has been addressed.
Ah, yeah, I forgot those. Sorry for that.
- 262. By Daniel d'Andrada
-
GTest doesn't need --std=c++0x
- 263. By Daniel d'Andrada
-
ADD_FAILURE() already prints the current file name and line number
- 264. By Daniel d'Andrada
-
Stop immediately if subscription creation fails
Daniel d'Andrada (dandrader) wrote : | # |
Updated.
ADD_FAILURE() does print the file name and line number but it does *not* return. Therefore a wrapping macro is still needed. So I removed the printf() command and renamed the macro.
I've removed the --std=c++0x flag from gtest
Chase Douglas (chasedouglas) wrote : | # |
On 04/24/2012 11:59 AM, Daniel d'Andrada wrote:
> ADD_FAILURE() does print the file name and line number but it does *not* return. Therefore a wrapping macro is still needed. So I removed the printf() command and renamed the macro.
Ahh, I remembered wrong. You want FAIL() << [message]; It's just like
ADD_FAILURE() except that it causes the function to return. It's
analogous to ASSERT_*() vs EXPECT_*().
http://
> I've removed the --std=c++0x flag from gtest
gtest_geis2_
Stephen M. Webb (bregma) wrote : | # |
"make distcheck" fails (there should be no nodist_ prefix on the SOURCES variable in testsuite/
Daniel d'Andrada (dandrader) wrote : | # |
> On 04/24/2012 11:59 AM, Daniel d'Andrada wrote:
> > ADD_FAILURE() does print the file name and line number but it does *not*
> return. Therefore a wrapping macro is still needed. So I removed the printf()
> command and renamed the macro.
>
> Ahh, I remembered wrong. You want FAIL() << [message]; It's just like
> ADD_FAILURE() except that it causes the function to return. It's
> analogous to ASSERT_*() vs EXPECT_*().
>
> http://
FAIL(), like ASSERT_*(), can only be used from within functions that return void. That's why I have to stick with ADD_FAILURE().
>
> > I've removed the --std=c++0x flag from gtest
>
> gtest_geis2_
I needs --std=c++0x because it uses c++0x stuff (like nullptr and range-based for loops)
Daniel d'Andrada (dandrader) wrote : | # |
> "make distcheck" fails (there should be no nodist_ prefix on the SOURCES
> variable in testsuite/
Fixed.
- 265. By Daniel d'Andrada
-
sources of x11_mocks are distributed
Chase Douglas (chasedouglas) : | # |
Chase Douglas (chasedouglas) wrote : | # |
On 04/24/2012 12:31 PM, Daniel d'Andrada wrote:
>> On 04/24/2012 11:59 AM, Daniel d'Andrada wrote:
>>> ADD_FAILURE() does print the file name and line number but it does *not*
>> return. Therefore a wrapping macro is still needed. So I removed the printf()
>> command and renamed the macro.
>>
>> Ahh, I remembered wrong. You want FAIL() << [message]; It's just like
>> ADD_FAILURE() except that it causes the function to return. It's
>> analogous to ASSERT_*() vs EXPECT_*().
>>
>> http://
>
> FAIL(), like ASSERT_*(), can only be used from within functions that return void. That's why I have to stick with ADD_FAILURE().
Ahh, yes, that would be an issue.
This is a bit bike-shedding, but I would prefer to unroll the macro
since it's two simple lines. I think it would make the code easier to
read. However, I'm ok with it as is.
>>
>>> I've removed the --std=c++0x flag from gtest
>>
>> gtest_geis2_
>
> I needs --std=c++0x because it uses c++0x stuff (like nullptr and range-based for loops)
Ok, I didn't realize that.
- 266. By Daniel d'Andrada
-
We don't need a macro anymore. Wrapped code is too simple
Preview Diff
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2012-04-11 16:18:03 +0000 | |||
3 | +++ .bzrignore 2012-04-24 19:38:21 +0000 | |||
4 | @@ -48,4 +48,5 @@ | |||
5 | 48 | TAGS | 48 | TAGS |
6 | 49 | testsuite/geistest/geistest | 49 | testsuite/geistest/geistest |
7 | 50 | testsuite/libutouch-geis/*.xml | 50 | testsuite/libutouch-geis/*.xml |
8 | 51 | testsuite/geis2/gtest_geis2_grail_backend | ||
9 | 51 | tools/geis-server/geis-server | 52 | tools/geis-server/geis-server |
10 | 52 | 53 | ||
11 | === modified file 'configure.ac' | |||
12 | --- configure.ac 2012-04-12 17:13:41 +0000 | |||
13 | +++ configure.ac 2012-04-24 19:38:21 +0000 | |||
14 | @@ -97,6 +97,10 @@ | |||
15 | 97 | [enable_integration_tests=$enableval], | 97 | [enable_integration_tests=$enableval], |
16 | 98 | [enable_integration_tests=auto]) | 98 | [enable_integration_tests=auto]) |
17 | 99 | 99 | ||
18 | 100 | # Check for Google C++ Testing Framework | ||
19 | 101 | CHECK_GTEST() | ||
20 | 102 | AM_CONDITIONAL([HAVE_GTEST], [test "x$have_gtest" = xyes]) | ||
21 | 103 | |||
22 | 100 | have_xorg_gtest=no | 104 | have_xorg_gtest=no |
23 | 101 | AS_IF([test "x$enable_integration_tests" != xno], | 105 | AS_IF([test "x$enable_integration_tests" != xno], |
24 | 102 | [CHECK_XORG_GTEST( | 106 | [CHECK_XORG_GTEST( |
25 | @@ -132,6 +136,7 @@ | |||
26 | 132 | testsuite/geis2/Makefile | 136 | testsuite/geis2/Makefile |
27 | 133 | testsuite/geis1/Makefile | 137 | testsuite/geis1/Makefile |
28 | 134 | testsuite/geistest/Makefile | 138 | testsuite/geistest/Makefile |
29 | 139 | testsuite/x11_mocks/Makefile | ||
30 | 135 | examples/Makefile | 140 | examples/Makefile |
31 | 136 | python/Makefile | 141 | python/Makefile |
32 | 137 | tools/Makefile | 142 | tools/Makefile |
33 | 138 | 143 | ||
34 | === modified file 'include/geis/geis.h' | |||
35 | --- include/geis/geis.h 2012-04-20 19:14:59 +0000 | |||
36 | +++ include/geis/geis.h 2012-04-24 19:38:21 +0000 | |||
37 | @@ -2061,6 +2061,11 @@ | |||
38 | 2061 | * is capable of reporting differing sets of touch attributes, so there is no | 2061 | * is capable of reporting differing sets of touch attributes, so there is no |
39 | 2062 | * guarantee that any or all of the defined touch attributes will bre present. | 2062 | * guarantee that any or all of the defined touch attributes will bre present. |
40 | 2063 | * | 2063 | * |
41 | 2064 | * If the touch comes from a direct device (see | ||
42 | 2065 | * GEIS_DEVICE_ATTRIBUTE_DIRECT_TOUCH) its position (x and y attributes) will | ||
43 | 2066 | * be in window coordinates, otherwise it will be in the input device's own | ||
44 | 2067 | * coordinate system. | ||
45 | 2068 | * | ||
46 | 2064 | * @{ | 2069 | * @{ |
47 | 2065 | * | 2070 | * |
48 | 2066 | * @def GEIS_TOUCH_ATTRIBUTE_ID | 2071 | * @def GEIS_TOUCH_ATTRIBUTE_ID |
49 | 2067 | 2072 | ||
50 | === modified file 'libutouch-geis/backend/grail/geis_grail_backend.c' | |||
51 | --- libutouch-geis/backend/grail/geis_grail_backend.c 2012-04-20 15:00:21 +0000 | |||
52 | +++ libutouch-geis/backend/grail/geis_grail_backend.c 2012-04-24 19:38:21 +0000 | |||
53 | @@ -635,19 +635,29 @@ | |||
54 | 635 | focus_y = frame_touch_get_window_y(uftouch); | 635 | focus_y = frame_touch_get_window_y(uftouch); |
55 | 636 | } | 636 | } |
56 | 637 | 637 | ||
60 | 638 | GeisFloat fval = frame_touch_get_device_x(uftouch); | 638 | GeisFloat touch_x, touch_y; |
61 | 639 | bboxMinX = fmin(bboxMinX, fval); | 639 | if (is_touchscreen) |
62 | 640 | bboxMaxX = fmax(bboxMaxX, fval); | 640 | { |
63 | 641 | touch_x = frame_touch_get_window_x(uftouch); | ||
64 | 642 | touch_y = frame_touch_get_window_y(uftouch); | ||
65 | 643 | } | ||
66 | 644 | else | ||
67 | 645 | { | ||
68 | 646 | touch_x = frame_touch_get_device_x(uftouch); | ||
69 | 647 | touch_y = frame_touch_get_device_y(uftouch); | ||
70 | 648 | } | ||
71 | 649 | |||
72 | 650 | bboxMinX = fmin(bboxMinX, touch_x); | ||
73 | 651 | bboxMaxX = fmax(bboxMaxX, touch_x); | ||
74 | 641 | geis_touch_add_attr(touch, geis_attr_new(GEIS_TOUCH_ATTRIBUTE_X, | 652 | geis_touch_add_attr(touch, geis_attr_new(GEIS_TOUCH_ATTRIBUTE_X, |
75 | 642 | GEIS_ATTR_TYPE_FLOAT, | 653 | GEIS_ATTR_TYPE_FLOAT, |
77 | 643 | &fval)); | 654 | &touch_x)); |
78 | 644 | 655 | ||
82 | 645 | fval = frame_touch_get_device_y(uftouch); | 656 | bboxMinY = fmin(bboxMinY, touch_y); |
83 | 646 | bboxMinY = fmin(bboxMinY, fval); | 657 | bboxMaxY = fmax(bboxMaxY, touch_y); |
81 | 647 | bboxMaxY = fmax(bboxMaxY, fval); | ||
84 | 648 | geis_touch_add_attr(touch, geis_attr_new(GEIS_TOUCH_ATTRIBUTE_Y, | 658 | geis_touch_add_attr(touch, geis_attr_new(GEIS_TOUCH_ATTRIBUTE_Y, |
85 | 649 | GEIS_ATTR_TYPE_FLOAT, | 659 | GEIS_ATTR_TYPE_FLOAT, |
87 | 650 | &fval)); | 660 | &touch_y)); |
88 | 651 | 661 | ||
89 | 652 | geis_touchset_insert(touchset, touch); | 662 | geis_touchset_insert(touchset, touch); |
90 | 653 | geis_frame_add_touchid(frame, geis_touch_id(touch)); | 663 | geis_frame_add_touchid(frame, geis_touch_id(touch)); |
91 | 654 | 664 | ||
92 | === added file 'm4/gtest.m4' | |||
93 | --- m4/gtest.m4 1970-01-01 00:00:00 +0000 | |||
94 | +++ m4/gtest.m4 2012-04-24 19:38:21 +0000 | |||
95 | @@ -0,0 +1,51 @@ | |||
96 | 1 | # serial 1 | ||
97 | 2 | |||
98 | 3 | # Copyright (C) 2012 Canonical, Ltd. | ||
99 | 4 | # | ||
100 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
101 | 6 | # of this software and associated documentation files (the "Software"), to deal | ||
102 | 7 | # in the Software without restriction, including without limitation the rights | ||
103 | 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
104 | 9 | # copies of the Software, and to permit persons to whom the Software is | ||
105 | 10 | # furnished to do so, subject to the following conditions: | ||
106 | 11 | # | ||
107 | 12 | # The above copyright notice and this permission notice (including the next | ||
108 | 13 | # paragraph) shall be included in all copies or substantial portions of the | ||
109 | 14 | # Software. | ||
110 | 15 | # | ||
111 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
112 | 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
113 | 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
114 | 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
115 | 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
116 | 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
117 | 22 | # SOFTWARE. | ||
118 | 23 | |||
119 | 24 | # Checks whether the gtest source is available on the system. Allows for | ||
120 | 25 | # adjusting the include and source path. Sets have_gtest=yes if the source is | ||
121 | 26 | # present. Sets GTEST_CPPFLAGS and GTEST_SOURCE to the preprocessor flags and | ||
122 | 27 | # source location respectively. | ||
123 | 28 | AC_DEFUN([CHECK_GTEST], | ||
124 | 29 | [ | ||
125 | 30 | AC_ARG_WITH([gtest-include-path], | ||
126 | 31 | [AS_HELP_STRING([--with-gtest-include-path], | ||
127 | 32 | [location of the Google test headers])], | ||
128 | 33 | [GTEST_CPPFLAGS="-I$withval"]) | ||
129 | 34 | |||
130 | 35 | AC_ARG_WITH([gtest-source-path], | ||
131 | 36 | [AS_HELP_STRING([--with-gtest-source-path], | ||
132 | 37 | [location of the Google test sources, defaults to /usr/src/gtest])], | ||
133 | 38 | [GTEST_SOURCE="$withval"], | ||
134 | 39 | [GTEST_SOURCE="/usr/src/gtest"]) | ||
135 | 40 | |||
136 | 41 | GTEST_CPPFLAGS="$GTEST_CPPFLAGS -I$GTEST_SOURCE" | ||
137 | 42 | |||
138 | 43 | AC_CHECK_FILES([$GTEST_SOURCE/src/gtest-all.cc] | ||
139 | 44 | [$GTEST_SOURCE/src/gtest_main.cc], | ||
140 | 45 | [have_gtest=yes], | ||
141 | 46 | [have_gtest=no]) | ||
142 | 47 | |||
143 | 48 | AS_IF([test "x$have_gtest_source" = xyes], | ||
144 | 49 | [AC_SUBST(GTEST_CPPFLAGS)] | ||
145 | 50 | [AC_SUBST(GTEST_SOURCE)]) | ||
146 | 51 | ]) # CHECK_GTEST | ||
147 | 0 | 52 | ||
148 | === modified file 'testsuite/Makefile.am' | |||
149 | --- testsuite/Makefile.am 2012-03-28 16:54:23 +0000 | |||
150 | +++ testsuite/Makefile.am 2012-04-24 19:38:21 +0000 | |||
151 | @@ -20,6 +20,6 @@ | |||
152 | 20 | # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 20 | # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
153 | 21 | # | 21 | # |
154 | 22 | 22 | ||
156 | 23 | SUBDIRS = gtest geis-util libutouch-geis geis2 geis1 geistest | 23 | SUBDIRS = gtest x11_mocks geis-util libutouch-geis geis2 geis1 geistest |
157 | 24 | 24 | ||
158 | 25 | EXTRA_DIST = recordings | 25 | EXTRA_DIST = recordings |
159 | 26 | 26 | ||
160 | === modified file 'testsuite/geis2/Makefile.am' | |||
161 | --- testsuite/geis2/Makefile.am 2012-04-16 19:12:46 +0000 | |||
162 | +++ testsuite/geis2/Makefile.am 2012-04-24 19:38:21 +0000 | |||
163 | @@ -1,19 +1,15 @@ | |||
164 | 1 | # | 1 | # |
167 | 2 | # @file testsuite/geis1/Makefile.am | 2 | # @file testsuite/geis2/Makefile.am |
168 | 3 | # @brief automake recipe for the geis v1.0 testsuite unit testing directory | 3 | # @brief automake recipe for the geis v2.0 testsuite testing directory |
169 | 4 | # | 4 | # |
170 | 5 | 5 | ||
171 | 6 | test_targets = | 6 | test_targets = |
172 | 7 | |||
173 | 8 | ##### check_geis2_api - Tests using Check C testing framework ##### | ||
174 | 9 | |||
175 | 7 | if HAVE_CHECK | 10 | if HAVE_CHECK |
176 | 8 | test_targets += check_geis2_api | 11 | test_targets += check_geis2_api |
177 | 9 | endif | 12 | endif |
178 | 10 | if ENABLE_INTEGRATION_TESTS | ||
179 | 11 | test_targets += gtest_geis2_api | ||
180 | 12 | endif | ||
181 | 13 | |||
182 | 14 | TESTS = $(test_targets) | ||
183 | 15 | |||
184 | 16 | check_PROGRAMS = $(test_targets) | ||
185 | 17 | 13 | ||
186 | 18 | check_geis2_api_SOURCES = \ | 14 | check_geis2_api_SOURCES = \ |
187 | 19 | check_attr.c \ | 15 | check_attr.c \ |
188 | @@ -42,6 +38,38 @@ | |||
189 | 42 | $(top_builddir)/libutouch-geis/libutouch-geis.la \ | 38 | $(top_builddir)/libutouch-geis/libutouch-geis.la \ |
190 | 43 | $(CHECK_LIBS) | 39 | $(CHECK_LIBS) |
191 | 44 | 40 | ||
192 | 41 | #### gtest_geis2_grail_backend - Test for the GRAIL backend of Geis v2 API ##### | ||
193 | 42 | #### using gtest ##### | ||
194 | 43 | |||
195 | 44 | if HAVE_GTEST | ||
196 | 45 | test_targets += gtest_geis2_grail_backend | ||
197 | 46 | endif | ||
198 | 47 | |||
199 | 48 | gtest_geis2_grail_backend_SOURCES = \ | ||
200 | 49 | gtest_grail_backend.cpp \ | ||
201 | 50 | gtest_gbe_direct_touch_coords.cpp | ||
202 | 51 | |||
203 | 52 | gtest_geis2_grail_backend_CPPFLAGS = \ | ||
204 | 53 | --std=c++0x \ | ||
205 | 54 | -I$(top_srcdir) \ | ||
206 | 55 | -I$(top_srcdir)/include \ | ||
207 | 56 | -I$(top_srcdir)/libutouch-geis \ | ||
208 | 57 | -I$(top_srcdir)/testsuite/gtest \ | ||
209 | 58 | -I$(top_srcdir)/testsuite/x11_mocks \ | ||
210 | 59 | -DTEST_ROOT_DIR=\"$(abs_top_srcdir)/testsuite/\" | ||
211 | 60 | $(GTEST_CFLAGS) | ||
212 | 61 | |||
213 | 62 | gtest_geis2_grail_backend_LDADD = \ | ||
214 | 63 | $(top_builddir)/testsuite/gtest/libgtest_geis.a \ | ||
215 | 64 | $(top_builddir)/testsuite/x11_mocks/libx11_mocks.a \ | ||
216 | 65 | $(top_builddir)/libutouch-geis/libutouch-geis.la | ||
217 | 66 | |||
218 | 67 | #### gtest_geis2_api - Integration tests using xorg-gest and evemu ##### | ||
219 | 68 | |||
220 | 69 | if ENABLE_INTEGRATION_TESTS | ||
221 | 70 | test_targets += gtest_geis2_api | ||
222 | 71 | endif | ||
223 | 72 | |||
224 | 45 | gtest_geis2_api_SOURCES = \ | 73 | gtest_geis2_api_SOURCES = \ |
225 | 46 | gtest_attrs.cpp \ | 74 | gtest_attrs.cpp \ |
226 | 47 | gtest_config.cpp \ | 75 | gtest_config.cpp \ |
227 | @@ -73,3 +101,5 @@ | |||
228 | 73 | geis2_api.log \ | 101 | geis2_api.log \ |
229 | 74 | geis2_api.xml | 102 | geis2_api.xml |
230 | 75 | 103 | ||
231 | 104 | TESTS = $(test_targets) | ||
232 | 105 | check_PROGRAMS = $(test_targets) | ||
233 | 76 | 106 | ||
234 | === added file 'testsuite/geis2/gtest_gbe_direct_touch_coords.cpp' | |||
235 | --- testsuite/geis2/gtest_gbe_direct_touch_coords.cpp 1970-01-01 00:00:00 +0000 | |||
236 | +++ testsuite/geis2/gtest_gbe_direct_touch_coords.cpp 2012-04-24 19:38:21 +0000 | |||
237 | @@ -0,0 +1,295 @@ | |||
238 | 1 | #include "gtest_grail_backend.h" | ||
239 | 2 | #include "x11_mocks.h" | ||
240 | 3 | |||
241 | 4 | /* | ||
242 | 5 | Check that when a direct device (e.g. a touchscreen) is being used, the | ||
243 | 6 | position of a GeisTouch will be in window coordinates instead of input | ||
244 | 7 | device coordinates. | ||
245 | 8 | |||
246 | 9 | This means that the x an y values of a GeisTouch should come from | ||
247 | 10 | XIDeviceEvent::event_x and XIDeviceEvent::event_y and not from | ||
248 | 11 | XIDeviceEvent::valuators.values[0] and XIDeviceEvent::valuators.values[1], | ||
249 | 12 | like it's the case for indirect devices (such as trackpads). | ||
250 | 13 | |||
251 | 14 | Regression test for https://bugs.launchpad.net/bugs/984069 | ||
252 | 15 | */ | ||
253 | 16 | |||
254 | 17 | class Geis2GrailBackend : public Geis2GrailBackendBase | ||
255 | 18 | { | ||
256 | 19 | protected: | ||
257 | 20 | Geis2GrailBackend() : _subscription(nullptr) {} | ||
258 | 21 | |||
259 | 22 | void CreateXMockDevices(); | ||
260 | 23 | void DestroyXMockDevices(); | ||
261 | 24 | void SendXInput2Events(); | ||
262 | 25 | |||
263 | 26 | virtual void OnEventInitComplete(GeisEvent event); | ||
264 | 27 | virtual void OnEventGestureBegin(GeisEvent event); | ||
265 | 28 | |||
266 | 29 | GeisSubscription _subscription; | ||
267 | 30 | }; | ||
268 | 31 | |||
269 | 32 | void Geis2GrailBackend::CreateXMockDevices() | ||
270 | 33 | { | ||
271 | 34 | xmock_devices_count = 1; | ||
272 | 35 | xmock_devices = (XIDeviceInfo*) calloc(xmock_devices_count, | ||
273 | 36 | sizeof(XIDeviceInfo)); | ||
274 | 37 | |||
275 | 38 | XITouchClassInfo *touch_info = (XITouchClassInfo*) malloc(sizeof(XITouchClassInfo)); | ||
276 | 39 | touch_info->type = XITouchClass; | ||
277 | 40 | touch_info->sourceid = 0; | ||
278 | 41 | touch_info->mode = XIDirectTouch; | ||
279 | 42 | touch_info->num_touches = 5; | ||
280 | 43 | |||
281 | 44 | XIValuatorClassInfo *x_axis_info = (XIValuatorClassInfo*) malloc(sizeof(XIValuatorClassInfo)); | ||
282 | 45 | x_axis_info->type = XIValuatorClass; | ||
283 | 46 | x_axis_info->sourceid = 0; | ||
284 | 47 | x_axis_info->number = 0; /* identifies it as being the X axis */ | ||
285 | 48 | x_axis_info->min = -500.0; | ||
286 | 49 | x_axis_info->max = 500.0; | ||
287 | 50 | x_axis_info->resolution = 3000; /* counts/meter */ | ||
288 | 51 | |||
289 | 52 | XIValuatorClassInfo *y_axis_info = (XIValuatorClassInfo*) malloc(sizeof(XIValuatorClassInfo)); | ||
290 | 53 | y_axis_info->type = XIValuatorClass; | ||
291 | 54 | y_axis_info->sourceid = 0; | ||
292 | 55 | y_axis_info->number = 1; /* identifies it as being the Y axis */ | ||
293 | 56 | y_axis_info->min = -500.0; | ||
294 | 57 | y_axis_info->max = 500.0; | ||
295 | 58 | y_axis_info->resolution = 3000; | ||
296 | 59 | |||
297 | 60 | XIAnyClassInfo **classes = (XIAnyClassInfo**) malloc(sizeof(XIAnyClassInfo*)*3); | ||
298 | 61 | classes[0] = (XIAnyClassInfo*) touch_info; | ||
299 | 62 | classes[1] = (XIAnyClassInfo*) x_axis_info; | ||
300 | 63 | classes[2] = (XIAnyClassInfo*) y_axis_info; | ||
301 | 64 | |||
302 | 65 | xmock_devices[0].deviceid = 0; | ||
303 | 66 | xmock_devices[0].name = const_cast<char *>("Fake Touch Screen"); | ||
304 | 67 | xmock_devices[0].use = XISlavePointer; | ||
305 | 68 | xmock_devices[0].attachment = 1; | ||
306 | 69 | xmock_devices[0].enabled = True; | ||
307 | 70 | xmock_devices[0].num_classes = 3; | ||
308 | 71 | xmock_devices[0].classes = classes; | ||
309 | 72 | } | ||
310 | 73 | |||
311 | 74 | void Geis2GrailBackend::DestroyXMockDevices() | ||
312 | 75 | { | ||
313 | 76 | for (int i = 0; i < xmock_devices_count; ++i) | ||
314 | 77 | { | ||
315 | 78 | for (int j = 0; j < xmock_devices[i].num_classes; ++j) | ||
316 | 79 | free(xmock_devices[i].classes[j]); | ||
317 | 80 | free(xmock_devices[i].classes); | ||
318 | 81 | } | ||
319 | 82 | free(xmock_devices); | ||
320 | 83 | } | ||
321 | 84 | |||
322 | 85 | void Geis2GrailBackend::SendXInput2Events() | ||
323 | 86 | { | ||
324 | 87 | XEvent event; | ||
325 | 88 | XGenericEventCookie *xcookie = 0; | ||
326 | 89 | XIDeviceEvent *device_event = 0; | ||
327 | 90 | XITouchOwnershipEvent *ownership_event = 0; | ||
328 | 91 | int serial = 0; | ||
329 | 92 | |||
330 | 93 | event.type = GenericEvent; | ||
331 | 94 | device_event = (XIDeviceEvent*)calloc(1, sizeof(XIDeviceEvent)); | ||
332 | 95 | device_event->serial = serial++; | ||
333 | 96 | device_event->display = xmock_display; | ||
334 | 97 | device_event->extension = xmock_xi2_opcode; | ||
335 | 98 | device_event->evtype = XI_TouchBegin; | ||
336 | 99 | device_event->time = xmock_server_time; | ||
337 | 100 | device_event->deviceid = 0; | ||
338 | 101 | /* The source device that originally generated the event. */ | ||
339 | 102 | device_event->sourceid = device_event->deviceid; | ||
340 | 103 | device_event->detail = 0; /* touch id */ | ||
341 | 104 | device_event->root = DefaultRootWindow(xmock_display); | ||
342 | 105 | device_event->event = DefaultRootWindow(xmock_display); | ||
343 | 106 | device_event->child = 0; | ||
344 | 107 | device_event->root_x = 123.0f; | ||
345 | 108 | device_event->root_y = 456.0f; | ||
346 | 109 | device_event->event_x = device_event->root_x; | ||
347 | 110 | device_event->event_y = device_event->root_y; | ||
348 | 111 | device_event->valuators.mask_len = 2; /* two bytes */ | ||
349 | 112 | device_event->valuators.mask = (unsigned char*) malloc(2); | ||
350 | 113 | XISetMask(device_event->valuators.mask, 0); /* X axis is present */ | ||
351 | 114 | XISetMask(device_event->valuators.mask, 1); /* Y axis is present */ | ||
352 | 115 | device_event->valuators.values = (double*) malloc(sizeof(double)*2); | ||
353 | 116 | device_event->valuators.values[0] = -200.0; | ||
354 | 117 | device_event->valuators.values[1] = -100.0; | ||
355 | 118 | xcookie = &event.xcookie; | ||
356 | 119 | xcookie->extension = xmock_xi2_opcode; | ||
357 | 120 | xcookie->evtype = XI_TouchBegin; | ||
358 | 121 | xcookie->data = device_event; | ||
359 | 122 | xmock_add_to_event_queue(&event); | ||
360 | 123 | |||
361 | 124 | event.type = GenericEvent; | ||
362 | 125 | device_event = (XIDeviceEvent*)calloc(1, sizeof(XIDeviceEvent)); | ||
363 | 126 | device_event->serial = serial++; | ||
364 | 127 | device_event->display = xmock_display; | ||
365 | 128 | device_event->extension = xmock_xi2_opcode; | ||
366 | 129 | device_event->evtype = XI_TouchBegin; | ||
367 | 130 | device_event->time = xmock_server_time; | ||
368 | 131 | device_event->deviceid = 0; | ||
369 | 132 | device_event->sourceid = device_event->deviceid; | ||
370 | 133 | device_event->detail = 1; /* touch id */ | ||
371 | 134 | device_event->root = DefaultRootWindow(xmock_display); | ||
372 | 135 | device_event->event = DefaultRootWindow(xmock_display); | ||
373 | 136 | device_event->child = 0; | ||
374 | 137 | device_event->root_x = 222.0f; | ||
375 | 138 | device_event->root_y = 456.0f; | ||
376 | 139 | device_event->event_x = device_event->root_x; | ||
377 | 140 | device_event->event_y = device_event->root_y; | ||
378 | 141 | device_event->valuators.mask_len = 2; | ||
379 | 142 | device_event->valuators.mask = (unsigned char*) malloc(2); | ||
380 | 143 | XISetMask(device_event->valuators.mask, 0); | ||
381 | 144 | XISetMask(device_event->valuators.mask, 1); | ||
382 | 145 | device_event->valuators.values = (double*) malloc(sizeof(double)*2); | ||
383 | 146 | device_event->valuators.values[0] = -150.0; | ||
384 | 147 | device_event->valuators.values[1] = -100.0; | ||
385 | 148 | xcookie = &event.xcookie; | ||
386 | 149 | xcookie->extension = xmock_xi2_opcode; | ||
387 | 150 | xcookie->evtype = XI_TouchBegin; | ||
388 | 151 | xcookie->data = device_event; | ||
389 | 152 | xmock_add_to_event_queue(&event); | ||
390 | 153 | |||
391 | 154 | xmock_server_time += 5; | ||
392 | 155 | |||
393 | 156 | event.type = GenericEvent; | ||
394 | 157 | ownership_event = (XITouchOwnershipEvent*)calloc(1, sizeof(XITouchOwnershipEvent)); | ||
395 | 158 | ownership_event->type = GenericEvent; | ||
396 | 159 | ownership_event->serial = serial++; | ||
397 | 160 | ownership_event->display = xmock_display; | ||
398 | 161 | ownership_event->extension = xmock_xi2_opcode; | ||
399 | 162 | ownership_event->evtype = XI_TouchOwnership; | ||
400 | 163 | ownership_event->time = xmock_server_time; | ||
401 | 164 | ownership_event->deviceid = 0; | ||
402 | 165 | ownership_event->sourceid = ownership_event->deviceid; | ||
403 | 166 | ownership_event->touchid = 0; | ||
404 | 167 | ownership_event->root = DefaultRootWindow(xmock_display); | ||
405 | 168 | ownership_event->event = DefaultRootWindow(xmock_display); | ||
406 | 169 | ownership_event->child = 0; | ||
407 | 170 | xcookie = &event.xcookie; | ||
408 | 171 | xcookie->extension = xmock_xi2_opcode; | ||
409 | 172 | xcookie->evtype = XI_TouchOwnership; | ||
410 | 173 | xcookie->data = ownership_event; | ||
411 | 174 | xmock_add_to_event_queue(&event); | ||
412 | 175 | |||
413 | 176 | event.type = GenericEvent; | ||
414 | 177 | ownership_event = (XITouchOwnershipEvent*)calloc(1, sizeof(XITouchOwnershipEvent)); | ||
415 | 178 | ownership_event->type = GenericEvent; | ||
416 | 179 | ownership_event->serial = serial++; | ||
417 | 180 | ownership_event->display = xmock_display; | ||
418 | 181 | ownership_event->extension = xmock_xi2_opcode; | ||
419 | 182 | ownership_event->evtype = XI_TouchOwnership; | ||
420 | 183 | ownership_event->time = xmock_server_time; | ||
421 | 184 | ownership_event->deviceid = 0; | ||
422 | 185 | ownership_event->sourceid = ownership_event->deviceid; | ||
423 | 186 | ownership_event->touchid = 1; | ||
424 | 187 | ownership_event->root = DefaultRootWindow(xmock_display); | ||
425 | 188 | ownership_event->event = DefaultRootWindow(xmock_display); | ||
426 | 189 | ownership_event->child = 0; | ||
427 | 190 | xcookie = &event.xcookie; | ||
428 | 191 | xcookie->extension = xmock_xi2_opcode; | ||
429 | 192 | xcookie->evtype = XI_TouchOwnership; | ||
430 | 193 | xcookie->data = ownership_event; | ||
431 | 194 | xmock_add_to_event_queue(&event); | ||
432 | 195 | |||
433 | 196 | event.type = GenericEvent; | ||
434 | 197 | device_event = (XIDeviceEvent*)calloc(1, sizeof(XIDeviceEvent)); | ||
435 | 198 | device_event->serial = serial++; | ||
436 | 199 | device_event->display = xmock_display; | ||
437 | 200 | device_event->extension = xmock_xi2_opcode; | ||
438 | 201 | device_event->evtype = XI_TouchUpdate; | ||
439 | 202 | device_event->time = xmock_server_time; | ||
440 | 203 | device_event->deviceid = 0; | ||
441 | 204 | device_event->sourceid = device_event->deviceid; | ||
442 | 205 | device_event->detail = 0; | ||
443 | 206 | device_event->root = DefaultRootWindow(xmock_display); | ||
444 | 207 | device_event->event = DefaultRootWindow(xmock_display); | ||
445 | 208 | device_event->child = 0; | ||
446 | 209 | device_event->root_x = 123.0f; | ||
447 | 210 | device_event->root_y = 466.0f; | ||
448 | 211 | device_event->event_x = device_event->root_x; | ||
449 | 212 | device_event->event_y = device_event->root_y; | ||
450 | 213 | device_event->valuators.mask_len = 2; /* two bytes */ | ||
451 | 214 | device_event->valuators.mask = (unsigned char*) malloc(2); | ||
452 | 215 | XISetMask(device_event->valuators.mask, 0); | ||
453 | 216 | XISetMask(device_event->valuators.mask, 1); | ||
454 | 217 | device_event->valuators.values = (double*) malloc(sizeof(double)*2); | ||
455 | 218 | device_event->valuators.values[0] = -200.0; | ||
456 | 219 | device_event->valuators.values[1] = -90.0; | ||
457 | 220 | xcookie = &event.xcookie; | ||
458 | 221 | xcookie->extension = xmock_xi2_opcode; | ||
459 | 222 | xcookie->evtype = XI_TouchUpdate; | ||
460 | 223 | xcookie->data = device_event; | ||
461 | 224 | xmock_add_to_event_queue(&event); | ||
462 | 225 | |||
463 | 226 | event.type = GenericEvent; | ||
464 | 227 | device_event = (XIDeviceEvent*)calloc(1, sizeof(XIDeviceEvent)); | ||
465 | 228 | device_event->serial = serial++; | ||
466 | 229 | device_event->display = xmock_display; | ||
467 | 230 | device_event->extension = xmock_xi2_opcode; | ||
468 | 231 | device_event->evtype = XI_TouchUpdate; | ||
469 | 232 | device_event->time = xmock_server_time; | ||
470 | 233 | device_event->deviceid = 0; | ||
471 | 234 | device_event->sourceid = device_event->deviceid; | ||
472 | 235 | device_event->detail = 1; /* touch id */ | ||
473 | 236 | device_event->root = DefaultRootWindow(xmock_display); | ||
474 | 237 | device_event->event = DefaultRootWindow(xmock_display); | ||
475 | 238 | device_event->child = 0; | ||
476 | 239 | device_event->root_x = 222.0f; | ||
477 | 240 | device_event->root_y = 466.0f; | ||
478 | 241 | device_event->event_x = device_event->root_x; | ||
479 | 242 | device_event->event_y = device_event->root_y; | ||
480 | 243 | device_event->valuators.mask_len = 2; | ||
481 | 244 | device_event->valuators.mask = (unsigned char*) malloc(2); | ||
482 | 245 | XISetMask(device_event->valuators.mask, 0); | ||
483 | 246 | XISetMask(device_event->valuators.mask, 1); | ||
484 | 247 | device_event->valuators.values = (double*) malloc(sizeof(double)*2); | ||
485 | 248 | device_event->valuators.values[0] = -150.0; | ||
486 | 249 | device_event->valuators.values[1] = -90.0; | ||
487 | 250 | xcookie = &event.xcookie; | ||
488 | 251 | xcookie->extension = xmock_xi2_opcode; | ||
489 | 252 | xcookie->evtype = XI_TouchUpdate; | ||
490 | 253 | xcookie->data = device_event; | ||
491 | 254 | xmock_add_to_event_queue(&event); | ||
492 | 255 | } | ||
493 | 256 | |||
494 | 257 | void Geis2GrailBackend::OnEventInitComplete(GeisEvent event) | ||
495 | 258 | { | ||
496 | 259 | _subscription = CreateFilteredSubscription( | ||
497 | 260 | "My 2-touches Touch", 2, GEIS_GESTURE_TOUCH); | ||
498 | 261 | ASSERT_NE(nullptr, _subscription); | ||
499 | 262 | |||
500 | 263 | SendXInput2Events(); | ||
501 | 264 | } | ||
502 | 265 | |||
503 | 266 | void Geis2GrailBackend::OnEventGestureBegin(GeisEvent event) | ||
504 | 267 | { | ||
505 | 268 | GeisAttr attr = geis_event_attr_by_name(event, GEIS_EVENT_ATTRIBUTE_TOUCHSET); | ||
506 | 269 | GeisTouchSet geis_touch_set = (GeisTouchSet) geis_attr_value_to_pointer(attr); | ||
507 | 270 | |||
508 | 271 | TouchSet touch_set(geis_touch_set); | ||
509 | 272 | |||
510 | 273 | /* check that there are two touch points and that they are in window coordinates | ||
511 | 274 | (instead of input device coordinates) */ | ||
512 | 275 | ASSERT_EQ(2, touch_set.size()); | ||
513 | 276 | ASSERT_TRUE(touch_set.contains(123.0f, 456.0f)); | ||
514 | 277 | ASSERT_TRUE(touch_set.contains(222.0f, 456.0f)); | ||
515 | 278 | } | ||
516 | 279 | |||
517 | 280 | TEST_F(Geis2GrailBackend, DirectDeviceTouchCoords) | ||
518 | 281 | { | ||
519 | 282 | CreateXMockDevices(); | ||
520 | 283 | |||
521 | 284 | Geis geis = geis_new(GEIS_INIT_UTOUCH_GRAIL_BACKEND, | ||
522 | 285 | nullptr); | ||
523 | 286 | ASSERT_NE(nullptr, geis); | ||
524 | 287 | |||
525 | 288 | Run(geis); | ||
526 | 289 | |||
527 | 290 | if (_subscription) | ||
528 | 291 | geis_subscription_delete(_subscription); | ||
529 | 292 | geis_delete(geis); | ||
530 | 293 | |||
531 | 294 | DestroyXMockDevices(); | ||
532 | 295 | } | ||
533 | 0 | 296 | ||
534 | === added file 'testsuite/geis2/gtest_grail_backend.cpp' | |||
535 | --- testsuite/geis2/gtest_grail_backend.cpp 1970-01-01 00:00:00 +0000 | |||
536 | +++ testsuite/geis2/gtest_grail_backend.cpp 2012-04-24 19:38:21 +0000 | |||
537 | @@ -0,0 +1,134 @@ | |||
538 | 1 | #include "gtest_grail_backend.h" | ||
539 | 2 | #include "x11_mocks.h" | ||
540 | 3 | #include <iostream> | ||
541 | 4 | |||
542 | 5 | #define ADD_FAILURE_AND_RETURN(ret) \ | ||
543 | 6 | {\ | ||
544 | 7 | ADD_FAILURE();\ | ||
545 | 8 | return ret;\ | ||
546 | 9 | }\ | ||
547 | 10 | |||
548 | 11 | Touch::Touch(GeisTouch geis_touch) | ||
549 | 12 | { | ||
550 | 13 | GeisAttr attr = geis_touch_attr_by_name(geis_touch, GEIS_TOUCH_ATTRIBUTE_X); | ||
551 | 14 | x = geis_attr_value_to_float(attr); | ||
552 | 15 | |||
553 | 16 | attr = geis_touch_attr_by_name(geis_touch, GEIS_TOUCH_ATTRIBUTE_Y); | ||
554 | 17 | y = geis_attr_value_to_float(attr); | ||
555 | 18 | |||
556 | 19 | attr = geis_touch_attr_by_name(geis_touch, GEIS_TOUCH_ATTRIBUTE_ID); | ||
557 | 20 | id = geis_attr_value_to_integer(attr); | ||
558 | 21 | } | ||
559 | 22 | |||
560 | 23 | TouchSet::TouchSet(GeisTouchSet geis_touch_set) | ||
561 | 24 | { | ||
562 | 25 | int count = geis_touchset_touch_count(geis_touch_set); | ||
563 | 26 | for (int i = 0; i < count; ++i) | ||
564 | 27 | push_back(Touch(geis_touchset_touch(geis_touch_set, i))); | ||
565 | 28 | } | ||
566 | 29 | |||
567 | 30 | bool TouchSet::contains(float x, float y) | ||
568 | 31 | { | ||
569 | 32 | for (auto touch : *this) | ||
570 | 33 | { | ||
571 | 34 | if (touch.x == x && touch.y == y) | ||
572 | 35 | return true; | ||
573 | 36 | } | ||
574 | 37 | return false; | ||
575 | 38 | } | ||
576 | 39 | |||
577 | 40 | GeisSubscription Geis2GrailBackendBase::CreateFilteredSubscription( | ||
578 | 41 | GeisString name, GeisSize num_touches, GeisString gesture_class) | ||
579 | 42 | { | ||
580 | 43 | GeisStatus status = GEIS_STATUS_UNKNOWN_ERROR; | ||
581 | 44 | GeisFilter filter = nullptr; | ||
582 | 45 | GeisSubscription sub = nullptr; | ||
583 | 46 | |||
584 | 47 | sub = geis_subscription_new(_geis, name, GEIS_SUBSCRIPTION_NONE); | ||
585 | 48 | |||
586 | 49 | filter = geis_filter_new(_geis, "filter"); | ||
587 | 50 | if (filter == nullptr) ADD_FAILURE_AND_RETURN(nullptr); | ||
588 | 51 | |||
589 | 52 | status = geis_filter_add_term(filter, | ||
590 | 53 | GEIS_FILTER_CLASS, | ||
591 | 54 | GEIS_CLASS_ATTRIBUTE_NAME, GEIS_FILTER_OP_EQ, gesture_class, | ||
592 | 55 | GEIS_GESTURE_ATTRIBUTE_TOUCHES, GEIS_FILTER_OP_EQ, num_touches, | ||
593 | 56 | nullptr); | ||
594 | 57 | if (status != GEIS_STATUS_SUCCESS) ADD_FAILURE_AND_RETURN(nullptr); | ||
595 | 58 | |||
596 | 59 | status = geis_filter_add_term(filter, | ||
597 | 60 | GEIS_FILTER_REGION, | ||
598 | 61 | GEIS_REGION_ATTRIBUTE_WINDOWID, GEIS_FILTER_OP_EQ, | ||
599 | 62 | DefaultRootWindow(xmock_display), | ||
600 | 63 | nullptr); | ||
601 | 64 | if (status != GEIS_STATUS_SUCCESS) ADD_FAILURE_AND_RETURN(nullptr); | ||
602 | 65 | |||
603 | 66 | status = geis_subscription_add_filter(sub, filter); | ||
604 | 67 | if (status != GEIS_STATUS_SUCCESS) ADD_FAILURE_AND_RETURN(nullptr); | ||
605 | 68 | |||
606 | 69 | status = geis_subscription_activate(sub); | ||
607 | 70 | if (status != GEIS_STATUS_SUCCESS) ADD_FAILURE_AND_RETURN(nullptr); | ||
608 | 71 | |||
609 | 72 | return sub; | ||
610 | 73 | } | ||
611 | 74 | |||
612 | 75 | bool Geis2GrailBackendBase::DispatchAndProcessEvents() | ||
613 | 76 | { | ||
614 | 77 | bool got_events = false; | ||
615 | 78 | GeisEvent event; | ||
616 | 79 | GeisStatus status; | ||
617 | 80 | |||
618 | 81 | status = geis_dispatch_events(_geis); | ||
619 | 82 | if (status != GEIS_STATUS_SUCCESS) ADD_FAILURE_AND_RETURN(false); | ||
620 | 83 | |||
621 | 84 | status = geis_next_event(_geis, &event); | ||
622 | 85 | if (status != GEIS_STATUS_SUCCESS | ||
623 | 86 | && status != GEIS_STATUS_CONTINUE | ||
624 | 87 | && status != GEIS_STATUS_EMPTY) | ||
625 | 88 | ADD_FAILURE_AND_RETURN(false); | ||
626 | 89 | |||
627 | 90 | if (status == GEIS_STATUS_SUCCESS || status == GEIS_STATUS_CONTINUE) | ||
628 | 91 | got_events = true; | ||
629 | 92 | |||
630 | 93 | while (status == GEIS_STATUS_CONTINUE || status == GEIS_STATUS_SUCCESS) | ||
631 | 94 | { | ||
632 | 95 | switch (geis_event_type(event)) | ||
633 | 96 | { | ||
634 | 97 | case GEIS_EVENT_INIT_COMPLETE: | ||
635 | 98 | OnEventInitComplete(event); | ||
636 | 99 | break; | ||
637 | 100 | case GEIS_EVENT_GESTURE_BEGIN: | ||
638 | 101 | OnEventGestureBegin(event); | ||
639 | 102 | break; | ||
640 | 103 | case GEIS_EVENT_GESTURE_UPDATE: | ||
641 | 104 | OnEventGestureUpdate(event); | ||
642 | 105 | break; | ||
643 | 106 | case GEIS_EVENT_GESTURE_END: | ||
644 | 107 | OnEventGestureEnd(event); | ||
645 | 108 | break; | ||
646 | 109 | default: | ||
647 | 110 | break; | ||
648 | 111 | } | ||
649 | 112 | geis_event_delete(event); | ||
650 | 113 | status = geis_next_event(_geis, &event); | ||
651 | 114 | } | ||
652 | 115 | |||
653 | 116 | return got_events; | ||
654 | 117 | } | ||
655 | 118 | |||
656 | 119 | void Geis2GrailBackendBase::Run(Geis geis) | ||
657 | 120 | { | ||
658 | 121 | _geis = geis; | ||
659 | 122 | |||
660 | 123 | bool got_events; | ||
661 | 124 | do | ||
662 | 125 | { | ||
663 | 126 | got_events = DispatchAndProcessEvents(); | ||
664 | 127 | } while (got_events); | ||
665 | 128 | } | ||
666 | 129 | |||
667 | 130 | int main(int argc, char **argv) | ||
668 | 131 | { | ||
669 | 132 | testing::InitGoogleTest(&argc, argv); | ||
670 | 133 | return RUN_ALL_TESTS(); | ||
671 | 134 | } | ||
672 | 0 | 135 | ||
673 | === added file 'testsuite/geis2/gtest_grail_backend.h' | |||
674 | --- testsuite/geis2/gtest_grail_backend.h 1970-01-01 00:00:00 +0000 | |||
675 | +++ testsuite/geis2/gtest_grail_backend.h 2012-04-24 19:38:21 +0000 | |||
676 | @@ -0,0 +1,52 @@ | |||
677 | 1 | #ifndef GTEST_GRAIL_BACKEND_H | ||
678 | 2 | #define GTEST_GRAIL_BACKEND_H | ||
679 | 3 | |||
680 | 4 | #include <gtest/gtest.h> | ||
681 | 5 | #include <geis/geis.h> | ||
682 | 6 | #include <vector> | ||
683 | 7 | |||
684 | 8 | class Touch | ||
685 | 9 | { | ||
686 | 10 | public: | ||
687 | 11 | Touch(GeisTouch geis_touch); | ||
688 | 12 | |||
689 | 13 | int id; | ||
690 | 14 | float x; | ||
691 | 15 | float y; | ||
692 | 16 | }; | ||
693 | 17 | |||
694 | 18 | class TouchSet : public std::vector<Touch> | ||
695 | 19 | { | ||
696 | 20 | public: | ||
697 | 21 | TouchSet(GeisTouchSet geis_touch_set); | ||
698 | 22 | bool contains(float x, float y); | ||
699 | 23 | }; | ||
700 | 24 | |||
701 | 25 | class Geis2GrailBackendBase : public ::testing::Test | ||
702 | 26 | { | ||
703 | 27 | protected: | ||
704 | 28 | Geis2GrailBackendBase() : _geis(nullptr) {} | ||
705 | 29 | virtual ~Geis2GrailBackendBase() {} | ||
706 | 30 | |||
707 | 31 | /* Dispatch and process Geis events in a loop until there are no more | ||
708 | 32 | events. */ | ||
709 | 33 | void Run(Geis geis); | ||
710 | 34 | |||
711 | 35 | |||
712 | 36 | /* Creates (and activates) a GeisSubscription with the given name | ||
713 | 37 | and with filters for the given number of touches and gesture class. */ | ||
714 | 38 | GeisSubscription CreateFilteredSubscription(GeisString name, | ||
715 | 39 | GeisSize num_touches, | ||
716 | 40 | GeisString gesture_class); | ||
717 | 41 | |||
718 | 42 | virtual void OnEventInitComplete(GeisEvent event) {} | ||
719 | 43 | virtual void OnEventGestureBegin(GeisEvent event) {} | ||
720 | 44 | virtual void OnEventGestureUpdate(GeisEvent event) {} | ||
721 | 45 | virtual void OnEventGestureEnd(GeisEvent event) {} | ||
722 | 46 | |||
723 | 47 | private: | ||
724 | 48 | Geis _geis; | ||
725 | 49 | bool DispatchAndProcessEvents(); | ||
726 | 50 | }; | ||
727 | 51 | |||
728 | 52 | #endif // GTEST_GRAIL_BACKEND_H | ||
729 | 0 | 53 | ||
730 | === modified file 'testsuite/gtest/Makefile.am' | |||
731 | --- testsuite/gtest/Makefile.am 2012-03-30 11:51:09 +0000 | |||
732 | +++ testsuite/gtest/Makefile.am 2012-04-24 19:38:21 +0000 | |||
733 | @@ -3,26 +3,31 @@ | |||
734 | 3 | # @brief automake recipe for the geis gtest testsuite harness directory | 3 | # @brief automake recipe for the geis gtest testsuite harness directory |
735 | 4 | # | 4 | # |
736 | 5 | 5 | ||
738 | 6 | if ENABLE_INTEGRATION_TESTS | 6 | if HAVE_GTEST |
739 | 7 | check_LIBRARIES = libgtest_geis.a | 7 | check_LIBRARIES = libgtest_geis.a |
740 | 8 | endif | 8 | endif |
741 | 9 | 9 | ||
742 | 10 | libgtest_geis_a_SOURCES = \ | ||
743 | 11 | gtest_evemu_device.h gtest_evemu_device.cpp \ | ||
744 | 12 | gtest_geis_fixture.h gtest_geis_fixture.cpp \ | ||
745 | 13 | gtest_geis1_fixture.h gtest_geis1_fixture.cpp | ||
746 | 14 | |||
747 | 15 | nodist_libgtest_geis_a_SOURCES = \ | 10 | nodist_libgtest_geis_a_SOURCES = \ |
748 | 16 | $(XORG_GTEST_SOURCE)/src/xorg-gtest-all.cpp \ | ||
749 | 17 | $(GTEST_SOURCE)/src/gtest-all.cc | 11 | $(GTEST_SOURCE)/src/gtest-all.cc |
750 | 18 | 12 | ||
751 | 19 | libgtest_geis_a_CPPFLAGS = \ | 13 | libgtest_geis_a_CPPFLAGS = \ |
752 | 20 | --std=c++0x \ | ||
753 | 21 | -I$(top_srcdir) \ | 14 | -I$(top_srcdir) \ |
754 | 22 | -I$(top_srcdir)/include \ | 15 | -I$(top_srcdir)/include \ |
755 | 23 | -I$(top_srcdir)/libutouch-geis \ | 16 | -I$(top_srcdir)/libutouch-geis \ |
756 | 24 | -DTEST_ROOT_DIR=\"$(abs_top_srcdir)/testsuite/\" \ | 17 | -DTEST_ROOT_DIR=\"$(abs_top_srcdir)/testsuite/\" \ |
757 | 18 | $(GTEST_CPPFLAGS) | ||
758 | 19 | |||
759 | 20 | if ENABLE_INTEGRATION_TESTS | ||
760 | 21 | libgtest_geis_a_SOURCES = \ | ||
761 | 22 | gtest_evemu_device.h gtest_evemu_device.cpp \ | ||
762 | 23 | gtest_geis_fixture.h gtest_geis_fixture.cpp \ | ||
763 | 24 | gtest_geis1_fixture.h gtest_geis1_fixture.cpp | ||
764 | 25 | |||
765 | 26 | nodist_libgtest_geis_a_SOURCES += \ | ||
766 | 27 | $(XORG_GTEST_SOURCE)/src/xorg-gtest-all.cpp | ||
767 | 28 | |||
768 | 29 | libgtest_geis_a_CPPFLAGS += \ | ||
769 | 25 | $(XORG_GTEST_CPPFLAGS) \ | 30 | $(XORG_GTEST_CPPFLAGS) \ |
770 | 26 | $(GTEST_CPPFLAGS) \ | ||
771 | 27 | $(EVEMU_CFLAGS) \ | 31 | $(EVEMU_CFLAGS) \ |
772 | 28 | $(XORG_GTEST_CFLAGS) | 32 | $(XORG_GTEST_CFLAGS) |
773 | 33 | endif | ||
774 | 29 | 34 | ||
775 | === added directory 'testsuite/x11_mocks' | |||
776 | === added file 'testsuite/x11_mocks/Makefile.am' | |||
777 | --- testsuite/x11_mocks/Makefile.am 1970-01-01 00:00:00 +0000 | |||
778 | +++ testsuite/x11_mocks/Makefile.am 2012-04-24 19:38:21 +0000 | |||
779 | @@ -0,0 +1,13 @@ | |||
780 | 1 | # | ||
781 | 2 | # @file testsuite/x11_mocks/Makefile.am | ||
782 | 3 | # @brief automake recipe for the X11 mockups | ||
783 | 4 | # | ||
784 | 5 | |||
785 | 6 | check_LIBRARIES = libx11_mocks.a | ||
786 | 7 | |||
787 | 8 | libx11_mocks_a_SOURCES = \ | ||
788 | 9 | x11_mocks.c | ||
789 | 10 | |||
790 | 11 | libx11_mocks_a_CFLAGS = \ | ||
791 | 12 | --std=c99 | ||
792 | 13 | |||
793 | 0 | 14 | ||
794 | === added file 'testsuite/x11_mocks/x11_mocks.c' | |||
795 | --- testsuite/x11_mocks/x11_mocks.c 1970-01-01 00:00:00 +0000 | |||
796 | +++ testsuite/x11_mocks/x11_mocks.c 2012-04-24 19:38:21 +0000 | |||
797 | @@ -0,0 +1,406 @@ | |||
798 | 1 | /* needed to break into 'Display' struct internals. */ | ||
799 | 2 | #define XLIB_ILLEGAL_ACCESS | ||
800 | 3 | #include <X11/Xlib.h> | ||
801 | 4 | |||
802 | 5 | #include <geis/geis.h> | ||
803 | 6 | |||
804 | 7 | #include "x11_mocks.h" | ||
805 | 8 | |||
806 | 9 | #include <sys/eventfd.h> | ||
807 | 10 | #include <stdio.h> | ||
808 | 11 | #include <unistd.h> | ||
809 | 12 | |||
810 | 13 | int xmock_xi2_opcode = 42; | ||
811 | 14 | int xmock_xi2_event_base = 40000; | ||
812 | 15 | int xmock_xi2_error_base = 40000; | ||
813 | 16 | int xmock_xsync_event_base = 50000; | ||
814 | 17 | int xmock_xsync_error_base = 50000; | ||
815 | 18 | Display *xmock_display = NULL; | ||
816 | 19 | uint64_t xmock_server_time = 0; | ||
817 | 20 | |||
818 | 21 | XIDeviceInfo *xmock_devices = NULL; | ||
819 | 22 | int xmock_devices_count = 0; | ||
820 | 23 | |||
821 | 24 | /* id to be used for the next alarm that gets created */ | ||
822 | 25 | XSyncAlarm _xmock_next_alarm = 1; | ||
823 | 26 | |||
824 | 27 | struct EventQueueItem | ||
825 | 28 | { | ||
826 | 29 | XEvent event; | ||
827 | 30 | struct EventQueueItem *next; | ||
828 | 31 | } *xmock_event_queue = NULL; | ||
829 | 32 | |||
830 | 33 | #define XMOCK_PRINT_FUNCTION _xmock_print_function(__func__) | ||
831 | 34 | void _xmock_print_function(const char *function) | ||
832 | 35 | { | ||
833 | 36 | static int debug_enabled = -1; | ||
834 | 37 | if (debug_enabled == -1) | ||
835 | 38 | { | ||
836 | 39 | if (getenv("XMOCK_DEBUG")) | ||
837 | 40 | debug_enabled = 1; | ||
838 | 41 | else | ||
839 | 42 | debug_enabled = 0; | ||
840 | 43 | } | ||
841 | 44 | |||
842 | 45 | if (debug_enabled) | ||
843 | 46 | printf("XMOCK: %s mock called.\n", function); | ||
844 | 47 | } | ||
845 | 48 | |||
846 | 49 | void xmock_add_to_event_queue(const XEvent *event) | ||
847 | 50 | { | ||
848 | 51 | struct EventQueueItem *new_item = malloc(sizeof(struct EventQueueItem)); | ||
849 | 52 | new_item->event = *event; | ||
850 | 53 | new_item->next = NULL; | ||
851 | 54 | |||
852 | 55 | if (!xmock_event_queue) | ||
853 | 56 | { | ||
854 | 57 | xmock_event_queue = new_item; | ||
855 | 58 | } | ||
856 | 59 | else | ||
857 | 60 | { | ||
858 | 61 | struct EventQueueItem *last_item = xmock_event_queue; | ||
859 | 62 | while (last_item->next) | ||
860 | 63 | { | ||
861 | 64 | last_item = last_item->next; | ||
862 | 65 | } | ||
863 | 66 | last_item->next = new_item; | ||
864 | 67 | } | ||
865 | 68 | |||
866 | 69 | static const uint64_t num = 1; | ||
867 | 70 | if (write(xmock_display->fd, &num, sizeof(num)) != sizeof(num)) | ||
868 | 71 | { | ||
869 | 72 | fprintf(stderr, "ERROR: failed to update eventfd instance,\n"); | ||
870 | 73 | exit(1); | ||
871 | 74 | } | ||
872 | 75 | } | ||
873 | 76 | |||
874 | 77 | Display *XOpenDisplay(_Xconst char *display_name) | ||
875 | 78 | { | ||
876 | 79 | XMOCK_PRINT_FUNCTION; | ||
877 | 80 | (void)display_name; | ||
878 | 81 | |||
879 | 82 | Display *display = (Display*)calloc(1, sizeof(Display)); | ||
880 | 83 | display->fd = eventfd(0, EFD_NONBLOCK); | ||
881 | 84 | display->default_screen = 0; | ||
882 | 85 | display->nscreens = 1; | ||
883 | 86 | display->screens = (Screen*)calloc(1, sizeof(Screen)); | ||
884 | 87 | display->screens[0].root = 1; | ||
885 | 88 | |||
886 | 89 | xmock_display = display; | ||
887 | 90 | |||
888 | 91 | return display; | ||
889 | 92 | } | ||
890 | 93 | |||
891 | 94 | int XCloseDisplay(Display *display) | ||
892 | 95 | { | ||
893 | 96 | XMOCK_PRINT_FUNCTION; | ||
894 | 97 | |||
895 | 98 | close(display->fd); | ||
896 | 99 | free(display->screens); | ||
897 | 100 | free(display); | ||
898 | 101 | |||
899 | 102 | xmock_display = NULL; | ||
900 | 103 | |||
901 | 104 | return 0; | ||
902 | 105 | } | ||
903 | 106 | |||
904 | 107 | int XSync(Display *display, Bool discard) | ||
905 | 108 | { | ||
906 | 109 | (void)display; | ||
907 | 110 | (void)discard; | ||
908 | 111 | return 0; | ||
909 | 112 | } | ||
910 | 113 | |||
911 | 114 | int XFlush(Display *display) | ||
912 | 115 | { | ||
913 | 116 | (void)display; | ||
914 | 117 | return 0; | ||
915 | 118 | } | ||
916 | 119 | |||
917 | 120 | Bool XQueryExtension(Display *display, const char *name, | ||
918 | 121 | int *major_opcode_return, int *first_event_return, int *first_error_return) | ||
919 | 122 | { | ||
920 | 123 | XMOCK_PRINT_FUNCTION; | ||
921 | 124 | (void)display; | ||
922 | 125 | (void)name; /* assuming name == "XInputExtension" */ | ||
923 | 126 | |||
924 | 127 | *major_opcode_return = xmock_xi2_opcode; | ||
925 | 128 | *first_event_return = xmock_xi2_event_base; | ||
926 | 129 | *first_error_return = xmock_xi2_error_base; | ||
927 | 130 | |||
928 | 131 | return True; | ||
929 | 132 | } | ||
930 | 133 | |||
931 | 134 | int XPending(Display *display) | ||
932 | 135 | { | ||
933 | 136 | XMOCK_PRINT_FUNCTION; | ||
934 | 137 | (void)display; | ||
935 | 138 | |||
936 | 139 | int pending_events_count = 0; | ||
937 | 140 | struct EventQueueItem *item = xmock_event_queue; | ||
938 | 141 | while (item != NULL) | ||
939 | 142 | { | ||
940 | 143 | ++pending_events_count; | ||
941 | 144 | item = item->next; | ||
942 | 145 | } | ||
943 | 146 | return pending_events_count; | ||
944 | 147 | } | ||
945 | 148 | |||
946 | 149 | int XNextEvent(Display *display, XEvent *event_return) | ||
947 | 150 | { | ||
948 | 151 | XMOCK_PRINT_FUNCTION; | ||
949 | 152 | (void)display; | ||
950 | 153 | |||
951 | 154 | |||
952 | 155 | if (xmock_event_queue) | ||
953 | 156 | { | ||
954 | 157 | uint64_t num = 1; | ||
955 | 158 | ssize_t bytes_read = read(xmock_display->fd, &num, sizeof(num)); | ||
956 | 159 | (void)bytes_read; | ||
957 | 160 | |||
958 | 161 | *event_return = xmock_event_queue->event; | ||
959 | 162 | |||
960 | 163 | struct EventQueueItem *removed_item = xmock_event_queue; | ||
961 | 164 | xmock_event_queue = xmock_event_queue->next; | ||
962 | 165 | free(removed_item); | ||
963 | 166 | } | ||
964 | 167 | else | ||
965 | 168 | { | ||
966 | 169 | /* not going to block... */ | ||
967 | 170 | } | ||
968 | 171 | |||
969 | 172 | return 0; | ||
970 | 173 | } | ||
971 | 174 | |||
972 | 175 | Bool XGetEventData(Display *display, XGenericEventCookie *cookie) | ||
973 | 176 | { | ||
974 | 177 | XMOCK_PRINT_FUNCTION; | ||
975 | 178 | (void)display; | ||
976 | 179 | (void)cookie; | ||
977 | 180 | return True; | ||
978 | 181 | } | ||
979 | 182 | |||
980 | 183 | void XFreeEventData(Display *display, XGenericEventCookie *cookie) | ||
981 | 184 | { | ||
982 | 185 | XMOCK_PRINT_FUNCTION; | ||
983 | 186 | (void)display; | ||
984 | 187 | |||
985 | 188 | if (cookie->data && cookie->extension == xmock_xi2_opcode) | ||
986 | 189 | { | ||
987 | 190 | if (cookie->evtype == XI_TouchBegin | ||
988 | 191 | || cookie->evtype == XI_TouchUpdate | ||
989 | 192 | || cookie->evtype == XI_TouchEnd) | ||
990 | 193 | { | ||
991 | 194 | XIDeviceEvent *device_event = (XIDeviceEvent*) cookie->data; | ||
992 | 195 | free(device_event->valuators.mask); | ||
993 | 196 | free(device_event->valuators.values); | ||
994 | 197 | } | ||
995 | 198 | free(cookie->data); | ||
996 | 199 | } | ||
997 | 200 | } | ||
998 | 201 | |||
999 | 202 | XIDeviceInfo* XIQueryDevice(Display * display, | ||
1000 | 203 | int deviceid, | ||
1001 | 204 | int * ndevices_return) | ||
1002 | 205 | { | ||
1003 | 206 | XMOCK_PRINT_FUNCTION; | ||
1004 | 207 | (void)display; | ||
1005 | 208 | (void)deviceid; /* assuming XIAllDevices */ | ||
1006 | 209 | |||
1007 | 210 | XIDeviceInfo *devices; | ||
1008 | 211 | |||
1009 | 212 | devices = calloc(xmock_devices_count, sizeof(XIDeviceInfo)); | ||
1010 | 213 | |||
1011 | 214 | for (int i = 0; i < xmock_devices_count; ++i) { | ||
1012 | 215 | devices[i] = xmock_devices[i]; | ||
1013 | 216 | } | ||
1014 | 217 | |||
1015 | 218 | *ndevices_return = xmock_devices_count; | ||
1016 | 219 | |||
1017 | 220 | return devices; | ||
1018 | 221 | } | ||
1019 | 222 | |||
1020 | 223 | void XIFreeDeviceInfo(XIDeviceInfo *info) | ||
1021 | 224 | { | ||
1022 | 225 | XMOCK_PRINT_FUNCTION; | ||
1023 | 226 | free(info); | ||
1024 | 227 | } | ||
1025 | 228 | |||
1026 | 229 | Status XIQueryVersion(Display *display, | ||
1027 | 230 | int *major_version_inout, | ||
1028 | 231 | int *minor_version_inout) | ||
1029 | 232 | { | ||
1030 | 233 | XMOCK_PRINT_FUNCTION; | ||
1031 | 234 | (void)display; | ||
1032 | 235 | *major_version_inout = 2; | ||
1033 | 236 | *minor_version_inout = 2; | ||
1034 | 237 | return Success; | ||
1035 | 238 | } | ||
1036 | 239 | |||
1037 | 240 | Status XISelectEvents(Display *display, | ||
1038 | 241 | Window win, | ||
1039 | 242 | XIEventMask *masks, | ||
1040 | 243 | int num_masks) | ||
1041 | 244 | { | ||
1042 | 245 | XMOCK_PRINT_FUNCTION; | ||
1043 | 246 | (void)display; | ||
1044 | 247 | (void)win; | ||
1045 | 248 | (void)masks; | ||
1046 | 249 | (void)num_masks; | ||
1047 | 250 | return Success; | ||
1048 | 251 | } | ||
1049 | 252 | |||
1050 | 253 | int XIGrabTouchBegin( | ||
1051 | 254 | Display* display, | ||
1052 | 255 | int deviceid, | ||
1053 | 256 | Window grab_window, | ||
1054 | 257 | int owner_events, | ||
1055 | 258 | XIEventMask *mask, | ||
1056 | 259 | int num_modifiers, | ||
1057 | 260 | XIGrabModifiers *modifiers_inout) | ||
1058 | 261 | { | ||
1059 | 262 | XMOCK_PRINT_FUNCTION; | ||
1060 | 263 | (void)display; | ||
1061 | 264 | (void)deviceid; | ||
1062 | 265 | (void)grab_window; | ||
1063 | 266 | (void)owner_events; | ||
1064 | 267 | (void)mask; | ||
1065 | 268 | |||
1066 | 269 | for (int i = 0; i < num_modifiers; ++i) | ||
1067 | 270 | { | ||
1068 | 271 | modifiers_inout[i].status = XIGrabSuccess; | ||
1069 | 272 | } | ||
1070 | 273 | |||
1071 | 274 | return 0; | ||
1072 | 275 | } | ||
1073 | 276 | |||
1074 | 277 | Status XIUngrabTouchBegin( | ||
1075 | 278 | Display* display, | ||
1076 | 279 | int deviceid, | ||
1077 | 280 | Window grab_window, | ||
1078 | 281 | int num_modifiers, | ||
1079 | 282 | XIGrabModifiers *modifiers) | ||
1080 | 283 | { | ||
1081 | 284 | XMOCK_PRINT_FUNCTION; | ||
1082 | 285 | (void)display; | ||
1083 | 286 | (void)deviceid; | ||
1084 | 287 | (void)grab_window; | ||
1085 | 288 | (void)num_modifiers; | ||
1086 | 289 | (void)modifiers; | ||
1087 | 290 | return Success; | ||
1088 | 291 | } | ||
1089 | 292 | |||
1090 | 293 | Status XIAllowTouchEvents( | ||
1091 | 294 | Display* display, | ||
1092 | 295 | int deviceid, | ||
1093 | 296 | unsigned int touchid, | ||
1094 | 297 | Window grab_window, | ||
1095 | 298 | int event_mode) | ||
1096 | 299 | { | ||
1097 | 300 | XMOCK_PRINT_FUNCTION; | ||
1098 | 301 | (void)display; | ||
1099 | 302 | (void)deviceid; | ||
1100 | 303 | (void)touchid; | ||
1101 | 304 | (void)grab_window; | ||
1102 | 305 | (void)event_mode; | ||
1103 | 306 | return Success; | ||
1104 | 307 | } | ||
1105 | 308 | |||
1106 | 309 | Status XSyncQueryExtension( | ||
1107 | 310 | Display* dpy, | ||
1108 | 311 | int* event_base_return, | ||
1109 | 312 | int* error_base_return) | ||
1110 | 313 | { | ||
1111 | 314 | XMOCK_PRINT_FUNCTION; | ||
1112 | 315 | (void)dpy; | ||
1113 | 316 | *event_base_return = xmock_xsync_event_base; | ||
1114 | 317 | *error_base_return = xmock_xsync_error_base; | ||
1115 | 318 | return True; | ||
1116 | 319 | } | ||
1117 | 320 | |||
1118 | 321 | Status XSyncInitialize( | ||
1119 | 322 | Display* dpy, | ||
1120 | 323 | int* major_version_return, | ||
1121 | 324 | int* minor_version_return) | ||
1122 | 325 | { | ||
1123 | 326 | XMOCK_PRINT_FUNCTION; | ||
1124 | 327 | (void)dpy; | ||
1125 | 328 | *major_version_return = 1; | ||
1126 | 329 | *minor_version_return = 0; | ||
1127 | 330 | return True; | ||
1128 | 331 | } | ||
1129 | 332 | |||
1130 | 333 | XSyncSystemCounter *XSyncListSystemCounters( | ||
1131 | 334 | Display* dpy, | ||
1132 | 335 | int* n_counters_return) | ||
1133 | 336 | { | ||
1134 | 337 | XMOCK_PRINT_FUNCTION; | ||
1135 | 338 | (void)dpy; | ||
1136 | 339 | *n_counters_return = 1; | ||
1137 | 340 | |||
1138 | 341 | XSyncSystemCounter *sys_counter = malloc(sizeof(XSyncSystemCounter)); | ||
1139 | 342 | sys_counter->name = "SERVERTIME"; | ||
1140 | 343 | sys_counter->counter = 1; | ||
1141 | 344 | sys_counter->resolution.hi = 1; | ||
1142 | 345 | sys_counter->resolution.lo = 0; | ||
1143 | 346 | return sys_counter; | ||
1144 | 347 | } | ||
1145 | 348 | |||
1146 | 349 | void XSyncFreeSystemCounterList(XSyncSystemCounter* list) | ||
1147 | 350 | { | ||
1148 | 351 | XMOCK_PRINT_FUNCTION; | ||
1149 | 352 | free(list); | ||
1150 | 353 | } | ||
1151 | 354 | |||
1152 | 355 | XSyncAlarm XSyncCreateAlarm( | ||
1153 | 356 | Display* dpy, | ||
1154 | 357 | unsigned long values_mask, | ||
1155 | 358 | XSyncAlarmAttributes* values) | ||
1156 | 359 | { | ||
1157 | 360 | XMOCK_PRINT_FUNCTION; | ||
1158 | 361 | (void)dpy; | ||
1159 | 362 | |||
1160 | 363 | XSyncAlarmNotifyEvent alarm_notify; | ||
1161 | 364 | alarm_notify.type = xmock_xsync_event_base + XSyncAlarmNotify; | ||
1162 | 365 | alarm_notify.alarm = _xmock_next_alarm; | ||
1163 | 366 | alarm_notify.counter_value = values->trigger.wait_value; | ||
1164 | 367 | xmock_add_to_event_queue((XEvent*)&alarm_notify); | ||
1165 | 368 | |||
1166 | 369 | XSyncValue time = values->trigger.wait_value; | ||
1167 | 370 | uint64_t timeout = (uint64_t)XSyncValueHigh32(time) << 32 | ||
1168 | 371 | | (uint64_t)XSyncValueLow32(time); | ||
1169 | 372 | xmock_server_time = timeout + 1; | ||
1170 | 373 | |||
1171 | 374 | return _xmock_next_alarm++; | ||
1172 | 375 | } | ||
1173 | 376 | |||
1174 | 377 | Status XSyncDestroyAlarm( | ||
1175 | 378 | Display* dpy, | ||
1176 | 379 | XSyncAlarm alarm) | ||
1177 | 380 | { | ||
1178 | 381 | XMOCK_PRINT_FUNCTION; | ||
1179 | 382 | (void)dpy; | ||
1180 | 383 | (void)alarm; | ||
1181 | 384 | } | ||
1182 | 385 | |||
1183 | 386 | void XSyncIntsToValue( | ||
1184 | 387 | XSyncValue* pv, | ||
1185 | 388 | unsigned int l, | ||
1186 | 389 | int h) | ||
1187 | 390 | { | ||
1188 | 391 | XMOCK_PRINT_FUNCTION; | ||
1189 | 392 | pv->hi = h; | ||
1190 | 393 | pv->lo = l; | ||
1191 | 394 | } | ||
1192 | 395 | |||
1193 | 396 | int XSyncValueHigh32(XSyncValue v) | ||
1194 | 397 | { | ||
1195 | 398 | XMOCK_PRINT_FUNCTION; | ||
1196 | 399 | return v.hi; | ||
1197 | 400 | } | ||
1198 | 401 | |||
1199 | 402 | unsigned int XSyncValueLow32(XSyncValue v) | ||
1200 | 403 | { | ||
1201 | 404 | XMOCK_PRINT_FUNCTION; | ||
1202 | 405 | return v.lo; | ||
1203 | 406 | } | ||
1204 | 0 | 407 | ||
1205 | === added file 'testsuite/x11_mocks/x11_mocks.h' | |||
1206 | --- testsuite/x11_mocks/x11_mocks.h 1970-01-01 00:00:00 +0000 | |||
1207 | +++ testsuite/x11_mocks/x11_mocks.h 2012-04-24 19:38:21 +0000 | |||
1208 | @@ -0,0 +1,34 @@ | |||
1209 | 1 | #ifndef X11_MOCKS_H | ||
1210 | 2 | #define X11_MOCKS_H | ||
1211 | 3 | |||
1212 | 4 | #include <X11/Xlib.h> | ||
1213 | 5 | #include <X11/extensions/XInput2.h> | ||
1214 | 6 | #include <X11/extensions/sync.h> | ||
1215 | 7 | |||
1216 | 8 | #ifdef __cplusplus | ||
1217 | 9 | extern "C" { | ||
1218 | 10 | #endif | ||
1219 | 11 | |||
1220 | 12 | extern int xmock_xi2_opcode; | ||
1221 | 13 | extern int xmock_xi2_event_base; | ||
1222 | 14 | extern int xmock_xi2_error_base; | ||
1223 | 15 | extern int xmock_xsync_event_base; | ||
1224 | 16 | extern int xmock_xsync_error_base; | ||
1225 | 17 | extern Display *xmock_display; | ||
1226 | 18 | extern uint64_t xmock_server_time; | ||
1227 | 19 | |||
1228 | 20 | /* to be filled by user. A copy of it will be returned by each | ||
1229 | 21 | XIQueryDevice call */ | ||
1230 | 22 | extern XIDeviceInfo *xmock_devices; | ||
1231 | 23 | extern int xmock_devices_count; | ||
1232 | 24 | |||
1233 | 25 | /* Adds the given XEvent to the xmock event queue. | ||
1234 | 26 | The Diplay connection will signal that there are | ||
1235 | 27 | pending events */ | ||
1236 | 28 | extern void xmock_add_to_event_queue(const XEvent* event); | ||
1237 | 29 | |||
1238 | 30 | #ifdef __cplusplus | ||
1239 | 31 | } | ||
1240 | 32 | #endif | ||
1241 | 33 | |||
1242 | 34 | #endif |
The code change looks OK. I built and tested with a touchscreen, and nothing appears to be broken, but I don't think that's really a valid test of this change. Is there a better interactive test?