Merge lp:~dandrader/unity/lp940612 into lp:unity

Proposed by Daniel d'Andrada
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 2240
Proposed branch: lp:~dandrader/unity/lp940612
Merge into: lp:unity
Diff against target: 1178 lines (+831/-69)
19 files modified
plugins/unityshell/src/GeisAdapter.cpp (+10/-10)
plugins/unityshell/src/GeisAdapter.h (+10/-10)
plugins/unityshell/src/GestureEngine.cpp (+22/-40)
plugins/unityshell/src/GestureEngine.h (+1/-2)
tests/CMakeLists.txt (+14/-7)
tests/test-gesture-engine/CMakeLists.txt (+40/-0)
tests/test-gesture-engine/GeisAdapterMock.cpp (+30/-0)
tests/test-gesture-engine/GeisAdapterMock.h (+148/-0)
tests/test-gesture-engine/PluginAdapterMock.cpp (+33/-0)
tests/test-gesture-engine/PluginAdapterMock.h (+37/-0)
tests/test-gesture-engine/X11_mock.cpp (+40/-0)
tests/test-gesture-engine/X11_mock.h (+37/-0)
tests/test-gesture-engine/compiz_mock/core/core.h (+29/-0)
tests/test-gesture-engine/compiz_mock/core/screen.h (+68/-0)
tests/test-gesture-engine/compiz_mock/core/window.h (+66/-0)
tests/test-gesture-engine/sed_script (+14/-0)
tests/test-gesture-engine/test_gesture_engine.cpp (+165/-0)
tests/test-gesture-engine/ubus-server-mock.cpp (+32/-0)
tests/test-gesture-engine/ubus-server-mock.h (+35/-0)
To merge this branch: bzr merge lp:~dandrader/unity/lp940612
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+99956@code.launchpad.net

This proposal supersedes a proposal from 2012-03-28.

Commit message

Fix the three-finger move for unity.

Description of the change

Fixes bug #940612.

Updated according to comments from previous proposal.

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote : Posted in a previous version of this proposal

Please keep the variable type and variable name separate:
  const CompWindowVector &client_list_stacking
should be
  CompWindowVector const& client_list_stacking
(or
  const CompWindowVector& client_list_stacking
   - but my preference is for the first)

> if (client_list_stacking.size() == 0)

can just be:

  if (client_list_stacking.empty())

> int pos_x = (int) fpos_x;

Please don't use C style casts. It isn't needed here (mostly
certain about that).

The do/while loop misses the first element of the vector if there
is more than one element.

A traditional for loop is more idiomatic and understandable.
Also, can remove the window and result temporaries from outside the loop.
And... if using the iterators, you don't need the empty check first
as the initial check makes sure of that too.

for (auto iter = client_list_stacking.rbegin(),
          end = client_list_stacking.rend();
     iter != end; ++iter)
{
    CompWindow* window = *iter;

    if (pos_x >= window->x() && pos_x <= (window->width() + window->x())
        &&
        pos_y >= window->y() && pos_y <= (window->height() + window->y()))
      return window;
}

return nullptr;

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

Updated. The loop sure looks better now.

Revision history for this message
Tim Penhey (thumper) wrote :

You don't need this check in the method any more, because it is caught by rbegin() == rend().

171 + if (client_list_stacking.empty())
172 + return nullptr;

Once you push, you don't need to resubmit. Launchpad will just update the diff.

Do we have any tests for this?

Is there any way to "fake" utouch events?

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

> You don't need this check in the method any more, because it is caught by
> rbegin() == rend().
>
> 171 + if (client_list_stacking.empty())
> 172 + return nullptr;

True. Line removed.

> Once you push, you don't need to resubmit. Launchpad will just update the
> diff.

Alright. I've pushed the updated version. Let's see.

> Do we have any tests for this?

No.

> Is there any way to "fake" utouch events?

Only if you do some mocking in a unity test.

But you can record and then replay multitouch events straight out of a /dev/input/eventX file using utouch-evemu-tools (for the recording) and libutouch-evemu1 in your test. But it would be a functional or integration test since several layers would be involved (events coming out of /dev/input/eventX into xserver and then sent as XInput2 events to compiz)

Revision history for this message
Tim Penhey (thumper) wrote :

Unless autopilot tests are trivial to add for this, I'd suggest we have a manual test for now.

There is a template in the manual-tests directory.

Code looks fine now.

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

> Unless autopilot tests are trivial to add for this, I'd suggest we have a
> manual test for now.
> [...]

It now has unit tests.

Revision history for this message
Tim Penhey (thumper) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/unityshell/src/GeisAdapter.cpp'
--- plugins/unityshell/src/GeisAdapter.cpp 2011-12-22 17:52:55 +0000
+++ plugins/unityshell/src/GeisAdapter.cpp 2012-04-04 14:40:28 +0000
@@ -237,9 +237,9 @@
237 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TIMESTAMP))237 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TIMESTAMP))
238 result->timestamp = attr.integer_val;238 result->timestamp = attr.integer_val;
239 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_X))239 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_X))
240 result->focus_x = attr.integer_val;240 result->focus_x = attr.float_val;
241 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_Y))241 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_Y))
242 result->focus_y = attr.integer_val;242 result->focus_y = attr.float_val;
243 else if (g_str_equal (attr.name, GEIS_GESTURE_ATTRIBUTE_TOUCHES))243 else if (g_str_equal (attr.name, GEIS_GESTURE_ATTRIBUTE_TOUCHES))
244 result->touches = attr.integer_val;244 result->touches = attr.integer_val;
245 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_GESTURE_NAME))245 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_GESTURE_NAME))
@@ -289,9 +289,9 @@
289 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TIMESTAMP))289 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TIMESTAMP))
290 result->timestamp = attr.integer_val;290 result->timestamp = attr.integer_val;
291 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_X))291 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_X))
292 result->focus_x = attr.integer_val;292 result->focus_x = attr.float_val;
293 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_Y))293 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_Y))
294 result->focus_y = attr.integer_val;294 result->focus_y = attr.float_val;
295 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TOUCHES))295 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TOUCHES))
296 result->touches = attr.integer_val;296 result->touches = attr.integer_val;
297 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_BOUNDINGBOX_X1))297 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_BOUNDINGBOX_X1))
@@ -322,9 +322,9 @@
322 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TIMESTAMP))322 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TIMESTAMP))
323 result->timestamp = attr.integer_val;323 result->timestamp = attr.integer_val;
324 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_X))324 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_X))
325 result->focus_x = attr.integer_val;325 result->focus_x = attr.float_val;
326 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_Y))326 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_Y))
327 result->focus_y = attr.integer_val;327 result->focus_y = attr.float_val;
328 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TOUCHES))328 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TOUCHES))
329 result->touches = attr.integer_val;329 result->touches = attr.integer_val;
330 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_POSITION_X))330 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_POSITION_X))
@@ -367,9 +367,9 @@
367 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TIMESTAMP))367 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TIMESTAMP))
368 result->timestamp = attr.integer_val;368 result->timestamp = attr.integer_val;
369 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_X))369 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_X))
370 result->focus_x = attr.integer_val;370 result->focus_x = attr.float_val;
371 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_Y))371 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_Y))
372 result->focus_y = attr.integer_val;372 result->focus_y = attr.float_val;
373 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TOUCHES))373 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TOUCHES))
374 result->touches = attr.integer_val;374 result->touches = attr.integer_val;
375 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_RADIUS))375 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_RADIUS))
@@ -406,9 +406,9 @@
406 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TIMESTAMP))406 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TIMESTAMP))
407 result->timestamp = attr.integer_val;407 result->timestamp = attr.integer_val;
408 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_X))408 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_X))
409 result->focus_x = attr.integer_val;409 result->focus_x = attr.float_val;
410 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_Y))410 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_FOCUS_Y))
411 result->focus_y = attr.integer_val;411 result->focus_y = attr.float_val;
412 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TOUCHES))412 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_TOUCHES))
413 result->touches = attr.integer_val;413 result->touches = attr.integer_val;
414 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_ANGLE))414 else if (g_str_equal(attr.name, GEIS_GESTURE_ATTRIBUTE_ANGLE))
415415
=== modified file 'plugins/unityshell/src/GeisAdapter.h'
--- plugins/unityshell/src/GeisAdapter.h 2011-08-29 23:36:21 +0000
+++ plugins/unityshell/src/GeisAdapter.h 2012-04-04 14:40:28 +0000
@@ -41,8 +41,8 @@
41 Window window;41 Window window;
42 int touches;42 int touches;
43 int timestamp;43 int timestamp;
44 int focus_x;44 float focus_x;
45 int focus_y;45 float focus_y;
46 int tap_length_ms;46 int tap_length_ms;
47 float position_x;47 float position_x;
48 float position_y;48 float position_y;
@@ -59,8 +59,8 @@
59 Window window;59 Window window;
60 int touches;60 int touches;
61 int timestamp;61 int timestamp;
62 int focus_x;62 float focus_x;
63 int focus_y;63 float focus_y;
64 float delta_x;64 float delta_x;
65 float delta_y;65 float delta_y;
66 float velocity_x;66 float velocity_x;
@@ -80,8 +80,8 @@
80 Window window;80 Window window;
81 int touches;81 int touches;
82 int timestamp;82 int timestamp;
83 int focus_x;83 float focus_x;
84 int focus_y;84 float focus_y;
85 float angle;85 float angle;
86 float angle_delta;86 float angle_delta;
87 float angle_velocity;87 float angle_velocity;
@@ -98,8 +98,8 @@
98 Window window;98 Window window;
99 int touches;99 int touches;
100 int timestamp;100 int timestamp;
101 int focus_x;101 float focus_x;
102 int focus_y;102 float focus_y;
103 float radius;103 float radius;
104 float radius_delta;104 float radius_delta;
105 float radius_velocity;105 float radius_velocity;
@@ -116,8 +116,8 @@
116 Window window;116 Window window;
117 int touches;117 int touches;
118 int timestamp;118 int timestamp;
119 int focus_x;119 float focus_x;
120 int focus_y;120 float focus_y;
121 float bound_x1;121 float bound_x1;
122 float bound_y1;122 float bound_y1;
123 float bound_x2;123 float bound_x2;
124124
=== modified file 'plugins/unityshell/src/GestureEngine.cpp'
--- plugins/unityshell/src/GestureEngine.cpp 2012-03-14 06:24:18 +0000
+++ plugins/unityshell/src/GestureEngine.cpp 2012-04-04 14:40:28 +0000
@@ -75,44 +75,26 @@
75 }75 }
76}76}
7777
78CompWindow*78CompWindow* GestureEngine::FindCompWindowAtPos(float fpos_x, float fpos_y)
79GestureEngine::FindCompWindow(Window window)
80{79{
81 CompWindow* result = _screen->findTopLevelWindow(window);80 const CompWindowVector& client_list_stacking = _screen->clientList(true);
8281
83 while (!result)82 int pos_x = fpos_x;
84 {83 int pos_y = fpos_y;
85 Window parent, root;84
86 Window* children = NULL;85 for (auto iter = client_list_stacking.rbegin(),
87 unsigned int nchildren;86 end = client_list_stacking.rend();
88 Status status;87 iter != end; ++iter)
8988 {
90 status = XQueryTree(_screen->dpy(), window, &root, &parent, &children, &nchildren);89 CompWindow* window = *iter;
91 if (status == 0)90
92 break;91 if (pos_x >= window->x() && pos_x <= (window->width() + window->x())
9392 &&
94 if (children)93 pos_y >= window->y() && pos_y <= (window->height() + window->y()))
95 XFree(children);94 return window;
9695 }
97 // parent will be zero when the window passed to this method is already the96
98 // root one.97 return nullptr;
99 if (parent == root || parent == 0)
100 break;
101
102 window = parent;
103 result = _screen->findTopLevelWindow(window);
104 }
105
106 if (result)
107 {
108 if (!(result->type() & (CompWindowTypeUtilMask |
109 CompWindowTypeNormalMask |
110 CompWindowTypeDialogMask |
111 CompWindowTypeModalDialogMask)))
112 result = 0;
113 }
114
115 return result;
116}98}
11799
118void100void
@@ -120,7 +102,7 @@
120{102{
121 if (data->touches == 3)103 if (data->touches == 3)
122 {104 {
123 _drag_window = FindCompWindow(data->window);105 _drag_window = FindCompWindowAtPos(data->focus_x, data->focus_y);
124106
125107
126 if (!_drag_window)108 if (!_drag_window)
@@ -222,7 +204,7 @@
222{204{
223 if (data->touches == 3 && data->window != 0)205 if (data->touches == 3 && data->window != 0)
224 {206 {
225 CompWindow* result = FindCompWindow(data->window);207 CompWindow* result = FindCompWindowAtPos(data->focus_x, data->focus_y);
226208
227 if (result)209 if (result)
228 {210 {
@@ -256,7 +238,7 @@
256{238{
257 if (data->touches == 3)239 if (data->touches == 3)
258 {240 {
259 _pinch_window = FindCompWindow(data->window);241 _pinch_window = FindCompWindowAtPos(data->focus_x, data->focus_y);
260242
261 if (!_pinch_window)243 if (!_pinch_window)
262 return;244 return;
263245
=== modified file 'plugins/unityshell/src/GestureEngine.h'
--- plugins/unityshell/src/GestureEngine.h 2011-09-28 14:31:35 +0000
+++ plugins/unityshell/src/GestureEngine.h 2012-04-04 14:40:28 +0000
@@ -23,7 +23,6 @@
23#include <core/core.h>23#include <core/core.h>
2424
25#include <sigc++/sigc++.h>25#include <sigc++/sigc++.h>
26#include <Nux/Nux.h>
27#include "GeisAdapter.h"26#include "GeisAdapter.h"
2827
29class GestureEngine : public sigc::trackable28class GestureEngine : public sigc::trackable
@@ -52,7 +51,7 @@
5251
53 void EndDrag();52 void EndDrag();
54private:53private:
55 CompWindow* FindCompWindow(Window window);54 CompWindow* FindCompWindowAtPos(float pos_x, float pos_y);
5655
57 CompScreen* _screen;56 CompScreen* _screen;
58 CompWindow* _drag_window;57 CompWindow* _drag_window;
5958
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2012-03-31 10:47:22 +0000
+++ tests/CMakeLists.txt 2012-04-04 14:40:28 +0000
@@ -34,7 +34,6 @@
34add_definitions (${CFLAGS})34add_definitions (${CFLAGS})
3535
36set (LIBS ${TEST_UNIT_DEPS_LIBRARIES} "-lunity-core-${UNITY_API_VERSION} -lm")36set (LIBS ${TEST_UNIT_DEPS_LIBRARIES} "-lunity-core-${UNITY_API_VERSION} -lm")
37link_libraries (${LIBS})
3837
39set (LIB_PATHS ${TEST_UNIT_DEPS_LIBRARY_DIRS})38set (LIB_PATHS ${TEST_UNIT_DEPS_LIBRARY_DIRS})
40link_directories (${CMAKE_BINARY_DIR}/UnityCore ${LIB_PATHS})39link_directories (${CMAKE_BINARY_DIR}/UnityCore ${LIB_PATHS})
@@ -72,6 +71,7 @@
72 ${CMAKE_CURRENT_BINARY_DIR}/panel-marshal.c71 ${CMAKE_CURRENT_BINARY_DIR}/panel-marshal.c
73 ${UNITY_SRC}/ubus-server.cpp72 ${UNITY_SRC}/ubus-server.cpp
74 )73 )
74target_link_libraries (test-unit ${LIBS})
75add_dependencies (test-unit unity-core-${UNITY_API_VERSION})75add_dependencies (test-unit unity-core-${UNITY_API_VERSION})
76add_subdirectory (test-input-remover)76add_subdirectory (test-input-remover)
77add_subdirectory (test-minimize-window-handler)77add_subdirectory (test-minimize-window-handler)
@@ -110,6 +110,7 @@
110 test_service_main.c110 test_service_main.c
111 test_service_model.c111 test_service_model.c
112 test_service_model.h)112 test_service_model.h)
113 target_link_libraries(test-gtest-service ${LIBS})
113 add_dependencies (test-gtest-service unity-core-${UNITY_API_VERSION} gtest)114 add_dependencies (test-gtest-service unity-core-${UNITY_API_VERSION} gtest)
114115
115116
@@ -166,7 +167,7 @@
166 ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-layout.cpp167 ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-layout.cpp
167 ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-texture.cpp168 ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-texture.cpp
168 )169 )
169 target_link_libraries(test-gtest-xless gtest ${GMOCK_LIB} ${GMOCK_MAIN_LIB})170 target_link_libraries(test-gtest-xless gtest ${GMOCK_LIB} ${GMOCK_MAIN_LIB} ${LIBS})
170 add_test(UnityGTestXless test-gtest-xless)171 add_test(UnityGTestXless test-gtest-xless)
171 add_dependencies(test-gtest-xless unity-core-${UNITY_API_VERSION} gtest)172 add_dependencies(test-gtest-xless unity-core-${UNITY_API_VERSION} gtest)
172173
@@ -184,7 +185,7 @@
184 test_ratings_filter.cpp185 test_ratings_filter.cpp
185 test_results.cpp186 test_results.cpp
186 )187 )
187 target_link_libraries(test-gtest-dbus gtest)188 target_link_libraries(test-gtest-dbus gtest ${LIBS})
188 add_test(UnityGTestDBus test-gtest-dbus)189 add_test(UnityGTestDBus test-gtest-dbus)
189 add_dependencies(test-gtest-dbus unity-core-${UNITY_API_VERSION} test-gtest-service gtest)190 add_dependencies(test-gtest-dbus unity-core-${UNITY_API_VERSION} test-gtest-service gtest)
190191
@@ -246,7 +247,7 @@
246 ${UNITY_SRC}/UScreen.cpp247 ${UNITY_SRC}/UScreen.cpp
247 ${UNITY_SRC}/WindowManager.cpp248 ${UNITY_SRC}/WindowManager.cpp
248 )249 )
249 target_link_libraries(test-gtest gtest)250 target_link_libraries(test-gtest gtest ${LIBS})
250 add_test(UnityGTest test-gtest)251 add_test(UnityGTest test-gtest)
251 add_dependencies(test-gtest unity-core-${UNITY_API_VERSION} gtest)252 add_dependencies(test-gtest unity-core-${UNITY_API_VERSION} gtest)
252253
@@ -254,6 +255,8 @@
254 GMOCK_LIB AND255 GMOCK_LIB AND
255 GMOCK_MAIN_LIB)256 GMOCK_MAIN_LIB)
256257
258add_subdirectory (test-gesture-engine)
259
257#260#
258# check target261# check target
259#262#
@@ -263,21 +266,25 @@
263set (GTEST_TEST_COMMAND ./test-gtest)266set (GTEST_TEST_COMMAND ./test-gtest)
264set (GTEST_TEST_COMMAND_XLESS ./test-gtest-xless)267set (GTEST_TEST_COMMAND_XLESS ./test-gtest-xless)
265set (GTEST_TEST_COMMAND_DBUS dbus-test-runner --task ./test-gtest-service --task ./test-gtest-dbus)268set (GTEST_TEST_COMMAND_DBUS dbus-test-runner --task ./test-gtest-service --task ./test-gtest-dbus)
269set (GTEST_TEST_COMMAND_GESTURE_ENGINE ./test-gesture-engine/test-gesture-engine)
266270
267set (TEST_COMMAND271set (TEST_COMMAND
268 gtester --verbose -k --g-fatal-warnings -o=${TEST_RESULT_XML} ./test-unit272 gtester --verbose -k --g-fatal-warnings -o=${TEST_RESULT_XML} ./test-unit
269 && ${GTEST_TEST_COMMAND}273 && ${GTEST_TEST_COMMAND}
270 && ${GTEST_TEST_COMMAND_XLESS}274 && ${GTEST_TEST_COMMAND_XLESS}
271 && ${GTEST_TEST_COMMAND_DBUS})275 && ${GTEST_TEST_COMMAND_GESTURE_ENGINE}
276 && ${GTEST_TEST_COMMAND_DBUS}
277 )
272278
273set (TEST_COMMAND_HEADLESS279set (TEST_COMMAND_HEADLESS
274 ${GTEST_TEST_COMMAND_XLESS}280 ${GTEST_TEST_COMMAND_XLESS}
281 && ${GTEST_TEST_COMMAND_GESTURE_ENGINE}
275 #&& ${GTEST_TEST_COMMAND_DBUS}282 #&& ${GTEST_TEST_COMMAND_DBUS}
276 && echo "Warning, DBus test cases are disabled!!")283 && echo "Warning, DBus test cases are disabled!!")
277284
278if (GTEST_SRC_DIR)285if (GTEST_SRC_DIR)
279 add_custom_target (check COMMAND ${TEST_COMMAND} DEPENDS test-unit test-gtest test-gtest-xless test-gtest-dbus)286 add_custom_target (check COMMAND ${TEST_COMMAND} DEPENDS test-unit test-gtest test-gtest-xless test-gtest-dbus test-gesture-engine)
280 add_custom_target (check-headless COMMAND ${TEST_COMMAND_HEADLESS} DEPENDS test-gtest-xless test-gtest-dbus)287 add_custom_target (check-headless COMMAND ${TEST_COMMAND_HEADLESS} DEPENDS test-gtest-xless test-gtest-dbus test-gesture-engine)
281 add_custom_target (check-report COMMAND ${TEST_UNIT_COMMAND} && gtester-report ${TEST_RESULT_XML} > ${TEST_RESULT_HTML})288 add_custom_target (check-report COMMAND ${TEST_UNIT_COMMAND} && gtester-report ${TEST_RESULT_XML} > ${TEST_RESULT_HTML})
282 add_custom_target (gcheck COMMAND ${DBUS_TEST_COMMAND} DEPENDS test-gtest test-gtest-xless)289 add_custom_target (gcheck COMMAND ${DBUS_TEST_COMMAND} DEPENDS test-gtest test-gtest-xless)
283else (GTEST_SRC_DIR)290else (GTEST_SRC_DIR)
284291
=== added directory 'tests/test-gesture-engine'
=== added file 'tests/test-gesture-engine/CMakeLists.txt'
--- tests/test-gesture-engine/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/test-gesture-engine/CMakeLists.txt 2012-04-04 14:40:28 +0000
@@ -0,0 +1,40 @@
1if (GTEST_SRC_DIR)
2 set(UNITY_SRC ${CMAKE_SOURCE_DIR}/plugins/unityshell/src)
3
4 add_custom_command(OUTPUT GestureEngine.cpp GestureEngine.h UBusMessages.h
5 COMMAND cp ${UNITY_SRC}/GestureEngine.cpp ${UNITY_SRC}/GestureEngine.h ${UNITY_SRC}/UBusMessages.h ${CMAKE_CURRENT_BINARY_DIR}
6 COMMAND sed -f ${CMAKE_CURRENT_SOURCE_DIR}/sed_script ${UNITY_SRC}/GestureEngine.cpp > ${CMAKE_CURRENT_BINARY_DIR}/GestureEngine.cpp
7 COMMAND sed -f ${CMAKE_CURRENT_SOURCE_DIR}/sed_script ${UNITY_SRC}/GestureEngine.h > ${CMAKE_CURRENT_BINARY_DIR}/GestureEngine.h
8 DEPENDS ${UNITY_SRC}/GestureEngine.cpp ${UNITY_SRC}/GestureEngine.h ${UNITY_SRC}/UBusMessages.h
9 COMMENT "Copying GestureEngine source.")
10
11 # Clean-up includes and definitions made in ../CmakeLists.txt
12 remove_definitions(${CFLAGS})
13 set_directory_properties(PROPERTY INCLUDE_DIRECTORIES "")
14 # And make our own
15 pkg_check_modules (TEST_GESTURE_ENGINE_DEPS REQUIRED QUIET "${UNITY_PLUGIN_DEPS}")
16 set(TEST_GESTURE_ENGINE_CFLAGS
17 "-g"
18 "-I${CMAKE_CURRENT_SOURCE_DIR}"
19 "-I${CMAKE_CURRENT_BINARY_DIR}"
20 ${TEST_GESTURE_ENGINE_DEPS_CFLAGS}
21 )
22 add_definitions(${TEST_GESTURE_ENGINE_CFLAGS})
23
24 pkg_check_modules (COMPIZ REQUIRED QUIET compiz)
25 link_directories (${COMPIZ_LIBDIR})
26
27 add_executable(test-gesture-engine
28 test_gesture_engine.cpp
29 X11_mock.cpp
30 GestureEngine.cpp
31 PluginAdapterMock.cpp
32 GeisAdapterMock.cpp
33 ubus-server-mock.cpp
34 )
35 target_link_libraries(test-gesture-engine gtest ${TEST_GESTURE_ENGINE_DEPS_LIBRARIES} -lcompiz_core)
36 add_test(UnityGTestGestureEngine test-gesture-engine)
37 add_dependencies(test-gesture-engine gtest)
38
39 add_custom_target (check-gesture-engine COMMAND ./test-gesture-engine DEPENDS test-gesture-engine)
40endif (GTEST_SRC_DIR)
041
=== added file 'tests/test-gesture-engine/GeisAdapterMock.cpp'
--- tests/test-gesture-engine/GeisAdapterMock.cpp 1970-01-01 00:00:00 +0000
+++ tests/test-gesture-engine/GeisAdapterMock.cpp 2012-04-04 14:40:28 +0000
@@ -0,0 +1,30 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
18 *
19 */
20
21#include "GeisAdapterMock.h"
22
23GeisAdapterMock *GeisAdapterMock::_default = 0;
24
25GeisAdapterMock* GeisAdapterMock::Default() {
26 if (!_default) {
27 _default = new GeisAdapterMock;
28 }
29 return _default;
30}
031
=== added file 'tests/test-gesture-engine/GeisAdapterMock.h'
--- tests/test-gesture-engine/GeisAdapterMock.h 1970-01-01 00:00:00 +0000
+++ tests/test-gesture-engine/GeisAdapterMock.h 2012-04-04 14:40:28 +0000
@@ -0,0 +1,148 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
18 *
19 */
20
21#ifndef GEISADAPTER_MOCK_H
22#define GEISADAPTER_MOCK_H
23
24#include <sigc++/sigc++.h>
25#include <X11/Xlib.h>
26
27class GeisAdapterMock : public sigc::trackable
28{
29public:
30 static GeisAdapterMock* Default();
31
32 ~GeisAdapterMock() {}
33
34 typedef struct _GeisTapData
35 {
36 int id;
37 int device_id;
38 Window window;
39 int touches;
40 int timestamp;
41 float focus_x;
42 float focus_y;
43 int tap_length_ms;
44 float position_x;
45 float position_y;
46 float bound_x1;
47 float bound_y1;
48 float bound_x2;
49 float bound_y2;
50 } GeisTapData;
51
52 typedef struct _GeisDragData
53 {
54 int id;
55 int device_id;
56 Window window;
57 int touches;
58 int timestamp;
59 float focus_x;
60 float focus_y;
61 float delta_x;
62 float delta_y;
63 float velocity_x;
64 float velocity_y;
65 float position_x;
66 float position_y;
67 float bound_x1;
68 float bound_y1;
69 float bound_x2;
70 float bound_y2;
71 } GeisDragData;
72
73 typedef struct _GeisRotateData
74 {
75 int id;
76 int device_id;
77 Window window;
78 int touches;
79 int timestamp;
80 float focus_x;
81 float focus_y;
82 float angle;
83 float angle_delta;
84 float angle_velocity;
85 float bound_x1;
86 float bound_y1;
87 float bound_x2;
88 float bound_y2;
89 } GeisRotateData;
90
91 typedef struct _GeisPinchData
92 {
93 int id;
94 int device_id;
95 Window window;
96 int touches;
97 int timestamp;
98 float focus_x;
99 float focus_y;
100 float radius;
101 float radius_delta;
102 float radius_velocity;
103 float bound_x1;
104 float bound_y1;
105 float bound_x2;
106 float bound_y2;
107 } GeisPinchData;
108
109 typedef struct _GeisTouchData
110 {
111 int id;
112 int device_id;
113 Window window;
114 int touches;
115 int timestamp;
116 float focus_x;
117 float focus_y;
118 float bound_x1;
119 float bound_y1;
120 float bound_x2;
121 float bound_y2;
122 } GeisTouchData;
123
124 sigc::signal<void, GeisTapData*> tap;
125
126 sigc::signal<void, GeisDragData*> drag_start;
127 sigc::signal<void, GeisDragData*> drag_update;
128 sigc::signal<void, GeisDragData*> drag_finish;
129
130 sigc::signal<void, GeisRotateData*> rotate_start;
131 sigc::signal<void, GeisRotateData*> rotate_update;
132 sigc::signal<void, GeisRotateData*> rotate_finish;
133
134 sigc::signal<void, GeisPinchData*> pinch_start;
135 sigc::signal<void, GeisPinchData*> pinch_update;
136 sigc::signal<void, GeisPinchData*> pinch_finish;
137
138 sigc::signal<void, GeisTouchData*> touch_start;
139 sigc::signal<void, GeisTouchData*> touch_update;
140 sigc::signal<void, GeisTouchData*> touch_finish;
141
142private:
143 GeisAdapterMock() {}
144
145 static GeisAdapterMock* _default;
146
147};
148#endif
0149
=== added file 'tests/test-gesture-engine/PluginAdapterMock.cpp'
--- tests/test-gesture-engine/PluginAdapterMock.cpp 1970-01-01 00:00:00 +0000
+++ tests/test-gesture-engine/PluginAdapterMock.cpp 2012-04-04 14:40:28 +0000
@@ -0,0 +1,33 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
18 *
19 */
20
21#include "PluginAdapterMock.h"
22
23PluginAdapterMock *PluginAdapterMock::_default = 0;
24
25PluginAdapterMock *PluginAdapterMock::Default() {
26 if (!_default) {
27 _default = new PluginAdapterMock;
28 }
29 return _default;
30}
31
32void PluginAdapterMock::ShowGrabHandles(CompWindowMock* window, bool use_timer) {
33}
034
=== added file 'tests/test-gesture-engine/PluginAdapterMock.h'
--- tests/test-gesture-engine/PluginAdapterMock.h 1970-01-01 00:00:00 +0000
+++ tests/test-gesture-engine/PluginAdapterMock.h 2012-04-04 14:40:28 +0000
@@ -0,0 +1,37 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
18 *
19 */
20
21#ifndef PLUGINADAPTER_MOCK_H
22#define PLUGINADAPTER_MOCK_H
23
24#include <compiz_mock/core/core.h>
25
26class PluginAdapterMock {
27public:
28 static PluginAdapterMock *Default();
29
30 void ShowGrabHandles(CompWindowMock* window, bool use_timer);
31
32private:
33 PluginAdapterMock() {}
34 static PluginAdapterMock* _default;
35};
36
37#endif
038
=== added file 'tests/test-gesture-engine/X11_mock.cpp'
--- tests/test-gesture-engine/X11_mock.cpp 1970-01-01 00:00:00 +0000
+++ tests/test-gesture-engine/X11_mock.cpp 2012-04-04 14:40:28 +0000
@@ -0,0 +1,40 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
18 *
19 */
20
21#include <X11/Xlib.h>
22
23Cursor XCreateFontCursorMock(Display * /*display*/, unsigned int /*shape*/) {
24 return 1;
25}
26
27int XFreeCursorMock(Display * /*display*/, Cursor /*cursor*/) {
28 return 1;
29}
30
31int XSyncMock(Display *display, Bool discard) {
32 return 1;
33}
34
35int XWarpPointerMock(Display *display, Window src_w, Window dest_w,
36 int src_x, int src_y,
37 unsigned int src_width, unsigned int src_height,
38 int dest_x, int dest_y) {
39 return 1;
40}
041
=== added file 'tests/test-gesture-engine/X11_mock.h'
--- tests/test-gesture-engine/X11_mock.h 1970-01-01 00:00:00 +0000
+++ tests/test-gesture-engine/X11_mock.h 2012-04-04 14:40:28 +0000
@@ -0,0 +1,37 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
18 *
19 */
20
21#ifndef X11_MOCK_H
22#define X11_MOCK_H
23
24#include <X11/Xlib.h>
25
26Cursor XCreateFontCursorMock(Display *display, unsigned int shape);
27
28int XFreeCursorMock(Display *display, Cursor cursor);
29
30int XSyncMock(Display *display, Bool discard);
31
32int XWarpPointerMock(Display *display, Window src_w, Window dest_w,
33 int src_x, int src_y,
34 unsigned int src_width, unsigned int src_height,
35 int dest_x, int dest_y);
36
37#endif // X11_MOCK_H
038
=== added directory 'tests/test-gesture-engine/compiz_mock'
=== added directory 'tests/test-gesture-engine/compiz_mock/core'
=== added file 'tests/test-gesture-engine/compiz_mock/core/core.h'
--- tests/test-gesture-engine/compiz_mock/core/core.h 1970-01-01 00:00:00 +0000
+++ tests/test-gesture-engine/compiz_mock/core/core.h 2012-04-04 14:40:28 +0000
@@ -0,0 +1,29 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
18 *
19 */
20
21#ifndef COMPIZ_CORE_MOCK_H
22#define COMPIZ_CORE_MOCK_H
23
24#include <X11_mock.h>
25
26#include <compiz_mock/core/window.h>
27#include <compiz_mock/core/screen.h>
28
29#endif
030
=== added file 'tests/test-gesture-engine/compiz_mock/core/screen.h'
--- tests/test-gesture-engine/compiz_mock/core/screen.h 1970-01-01 00:00:00 +0000
+++ tests/test-gesture-engine/compiz_mock/core/screen.h 2012-04-04 14:40:28 +0000
@@ -0,0 +1,68 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
18 *
19 */
20
21#ifndef COMPIZ_SCREEN_MOCK_H
22#define COMPIZ_SCREEN_MOCK_H
23
24#include <X11/Xlib.h>
25#include <vector>
26
27// The real CompScreen
28#include <core/screen.h>
29
30typedef std::vector<CompWindowMock*> CompWindowMockVector;
31
32class CompScreenMock {
33public:
34 typedef int GrabHandle;
35
36 int width() const {return _width;}
37 int height() const {return _height;}
38
39 Display *dpy() {return _dpy;}
40
41 const CompWindowMockVector & clientList(bool stackingOrder = true) {
42 if (stackingOrder)
43 return _client_list_stacking;
44 else
45 return _client_list;
46 }
47
48 Window root() {return _root;}
49
50 GrabHandle pushGrab(Cursor cursor, const char *name) {return 0;}
51 void removeGrab(GrabHandle handle, CompPoint *restorePointer) {}
52
53 Cursor invisibleCursor() {return 1;}
54
55 int _width;
56 int _height;
57 Display *_dpy;
58 CompWindowMockVector _client_list;
59 CompWindowMockVector _client_list_stacking;
60 Window _root;
61};
62
63extern CompScreenMock *screen_mock;
64extern int pointerX_mock;
65extern int pointerY_mock;
66
67#endif
68
069
=== added file 'tests/test-gesture-engine/compiz_mock/core/window.h'
--- tests/test-gesture-engine/compiz_mock/core/window.h 1970-01-01 00:00:00 +0000
+++ tests/test-gesture-engine/compiz_mock/core/window.h 2012-04-04 14:40:28 +0000
@@ -0,0 +1,66 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
18 *
19 */
20
21#ifndef COMPIZ_WINDOW_MOCK_H
22#define COMPIZ_WINDOW_MOCK_H
23
24/* The real CompWindow */
25#include <core/window.h>
26
27class CompWindowMock {
28public:
29 CompWindowMock() : _moved(false) {}
30
31 int x() const {return _geometry.x();}
32 int y() const {return _geometry.y();}
33 int width() const {return _geometry.width() + (_geometry.border()*2);}
34 int height() const {return _geometry.height() + (_geometry.border()*2);}
35
36 void move(int dx, int dy, bool immediate = true) {
37 _moved = true;
38 _movement_x = dx;
39 _movement_y = dy;
40 }
41
42 unsigned int actions () {return _actions;}
43
44 void maximize(int state) {}
45
46 /* OBS: I wonder why it returns a reference */
47 unsigned int &state() {return _state;}
48
49 void grabNotify(int x, int y, unsigned int state, unsigned int mask) {}
50 void ungrabNotify() {}
51
52 void syncPosition() {}
53
54 compiz::window::Geometry &serverGeometry() {return _serverGeometry;}
55
56 unsigned int _actions;
57 unsigned int _state;
58 compiz::window::Geometry _serverGeometry;
59 compiz::window::Geometry _geometry;
60
61 bool _moved;
62 int _movement_x;
63 int _movement_y;
64};
65
66#endif
067
=== added file 'tests/test-gesture-engine/sed_script'
--- tests/test-gesture-engine/sed_script 1970-01-01 00:00:00 +0000
+++ tests/test-gesture-engine/sed_script 2012-04-04 14:40:28 +0000
@@ -0,0 +1,14 @@
1s|<core/core.h>|<compiz_mock/core/core.h>|
2s|\<CompScreen\>|CompScreenMock|g
3s|\<CompWindow\>|CompWindowMock|g
4s|\<CompWindowVector\>|CompWindowMockVector|g
5s|\<screen\>|screen_mock|g
6s|\<pointerX\>|pointerX_mock|g
7s|\<pointerY\>|pointerY_mock|g
8s|\<XSync\>|XSyncMock|g
9s|\<XWarpPointer\>|XWarpPointerMock|g
10s|\<XFreeCursor\>|XFreeCursorMock|g
11s|\<XCreateFontCursor\>|XCreateFontCursorMock|g
12s|\<GeisAdapter\>|GeisAdapterMock|g
13s|\<PluginAdapter\>|PluginAdapterMock|g
14s|\<ubus-server.h\>|ubus-server-mock.h|g
015
=== added file 'tests/test-gesture-engine/test_gesture_engine.cpp'
--- tests/test-gesture-engine/test_gesture_engine.cpp 1970-01-01 00:00:00 +0000
+++ tests/test-gesture-engine/test_gesture_engine.cpp 2012-04-04 14:40:28 +0000
@@ -0,0 +1,165 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
18 *
19 */
20
21#include <gtest/gtest.h>
22#include <compiz_mock/core/core.h>
23#include "GestureEngine.h"
24
25CompScreenMock concrete_screen_mock;
26CompScreenMock *screen_mock = &concrete_screen_mock;
27int pointerX_mock = 0;
28int pointerY_mock = 0;
29
30class GestureEngineTest : public ::testing::Test {
31 protected:
32 virtual void SetUp() {
33 screen_mock->_width = 1280;
34 screen_mock->_height = 1024;
35
36 GenerateWindows();
37 }
38
39 private:
40 void GenerateWindows() {
41 /* remove windows from previous test */
42 for (auto window : screen_mock->_client_list_stacking) {
43 delete window;
44 }
45 screen_mock->_client_list_stacking.clear();
46
47 /* and generate new ones */
48 CompWindowMock *window;
49
50 /* the root window */
51 window = new CompWindowMock;
52 /* x, y, width, height, border */
53 window->_geometry.set(0, 0, screen_mock->width(), screen_mock->height(), 0);
54 window->_serverGeometry = window->_geometry;
55 window->_actions = 0;
56 window->_state = 0;
57 screen_mock->_client_list_stacking.push_back(window);
58
59 /* middle window */
60 window = new CompWindowMock;
61 window->_geometry.set(10, 10, 400, 400, 0);
62 window->_serverGeometry = window->_geometry;
63 window->_actions = CompWindowActionMoveMask;
64 window->_state = 0;
65 screen_mock->_client_list_stacking.push_back(window);
66
67 /* top-level window */
68 window = new CompWindowMock;
69 window->_geometry.set(500, 500, 410, 410, 0);
70 window->_serverGeometry = window->_geometry;
71 window->_actions = CompWindowActionMoveMask;
72 window->_state = 0;
73 screen_mock->_client_list_stacking.push_back(window);
74
75 screen_mock->_client_list = screen_mock->_client_list_stacking;
76 std::reverse(screen_mock->_client_list.begin(),
77 screen_mock->_client_list.end());
78 }
79};
80
81TEST_F(GestureEngineTest, ThreeFingersDragMovesWindow)
82{
83 GestureEngine gestureEngine(screen_mock);
84 CompWindowMock *middle_window = screen_mock->_client_list_stacking[1];
85
86 GeisAdapterMock::GeisTouchData touch_data;
87 touch_data.id = 1;
88 touch_data.touches = 3;
89 touch_data.window = 123;
90 touch_data.focus_x = 100; /* hits the middle window */
91 touch_data.focus_y = 100;
92 gestureEngine.OnTouchStart(&touch_data);
93
94 GeisAdapterMock::GeisDragData drag_data;
95 drag_data.id = 1;
96 drag_data.touches = 3;
97 drag_data.window = 123;
98 drag_data.focus_x = 100; /* hits the middle window */
99 drag_data.focus_y = 100;
100 gestureEngine.OnDragStart(&drag_data);
101
102 ASSERT_FALSE(middle_window->_moved);
103
104 touch_data.focus_x += 10;
105 touch_data.focus_y += 20;
106 gestureEngine.OnTouchUpdate(&touch_data);
107
108 drag_data.delta_x = 10;
109 drag_data.delta_y = 20;
110 drag_data.focus_x += drag_data.delta_x;
111 drag_data.focus_y += drag_data.delta_x;
112 gestureEngine.OnDragUpdate(&drag_data);
113
114 ASSERT_TRUE(middle_window->_moved);
115 ASSERT_EQ(drag_data.delta_x, middle_window->_movement_x);
116 ASSERT_EQ(drag_data.delta_y, middle_window->_movement_y);
117}
118
119TEST_F(GestureEngineTest, ThreeFingersDragDoesntMoveStaticWindow)
120{
121 GestureEngine gestureEngine(screen_mock);
122 CompWindowMock *middle_window = screen_mock->_client_list_stacking[1];
123
124 /* can't be moved */
125 middle_window->_actions = 0;
126
127 GeisAdapterMock::GeisTouchData touch_data;
128 touch_data.id = 1;
129 touch_data.touches = 3;
130 touch_data.window = 123;
131 touch_data.focus_x = 100; /* hits the middle window */
132 touch_data.focus_y = 100;
133 gestureEngine.OnTouchStart(&touch_data);
134
135 GeisAdapterMock::GeisDragData drag_data;
136 drag_data.id = 1;
137 drag_data.touches = 3;
138 drag_data.window = 123;
139 drag_data.focus_x = 100; /* hits the middle window */
140 drag_data.focus_y = 100;
141 gestureEngine.OnDragStart(&drag_data);
142
143 ASSERT_FALSE(middle_window->_moved);
144
145 touch_data.focus_x += 10;
146 touch_data.focus_y += 20;
147 gestureEngine.OnTouchUpdate(&touch_data);
148
149 drag_data.delta_x = 10;
150 drag_data.delta_y = 20;
151 drag_data.focus_x += drag_data.delta_x;
152 drag_data.focus_y += drag_data.delta_x;
153 gestureEngine.OnDragUpdate(&drag_data);
154
155 ASSERT_FALSE(middle_window->_moved);
156}
157
158int main(int argc, char** argv)
159{
160 ::testing::InitGoogleTest(&argc, argv);
161
162 int ret = RUN_ALL_TESTS();
163
164 return ret;
165}
0166
=== added file 'tests/test-gesture-engine/ubus-server-mock.cpp'
--- tests/test-gesture-engine/ubus-server-mock.cpp 1970-01-01 00:00:00 +0000
+++ tests/test-gesture-engine/ubus-server-mock.cpp 2012-04-04 14:40:28 +0000
@@ -0,0 +1,32 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
18 *
19 */
20
21#include <ubus-server-mock.h>
22
23UBusServer default_server;
24
25UBusServer* ubus_server_get_default() {
26 return &default_server;
27}
28
29void ubus_server_send_message(UBusServer* server,
30 const gchar* message,
31 GVariant* data) {
32}
033
=== added file 'tests/test-gesture-engine/ubus-server-mock.h'
--- tests/test-gesture-engine/ubus-server-mock.h 1970-01-01 00:00:00 +0000
+++ tests/test-gesture-engine/ubus-server-mock.h 2012-04-04 14:40:28 +0000
@@ -0,0 +1,35 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
18 *
19 */
20
21#ifndef UBUS_SERVER_MOCK_H
22#define UBUS_SERVER_MOCK_H
23
24#include <glib-object.h>
25#include <glib.h>
26
27class UBusServer {
28};
29
30UBusServer* ubus_server_get_default();
31
32void ubus_server_send_message(UBusServer* server,
33 const gchar* message,
34 GVariant* data);
35#endif // UBUS_SERVER_MOCK_H