Merge lp:~pete-woods/gmenuharness/functional-tests into lp:gmenuharness
- functional-tests
- Merge into trunk
Proposed by
Pete Woods
Status: | Merged |
---|---|
Approved by: | Pete Woods |
Approved revision: | 27 |
Merged at revision: | 22 |
Proposed branch: | lp:~pete-woods/gmenuharness/functional-tests |
Merge into: | lp:gmenuharness |
Prerequisite: | lp:~pete-woods/gmenuharness/empty-commit |
Diff against target: |
783 lines (+697/-0) 13 files modified
CMakeLists.txt (+1/-0) debian/control (+4/-0) debian/rules (+1/-0) tests/CMakeLists.txt (+49/-0) tests/functional/CMakeLists.txt (+2/-0) tests/functional/FunctionalTests.cpp (+162/-0) tests/functional/menus/CMakeLists.txt (+25/-0) tests/functional/menus/Deeper.cpp (+156/-0) tests/functional/menus/MenuMain.cpp (+93/-0) tests/functional/menus/Simple.cpp (+65/-0) tests/unit/TestMatchResult.cpp (+98/-0) tests/utils/CMakeLists.txt (+12/-0) tests/utils/TestMain.cpp (+29/-0) |
To merge this branch: | bzr merge lp:~pete-woods/gmenuharness/functional-tests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Charles Kerr (community) | Approve | ||
Review via email: mp+277821@code.launchpad.net |
Commit message
Add a very basic level of functional testing
Description of the change
Add a very basic level of functional testing
To post a comment you must log in.
- 28. By Pete Woods
-
Use debian-approved method of making qt5 the default
- 29. By Pete Woods
-
Actually enable the tests
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2015-11-17 11:47:19 +0000 | |||
3 | +++ CMakeLists.txt 2015-11-19 11:03:01 +0000 | |||
4 | @@ -36,3 +36,4 @@ | |||
5 | 36 | 36 | ||
6 | 37 | add_subdirectory(src) | 37 | add_subdirectory(src) |
7 | 38 | add_subdirectory(include) | 38 | add_subdirectory(include) |
8 | 39 | add_subdirectory(tests) | ||
9 | 39 | 40 | ||
10 | === modified file 'debian/control' | |||
11 | --- debian/control 2015-11-17 15:32:29 +0000 | |||
12 | +++ debian/control 2015-11-19 11:03:01 +0000 | |||
13 | @@ -5,8 +5,12 @@ | |||
14 | 5 | XSBC-Original-Maintainer: Pete Woods <pete.woods@canonical.com> | 5 | XSBC-Original-Maintainer: Pete Woods <pete.woods@canonical.com> |
15 | 6 | Build-Depends: cmake, | 6 | Build-Depends: cmake, |
16 | 7 | cmake-extras (>= 0.4), | 7 | cmake-extras (>= 0.4), |
17 | 8 | dbus, | ||
18 | 8 | debhelper (>= 9.0.0), | 9 | debhelper (>= 9.0.0), |
19 | 10 | google-mock (>= 1.6.0+svn437), | ||
20 | 11 | qtbase5-dev, | ||
21 | 9 | libglib2.0-dev, | 12 | libglib2.0-dev, |
22 | 13 | libqtdbustest1-dev (>= 0.2), | ||
23 | 10 | libunity-api-dev, | 14 | libunity-api-dev, |
24 | 11 | lsb-release, | 15 | lsb-release, |
25 | 12 | pkg-config, | 16 | pkg-config, |
26 | 13 | 17 | ||
27 | === modified file 'debian/rules' | |||
28 | --- debian/rules 2015-11-17 15:32:26 +0000 | |||
29 | +++ debian/rules 2015-11-19 11:03:01 +0000 | |||
30 | @@ -1,6 +1,7 @@ | |||
31 | 1 | #!/usr/bin/make -f | 1 | #!/usr/bin/make -f |
32 | 2 | # -*- makefile -*- | 2 | # -*- makefile -*- |
33 | 3 | 3 | ||
34 | 4 | export QT_SELECT := qt5 | ||
35 | 4 | export DPKG_GENSYMBOLS_CHECK_LEVEL=4 | 5 | export DPKG_GENSYMBOLS_CHECK_LEVEL=4 |
36 | 5 | 6 | ||
37 | 6 | %: | 7 | %: |
38 | 7 | 8 | ||
39 | === added directory 'tests' | |||
40 | === added file 'tests/CMakeLists.txt' | |||
41 | --- tests/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
42 | +++ tests/CMakeLists.txt 2015-11-19 11:03:01 +0000 | |||
43 | @@ -0,0 +1,49 @@ | |||
44 | 1 | |||
45 | 2 | enable_testing() | ||
46 | 3 | ADD_CUSTOM_TARGET( | ||
47 | 4 | check | ||
48 | 5 | ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure | ||
49 | 6 | ) | ||
50 | 7 | |||
51 | 8 | find_package(GMock REQUIRED) | ||
52 | 9 | find_package(Qt5Core REQUIRED) | ||
53 | 10 | find_package(Qt5DBus REQUIRED) | ||
54 | 11 | |||
55 | 12 | pkg_check_modules( | ||
56 | 13 | TEST_DEPENDENCIES | ||
57 | 14 | libqtdbustest-1>=0.2 REQUIRED | ||
58 | 15 | ) | ||
59 | 16 | |||
60 | 17 | include_directories( | ||
61 | 18 | ${Qt5Core_INCLUDE_DIRS} | ||
62 | 19 | ${Qt5DBus_INCLUDE_DIRS} | ||
63 | 20 | ${TEST_DEPENDENCIES_INCLUDE_DIRS} | ||
64 | 21 | "${CMAKE_SOURCE_DIR}/include" | ||
65 | 22 | ) | ||
66 | 23 | |||
67 | 24 | add_subdirectory(functional) | ||
68 | 25 | add_subdirectory(utils) | ||
69 | 26 | |||
70 | 27 | add_definitions( | ||
71 | 28 | -DMENU_DIR="${CMAKE_CURRENT_BINARY_DIR}/functional/menus" | ||
72 | 29 | ) | ||
73 | 30 | |||
74 | 31 | add_executable( | ||
75 | 32 | tests | ||
76 | 33 | functional/FunctionalTests.cpp | ||
77 | 34 | unit/TestMatchResult.cpp | ||
78 | 35 | ) | ||
79 | 36 | |||
80 | 37 | target_link_libraries( | ||
81 | 38 | tests | ||
82 | 39 | test-main | ||
83 | 40 | ${GMENU_HARNESS} | ||
84 | 41 | ${TEST_DEPENDENCIES_LDFLAGS} | ||
85 | 42 | Qt5::DBus | ||
86 | 43 | ) | ||
87 | 44 | |||
88 | 45 | add_test( | ||
89 | 46 | tests | ||
90 | 47 | tests | ||
91 | 48 | ) | ||
92 | 49 | |||
93 | 0 | 50 | ||
94 | === added directory 'tests/functional' | |||
95 | === added file 'tests/functional/CMakeLists.txt' | |||
96 | --- tests/functional/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
97 | +++ tests/functional/CMakeLists.txt 2015-11-19 11:03:01 +0000 | |||
98 | @@ -0,0 +1,2 @@ | |||
99 | 1 | |||
100 | 2 | add_subdirectory(menus) | ||
101 | 0 | 3 | ||
102 | === added file 'tests/functional/FunctionalTests.cpp' | |||
103 | --- tests/functional/FunctionalTests.cpp 1970-01-01 00:00:00 +0000 | |||
104 | +++ tests/functional/FunctionalTests.cpp 2015-11-19 11:03:01 +0000 | |||
105 | @@ -0,0 +1,162 @@ | |||
106 | 1 | /* | ||
107 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
108 | 3 | * | ||
109 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
110 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
111 | 6 | * by the Free Software Foundation. | ||
112 | 7 | * | ||
113 | 8 | * This program is distributed in the hope that it will be useful, but | ||
114 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
115 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
116 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
117 | 12 | * | ||
118 | 13 | * You should have received a copy of the GNU General Public License along | ||
119 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
120 | 15 | * | ||
121 | 16 | * Author: Pete Woods <pete.woods@canonical.com> | ||
122 | 17 | */ | ||
123 | 18 | |||
124 | 19 | #include <unity/gmenuharness/MenuMatcher.h> | ||
125 | 20 | |||
126 | 21 | #include <gtest/gtest.h> | ||
127 | 22 | |||
128 | 23 | #include <libqtdbustest/DBusTestRunner.h> | ||
129 | 24 | #include <libqtdbustest/QProcessDBusService.h> | ||
130 | 25 | |||
131 | 26 | #include <QDBusConnection> | ||
132 | 27 | #include <QString> | ||
133 | 28 | |||
134 | 29 | using namespace std; | ||
135 | 30 | using namespace QtDBusTest; | ||
136 | 31 | namespace mh = unity::gmenuharness; | ||
137 | 32 | |||
138 | 33 | namespace | ||
139 | 34 | { | ||
140 | 35 | |||
141 | 36 | static const char* DEFAULT_NAME {"default.name"}; | ||
142 | 37 | static const char* DEFAULT_MENU_PATH {"/default/menu/path"}; | ||
143 | 38 | static const char* DEFAULT_ACTIONS_PATH {"/default/actions/path"}; | ||
144 | 39 | |||
145 | 40 | class FunctionalTests : public testing::Test | ||
146 | 41 | { | ||
147 | 42 | protected: | ||
148 | 43 | void addMenu(const QString& menu, const QString& dbusName = DEFAULT_NAME, | ||
149 | 44 | const QString& menuPath = DEFAULT_MENU_PATH, | ||
150 | 45 | const QString& actionsPath = DEFAULT_ACTIONS_PATH) | ||
151 | 46 | { | ||
152 | 47 | dbus.registerService( | ||
153 | 48 | DBusServicePtr( | ||
154 | 49 | new QProcessDBusService(dbusName, | ||
155 | 50 | QDBusConnection::SessionBus, | ||
156 | 51 | MENU_DIR "/" + menu, | ||
157 | 52 | { dbusName, menuPath, actionsPath }))); | ||
158 | 53 | } | ||
159 | 54 | |||
160 | 55 | void start() | ||
161 | 56 | { | ||
162 | 57 | dbus.startServices(); | ||
163 | 58 | } | ||
164 | 59 | |||
165 | 60 | mh::MenuMatcher::Parameters parameters(const string& dbusName = DEFAULT_NAME, | ||
166 | 61 | const string& menuPath = DEFAULT_MENU_PATH, | ||
167 | 62 | const string& actionsPath = DEFAULT_ACTIONS_PATH) | ||
168 | 63 | { | ||
169 | 64 | return mh::MenuMatcher::Parameters(dbusName, {{ "app", actionsPath }}, | ||
170 | 65 | menuPath); | ||
171 | 66 | } | ||
172 | 67 | |||
173 | 68 | DBusTestRunner dbus; | ||
174 | 69 | }; | ||
175 | 70 | |||
176 | 71 | TEST_F(FunctionalTests, ImportSimple) | ||
177 | 72 | { | ||
178 | 73 | addMenu("Simple"); | ||
179 | 74 | ASSERT_NO_THROW(start()); | ||
180 | 75 | |||
181 | 76 | EXPECT_MATCHRESULT(mh::MenuMatcher(parameters()) | ||
182 | 77 | .item(mh::MenuItemMatcher() | ||
183 | 78 | .label("Main") | ||
184 | 79 | .mode(mh::MenuItemMatcher::Mode::all) | ||
185 | 80 | .submenu() | ||
186 | 81 | .item(mh::MenuItemMatcher() | ||
187 | 82 | .submenu() | ||
188 | 83 | .label("First") | ||
189 | 84 | .string_attribute("description", "First description") | ||
190 | 85 | .action("app.first") | ||
191 | 86 | ) | ||
192 | 87 | .item(mh::MenuItemMatcher() | ||
193 | 88 | .submenu() | ||
194 | 89 | .label("Second") | ||
195 | 90 | .string_attribute("description", "Second description") | ||
196 | 91 | .action("app.second") | ||
197 | 92 | ) | ||
198 | 93 | ).match()); | ||
199 | 94 | } | ||
200 | 95 | |||
201 | 96 | TEST_F(FunctionalTests, ImportDeeperMatchAll) | ||
202 | 97 | { | ||
203 | 98 | addMenu("Deeper"); | ||
204 | 99 | ASSERT_NO_THROW(start()); | ||
205 | 100 | |||
206 | 101 | EXPECT_MATCHRESULT(mh::MenuMatcher(parameters()) | ||
207 | 102 | .item(mh::MenuItemMatcher() | ||
208 | 103 | .label("File") | ||
209 | 104 | .mode(mh::MenuItemMatcher::Mode::all) | ||
210 | 105 | .submenu() | ||
211 | 106 | .item(mh::MenuItemMatcher() | ||
212 | 107 | .submenu() | ||
213 | 108 | .label("New") | ||
214 | 109 | .mode(mh::MenuItemMatcher::Mode::all) | ||
215 | 110 | .item(mh::MenuItemMatcher() | ||
216 | 111 | .label("Apple") | ||
217 | 112 | .action("app.new-apple") | ||
218 | 113 | .pass_through_string_attribute("x-foo-pass-through-action", "string-value-passthrough") | ||
219 | 114 | ) | ||
220 | 115 | .item(mh::MenuItemMatcher() | ||
221 | 116 | .label("Banana") | ||
222 | 117 | .action("app.new-banana") | ||
223 | 118 | .pass_through_boolean_attribute("x-foo-pass-through-action", true) | ||
224 | 119 | ) | ||
225 | 120 | .item(mh::MenuItemMatcher() | ||
226 | 121 | .label("Coconut") | ||
227 | 122 | .action("app.new-coconut") | ||
228 | 123 | .pass_through_double_attribute("x-foo-pass-through-action", 3.14) | ||
229 | 124 | ) | ||
230 | 125 | ) | ||
231 | 126 | .item(mh::MenuItemMatcher() | ||
232 | 127 | .label("Open") | ||
233 | 128 | .action("app.open") | ||
234 | 129 | ) | ||
235 | 130 | .item(mh::MenuItemMatcher() | ||
236 | 131 | .label("Save") | ||
237 | 132 | .action("app.save") | ||
238 | 133 | ) | ||
239 | 134 | .item(mh::MenuItemMatcher() | ||
240 | 135 | .label("Quit") | ||
241 | 136 | .action("app.quit") | ||
242 | 137 | ) | ||
243 | 138 | ) | ||
244 | 139 | .item(mh::MenuItemMatcher() | ||
245 | 140 | .label("Edit") | ||
246 | 141 | .mode(mh::MenuItemMatcher::Mode::all) | ||
247 | 142 | .submenu() | ||
248 | 143 | .item(mh::MenuItemMatcher() | ||
249 | 144 | .label("Undo") | ||
250 | 145 | .action("app.undo") | ||
251 | 146 | ) | ||
252 | 147 | .item(mh::MenuItemMatcher() | ||
253 | 148 | .label("Cut") | ||
254 | 149 | .action("app.cut") | ||
255 | 150 | ) | ||
256 | 151 | .item(mh::MenuItemMatcher() | ||
257 | 152 | .label("Copy") | ||
258 | 153 | .action("app.copy") | ||
259 | 154 | ) | ||
260 | 155 | .item(mh::MenuItemMatcher() | ||
261 | 156 | .label("Paste") | ||
262 | 157 | .action("app.paste") | ||
263 | 158 | ) | ||
264 | 159 | ).match()); | ||
265 | 160 | } | ||
266 | 161 | |||
267 | 162 | } | ||
268 | 0 | 163 | ||
269 | === added directory 'tests/functional/menus' | |||
270 | === added file 'tests/functional/menus/CMakeLists.txt' | |||
271 | --- tests/functional/menus/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
272 | +++ tests/functional/menus/CMakeLists.txt 2015-11-19 11:03:01 +0000 | |||
273 | @@ -0,0 +1,25 @@ | |||
274 | 1 | |||
275 | 2 | add_library( | ||
276 | 3 | menu-main SHARED | ||
277 | 4 | MenuMain.cpp | ||
278 | 5 | ) | ||
279 | 6 | |||
280 | 7 | target_link_libraries( | ||
281 | 8 | menu-main | ||
282 | 9 | ${GMENU_HARNESS} | ||
283 | 10 | ) | ||
284 | 11 | |||
285 | 12 | function(add_menu NAME) | ||
286 | 13 | add_executable( | ||
287 | 14 | ${NAME} | ||
288 | 15 | ${NAME}.cpp | ||
289 | 16 | ) | ||
290 | 17 | |||
291 | 18 | target_link_libraries( | ||
292 | 19 | ${NAME} | ||
293 | 20 | menu-main | ||
294 | 21 | ) | ||
295 | 22 | endfunction() | ||
296 | 23 | |||
297 | 24 | add_menu(Simple) | ||
298 | 25 | add_menu(Deeper) | ||
299 | 0 | 26 | ||
300 | === added file 'tests/functional/menus/Deeper.cpp' | |||
301 | --- tests/functional/menus/Deeper.cpp 1970-01-01 00:00:00 +0000 | |||
302 | +++ tests/functional/menus/Deeper.cpp 2015-11-19 11:03:01 +0000 | |||
303 | @@ -0,0 +1,156 @@ | |||
304 | 1 | /* | ||
305 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
306 | 3 | * | ||
307 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
308 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
309 | 6 | * by the Free Software Foundation. | ||
310 | 7 | * | ||
311 | 8 | * This program is distributed in the hope that it will be useful, but | ||
312 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
313 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
314 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
315 | 12 | * | ||
316 | 13 | * You should have received a copy of the GNU General Public License along | ||
317 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
318 | 15 | * | ||
319 | 16 | * Author: Pete Woods <pete.woods@canonical.com> | ||
320 | 17 | */ | ||
321 | 18 | |||
322 | 19 | #include <unity/gmenuharness/MatchUtils.h> | ||
323 | 20 | |||
324 | 21 | #include <glib-object.h> | ||
325 | 22 | #include <gio/gio.h> | ||
326 | 23 | |||
327 | 24 | #include <memory> | ||
328 | 25 | |||
329 | 26 | using namespace std; | ||
330 | 27 | using namespace unity::gmenuharness; | ||
331 | 28 | |||
332 | 29 | pair<shared_ptr<GMenu>, shared_ptr<GSimpleActionGroup>> | ||
333 | 30 | createMenu() | ||
334 | 31 | { | ||
335 | 32 | // Main menu | ||
336 | 33 | shared_ptr<GMenu> menu(g_menu_new(), &g_object_deleter); | ||
337 | 34 | |||
338 | 35 | // Actions | ||
339 | 36 | shared_ptr<GSimpleActionGroup> ag(g_simple_action_group_new(), &g_object_deleter); | ||
340 | 37 | |||
341 | 38 | // File menu | ||
342 | 39 | { | ||
343 | 40 | shared_ptr<GMenu> fileMenu(g_menu_new(), &g_object_deleter); | ||
344 | 41 | { | ||
345 | 42 | shared_ptr<GMenu> newMenu(g_menu_new(), &g_object_deleter); | ||
346 | 43 | { | ||
347 | 44 | { | ||
348 | 45 | shared_ptr<GMenuItem> item(g_menu_item_new("Apple", "app.new-apple"), &g_object_deleter); | ||
349 | 46 | g_menu_item_set_attribute_value( | ||
350 | 47 | item.get(), "x-foo-pass-through-action", | ||
351 | 48 | g_variant_new_string("app.pass-through-action-string")); | ||
352 | 49 | g_menu_append_item(newMenu.get(), item.get()); | ||
353 | 50 | g_action_map_add_action(G_ACTION_MAP(ag.get()), | ||
354 | 51 | G_ACTION(g_simple_action_new("new-apple", NULL))); | ||
355 | 52 | |||
356 | 53 | shared_ptr<GSimpleAction> passThroughAction( | ||
357 | 54 | g_simple_action_new_stateful( | ||
358 | 55 | "pass-through-action-string", NULL, | ||
359 | 56 | g_variant_new_string("string-value-passthrough")), | ||
360 | 57 | &g_object_deleter); | ||
361 | 58 | g_action_map_add_action(G_ACTION_MAP(ag.get()), | ||
362 | 59 | G_ACTION(passThroughAction.get())); | ||
363 | 60 | } | ||
364 | 61 | { | ||
365 | 62 | shared_ptr<GMenuItem> item(g_menu_item_new("Banana", "app.new-banana"), &g_object_deleter); | ||
366 | 63 | g_menu_item_set_attribute_value( | ||
367 | 64 | item.get(), "x-foo-pass-through-action", | ||
368 | 65 | g_variant_new_string("app.pass-through-action-bool")); | ||
369 | 66 | g_menu_append_item(newMenu.get(), item.get()); | ||
370 | 67 | g_action_map_add_action(G_ACTION_MAP(ag.get()), | ||
371 | 68 | G_ACTION(g_simple_action_new("new-banana", NULL))); | ||
372 | 69 | |||
373 | 70 | shared_ptr<GSimpleAction> passThroughAction( | ||
374 | 71 | g_simple_action_new_stateful( | ||
375 | 72 | "pass-through-action-bool", NULL, | ||
376 | 73 | g_variant_new_boolean(TRUE)), | ||
377 | 74 | &g_object_deleter); | ||
378 | 75 | g_action_map_add_action(G_ACTION_MAP(ag.get()), | ||
379 | 76 | G_ACTION(passThroughAction.get())); | ||
380 | 77 | } | ||
381 | 78 | { | ||
382 | 79 | shared_ptr<GMenuItem> item(g_menu_item_new("Coconut", "app.new-coconut"), &g_object_deleter); | ||
383 | 80 | g_menu_item_set_attribute_value( | ||
384 | 81 | item.get(), "x-foo-pass-through-action", | ||
385 | 82 | g_variant_new_string("app.pass-through-action-double")); | ||
386 | 83 | g_menu_append_item(newMenu.get(), item.get()); | ||
387 | 84 | g_action_map_add_action(G_ACTION_MAP(ag.get()), | ||
388 | 85 | G_ACTION(g_simple_action_new("new-coconut", NULL))); | ||
389 | 86 | |||
390 | 87 | shared_ptr<GSimpleAction> passThroughAction( | ||
391 | 88 | g_simple_action_new_stateful( | ||
392 | 89 | "pass-through-action-double", NULL, | ||
393 | 90 | g_variant_new_double(3.14)), | ||
394 | 91 | &g_object_deleter); | ||
395 | 92 | g_action_map_add_action(G_ACTION_MAP(ag.get()), | ||
396 | 93 | G_ACTION(passThroughAction.get())); | ||
397 | 94 | } | ||
398 | 95 | |||
399 | 96 | shared_ptr<GMenuItem> item(g_menu_item_new_submenu("New", G_MENU_MODEL(newMenu.get())), &g_object_deleter); | ||
400 | 97 | g_menu_append_item(fileMenu.get(), item.get()); | ||
401 | 98 | } | ||
402 | 99 | } | ||
403 | 100 | { | ||
404 | 101 | shared_ptr<GMenuItem> item(g_menu_item_new("Open", "app.open"), &g_object_deleter); | ||
405 | 102 | g_menu_append_item(fileMenu.get(), item.get()); | ||
406 | 103 | g_action_map_add_action(G_ACTION_MAP(ag.get()), | ||
407 | 104 | G_ACTION(g_simple_action_new("open", NULL))); | ||
408 | 105 | } | ||
409 | 106 | { | ||
410 | 107 | shared_ptr<GMenuItem> item(g_menu_item_new("Save", "app.save"), &g_object_deleter); | ||
411 | 108 | g_menu_append_item(fileMenu.get(), item.get()); | ||
412 | 109 | g_action_map_add_action(G_ACTION_MAP(ag.get()), | ||
413 | 110 | G_ACTION(g_simple_action_new("save", NULL))); | ||
414 | 111 | } | ||
415 | 112 | { | ||
416 | 113 | shared_ptr<GMenuItem> item(g_menu_item_new("Quit", "app.quit"), &g_object_deleter); | ||
417 | 114 | g_menu_append_item(fileMenu.get(), item.get()); | ||
418 | 115 | g_action_map_add_action(G_ACTION_MAP(ag.get()), | ||
419 | 116 | G_ACTION(g_simple_action_new("quit", NULL))); | ||
420 | 117 | } | ||
421 | 118 | |||
422 | 119 | shared_ptr<GMenuItem> item(g_menu_item_new_submenu("File", G_MENU_MODEL(fileMenu.get())), &g_object_deleter); | ||
423 | 120 | g_menu_append_item(menu.get(), item.get()); | ||
424 | 121 | } | ||
425 | 122 | |||
426 | 123 | // Edit menu | ||
427 | 124 | { | ||
428 | 125 | shared_ptr<GMenu> editMenu(g_menu_new(), &g_object_deleter); | ||
429 | 126 | { | ||
430 | 127 | shared_ptr<GMenuItem> item(g_menu_item_new("Undo", "app.undo"), &g_object_deleter); | ||
431 | 128 | g_menu_append_item(editMenu.get(), item.get()); | ||
432 | 129 | g_action_map_add_action(G_ACTION_MAP(ag.get()), | ||
433 | 130 | G_ACTION(g_simple_action_new("undo", NULL))); | ||
434 | 131 | } | ||
435 | 132 | { | ||
436 | 133 | shared_ptr<GMenuItem> item(g_menu_item_new("Cut", "app.cut"), &g_object_deleter); | ||
437 | 134 | g_menu_append_item(editMenu.get(), item.get()); | ||
438 | 135 | g_action_map_add_action(G_ACTION_MAP(ag.get()), | ||
439 | 136 | G_ACTION(g_simple_action_new("cut", NULL))); | ||
440 | 137 | } | ||
441 | 138 | { | ||
442 | 139 | shared_ptr<GMenuItem> item(g_menu_item_new("Copy", "app.copy"), &g_object_deleter); | ||
443 | 140 | g_menu_append_item(editMenu.get(), item.get()); | ||
444 | 141 | g_action_map_add_action(G_ACTION_MAP(ag.get()), | ||
445 | 142 | G_ACTION(g_simple_action_new("copy", NULL))); | ||
446 | 143 | } | ||
447 | 144 | { | ||
448 | 145 | shared_ptr<GMenuItem> item(g_menu_item_new("Paste", "app.paste"), &g_object_deleter); | ||
449 | 146 | g_menu_append_item(editMenu.get(), item.get()); | ||
450 | 147 | g_action_map_add_action(G_ACTION_MAP(ag.get()), | ||
451 | 148 | G_ACTION(g_simple_action_new("paste", NULL))); | ||
452 | 149 | } | ||
453 | 150 | |||
454 | 151 | shared_ptr<GMenuItem> item(g_menu_item_new_submenu("Edit", G_MENU_MODEL(editMenu.get())), &g_object_deleter); | ||
455 | 152 | g_menu_append_item(menu.get(), item.get()); | ||
456 | 153 | } | ||
457 | 154 | |||
458 | 155 | return make_pair(menu, ag); | ||
459 | 156 | } | ||
460 | 0 | 157 | ||
461 | === added file 'tests/functional/menus/MenuMain.cpp' | |||
462 | --- tests/functional/menus/MenuMain.cpp 1970-01-01 00:00:00 +0000 | |||
463 | +++ tests/functional/menus/MenuMain.cpp 2015-11-19 11:03:01 +0000 | |||
464 | @@ -0,0 +1,93 @@ | |||
465 | 1 | /* | ||
466 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
467 | 3 | * | ||
468 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
469 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
470 | 6 | * by the Free Software Foundation. | ||
471 | 7 | * | ||
472 | 8 | * This program is distributed in the hope that it will be useful, but | ||
473 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
474 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
475 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
476 | 12 | * | ||
477 | 13 | * You should have received a copy of the GNU General Public License along | ||
478 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
479 | 15 | * | ||
480 | 16 | * Author: Pete Woods <pete.woods@canonical.com> | ||
481 | 17 | */ | ||
482 | 18 | |||
483 | 19 | #include <unity/gmenuharness/MatchUtils.h> | ||
484 | 20 | #include <unity/util/ResourcePtr.h> | ||
485 | 21 | |||
486 | 22 | #include <glib-object.h> | ||
487 | 23 | #include <gio/gio.h> | ||
488 | 24 | #include <glib-unix.h> | ||
489 | 25 | |||
490 | 26 | #include <iostream> | ||
491 | 27 | #include <memory> | ||
492 | 28 | |||
493 | 29 | using namespace std; | ||
494 | 30 | using namespace unity::util; | ||
495 | 31 | using namespace unity::gmenuharness; | ||
496 | 32 | |||
497 | 33 | static gboolean | ||
498 | 34 | onSignal(gpointer data) | ||
499 | 35 | { | ||
500 | 36 | g_main_loop_quit((GMainLoop*) data); | ||
501 | 37 | return G_SOURCE_REMOVE; | ||
502 | 38 | } | ||
503 | 39 | |||
504 | 40 | pair<shared_ptr<GMenu>, shared_ptr<GSimpleActionGroup>> | ||
505 | 41 | createMenu(); | ||
506 | 42 | |||
507 | 43 | int | ||
508 | 44 | main(int argc, char** argv) | ||
509 | 45 | { | ||
510 | 46 | if (argc != 4) | ||
511 | 47 | { | ||
512 | 48 | cerr << "Usage: " << argv[0] << " DBUS_NAME MENU_PATH ACTIONS_PATH" << endl; | ||
513 | 49 | return 1; | ||
514 | 50 | } | ||
515 | 51 | |||
516 | 52 | auto menu = createMenu(); | ||
517 | 53 | |||
518 | 54 | shared_ptr<GDBusConnection> session( | ||
519 | 55 | g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL), &g_object_deleter); | ||
520 | 56 | |||
521 | 57 | ResourcePtr<guint, function<void(guint)>> actionGroupExport( | ||
522 | 58 | g_dbus_connection_export_action_group( | ||
523 | 59 | session.get(), argv[3], G_ACTION_GROUP(menu.second.get()), | ||
524 | 60 | NULL), | ||
525 | 61 | [session](guint id) | ||
526 | 62 | { | ||
527 | 63 | g_dbus_connection_unexport_action_group(session.get(), id); | ||
528 | 64 | }); | ||
529 | 65 | |||
530 | 66 | ResourcePtr<guint, function<void(guint)>> menuExport( | ||
531 | 67 | g_dbus_connection_export_menu_model(session.get(), argv[2], | ||
532 | 68 | G_MENU_MODEL(menu.first.get()), | ||
533 | 69 | NULL), | ||
534 | 70 | [session](guint id) | ||
535 | 71 | { | ||
536 | 72 | g_dbus_connection_unexport_menu_model(session.get(), id); | ||
537 | 73 | }); | ||
538 | 74 | |||
539 | 75 | ResourcePtr<guint, function<void(guint)>> ownName( | ||
540 | 76 | g_bus_own_name(G_BUS_TYPE_SESSION, argv[1], G_BUS_NAME_OWNER_FLAGS_NONE, | ||
541 | 77 | NULL, NULL, NULL, NULL, NULL), | ||
542 | 78 | [](guint id) | ||
543 | 79 | { | ||
544 | 80 | g_bus_unown_name(id); | ||
545 | 81 | }); | ||
546 | 82 | |||
547 | 83 | shared_ptr<GMainLoop> mainloop(g_main_loop_new(NULL, FALSE), | ||
548 | 84 | &g_main_loop_unref); | ||
549 | 85 | |||
550 | 86 | g_unix_signal_add(SIGTERM, onSignal, mainloop.get()); | ||
551 | 87 | g_unix_signal_add(SIGHUP, onSignal, mainloop.get()); | ||
552 | 88 | g_unix_signal_add(SIGINT, onSignal, mainloop.get()); | ||
553 | 89 | |||
554 | 90 | g_main_loop_run(mainloop.get()); | ||
555 | 91 | |||
556 | 92 | return 0; | ||
557 | 93 | } | ||
558 | 0 | 94 | ||
559 | === added file 'tests/functional/menus/Simple.cpp' | |||
560 | --- tests/functional/menus/Simple.cpp 1970-01-01 00:00:00 +0000 | |||
561 | +++ tests/functional/menus/Simple.cpp 2015-11-19 11:03:01 +0000 | |||
562 | @@ -0,0 +1,65 @@ | |||
563 | 1 | /* | ||
564 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
565 | 3 | * | ||
566 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
567 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
568 | 6 | * by the Free Software Foundation. | ||
569 | 7 | * | ||
570 | 8 | * This program is distributed in the hope that it will be useful, but | ||
571 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
572 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
573 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
574 | 12 | * | ||
575 | 13 | * You should have received a copy of the GNU General Public License along | ||
576 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
577 | 15 | * | ||
578 | 16 | * Author: Pete Woods <pete.woods@canonical.com> | ||
579 | 17 | */ | ||
580 | 18 | |||
581 | 19 | #include <unity/gmenuharness/MatchUtils.h> | ||
582 | 20 | |||
583 | 21 | #include <glib-object.h> | ||
584 | 22 | #include <gio/gio.h> | ||
585 | 23 | |||
586 | 24 | #include <memory> | ||
587 | 25 | |||
588 | 26 | using namespace std; | ||
589 | 27 | using namespace unity::gmenuharness; | ||
590 | 28 | |||
591 | 29 | pair<shared_ptr<GMenu>, shared_ptr<GSimpleActionGroup>> | ||
592 | 30 | createMenu() | ||
593 | 31 | { | ||
594 | 32 | // Main menu | ||
595 | 33 | shared_ptr<GMenu> menu(g_menu_new(), &g_object_deleter); | ||
596 | 34 | |||
597 | 35 | // Actions | ||
598 | 36 | shared_ptr<GSimpleActionGroup> ag(g_simple_action_group_new(), &g_object_deleter); | ||
599 | 37 | |||
600 | 38 | // Submenu | ||
601 | 39 | { | ||
602 | 40 | shared_ptr<GMenu> submenu(g_menu_new(), &g_object_deleter); | ||
603 | 41 | { | ||
604 | 42 | shared_ptr<GMenuItem> item(g_menu_item_new("First", "app.first"), &g_object_deleter); | ||
605 | 43 | g_menu_item_set_attribute_value(item.get(), "description", g_variant_new_string("First description")); | ||
606 | 44 | g_menu_append_item(submenu.get(), item.get()); | ||
607 | 45 | |||
608 | 46 | shared_ptr<GSimpleAction> action(g_simple_action_new("first", NULL), | ||
609 | 47 | &g_object_deleter); | ||
610 | 48 | g_simple_action_set_enabled(action.get(), FALSE); | ||
611 | 49 | g_action_map_add_action(G_ACTION_MAP(ag.get()), G_ACTION(action.get())); | ||
612 | 50 | } | ||
613 | 51 | { | ||
614 | 52 | shared_ptr<GMenuItem> item(g_menu_item_new("Second", "app.second"), &g_object_deleter); | ||
615 | 53 | g_menu_item_set_attribute_value(item.get(), "description", g_variant_new_string("Second description")); | ||
616 | 54 | g_menu_append_item(submenu.get(), item.get()); | ||
617 | 55 | |||
618 | 56 | g_action_map_add_action(G_ACTION_MAP(ag.get()), | ||
619 | 57 | G_ACTION(g_simple_action_new("second", NULL))); | ||
620 | 58 | } | ||
621 | 59 | |||
622 | 60 | shared_ptr<GMenuItem> item(g_menu_item_new_submenu("Main", G_MENU_MODEL(submenu.get())), &g_object_deleter); | ||
623 | 61 | g_menu_append_item(menu.get(), item.get()); | ||
624 | 62 | } | ||
625 | 63 | |||
626 | 64 | return make_pair(menu, ag); | ||
627 | 65 | } | ||
628 | 0 | 66 | ||
629 | === added directory 'tests/unit' | |||
630 | === added file 'tests/unit/TestMatchResult.cpp' | |||
631 | --- tests/unit/TestMatchResult.cpp 1970-01-01 00:00:00 +0000 | |||
632 | +++ tests/unit/TestMatchResult.cpp 2015-11-19 11:03:01 +0000 | |||
633 | @@ -0,0 +1,98 @@ | |||
634 | 1 | /* | ||
635 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
636 | 3 | * | ||
637 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
638 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
639 | 6 | * by the Free Software Foundation. | ||
640 | 7 | * | ||
641 | 8 | * This program is distributed in the hope that it will be useful, but | ||
642 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
643 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
644 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
645 | 12 | * | ||
646 | 13 | * You should have received a copy of the GNU General Public License along | ||
647 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
648 | 15 | * | ||
649 | 16 | * Author: Pete Woods <pete.woods@canonical.com> | ||
650 | 17 | */ | ||
651 | 18 | |||
652 | 19 | #include <unity/gmenuharness/MatchResult.h> | ||
653 | 20 | |||
654 | 21 | #include <gtest/gtest.h> | ||
655 | 22 | |||
656 | 23 | using namespace std; | ||
657 | 24 | namespace mh = unity::gmenuharness; | ||
658 | 25 | |||
659 | 26 | namespace | ||
660 | 27 | { | ||
661 | 28 | |||
662 | 29 | class TestMatchResult : public testing::Test | ||
663 | 30 | { | ||
664 | 31 | }; | ||
665 | 32 | |||
666 | 33 | TEST_F(TestMatchResult, SuccessFailAndMessage) | ||
667 | 34 | { | ||
668 | 35 | mh::MatchResult matchResult; | ||
669 | 36 | EXPECT_TRUE(matchResult.success()); | ||
670 | 37 | |||
671 | 38 | matchResult.failure({1, 2, 3}, "the message"); | ||
672 | 39 | matchResult.failure({1, 3, 4}, "the other message"); | ||
673 | 40 | EXPECT_FALSE(matchResult.success()); | ||
674 | 41 | EXPECT_EQ("Failed expectations:\n 1 2 3 the message\n 1 3 4 the other message\n", matchResult.concat_failures()); | ||
675 | 42 | } | ||
676 | 43 | |||
677 | 44 | TEST_F(TestMatchResult, MergeTwoFailed) | ||
678 | 45 | { | ||
679 | 46 | mh::MatchResult matchResult; | ||
680 | 47 | matchResult.failure({1, 2, 3}, "m1a"); | ||
681 | 48 | matchResult.failure({1, 3, 4}, "m1b"); | ||
682 | 49 | |||
683 | 50 | mh::MatchResult matchResult2; | ||
684 | 51 | matchResult2.failure({2, 2, 3}, "m2a"); | ||
685 | 52 | matchResult2.failure({2, 3, 4}, "m2b"); | ||
686 | 53 | EXPECT_FALSE(matchResult2.success()); | ||
687 | 54 | |||
688 | 55 | matchResult.merge(matchResult2); | ||
689 | 56 | EXPECT_FALSE(matchResult.success()); | ||
690 | 57 | EXPECT_EQ("Failed expectations:\n 1 2 3 m1a\n 1 3 4 m1b\n 2 2 3 m2a\n 2 3 4 m2b\n", matchResult.concat_failures()); | ||
691 | 58 | } | ||
692 | 59 | |||
693 | 60 | TEST_F(TestMatchResult, MergeFailedIntoSuccess) | ||
694 | 61 | { | ||
695 | 62 | mh::MatchResult matchResult; | ||
696 | 63 | EXPECT_TRUE(matchResult.success()); | ||
697 | 64 | |||
698 | 65 | mh::MatchResult matchResult2; | ||
699 | 66 | matchResult2.failure({2, 2, 3}, "m2a"); | ||
700 | 67 | matchResult2.failure({2, 3, 4}, "m2b"); | ||
701 | 68 | EXPECT_FALSE(matchResult2.success()); | ||
702 | 69 | |||
703 | 70 | matchResult.merge(matchResult2); | ||
704 | 71 | EXPECT_FALSE(matchResult.success()); | ||
705 | 72 | EXPECT_EQ("Failed expectations:\n 2 2 3 m2a\n 2 3 4 m2b\n", matchResult.concat_failures()); | ||
706 | 73 | } | ||
707 | 74 | |||
708 | 75 | TEST_F(TestMatchResult, CopyAssignment) | ||
709 | 76 | { | ||
710 | 77 | mh::MatchResult matchResult; | ||
711 | 78 | matchResult.failure({1, 2, 3}, "m1a"); | ||
712 | 79 | matchResult.failure({1, 3, 4}, "m1b"); | ||
713 | 80 | |||
714 | 81 | // Copy constructor | ||
715 | 82 | { | ||
716 | 83 | mh::MatchResult matchResult2(matchResult); | ||
717 | 84 | EXPECT_EQ("Failed expectations:\n 1 2 3 m1a\n 1 3 4 m1b\n", matchResult2.concat_failures()); | ||
718 | 85 | } | ||
719 | 86 | // Assignment operator | ||
720 | 87 | { | ||
721 | 88 | mh::MatchResult matchResult2 = matchResult; | ||
722 | 89 | EXPECT_EQ("Failed expectations:\n 1 2 3 m1a\n 1 3 4 m1b\n", matchResult2.concat_failures()); | ||
723 | 90 | } | ||
724 | 91 | // Move operator | ||
725 | 92 | { | ||
726 | 93 | mh::MatchResult matchResult2 = move(matchResult); | ||
727 | 94 | EXPECT_EQ("Failed expectations:\n 1 2 3 m1a\n 1 3 4 m1b\n", matchResult2.concat_failures()); | ||
728 | 95 | } | ||
729 | 96 | } | ||
730 | 97 | |||
731 | 98 | } | ||
732 | 0 | 99 | ||
733 | === added directory 'tests/utils' | |||
734 | === added file 'tests/utils/CMakeLists.txt' | |||
735 | --- tests/utils/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
736 | +++ tests/utils/CMakeLists.txt 2015-11-19 11:03:01 +0000 | |||
737 | @@ -0,0 +1,12 @@ | |||
738 | 1 | |||
739 | 2 | add_library( | ||
740 | 3 | test-main STATIC | ||
741 | 4 | TestMain.cpp | ||
742 | 5 | ) | ||
743 | 6 | |||
744 | 7 | target_link_libraries( | ||
745 | 8 | test-main | ||
746 | 9 | Qt5::Core | ||
747 | 10 | ${GTEST_LIBRARIES} | ||
748 | 11 | ) | ||
749 | 12 | |||
750 | 0 | 13 | ||
751 | === added file 'tests/utils/TestMain.cpp' | |||
752 | --- tests/utils/TestMain.cpp 1970-01-01 00:00:00 +0000 | |||
753 | +++ tests/utils/TestMain.cpp 2015-11-19 11:03:01 +0000 | |||
754 | @@ -0,0 +1,29 @@ | |||
755 | 1 | /* | ||
756 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
757 | 3 | * | ||
758 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
759 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
760 | 6 | * by the Free Software Foundation. | ||
761 | 7 | * | ||
762 | 8 | * This program is distributed in the hope that it will be useful, but | ||
763 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
764 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
765 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
766 | 12 | * | ||
767 | 13 | * You should have received a copy of the GNU General Public License along | ||
768 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
769 | 15 | * | ||
770 | 16 | * Author: Pete Woods <pete.woods@canonical.com> | ||
771 | 17 | */ | ||
772 | 18 | |||
773 | 19 | #include <QCoreApplication> | ||
774 | 20 | |||
775 | 21 | #include <gtest/gtest.h> | ||
776 | 22 | |||
777 | 23 | int main(int argc, char **argv) | ||
778 | 24 | { | ||
779 | 25 | qputenv("QT_QPA_PLATFORM", "minimal"); | ||
780 | 26 | QCoreApplication application(argc, argv); | ||
781 | 27 | ::testing::InitGoogleTest(&argc, argv); | ||
782 | 28 | return RUN_ALL_TESTS(); | ||
783 | 29 | } |
I made optional suggestions to pete in IRC but this also looks fine as-is.