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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2015-11-17 11:47:19 +0000
+++ CMakeLists.txt 2015-11-19 11:03:01 +0000
@@ -36,3 +36,4 @@
3636
37add_subdirectory(src)37add_subdirectory(src)
38add_subdirectory(include)38add_subdirectory(include)
39add_subdirectory(tests)
3940
=== modified file 'debian/control'
--- debian/control 2015-11-17 15:32:29 +0000
+++ debian/control 2015-11-19 11:03:01 +0000
@@ -5,8 +5,12 @@
5XSBC-Original-Maintainer: Pete Woods <pete.woods@canonical.com>5XSBC-Original-Maintainer: Pete Woods <pete.woods@canonical.com>
6Build-Depends: cmake,6Build-Depends: cmake,
7 cmake-extras (>= 0.4),7 cmake-extras (>= 0.4),
8 dbus,
8 debhelper (>= 9.0.0),9 debhelper (>= 9.0.0),
10 google-mock (>= 1.6.0+svn437),
11 qtbase5-dev,
9 libglib2.0-dev,12 libglib2.0-dev,
13 libqtdbustest1-dev (>= 0.2),
10 libunity-api-dev,14 libunity-api-dev,
11 lsb-release,15 lsb-release,
12 pkg-config,16 pkg-config,
1317
=== modified file 'debian/rules'
--- debian/rules 2015-11-17 15:32:26 +0000
+++ debian/rules 2015-11-19 11:03:01 +0000
@@ -1,6 +1,7 @@
1#!/usr/bin/make -f1#!/usr/bin/make -f
2# -*- makefile -*-2# -*- makefile -*-
33
4export QT_SELECT := qt5
4export DPKG_GENSYMBOLS_CHECK_LEVEL=45export DPKG_GENSYMBOLS_CHECK_LEVEL=4
56
6%:7%:
78
=== added directory 'tests'
=== added file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/CMakeLists.txt 2015-11-19 11:03:01 +0000
@@ -0,0 +1,49 @@
1
2enable_testing()
3ADD_CUSTOM_TARGET(
4 check
5 ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure
6)
7
8find_package(GMock REQUIRED)
9find_package(Qt5Core REQUIRED)
10find_package(Qt5DBus REQUIRED)
11
12pkg_check_modules(
13 TEST_DEPENDENCIES
14 libqtdbustest-1>=0.2 REQUIRED
15)
16
17include_directories(
18 ${Qt5Core_INCLUDE_DIRS}
19 ${Qt5DBus_INCLUDE_DIRS}
20 ${TEST_DEPENDENCIES_INCLUDE_DIRS}
21 "${CMAKE_SOURCE_DIR}/include"
22)
23
24add_subdirectory(functional)
25add_subdirectory(utils)
26
27add_definitions(
28 -DMENU_DIR="${CMAKE_CURRENT_BINARY_DIR}/functional/menus"
29)
30
31add_executable(
32 tests
33 functional/FunctionalTests.cpp
34 unit/TestMatchResult.cpp
35)
36
37target_link_libraries(
38 tests
39 test-main
40 ${GMENU_HARNESS}
41 ${TEST_DEPENDENCIES_LDFLAGS}
42 Qt5::DBus
43)
44
45add_test(
46 tests
47 tests
48)
49
050
=== added directory 'tests/functional'
=== added file 'tests/functional/CMakeLists.txt'
--- tests/functional/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/functional/CMakeLists.txt 2015-11-19 11:03:01 +0000
@@ -0,0 +1,2 @@
1
2add_subdirectory(menus)
03
=== added file 'tests/functional/FunctionalTests.cpp'
--- tests/functional/FunctionalTests.cpp 1970-01-01 00:00:00 +0000
+++ tests/functional/FunctionalTests.cpp 2015-11-19 11:03:01 +0000
@@ -0,0 +1,162 @@
1/*
2 * Copyright (C) 2015 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 along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Pete Woods <pete.woods@canonical.com>
17 */
18
19#include <unity/gmenuharness/MenuMatcher.h>
20
21#include <gtest/gtest.h>
22
23#include <libqtdbustest/DBusTestRunner.h>
24#include <libqtdbustest/QProcessDBusService.h>
25
26#include <QDBusConnection>
27#include <QString>
28
29using namespace std;
30using namespace QtDBusTest;
31namespace mh = unity::gmenuharness;
32
33namespace
34{
35
36static const char* DEFAULT_NAME {"default.name"};
37static const char* DEFAULT_MENU_PATH {"/default/menu/path"};
38static const char* DEFAULT_ACTIONS_PATH {"/default/actions/path"};
39
40class FunctionalTests : public testing::Test
41{
42protected:
43 void addMenu(const QString& menu, const QString& dbusName = DEFAULT_NAME,
44 const QString& menuPath = DEFAULT_MENU_PATH,
45 const QString& actionsPath = DEFAULT_ACTIONS_PATH)
46 {
47 dbus.registerService(
48 DBusServicePtr(
49 new QProcessDBusService(dbusName,
50 QDBusConnection::SessionBus,
51 MENU_DIR "/" + menu,
52 { dbusName, menuPath, actionsPath })));
53 }
54
55 void start()
56 {
57 dbus.startServices();
58 }
59
60 mh::MenuMatcher::Parameters parameters(const string& dbusName = DEFAULT_NAME,
61 const string& menuPath = DEFAULT_MENU_PATH,
62 const string& actionsPath = DEFAULT_ACTIONS_PATH)
63 {
64 return mh::MenuMatcher::Parameters(dbusName, {{ "app", actionsPath }},
65 menuPath);
66 }
67
68 DBusTestRunner dbus;
69};
70
71TEST_F(FunctionalTests, ImportSimple)
72{
73 addMenu("Simple");
74 ASSERT_NO_THROW(start());
75
76 EXPECT_MATCHRESULT(mh::MenuMatcher(parameters())
77 .item(mh::MenuItemMatcher()
78 .label("Main")
79 .mode(mh::MenuItemMatcher::Mode::all)
80 .submenu()
81 .item(mh::MenuItemMatcher()
82 .submenu()
83 .label("First")
84 .string_attribute("description", "First description")
85 .action("app.first")
86 )
87 .item(mh::MenuItemMatcher()
88 .submenu()
89 .label("Second")
90 .string_attribute("description", "Second description")
91 .action("app.second")
92 )
93 ).match());
94}
95
96TEST_F(FunctionalTests, ImportDeeperMatchAll)
97{
98 addMenu("Deeper");
99 ASSERT_NO_THROW(start());
100
101 EXPECT_MATCHRESULT(mh::MenuMatcher(parameters())
102 .item(mh::MenuItemMatcher()
103 .label("File")
104 .mode(mh::MenuItemMatcher::Mode::all)
105 .submenu()
106 .item(mh::MenuItemMatcher()
107 .submenu()
108 .label("New")
109 .mode(mh::MenuItemMatcher::Mode::all)
110 .item(mh::MenuItemMatcher()
111 .label("Apple")
112 .action("app.new-apple")
113 .pass_through_string_attribute("x-foo-pass-through-action", "string-value-passthrough")
114 )
115 .item(mh::MenuItemMatcher()
116 .label("Banana")
117 .action("app.new-banana")
118 .pass_through_boolean_attribute("x-foo-pass-through-action", true)
119 )
120 .item(mh::MenuItemMatcher()
121 .label("Coconut")
122 .action("app.new-coconut")
123 .pass_through_double_attribute("x-foo-pass-through-action", 3.14)
124 )
125 )
126 .item(mh::MenuItemMatcher()
127 .label("Open")
128 .action("app.open")
129 )
130 .item(mh::MenuItemMatcher()
131 .label("Save")
132 .action("app.save")
133 )
134 .item(mh::MenuItemMatcher()
135 .label("Quit")
136 .action("app.quit")
137 )
138 )
139 .item(mh::MenuItemMatcher()
140 .label("Edit")
141 .mode(mh::MenuItemMatcher::Mode::all)
142 .submenu()
143 .item(mh::MenuItemMatcher()
144 .label("Undo")
145 .action("app.undo")
146 )
147 .item(mh::MenuItemMatcher()
148 .label("Cut")
149 .action("app.cut")
150 )
151 .item(mh::MenuItemMatcher()
152 .label("Copy")
153 .action("app.copy")
154 )
155 .item(mh::MenuItemMatcher()
156 .label("Paste")
157 .action("app.paste")
158 )
159 ).match());
160}
161
162}
0163
=== added directory 'tests/functional/menus'
=== added file 'tests/functional/menus/CMakeLists.txt'
--- tests/functional/menus/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/functional/menus/CMakeLists.txt 2015-11-19 11:03:01 +0000
@@ -0,0 +1,25 @@
1
2add_library(
3 menu-main SHARED
4 MenuMain.cpp
5)
6
7target_link_libraries(
8 menu-main
9 ${GMENU_HARNESS}
10)
11
12function(add_menu NAME)
13 add_executable(
14 ${NAME}
15 ${NAME}.cpp
16 )
17
18 target_link_libraries(
19 ${NAME}
20 menu-main
21 )
22endfunction()
23
24add_menu(Simple)
25add_menu(Deeper)
026
=== added file 'tests/functional/menus/Deeper.cpp'
--- tests/functional/menus/Deeper.cpp 1970-01-01 00:00:00 +0000
+++ tests/functional/menus/Deeper.cpp 2015-11-19 11:03:01 +0000
@@ -0,0 +1,156 @@
1/*
2 * Copyright (C) 2015 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 along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Pete Woods <pete.woods@canonical.com>
17 */
18
19#include <unity/gmenuharness/MatchUtils.h>
20
21#include <glib-object.h>
22#include <gio/gio.h>
23
24#include <memory>
25
26using namespace std;
27using namespace unity::gmenuharness;
28
29pair<shared_ptr<GMenu>, shared_ptr<GSimpleActionGroup>>
30createMenu()
31{
32 // Main menu
33 shared_ptr<GMenu> menu(g_menu_new(), &g_object_deleter);
34
35 // Actions
36 shared_ptr<GSimpleActionGroup> ag(g_simple_action_group_new(), &g_object_deleter);
37
38 // File menu
39 {
40 shared_ptr<GMenu> fileMenu(g_menu_new(), &g_object_deleter);
41 {
42 shared_ptr<GMenu> newMenu(g_menu_new(), &g_object_deleter);
43 {
44 {
45 shared_ptr<GMenuItem> item(g_menu_item_new("Apple", "app.new-apple"), &g_object_deleter);
46 g_menu_item_set_attribute_value(
47 item.get(), "x-foo-pass-through-action",
48 g_variant_new_string("app.pass-through-action-string"));
49 g_menu_append_item(newMenu.get(), item.get());
50 g_action_map_add_action(G_ACTION_MAP(ag.get()),
51 G_ACTION(g_simple_action_new("new-apple", NULL)));
52
53 shared_ptr<GSimpleAction> passThroughAction(
54 g_simple_action_new_stateful(
55 "pass-through-action-string", NULL,
56 g_variant_new_string("string-value-passthrough")),
57 &g_object_deleter);
58 g_action_map_add_action(G_ACTION_MAP(ag.get()),
59 G_ACTION(passThroughAction.get()));
60 }
61 {
62 shared_ptr<GMenuItem> item(g_menu_item_new("Banana", "app.new-banana"), &g_object_deleter);
63 g_menu_item_set_attribute_value(
64 item.get(), "x-foo-pass-through-action",
65 g_variant_new_string("app.pass-through-action-bool"));
66 g_menu_append_item(newMenu.get(), item.get());
67 g_action_map_add_action(G_ACTION_MAP(ag.get()),
68 G_ACTION(g_simple_action_new("new-banana", NULL)));
69
70 shared_ptr<GSimpleAction> passThroughAction(
71 g_simple_action_new_stateful(
72 "pass-through-action-bool", NULL,
73 g_variant_new_boolean(TRUE)),
74 &g_object_deleter);
75 g_action_map_add_action(G_ACTION_MAP(ag.get()),
76 G_ACTION(passThroughAction.get()));
77 }
78 {
79 shared_ptr<GMenuItem> item(g_menu_item_new("Coconut", "app.new-coconut"), &g_object_deleter);
80 g_menu_item_set_attribute_value(
81 item.get(), "x-foo-pass-through-action",
82 g_variant_new_string("app.pass-through-action-double"));
83 g_menu_append_item(newMenu.get(), item.get());
84 g_action_map_add_action(G_ACTION_MAP(ag.get()),
85 G_ACTION(g_simple_action_new("new-coconut", NULL)));
86
87 shared_ptr<GSimpleAction> passThroughAction(
88 g_simple_action_new_stateful(
89 "pass-through-action-double", NULL,
90 g_variant_new_double(3.14)),
91 &g_object_deleter);
92 g_action_map_add_action(G_ACTION_MAP(ag.get()),
93 G_ACTION(passThroughAction.get()));
94 }
95
96 shared_ptr<GMenuItem> item(g_menu_item_new_submenu("New", G_MENU_MODEL(newMenu.get())), &g_object_deleter);
97 g_menu_append_item(fileMenu.get(), item.get());
98 }
99 }
100 {
101 shared_ptr<GMenuItem> item(g_menu_item_new("Open", "app.open"), &g_object_deleter);
102 g_menu_append_item(fileMenu.get(), item.get());
103 g_action_map_add_action(G_ACTION_MAP(ag.get()),
104 G_ACTION(g_simple_action_new("open", NULL)));
105 }
106 {
107 shared_ptr<GMenuItem> item(g_menu_item_new("Save", "app.save"), &g_object_deleter);
108 g_menu_append_item(fileMenu.get(), item.get());
109 g_action_map_add_action(G_ACTION_MAP(ag.get()),
110 G_ACTION(g_simple_action_new("save", NULL)));
111 }
112 {
113 shared_ptr<GMenuItem> item(g_menu_item_new("Quit", "app.quit"), &g_object_deleter);
114 g_menu_append_item(fileMenu.get(), item.get());
115 g_action_map_add_action(G_ACTION_MAP(ag.get()),
116 G_ACTION(g_simple_action_new("quit", NULL)));
117 }
118
119 shared_ptr<GMenuItem> item(g_menu_item_new_submenu("File", G_MENU_MODEL(fileMenu.get())), &g_object_deleter);
120 g_menu_append_item(menu.get(), item.get());
121 }
122
123 // Edit menu
124 {
125 shared_ptr<GMenu> editMenu(g_menu_new(), &g_object_deleter);
126 {
127 shared_ptr<GMenuItem> item(g_menu_item_new("Undo", "app.undo"), &g_object_deleter);
128 g_menu_append_item(editMenu.get(), item.get());
129 g_action_map_add_action(G_ACTION_MAP(ag.get()),
130 G_ACTION(g_simple_action_new("undo", NULL)));
131 }
132 {
133 shared_ptr<GMenuItem> item(g_menu_item_new("Cut", "app.cut"), &g_object_deleter);
134 g_menu_append_item(editMenu.get(), item.get());
135 g_action_map_add_action(G_ACTION_MAP(ag.get()),
136 G_ACTION(g_simple_action_new("cut", NULL)));
137 }
138 {
139 shared_ptr<GMenuItem> item(g_menu_item_new("Copy", "app.copy"), &g_object_deleter);
140 g_menu_append_item(editMenu.get(), item.get());
141 g_action_map_add_action(G_ACTION_MAP(ag.get()),
142 G_ACTION(g_simple_action_new("copy", NULL)));
143 }
144 {
145 shared_ptr<GMenuItem> item(g_menu_item_new("Paste", "app.paste"), &g_object_deleter);
146 g_menu_append_item(editMenu.get(), item.get());
147 g_action_map_add_action(G_ACTION_MAP(ag.get()),
148 G_ACTION(g_simple_action_new("paste", NULL)));
149 }
150
151 shared_ptr<GMenuItem> item(g_menu_item_new_submenu("Edit", G_MENU_MODEL(editMenu.get())), &g_object_deleter);
152 g_menu_append_item(menu.get(), item.get());
153 }
154
155 return make_pair(menu, ag);
156}
0157
=== added file 'tests/functional/menus/MenuMain.cpp'
--- tests/functional/menus/MenuMain.cpp 1970-01-01 00:00:00 +0000
+++ tests/functional/menus/MenuMain.cpp 2015-11-19 11:03:01 +0000
@@ -0,0 +1,93 @@
1/*
2 * Copyright (C) 2015 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 along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Pete Woods <pete.woods@canonical.com>
17 */
18
19#include <unity/gmenuharness/MatchUtils.h>
20#include <unity/util/ResourcePtr.h>
21
22#include <glib-object.h>
23#include <gio/gio.h>
24#include <glib-unix.h>
25
26#include <iostream>
27#include <memory>
28
29using namespace std;
30using namespace unity::util;
31using namespace unity::gmenuharness;
32
33static gboolean
34onSignal(gpointer data)
35{
36 g_main_loop_quit((GMainLoop*) data);
37 return G_SOURCE_REMOVE;
38}
39
40pair<shared_ptr<GMenu>, shared_ptr<GSimpleActionGroup>>
41createMenu();
42
43int
44main(int argc, char** argv)
45{
46 if (argc != 4)
47 {
48 cerr << "Usage: " << argv[0] << " DBUS_NAME MENU_PATH ACTIONS_PATH" << endl;
49 return 1;
50 }
51
52 auto menu = createMenu();
53
54 shared_ptr<GDBusConnection> session(
55 g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL), &g_object_deleter);
56
57 ResourcePtr<guint, function<void(guint)>> actionGroupExport(
58 g_dbus_connection_export_action_group(
59 session.get(), argv[3], G_ACTION_GROUP(menu.second.get()),
60 NULL),
61 [session](guint id)
62 {
63 g_dbus_connection_unexport_action_group(session.get(), id);
64 });
65
66 ResourcePtr<guint, function<void(guint)>> menuExport(
67 g_dbus_connection_export_menu_model(session.get(), argv[2],
68 G_MENU_MODEL(menu.first.get()),
69 NULL),
70 [session](guint id)
71 {
72 g_dbus_connection_unexport_menu_model(session.get(), id);
73 });
74
75 ResourcePtr<guint, function<void(guint)>> ownName(
76 g_bus_own_name(G_BUS_TYPE_SESSION, argv[1], G_BUS_NAME_OWNER_FLAGS_NONE,
77 NULL, NULL, NULL, NULL, NULL),
78 [](guint id)
79 {
80 g_bus_unown_name(id);
81 });
82
83 shared_ptr<GMainLoop> mainloop(g_main_loop_new(NULL, FALSE),
84 &g_main_loop_unref);
85
86 g_unix_signal_add(SIGTERM, onSignal, mainloop.get());
87 g_unix_signal_add(SIGHUP, onSignal, mainloop.get());
88 g_unix_signal_add(SIGINT, onSignal, mainloop.get());
89
90 g_main_loop_run(mainloop.get());
91
92 return 0;
93}
094
=== added file 'tests/functional/menus/Simple.cpp'
--- tests/functional/menus/Simple.cpp 1970-01-01 00:00:00 +0000
+++ tests/functional/menus/Simple.cpp 2015-11-19 11:03:01 +0000
@@ -0,0 +1,65 @@
1/*
2 * Copyright (C) 2015 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 along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Pete Woods <pete.woods@canonical.com>
17 */
18
19#include <unity/gmenuharness/MatchUtils.h>
20
21#include <glib-object.h>
22#include <gio/gio.h>
23
24#include <memory>
25
26using namespace std;
27using namespace unity::gmenuharness;
28
29pair<shared_ptr<GMenu>, shared_ptr<GSimpleActionGroup>>
30createMenu()
31{
32 // Main menu
33 shared_ptr<GMenu> menu(g_menu_new(), &g_object_deleter);
34
35 // Actions
36 shared_ptr<GSimpleActionGroup> ag(g_simple_action_group_new(), &g_object_deleter);
37
38 // Submenu
39 {
40 shared_ptr<GMenu> submenu(g_menu_new(), &g_object_deleter);
41 {
42 shared_ptr<GMenuItem> item(g_menu_item_new("First", "app.first"), &g_object_deleter);
43 g_menu_item_set_attribute_value(item.get(), "description", g_variant_new_string("First description"));
44 g_menu_append_item(submenu.get(), item.get());
45
46 shared_ptr<GSimpleAction> action(g_simple_action_new("first", NULL),
47 &g_object_deleter);
48 g_simple_action_set_enabled(action.get(), FALSE);
49 g_action_map_add_action(G_ACTION_MAP(ag.get()), G_ACTION(action.get()));
50 }
51 {
52 shared_ptr<GMenuItem> item(g_menu_item_new("Second", "app.second"), &g_object_deleter);
53 g_menu_item_set_attribute_value(item.get(), "description", g_variant_new_string("Second description"));
54 g_menu_append_item(submenu.get(), item.get());
55
56 g_action_map_add_action(G_ACTION_MAP(ag.get()),
57 G_ACTION(g_simple_action_new("second", NULL)));
58 }
59
60 shared_ptr<GMenuItem> item(g_menu_item_new_submenu("Main", G_MENU_MODEL(submenu.get())), &g_object_deleter);
61 g_menu_append_item(menu.get(), item.get());
62 }
63
64 return make_pair(menu, ag);
65}
066
=== added directory 'tests/unit'
=== added file 'tests/unit/TestMatchResult.cpp'
--- tests/unit/TestMatchResult.cpp 1970-01-01 00:00:00 +0000
+++ tests/unit/TestMatchResult.cpp 2015-11-19 11:03:01 +0000
@@ -0,0 +1,98 @@
1/*
2 * Copyright (C) 2015 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 along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Pete Woods <pete.woods@canonical.com>
17 */
18
19#include <unity/gmenuharness/MatchResult.h>
20
21#include <gtest/gtest.h>
22
23using namespace std;
24namespace mh = unity::gmenuharness;
25
26namespace
27{
28
29class TestMatchResult : public testing::Test
30{
31};
32
33TEST_F(TestMatchResult, SuccessFailAndMessage)
34{
35 mh::MatchResult matchResult;
36 EXPECT_TRUE(matchResult.success());
37
38 matchResult.failure({1, 2, 3}, "the message");
39 matchResult.failure({1, 3, 4}, "the other message");
40 EXPECT_FALSE(matchResult.success());
41 EXPECT_EQ("Failed expectations:\n 1 2 3 the message\n 1 3 4 the other message\n", matchResult.concat_failures());
42}
43
44TEST_F(TestMatchResult, MergeTwoFailed)
45{
46 mh::MatchResult matchResult;
47 matchResult.failure({1, 2, 3}, "m1a");
48 matchResult.failure({1, 3, 4}, "m1b");
49
50 mh::MatchResult matchResult2;
51 matchResult2.failure({2, 2, 3}, "m2a");
52 matchResult2.failure({2, 3, 4}, "m2b");
53 EXPECT_FALSE(matchResult2.success());
54
55 matchResult.merge(matchResult2);
56 EXPECT_FALSE(matchResult.success());
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());
58}
59
60TEST_F(TestMatchResult, MergeFailedIntoSuccess)
61{
62 mh::MatchResult matchResult;
63 EXPECT_TRUE(matchResult.success());
64
65 mh::MatchResult matchResult2;
66 matchResult2.failure({2, 2, 3}, "m2a");
67 matchResult2.failure({2, 3, 4}, "m2b");
68 EXPECT_FALSE(matchResult2.success());
69
70 matchResult.merge(matchResult2);
71 EXPECT_FALSE(matchResult.success());
72 EXPECT_EQ("Failed expectations:\n 2 2 3 m2a\n 2 3 4 m2b\n", matchResult.concat_failures());
73}
74
75TEST_F(TestMatchResult, CopyAssignment)
76{
77 mh::MatchResult matchResult;
78 matchResult.failure({1, 2, 3}, "m1a");
79 matchResult.failure({1, 3, 4}, "m1b");
80
81 // Copy constructor
82 {
83 mh::MatchResult matchResult2(matchResult);
84 EXPECT_EQ("Failed expectations:\n 1 2 3 m1a\n 1 3 4 m1b\n", matchResult2.concat_failures());
85 }
86 // Assignment operator
87 {
88 mh::MatchResult matchResult2 = matchResult;
89 EXPECT_EQ("Failed expectations:\n 1 2 3 m1a\n 1 3 4 m1b\n", matchResult2.concat_failures());
90 }
91 // Move operator
92 {
93 mh::MatchResult matchResult2 = move(matchResult);
94 EXPECT_EQ("Failed expectations:\n 1 2 3 m1a\n 1 3 4 m1b\n", matchResult2.concat_failures());
95 }
96}
97
98}
099
=== added directory 'tests/utils'
=== added file 'tests/utils/CMakeLists.txt'
--- tests/utils/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/utils/CMakeLists.txt 2015-11-19 11:03:01 +0000
@@ -0,0 +1,12 @@
1
2add_library(
3 test-main STATIC
4 TestMain.cpp
5)
6
7target_link_libraries(
8 test-main
9 Qt5::Core
10 ${GTEST_LIBRARIES}
11)
12
013
=== added file 'tests/utils/TestMain.cpp'
--- tests/utils/TestMain.cpp 1970-01-01 00:00:00 +0000
+++ tests/utils/TestMain.cpp 2015-11-19 11:03:01 +0000
@@ -0,0 +1,29 @@
1/*
2 * Copyright (C) 2015 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 along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Pete Woods <pete.woods@canonical.com>
17 */
18
19#include <QCoreApplication>
20
21#include <gtest/gtest.h>
22
23int main(int argc, char **argv)
24{
25 qputenv("QT_QPA_PLATFORM", "minimal");
26 QCoreApplication application(argc, argv);
27 ::testing::InitGoogleTest(&argc, argv);
28 return RUN_ALL_TESTS();
29}

Subscribers

People subscribed via source and target branches