Merge lp:~pete-woods/gmenuharness/functional-tests into lp:gmenuharness

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
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.
Revision history for this message
Charles Kerr (charlesk) wrote :

I made optional suggestions to pete in IRC but this also looks fine as-is.

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

Subscribers

People subscribed via source and target branches