diff -Nru gmenuharness-0.1+16.04.20151118/CMakeLists.txt gmenuharness-0.1+16.04.20151119.3/CMakeLists.txt --- gmenuharness-0.1+16.04.20151118/CMakeLists.txt 2015-11-18 09:21:42.000000000 +0000 +++ gmenuharness-0.1+16.04.20151119.3/CMakeLists.txt 2015-11-19 11:12:19.000000000 +0000 @@ -36,3 +36,4 @@ add_subdirectory(src) add_subdirectory(include) +add_subdirectory(tests) diff -Nru gmenuharness-0.1+16.04.20151118/debian/changelog gmenuharness-0.1+16.04.20151119.3/debian/changelog --- gmenuharness-0.1+16.04.20151118/debian/changelog 2015-11-19 12:45:40.000000000 +0000 +++ gmenuharness-0.1+16.04.20151119.3/debian/changelog 2015-11-19 12:45:40.000000000 +0000 @@ -1,3 +1,9 @@ +gmenuharness (0.1+16.04.20151119.3-0ubuntu1) xenial; urgency=medium + + * Add a very basic level of functional testing + + -- Pete Woods Thu, 19 Nov 2015 11:12:21 +0000 + gmenuharness (0.1+16.04.20151118-0ubuntu1) xenial; urgency=medium [ Xavi Garcia ] diff -Nru gmenuharness-0.1+16.04.20151118/debian/control gmenuharness-0.1+16.04.20151119.3/debian/control --- gmenuharness-0.1+16.04.20151118/debian/control 2015-11-19 12:45:40.000000000 +0000 +++ gmenuharness-0.1+16.04.20151119.3/debian/control 2015-11-19 12:45:40.000000000 +0000 @@ -5,8 +5,12 @@ XSBC-Original-Maintainer: Pete Woods Build-Depends: cmake, cmake-extras (>= 0.4), + dbus, debhelper (>= 9.0.0), + google-mock (>= 1.6.0+svn437), + qtbase5-dev, libglib2.0-dev, + libqtdbustest1-dev (>= 0.2), libunity-api-dev, lsb-release, pkg-config, diff -Nru gmenuharness-0.1+16.04.20151118/debian/rules gmenuharness-0.1+16.04.20151119.3/debian/rules --- gmenuharness-0.1+16.04.20151118/debian/rules 2015-11-19 12:45:40.000000000 +0000 +++ gmenuharness-0.1+16.04.20151119.3/debian/rules 2015-11-19 12:45:40.000000000 +0000 @@ -1,6 +1,7 @@ #!/usr/bin/make -f # -*- makefile -*- +export QT_SELECT := qt5 export DPKG_GENSYMBOLS_CHECK_LEVEL=4 %: diff -Nru gmenuharness-0.1+16.04.20151118/tests/CMakeLists.txt gmenuharness-0.1+16.04.20151119.3/tests/CMakeLists.txt --- gmenuharness-0.1+16.04.20151118/tests/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gmenuharness-0.1+16.04.20151119.3/tests/CMakeLists.txt 2015-11-19 11:12:19.000000000 +0000 @@ -0,0 +1,49 @@ + +enable_testing() +ADD_CUSTOM_TARGET( + check + ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure +) + +find_package(GMock REQUIRED) +find_package(Qt5Core REQUIRED) +find_package(Qt5DBus REQUIRED) + +pkg_check_modules( + TEST_DEPENDENCIES + libqtdbustest-1>=0.2 REQUIRED +) + +include_directories( + ${Qt5Core_INCLUDE_DIRS} + ${Qt5DBus_INCLUDE_DIRS} + ${TEST_DEPENDENCIES_INCLUDE_DIRS} + "${CMAKE_SOURCE_DIR}/include" +) + +add_subdirectory(functional) +add_subdirectory(utils) + +add_definitions( + -DMENU_DIR="${CMAKE_CURRENT_BINARY_DIR}/functional/menus" +) + +add_executable( + tests + functional/FunctionalTests.cpp + unit/TestMatchResult.cpp +) + +target_link_libraries( + tests + test-main + ${GMENU_HARNESS} + ${TEST_DEPENDENCIES_LDFLAGS} + Qt5::DBus +) + +add_test( + tests + tests +) + diff -Nru gmenuharness-0.1+16.04.20151118/tests/functional/CMakeLists.txt gmenuharness-0.1+16.04.20151119.3/tests/functional/CMakeLists.txt --- gmenuharness-0.1+16.04.20151118/tests/functional/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gmenuharness-0.1+16.04.20151119.3/tests/functional/CMakeLists.txt 2015-11-19 11:12:19.000000000 +0000 @@ -0,0 +1,2 @@ + +add_subdirectory(menus) diff -Nru gmenuharness-0.1+16.04.20151118/tests/functional/FunctionalTests.cpp gmenuharness-0.1+16.04.20151119.3/tests/functional/FunctionalTests.cpp --- gmenuharness-0.1+16.04.20151118/tests/functional/FunctionalTests.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gmenuharness-0.1+16.04.20151119.3/tests/functional/FunctionalTests.cpp 2015-11-19 11:12:19.000000000 +0000 @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2015 Canonical, Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Author: Pete Woods + */ + +#include + +#include + +#include +#include + +#include +#include + +using namespace std; +using namespace QtDBusTest; +namespace mh = unity::gmenuharness; + +namespace +{ + +static const char* DEFAULT_NAME {"default.name"}; +static const char* DEFAULT_MENU_PATH {"/default/menu/path"}; +static const char* DEFAULT_ACTIONS_PATH {"/default/actions/path"}; + +class FunctionalTests : public testing::Test +{ +protected: + void addMenu(const QString& menu, const QString& dbusName = DEFAULT_NAME, + const QString& menuPath = DEFAULT_MENU_PATH, + const QString& actionsPath = DEFAULT_ACTIONS_PATH) + { + dbus.registerService( + DBusServicePtr( + new QProcessDBusService(dbusName, + QDBusConnection::SessionBus, + MENU_DIR "/" + menu, + { dbusName, menuPath, actionsPath }))); + } + + void start() + { + dbus.startServices(); + } + + mh::MenuMatcher::Parameters parameters(const string& dbusName = DEFAULT_NAME, + const string& menuPath = DEFAULT_MENU_PATH, + const string& actionsPath = DEFAULT_ACTIONS_PATH) + { + return mh::MenuMatcher::Parameters(dbusName, {{ "app", actionsPath }}, + menuPath); + } + + DBusTestRunner dbus; +}; + +TEST_F(FunctionalTests, ImportSimple) +{ + addMenu("Simple"); + ASSERT_NO_THROW(start()); + + EXPECT_MATCHRESULT(mh::MenuMatcher(parameters()) + .item(mh::MenuItemMatcher() + .label("Main") + .mode(mh::MenuItemMatcher::Mode::all) + .submenu() + .item(mh::MenuItemMatcher() + .submenu() + .label("First") + .string_attribute("description", "First description") + .action("app.first") + ) + .item(mh::MenuItemMatcher() + .submenu() + .label("Second") + .string_attribute("description", "Second description") + .action("app.second") + ) + ).match()); +} + +TEST_F(FunctionalTests, ImportDeeperMatchAll) +{ + addMenu("Deeper"); + ASSERT_NO_THROW(start()); + + EXPECT_MATCHRESULT(mh::MenuMatcher(parameters()) + .item(mh::MenuItemMatcher() + .label("File") + .mode(mh::MenuItemMatcher::Mode::all) + .submenu() + .item(mh::MenuItemMatcher() + .submenu() + .label("New") + .mode(mh::MenuItemMatcher::Mode::all) + .item(mh::MenuItemMatcher() + .label("Apple") + .action("app.new-apple") + .pass_through_string_attribute("x-foo-pass-through-action", "string-value-passthrough") + ) + .item(mh::MenuItemMatcher() + .label("Banana") + .action("app.new-banana") + .pass_through_boolean_attribute("x-foo-pass-through-action", true) + ) + .item(mh::MenuItemMatcher() + .label("Coconut") + .action("app.new-coconut") + .pass_through_double_attribute("x-foo-pass-through-action", 3.14) + ) + ) + .item(mh::MenuItemMatcher() + .label("Open") + .action("app.open") + ) + .item(mh::MenuItemMatcher() + .label("Save") + .action("app.save") + ) + .item(mh::MenuItemMatcher() + .label("Quit") + .action("app.quit") + ) + ) + .item(mh::MenuItemMatcher() + .label("Edit") + .mode(mh::MenuItemMatcher::Mode::all) + .submenu() + .item(mh::MenuItemMatcher() + .label("Undo") + .action("app.undo") + ) + .item(mh::MenuItemMatcher() + .label("Cut") + .action("app.cut") + ) + .item(mh::MenuItemMatcher() + .label("Copy") + .action("app.copy") + ) + .item(mh::MenuItemMatcher() + .label("Paste") + .action("app.paste") + ) + ).match()); +} + +} diff -Nru gmenuharness-0.1+16.04.20151118/tests/functional/menus/CMakeLists.txt gmenuharness-0.1+16.04.20151119.3/tests/functional/menus/CMakeLists.txt --- gmenuharness-0.1+16.04.20151118/tests/functional/menus/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gmenuharness-0.1+16.04.20151119.3/tests/functional/menus/CMakeLists.txt 2015-11-19 11:12:19.000000000 +0000 @@ -0,0 +1,25 @@ + +add_library( + menu-main SHARED + MenuMain.cpp +) + +target_link_libraries( + menu-main + ${GMENU_HARNESS} +) + +function(add_menu NAME) + add_executable( + ${NAME} + ${NAME}.cpp + ) + + target_link_libraries( + ${NAME} + menu-main + ) +endfunction() + +add_menu(Simple) +add_menu(Deeper) diff -Nru gmenuharness-0.1+16.04.20151118/tests/functional/menus/Deeper.cpp gmenuharness-0.1+16.04.20151119.3/tests/functional/menus/Deeper.cpp --- gmenuharness-0.1+16.04.20151118/tests/functional/menus/Deeper.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gmenuharness-0.1+16.04.20151119.3/tests/functional/menus/Deeper.cpp 2015-11-19 11:12:19.000000000 +0000 @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2015 Canonical, Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Author: Pete Woods + */ + +#include + +#include +#include + +#include + +using namespace std; +using namespace unity::gmenuharness; + +pair, shared_ptr> +createMenu() +{ + // Main menu + shared_ptr menu(g_menu_new(), &g_object_deleter); + + // Actions + shared_ptr ag(g_simple_action_group_new(), &g_object_deleter); + + // File menu + { + shared_ptr fileMenu(g_menu_new(), &g_object_deleter); + { + shared_ptr newMenu(g_menu_new(), &g_object_deleter); + { + { + shared_ptr item(g_menu_item_new("Apple", "app.new-apple"), &g_object_deleter); + g_menu_item_set_attribute_value( + item.get(), "x-foo-pass-through-action", + g_variant_new_string("app.pass-through-action-string")); + g_menu_append_item(newMenu.get(), item.get()); + g_action_map_add_action(G_ACTION_MAP(ag.get()), + G_ACTION(g_simple_action_new("new-apple", NULL))); + + shared_ptr passThroughAction( + g_simple_action_new_stateful( + "pass-through-action-string", NULL, + g_variant_new_string("string-value-passthrough")), + &g_object_deleter); + g_action_map_add_action(G_ACTION_MAP(ag.get()), + G_ACTION(passThroughAction.get())); + } + { + shared_ptr item(g_menu_item_new("Banana", "app.new-banana"), &g_object_deleter); + g_menu_item_set_attribute_value( + item.get(), "x-foo-pass-through-action", + g_variant_new_string("app.pass-through-action-bool")); + g_menu_append_item(newMenu.get(), item.get()); + g_action_map_add_action(G_ACTION_MAP(ag.get()), + G_ACTION(g_simple_action_new("new-banana", NULL))); + + shared_ptr passThroughAction( + g_simple_action_new_stateful( + "pass-through-action-bool", NULL, + g_variant_new_boolean(TRUE)), + &g_object_deleter); + g_action_map_add_action(G_ACTION_MAP(ag.get()), + G_ACTION(passThroughAction.get())); + } + { + shared_ptr item(g_menu_item_new("Coconut", "app.new-coconut"), &g_object_deleter); + g_menu_item_set_attribute_value( + item.get(), "x-foo-pass-through-action", + g_variant_new_string("app.pass-through-action-double")); + g_menu_append_item(newMenu.get(), item.get()); + g_action_map_add_action(G_ACTION_MAP(ag.get()), + G_ACTION(g_simple_action_new("new-coconut", NULL))); + + shared_ptr passThroughAction( + g_simple_action_new_stateful( + "pass-through-action-double", NULL, + g_variant_new_double(3.14)), + &g_object_deleter); + g_action_map_add_action(G_ACTION_MAP(ag.get()), + G_ACTION(passThroughAction.get())); + } + + shared_ptr item(g_menu_item_new_submenu("New", G_MENU_MODEL(newMenu.get())), &g_object_deleter); + g_menu_append_item(fileMenu.get(), item.get()); + } + } + { + shared_ptr item(g_menu_item_new("Open", "app.open"), &g_object_deleter); + g_menu_append_item(fileMenu.get(), item.get()); + g_action_map_add_action(G_ACTION_MAP(ag.get()), + G_ACTION(g_simple_action_new("open", NULL))); + } + { + shared_ptr item(g_menu_item_new("Save", "app.save"), &g_object_deleter); + g_menu_append_item(fileMenu.get(), item.get()); + g_action_map_add_action(G_ACTION_MAP(ag.get()), + G_ACTION(g_simple_action_new("save", NULL))); + } + { + shared_ptr item(g_menu_item_new("Quit", "app.quit"), &g_object_deleter); + g_menu_append_item(fileMenu.get(), item.get()); + g_action_map_add_action(G_ACTION_MAP(ag.get()), + G_ACTION(g_simple_action_new("quit", NULL))); + } + + shared_ptr item(g_menu_item_new_submenu("File", G_MENU_MODEL(fileMenu.get())), &g_object_deleter); + g_menu_append_item(menu.get(), item.get()); + } + + // Edit menu + { + shared_ptr editMenu(g_menu_new(), &g_object_deleter); + { + shared_ptr item(g_menu_item_new("Undo", "app.undo"), &g_object_deleter); + g_menu_append_item(editMenu.get(), item.get()); + g_action_map_add_action(G_ACTION_MAP(ag.get()), + G_ACTION(g_simple_action_new("undo", NULL))); + } + { + shared_ptr item(g_menu_item_new("Cut", "app.cut"), &g_object_deleter); + g_menu_append_item(editMenu.get(), item.get()); + g_action_map_add_action(G_ACTION_MAP(ag.get()), + G_ACTION(g_simple_action_new("cut", NULL))); + } + { + shared_ptr item(g_menu_item_new("Copy", "app.copy"), &g_object_deleter); + g_menu_append_item(editMenu.get(), item.get()); + g_action_map_add_action(G_ACTION_MAP(ag.get()), + G_ACTION(g_simple_action_new("copy", NULL))); + } + { + shared_ptr item(g_menu_item_new("Paste", "app.paste"), &g_object_deleter); + g_menu_append_item(editMenu.get(), item.get()); + g_action_map_add_action(G_ACTION_MAP(ag.get()), + G_ACTION(g_simple_action_new("paste", NULL))); + } + + shared_ptr item(g_menu_item_new_submenu("Edit", G_MENU_MODEL(editMenu.get())), &g_object_deleter); + g_menu_append_item(menu.get(), item.get()); + } + + return make_pair(menu, ag); +} diff -Nru gmenuharness-0.1+16.04.20151118/tests/functional/menus/MenuMain.cpp gmenuharness-0.1+16.04.20151119.3/tests/functional/menus/MenuMain.cpp --- gmenuharness-0.1+16.04.20151118/tests/functional/menus/MenuMain.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gmenuharness-0.1+16.04.20151119.3/tests/functional/menus/MenuMain.cpp 2015-11-19 11:12:19.000000000 +0000 @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2015 Canonical, Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Author: Pete Woods + */ + +#include +#include + +#include +#include +#include + +#include +#include + +using namespace std; +using namespace unity::util; +using namespace unity::gmenuharness; + +static gboolean +onSignal(gpointer data) +{ + g_main_loop_quit((GMainLoop*) data); + return G_SOURCE_REMOVE; +} + +pair, shared_ptr> +createMenu(); + +int +main(int argc, char** argv) +{ + if (argc != 4) + { + cerr << "Usage: " << argv[0] << " DBUS_NAME MENU_PATH ACTIONS_PATH" << endl; + return 1; + } + + auto menu = createMenu(); + + shared_ptr session( + g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL), &g_object_deleter); + + ResourcePtr> actionGroupExport( + g_dbus_connection_export_action_group( + session.get(), argv[3], G_ACTION_GROUP(menu.second.get()), + NULL), + [session](guint id) + { + g_dbus_connection_unexport_action_group(session.get(), id); + }); + + ResourcePtr> menuExport( + g_dbus_connection_export_menu_model(session.get(), argv[2], + G_MENU_MODEL(menu.first.get()), + NULL), + [session](guint id) + { + g_dbus_connection_unexport_menu_model(session.get(), id); + }); + + ResourcePtr> ownName( + g_bus_own_name(G_BUS_TYPE_SESSION, argv[1], G_BUS_NAME_OWNER_FLAGS_NONE, + NULL, NULL, NULL, NULL, NULL), + [](guint id) + { + g_bus_unown_name(id); + }); + + shared_ptr mainloop(g_main_loop_new(NULL, FALSE), + &g_main_loop_unref); + + g_unix_signal_add(SIGTERM, onSignal, mainloop.get()); + g_unix_signal_add(SIGHUP, onSignal, mainloop.get()); + g_unix_signal_add(SIGINT, onSignal, mainloop.get()); + + g_main_loop_run(mainloop.get()); + + return 0; +} diff -Nru gmenuharness-0.1+16.04.20151118/tests/functional/menus/Simple.cpp gmenuharness-0.1+16.04.20151119.3/tests/functional/menus/Simple.cpp --- gmenuharness-0.1+16.04.20151118/tests/functional/menus/Simple.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gmenuharness-0.1+16.04.20151119.3/tests/functional/menus/Simple.cpp 2015-11-19 11:12:19.000000000 +0000 @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2015 Canonical, Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Author: Pete Woods + */ + +#include + +#include +#include + +#include + +using namespace std; +using namespace unity::gmenuharness; + +pair, shared_ptr> +createMenu() +{ + // Main menu + shared_ptr menu(g_menu_new(), &g_object_deleter); + + // Actions + shared_ptr ag(g_simple_action_group_new(), &g_object_deleter); + + // Submenu + { + shared_ptr submenu(g_menu_new(), &g_object_deleter); + { + shared_ptr item(g_menu_item_new("First", "app.first"), &g_object_deleter); + g_menu_item_set_attribute_value(item.get(), "description", g_variant_new_string("First description")); + g_menu_append_item(submenu.get(), item.get()); + + shared_ptr action(g_simple_action_new("first", NULL), + &g_object_deleter); + g_simple_action_set_enabled(action.get(), FALSE); + g_action_map_add_action(G_ACTION_MAP(ag.get()), G_ACTION(action.get())); + } + { + shared_ptr item(g_menu_item_new("Second", "app.second"), &g_object_deleter); + g_menu_item_set_attribute_value(item.get(), "description", g_variant_new_string("Second description")); + g_menu_append_item(submenu.get(), item.get()); + + g_action_map_add_action(G_ACTION_MAP(ag.get()), + G_ACTION(g_simple_action_new("second", NULL))); + } + + shared_ptr item(g_menu_item_new_submenu("Main", G_MENU_MODEL(submenu.get())), &g_object_deleter); + g_menu_append_item(menu.get(), item.get()); + } + + return make_pair(menu, ag); +} diff -Nru gmenuharness-0.1+16.04.20151118/tests/unit/TestMatchResult.cpp gmenuharness-0.1+16.04.20151119.3/tests/unit/TestMatchResult.cpp --- gmenuharness-0.1+16.04.20151118/tests/unit/TestMatchResult.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gmenuharness-0.1+16.04.20151119.3/tests/unit/TestMatchResult.cpp 2015-11-19 11:12:19.000000000 +0000 @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2015 Canonical, Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Author: Pete Woods + */ + +#include + +#include + +using namespace std; +namespace mh = unity::gmenuharness; + +namespace +{ + +class TestMatchResult : public testing::Test +{ +}; + +TEST_F(TestMatchResult, SuccessFailAndMessage) +{ + mh::MatchResult matchResult; + EXPECT_TRUE(matchResult.success()); + + matchResult.failure({1, 2, 3}, "the message"); + matchResult.failure({1, 3, 4}, "the other message"); + EXPECT_FALSE(matchResult.success()); + EXPECT_EQ("Failed expectations:\n 1 2 3 the message\n 1 3 4 the other message\n", matchResult.concat_failures()); +} + +TEST_F(TestMatchResult, MergeTwoFailed) +{ + mh::MatchResult matchResult; + matchResult.failure({1, 2, 3}, "m1a"); + matchResult.failure({1, 3, 4}, "m1b"); + + mh::MatchResult matchResult2; + matchResult2.failure({2, 2, 3}, "m2a"); + matchResult2.failure({2, 3, 4}, "m2b"); + EXPECT_FALSE(matchResult2.success()); + + matchResult.merge(matchResult2); + EXPECT_FALSE(matchResult.success()); + 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()); +} + +TEST_F(TestMatchResult, MergeFailedIntoSuccess) +{ + mh::MatchResult matchResult; + EXPECT_TRUE(matchResult.success()); + + mh::MatchResult matchResult2; + matchResult2.failure({2, 2, 3}, "m2a"); + matchResult2.failure({2, 3, 4}, "m2b"); + EXPECT_FALSE(matchResult2.success()); + + matchResult.merge(matchResult2); + EXPECT_FALSE(matchResult.success()); + EXPECT_EQ("Failed expectations:\n 2 2 3 m2a\n 2 3 4 m2b\n", matchResult.concat_failures()); +} + +TEST_F(TestMatchResult, CopyAssignment) +{ + mh::MatchResult matchResult; + matchResult.failure({1, 2, 3}, "m1a"); + matchResult.failure({1, 3, 4}, "m1b"); + + // Copy constructor + { + mh::MatchResult matchResult2(matchResult); + EXPECT_EQ("Failed expectations:\n 1 2 3 m1a\n 1 3 4 m1b\n", matchResult2.concat_failures()); + } + // Assignment operator + { + mh::MatchResult matchResult2 = matchResult; + EXPECT_EQ("Failed expectations:\n 1 2 3 m1a\n 1 3 4 m1b\n", matchResult2.concat_failures()); + } + // Move operator + { + mh::MatchResult matchResult2 = move(matchResult); + EXPECT_EQ("Failed expectations:\n 1 2 3 m1a\n 1 3 4 m1b\n", matchResult2.concat_failures()); + } +} + +} diff -Nru gmenuharness-0.1+16.04.20151118/tests/utils/CMakeLists.txt gmenuharness-0.1+16.04.20151119.3/tests/utils/CMakeLists.txt --- gmenuharness-0.1+16.04.20151118/tests/utils/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gmenuharness-0.1+16.04.20151119.3/tests/utils/CMakeLists.txt 2015-11-19 11:12:19.000000000 +0000 @@ -0,0 +1,12 @@ + +add_library( + test-main STATIC + TestMain.cpp +) + +target_link_libraries( + test-main + Qt5::Core + ${GTEST_LIBRARIES} +) + diff -Nru gmenuharness-0.1+16.04.20151118/tests/utils/TestMain.cpp gmenuharness-0.1+16.04.20151119.3/tests/utils/TestMain.cpp --- gmenuharness-0.1+16.04.20151118/tests/utils/TestMain.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gmenuharness-0.1+16.04.20151119.3/tests/utils/TestMain.cpp 2015-11-19 11:12:19.000000000 +0000 @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2015 Canonical, Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Author: Pete Woods + */ + +#include + +#include + +int main(int argc, char **argv) +{ + qputenv("QT_QPA_PLATFORM", "minimal"); + QCoreApplication application(argc, argv); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}