gmenuharness-0.1+16.04.20151119.3/0000755000015300001610000000000012623330006016542 5ustar pbuserpbgroup00000000000000gmenuharness-0.1+16.04.20151119.3/src/0000755000015300001610000000000012623330006017331 5ustar pbuserpbgroup00000000000000gmenuharness-0.1+16.04.20151119.3/src/MatchUtils.cpp0000644000015300001610000000414112623327216022123 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser 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 warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authored by: Pete Woods */ #include #include using namespace std; namespace util = unity::util; namespace unity { namespace gmenuharness { void waitForCore (GObject * obj, const string& signalName, unsigned int timeout) { shared_ptr loop(g_main_loop_new(nullptr, false), &g_main_loop_unref); /* Our two exit criteria */ util::ResourcePtr> signal( g_signal_connect_swapped(obj, signalName.c_str(), G_CALLBACK(g_main_loop_quit), loop.get()), [obj](gulong s) { g_signal_handler_disconnect(obj, s); }); util::ResourcePtr> timer(g_timeout_add(timeout, [](gpointer user_data) -> gboolean { g_main_loop_quit((GMainLoop *)user_data); return G_SOURCE_CONTINUE; }, loop.get()), &g_source_remove); /* Wait for sync */ g_main_loop_run(loop.get()); } void menuWaitForItems(const shared_ptr& menu, unsigned int timeout) { waitForCore(G_OBJECT(menu.get()), "items-changed", timeout); } void g_object_deleter(gpointer object) { g_clear_object(&object); } void gvariant_deleter(GVariant* varptr) { g_clear_pointer(&varptr, g_variant_unref); } } // namespace gmenuharness } // namespace unity gmenuharness-0.1+16.04.20151119.3/src/MenuItemMatcher.cpp0000644000015300001610000007707012623327216023110 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser 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 warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authored by: Pete Woods */ #include #include #include #include #include #include using namespace std; namespace unity { namespace gmenuharness { namespace { enum class LinkType { any, section, submenu }; static string bool_to_string(bool value) { return value? "true" : "false"; } static shared_ptr get_action_group_attribute(const shared_ptr& actionGroup, const gchar* attribute) { shared_ptr value( g_action_group_get_action_state(actionGroup.get(), attribute), &gvariant_deleter); return value; } static shared_ptr get_attribute(const shared_ptr menuItem, const gchar* attribute) { shared_ptr value( g_menu_item_get_attribute_value(menuItem.get(), attribute, nullptr), &gvariant_deleter); return value; } static string get_string_attribute(const shared_ptr menuItem, const gchar* attribute) { string result; char* temp = nullptr; if (g_menu_item_get_attribute(menuItem.get(), attribute, "s", &temp)) { result = temp; g_free(temp); } return result; } static pair split_action(const string& action) { auto index = action.find('.'); if (index == string::npos) { return make_pair(string(), action); } return make_pair(action.substr(0, index), action.substr(index + 1, action.size())); } static string type_to_string(MenuItemMatcher::Type type) { switch(type) { case MenuItemMatcher::Type::plain: return "plain"; case MenuItemMatcher::Type::checkbox: return "checkbox"; case MenuItemMatcher::Type::radio: return "radio"; } return string(); } } struct MenuItemMatcher::Priv { void all(MatchResult& matchResult, const vector& location, const shared_ptr& menu, map>& actions) { int count = g_menu_model_get_n_items(menu.get()); if (m_items.size() != (unsigned int) count) { matchResult.failure( location, "Expected " + to_string(m_items.size()) + " children, but found " + to_string(count)); return; } for (size_t i = 0; i < m_items.size(); ++i) { const auto& matcher = m_items.at(i); matcher.match(matchResult, location, menu, actions, i); } } void startsWith(MatchResult& matchResult, const vector& location, const shared_ptr& menu, map>& actions) { int count = g_menu_model_get_n_items(menu.get()); if (m_items.size() > (unsigned int) count) { matchResult.failure( location, "Expected at least " + to_string(m_items.size()) + " children, but found " + to_string(count)); return; } for (size_t i = 0; i < m_items.size(); ++i) { const auto& matcher = m_items.at(i); matcher.match(matchResult, location, menu, actions, i); } } void endsWith(MatchResult& matchResult, const vector& location, const shared_ptr& menu, map>& actions) { int count = g_menu_model_get_n_items(menu.get()); if (m_items.size() > (unsigned int) count) { matchResult.failure( location, "Expected at least " + to_string(m_items.size()) + " children, but found " + to_string(count)); return; } // match the last N items size_t j; for (size_t i = count - m_items.size(), j = 0; i < count && j < m_items.size(); ++i, ++j) { const auto& matcher = m_items.at(j); matcher.match(matchResult, location, menu, actions, i); } } Type m_type = Type::plain; Mode m_mode = Mode::all; LinkType m_linkType = LinkType::any; shared_ptr m_expectedSize; shared_ptr m_label; shared_ptr m_icon; map> m_themed_icons; shared_ptr m_action; vector m_state_icons; vector>> m_attributes; vector m_not_exist_attributes; vector>> m_pass_through_attributes; shared_ptr m_isToggled; vector m_items; vector>> m_activations; vector>> m_setActionStates; double m_maxDifference = 0.0; }; MenuItemMatcher MenuItemMatcher::checkbox() { MenuItemMatcher matcher; matcher.type(Type::checkbox); return matcher; } MenuItemMatcher MenuItemMatcher::radio() { MenuItemMatcher matcher; matcher.type(Type::radio); return matcher; } MenuItemMatcher::MenuItemMatcher() : p(new Priv) { } MenuItemMatcher::~MenuItemMatcher() { } MenuItemMatcher::MenuItemMatcher(const MenuItemMatcher& other) : p(new Priv) { *this = other; } MenuItemMatcher::MenuItemMatcher(MenuItemMatcher&& other) { *this = move(other); } MenuItemMatcher& MenuItemMatcher::operator=(const MenuItemMatcher& other) { p->m_type = other.p->m_type; p->m_mode = other.p->m_mode; p->m_expectedSize = other.p->m_expectedSize; p->m_label = other.p->m_label; p->m_icon = other.p->m_icon; p->m_themed_icons = other.p->m_themed_icons; p->m_action = other.p->m_action; p->m_state_icons = other.p->m_state_icons; p->m_attributes = other.p->m_attributes; p->m_not_exist_attributes = other.p->m_not_exist_attributes; p->m_pass_through_attributes = other.p->m_pass_through_attributes; p->m_isToggled = other.p->m_isToggled; p->m_linkType = other.p->m_linkType; p->m_items = other.p->m_items; p->m_activations = other.p->m_activations; p->m_setActionStates = other.p->m_setActionStates; p->m_maxDifference = other.p->m_maxDifference; return *this; } MenuItemMatcher& MenuItemMatcher::operator=(MenuItemMatcher&& other) { p = move(other.p); return *this; } MenuItemMatcher& MenuItemMatcher::type(Type type) { p->m_type = type; return *this; } MenuItemMatcher& MenuItemMatcher::label(const string& label) { p->m_label = make_shared(label); return *this; } MenuItemMatcher& MenuItemMatcher::action(const string& action) { p->m_action = make_shared(action); return *this; } MenuItemMatcher& MenuItemMatcher::state_icons(const std::vector& state_icons) { p->m_state_icons = state_icons; return *this; } MenuItemMatcher& MenuItemMatcher::icon(const string& icon) { p->m_icon = make_shared(icon); return *this; } MenuItemMatcher& MenuItemMatcher::themed_icon(const std::string& iconName, const std::vector& icons) { p->m_themed_icons[iconName] = icons; return *this; } MenuItemMatcher& MenuItemMatcher::widget(const string& widget) { return string_attribute("x-canonical-type", widget); } MenuItemMatcher& MenuItemMatcher::pass_through_attribute(const string& actionName, const shared_ptr& value) { p->m_pass_through_attributes.emplace_back(actionName, value); return *this; } MenuItemMatcher& MenuItemMatcher::pass_through_boolean_attribute(const string& actionName, bool value) { return pass_through_attribute( actionName, shared_ptr(g_variant_new_boolean(value), &gvariant_deleter)); } MenuItemMatcher& MenuItemMatcher::pass_through_string_attribute(const string& actionName, const string& value) { return pass_through_attribute( actionName, shared_ptr(g_variant_new_string(value.c_str()), &gvariant_deleter)); } MenuItemMatcher& MenuItemMatcher::pass_through_double_attribute(const std::string& actionName, double value) { return pass_through_attribute( actionName, shared_ptr(g_variant_new_double(value), &gvariant_deleter)); } MenuItemMatcher& MenuItemMatcher::round_doubles(double maxDifference) { p->m_maxDifference = maxDifference; return *this; } MenuItemMatcher& MenuItemMatcher::attribute(const string& name, const shared_ptr& value) { p->m_attributes.emplace_back(name, value); return *this; } MenuItemMatcher& MenuItemMatcher::boolean_attribute(const string& name, bool value) { return attribute( name, shared_ptr(g_variant_new_boolean(value), &gvariant_deleter)); } MenuItemMatcher& MenuItemMatcher::string_attribute(const string& name, const string& value) { return attribute( name, shared_ptr(g_variant_new_string(value.c_str()), &gvariant_deleter)); } MenuItemMatcher& MenuItemMatcher::int32_attribute(const std::string& name, int value) { return attribute( name, shared_ptr(g_variant_new_int32 (value), &gvariant_deleter)); } MenuItemMatcher& MenuItemMatcher::int64_attribute(const std::string& name, int value) { return attribute( name, shared_ptr(g_variant_new_int64 (value), &gvariant_deleter)); } MenuItemMatcher& MenuItemMatcher::double_attribute(const std::string& name, double value) { return attribute( name, shared_ptr(g_variant_new_double (value), &gvariant_deleter)); } MenuItemMatcher& MenuItemMatcher::attribute_not_set(const std::string& name) { p->m_not_exist_attributes.emplace_back (name); return *this; } MenuItemMatcher& MenuItemMatcher::toggled(bool isToggled) { p->m_isToggled = make_shared(isToggled); return *this; } MenuItemMatcher& MenuItemMatcher::submenu() { p->m_linkType = LinkType::submenu; return *this; } MenuItemMatcher& MenuItemMatcher::section() { p->m_linkType = LinkType::section; return *this; } MenuItemMatcher& MenuItemMatcher::is_empty() { return has_exactly(0); } MenuItemMatcher& MenuItemMatcher::has_exactly(unsigned int children) { p->m_expectedSize = make_shared(children); return *this; } MenuItemMatcher& MenuItemMatcher::item(const MenuItemMatcher& item) { p->m_items.emplace_back(item); return *this; } MenuItemMatcher& MenuItemMatcher::item(MenuItemMatcher&& item) { p->m_items.emplace_back(item); return *this; } MenuItemMatcher& MenuItemMatcher::pass_through_activate(std::string const& action, const shared_ptr& parameter) { p->m_activations.emplace_back(action, parameter); return *this; } MenuItemMatcher& MenuItemMatcher::activate(const shared_ptr& parameter) { p->m_activations.emplace_back(string(), parameter); return *this; } MenuItemMatcher& MenuItemMatcher::set_pass_through_action_state(const std::string& action, const std::shared_ptr& state) { p->m_setActionStates.emplace_back(action, state); return *this; } MenuItemMatcher& MenuItemMatcher::set_action_state(const std::shared_ptr& state) { p->m_setActionStates.emplace_back("", state); return *this; } MenuItemMatcher& MenuItemMatcher::mode(Mode mode) { p->m_mode = mode; return *this; } void MenuItemMatcher::match( MatchResult& matchResult, const vector& parentLocation, const shared_ptr& menu, map>& actions, unsigned int index) const { shared_ptr menuItem(g_menu_item_new_from_model(menu.get(), index), &g_object_deleter); vector location(parentLocation); location.emplace_back(index); string action = get_string_attribute(menuItem, G_MENU_ATTRIBUTE_ACTION); bool isCheckbox = false; bool isRadio = false; bool isToggled = false; pair idPair; shared_ptr actionGroup; shared_ptr state; if (!action.empty()) { idPair = split_action(action); actionGroup = actions[idPair.first]; state = shared_ptr(g_action_group_get_action_state(actionGroup.get(), idPair.second.c_str()), &gvariant_deleter); auto attributeTarget = get_attribute(menuItem, G_MENU_ATTRIBUTE_TARGET); if (attributeTarget && state) { isToggled = g_variant_equal(state.get(), attributeTarget.get()); isRadio = true; } else if (state && g_variant_is_of_type(state.get(), G_VARIANT_TYPE_BOOLEAN)) { isToggled = g_variant_get_boolean(state.get()); isCheckbox = true; } } Type actualType = Type::plain; if (isCheckbox) { actualType = Type::checkbox; } else if (isRadio) { actualType = Type::radio; } if (actualType != p->m_type) { matchResult.failure( location, "Expected " + type_to_string(p->m_type) + ", found " + type_to_string(actualType)); } // check themed icons map>::iterator iter; for (iter = p->m_themed_icons.begin(); iter != p->m_themed_icons.end(); ++iter) { auto icon_val = g_menu_item_get_attribute_value(menuItem.get(), iter->first.c_str(), nullptr); if (!icon_val) { matchResult.failure( location, "Expected themed icon " + iter->first + " was not found"); } auto gicon = shared_ptr(g_icon_deserialize(icon_val), &g_object_deleter); if (!gicon.get() || !G_IS_THEMED_ICON(gicon.get())) { matchResult.failure( location, "Expected attribute " + iter->first + " is not a themed icon"); } else { auto iconNames = g_themed_icon_get_names(G_THEMED_ICON(gicon.get())); int nb_icons = 0; while(iconNames[nb_icons]) { ++nb_icons; } if (nb_icons != iter->second.size()) { matchResult.failure( location, "Expected " + to_string(iter->second.size()) + " icons for themed icon [" + iter->first + "], but " + to_string(nb_icons) + " were found."); } else { // now compare all the icons for (int i = 0; i < nb_icons; ++i) { if (iter->second[i] != iconNames[i]) { matchResult.failure( location, "Icon at position " + to_string(i) + " for themed icon [" + iter->first + "], mismatchs. Expected: " + iconNames[i] + " but found " + iter->second[i]); } } } } } string label = get_string_attribute(menuItem, G_MENU_ATTRIBUTE_LABEL); if (p->m_label && (*p->m_label) != label) { matchResult.failure( location, "Expected label '" + *p->m_label + "', but found '" + label + "'"); } string icon = get_string_attribute(menuItem, G_MENU_ATTRIBUTE_ICON); if (p->m_icon && (*p->m_icon) != icon) { matchResult.failure( location, "Expected icon '" + *p->m_icon + "', but found '" + icon + "'"); } if (p->m_action && (*p->m_action) != action) { matchResult.failure( location, "Expected action '" + *p->m_action + "', but found '" + action + "'"); } if (!p->m_state_icons.empty() && !state) { matchResult.failure( location, "Expected state icons but no state was found"); } else if (!p->m_state_icons.empty() && state && !g_variant_is_of_type(state.get(), G_VARIANT_TYPE_VARDICT)) { matchResult.failure( location, "Expected state icons vardict, found " + type_to_string(actualType)); } else if (!p->m_state_icons.empty() && state && g_variant_is_of_type(state.get(), G_VARIANT_TYPE_VARDICT)) { std::vector actual_state_icons; GVariantIter it; gchar* key; GVariant* value; g_variant_iter_init(&it, state.get()); while (g_variant_iter_loop(&it, "{sv}", &key, &value)) { if (std::string(key) == "icon") { auto gicon = g_icon_deserialize(value); if (G_IS_THEMED_ICON(gicon)) { auto iconNames = g_themed_icon_get_names(G_THEMED_ICON(gicon)); // Just take the first icon in the list (there is only ever one) actual_state_icons.push_back(iconNames[0]); } g_object_unref(gicon); } else if (std::string(key) == "icons" && g_variant_is_of_type(value, G_VARIANT_TYPE("av"))) { // If we find "icons" in the map, clear any icons we may have found in "icon", // then break from the loop as we have found all icons now. actual_state_icons.clear(); GVariantIter icon_it; GVariant* icon_value; g_variant_iter_init(&icon_it, value); while (g_variant_iter_loop(&icon_it, "v", &icon_value)) { auto gicon = g_icon_deserialize(icon_value); if (G_IS_THEMED_ICON(gicon)) { auto iconNames = g_themed_icon_get_names(G_THEMED_ICON(gicon)); // Just take the first icon in the list (there is only ever one) actual_state_icons.push_back(iconNames[0]); } g_object_unref(gicon); } // We're breaking out of g_variant_iter_loop here so clean up g_variant_unref(value); g_free(key); break; } } if (p->m_state_icons != actual_state_icons) { std::string expected_icons; for (unsigned int i = 0; i < p->m_state_icons.size(); ++i) { expected_icons += i == 0 ? p->m_state_icons[i] : ", " + p->m_state_icons[i]; } std::string actual_icons; for (unsigned int i = 0; i < actual_state_icons.size(); ++i) { actual_icons += i == 0 ? actual_state_icons[i] : ", " + actual_state_icons[i]; } matchResult.failure( location, "Expected state_icons == {" + expected_icons + "} but found {" + actual_icons + "}"); } } for (const auto& e: p->m_pass_through_attributes) { string actionName = get_string_attribute(menuItem, e.first.c_str()); if (actionName.empty()) { matchResult.failure( location, "Could not find action name '" + e.first + "'"); } else { auto passThroughIdPair = split_action(actionName); auto actionGroup = actions[passThroughIdPair.first]; if (actionGroup) { auto value = get_action_group_attribute( actionGroup, passThroughIdPair.second.c_str()); if (!value) { matchResult.failure( location, "Expected pass-through attribute '" + e.first + "' was not present"); } else if (!g_variant_is_of_type(e.second.get(), g_variant_get_type(value.get()))) { std::string expectedType = g_variant_get_type_string(e.second.get()); std::string actualType = g_variant_get_type_string(value.get()); matchResult.failure( location, "Expected pass-through attribute type '" + expectedType + "' but found '" + actualType + "'"); } else if (g_variant_compare(e.second.get(), value.get())) { bool reportMismatch = true; if (g_strcmp0(g_variant_get_type_string(value.get()),"d") == 0 && p->m_maxDifference != 0.0) { auto actualDouble = g_variant_get_double(value.get()); auto expectedDouble = g_variant_get_double(e.second.get()); auto difference = actualDouble-expectedDouble; if (difference < 0) difference = difference * -1.0; if (difference <= p->m_maxDifference) { reportMismatch = false; } } if (reportMismatch) { gchar* expectedString = g_variant_print(e.second.get(), true); gchar* actualString = g_variant_print(value.get(), true); matchResult.failure( location, "Expected pass-through attribute '" + e.first + "' == " + expectedString + " but found " + actualString); g_free(expectedString); g_free(actualString); } } } else { matchResult.failure(location, "Could not find action group for ID '" + passThroughIdPair.first + "'"); } } } for (const auto& e: p->m_attributes) { auto value = get_attribute(menuItem, e.first.c_str()); if (!value) { matchResult.failure(location, "Expected attribute '" + e.first + "' could not be found"); } else if (!g_variant_is_of_type(e.second.get(), g_variant_get_type(value.get()))) { std::string expectedType = g_variant_get_type_string(e.second.get()); std::string actualType = g_variant_get_type_string(value.get()); matchResult.failure( location, "Expected attribute type '" + expectedType + "' but found '" + actualType + "'"); } else if (g_variant_compare(e.second.get(), value.get())) { gchar* expectedString = g_variant_print(e.second.get(), true); gchar* actualString = g_variant_print(value.get(), true); matchResult.failure( location, "Expected attribute '" + e.first + "' == " + expectedString + ", but found " + actualString); g_free(expectedString); g_free(actualString); } } for (const auto& e: p->m_not_exist_attributes) { auto value = get_attribute(menuItem, e.c_str()); if (value) { matchResult.failure(location, "Not expected attribute '" + e + "' was found"); } } if (p->m_isToggled && (*p->m_isToggled) != isToggled) { matchResult.failure( location, "Expected toggled = " + bool_to_string(*p->m_isToggled) + ", but found " + bool_to_string(isToggled)); } if (!matchResult.success()) { return; } if (!p->m_items.empty() || p->m_expectedSize) { shared_ptr link; switch (p->m_linkType) { case LinkType::any: { link.reset(g_menu_model_get_item_link(menu.get(), (int) index, G_MENU_LINK_SUBMENU), &g_object_deleter); if (!link) { link.reset(g_menu_model_get_item_link(menu.get(), (int) index, G_MENU_LINK_SECTION), &g_object_deleter); } break; } case LinkType::submenu: { link.reset(g_menu_model_get_item_link(menu.get(), (int) index, G_MENU_LINK_SUBMENU), &g_object_deleter); break; } case LinkType::section: { link.reset(g_menu_model_get_item_link(menu.get(), (int) index, G_MENU_LINK_SECTION), &g_object_deleter); break; } } if (!link) { if (p->m_expectedSize) { matchResult.failure( location, "Expected " + to_string(*p->m_expectedSize) + " children, but found none"); } else { matchResult.failure( location, "Expected " + to_string(p->m_items.size()) + " children, but found none"); } return; } else { while (true) { MatchResult childMatchResult(matchResult.createChild()); if (p->m_expectedSize && *p->m_expectedSize != (unsigned int) g_menu_model_get_n_items( link.get())) { childMatchResult.failure( location, "Expected " + to_string(*p->m_expectedSize) + " child items, but found " + to_string( g_menu_model_get_n_items( link.get()))); } else if (!p->m_items.empty()) { switch (p->m_mode) { case Mode::all: p->all(childMatchResult, location, link, actions); break; case Mode::starts_with: p->startsWith(childMatchResult, location, link, actions); break; case Mode::ends_with: p->endsWith(childMatchResult, location, link, actions); break; } } if (childMatchResult.success()) { matchResult.merge(childMatchResult); break; } else { if (matchResult.hasTimedOut()) { matchResult.merge(childMatchResult); break; } menuWaitForItems(link); } } } } for (const auto& a: p->m_setActionStates) { auto stateAction = action; auto stateIdPair = idPair; auto stateActionGroup = actionGroup; if (!a.first.empty()) { stateAction = get_string_attribute(menuItem, a.first.c_str());; stateIdPair = split_action(stateAction); stateActionGroup = actions[stateIdPair.first]; } if (stateAction.empty()) { matchResult.failure( location, "Tried to set action state, but no action was found"); } else if(!stateActionGroup) { matchResult.failure( location, "Tried to set action state for action group '" + stateIdPair.first + "', but action group wasn't found"); } else if (!g_action_group_has_action(stateActionGroup.get(), stateIdPair.second.c_str())) { matchResult.failure( location, "Tried to set action state for action '" + stateAction + "', but action was not found"); } else { g_action_group_change_action_state(stateActionGroup.get(), stateIdPair.second.c_str(), g_variant_ref(a.second.get())); } // FIXME this is a dodgy way to ensure the action state change gets dispatched menuWaitForItems(menu, 100); } for (const auto& a: p->m_activations) { string tmpAction = action; auto tmpIdPair = idPair; auto tmpActionGroup = actionGroup; if (!a.first.empty()) { tmpAction = get_string_attribute(menuItem, a.first.c_str()); tmpIdPair = split_action(tmpAction); tmpActionGroup = actions[tmpIdPair.first]; } if (tmpAction.empty()) { matchResult.failure( location, "Tried to activate action, but no action was found"); } else if(!tmpActionGroup) { matchResult.failure( location, "Tried to activate action group '" + tmpIdPair.first + "', but action group wasn't found"); } else if (!g_action_group_has_action(tmpActionGroup.get(), tmpIdPair.second.c_str())) { matchResult.failure( location, "Tried to activate action '" + tmpAction + "', but action was not found"); } else { if (a.second) { g_action_group_activate_action(tmpActionGroup.get(), tmpIdPair.second.c_str(), g_variant_ref(a.second.get())); } else { g_action_group_activate_action(tmpActionGroup.get(), tmpIdPair.second.c_str(), nullptr); } // FIXME this is a dodgy way to ensure the activation gets dispatched menuWaitForItems(menu, 100); } } } } // namepsace gmenuharness } // namespace unity gmenuharness-0.1+16.04.20151119.3/src/libgmenuharness.map0000644000015300001610000000047112623327216023231 0ustar pbuserpbgroup00000000000000{ global: extern "C++" { unity::gmenuharness::[!i]*; typeinfo?for?unity::gmenuharness::[!i]*; typeinfo?name?for?unity::gmenuharness::[!i]*; vtable?for?unity::gmenuharness::[!i]*; VTT?for?unity::gmenuharness::[!i]*; }; local: extern "C++" { *; }; }; gmenuharness-0.1+16.04.20151119.3/src/CMakeLists.txt0000644000015300001610000000214212623327216022101 0ustar pbuserpbgroup00000000000000pkg_check_modules(UNITY_API libunity-api>=0.1.3 REQUIRED) include_directories(${UNITY_API_INCLUDE_DIRS}) add_library( ${GMENU_HARNESS} SHARED MatchResult.cpp MatchUtils.cpp MenuItemMatcher.cpp MenuMatcher.cpp ) set_target_properties(${GMENU_HARNESS} PROPERTIES VERSION "${GMENU_HARNESS_SO_VERSION_MAJOR}.${GMENU_HARNESS_SO_VERSION_MINOR}.${GMENU_HARNESS_SO_VERSION_MICRO}" SOVERSION ${GMENU_HARNESS_SO_VERSION} ) set(symbol_map "${CMAKE_SOURCE_DIR}/src/libgmenuharness.map") set_target_properties(${GMENU_HARNESS} PROPERTIES LINK_FLAGS "${ldflags} -Wl,--version-script,${symbol_map} ") set_target_properties(${GMENU_HARNESS} PROPERTIES LINK_DEPENDS ${symbol_map}) target_link_libraries( gmenuharness ${GLIB_LDFLAGS} ) install( TARGETS ${GMENU_HARNESS} LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} ) # Set up package config. configure_file(lib${GMENU_HARNESS}.pc.in lib${GMENU_HARNESS}.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${GMENU_HARNESS}.pc DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig)gmenuharness-0.1+16.04.20151119.3/src/MenuMatcher.cpp0000644000015300001610000001234712623327216022265 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser 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 warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authored by: Pete Woods */ #include #include #include #include using namespace std; namespace unity { namespace gmenuharness { namespace { static void gdbus_connection_deleter(GDBusConnection* connection) { // if (!g_dbus_connection_is_closed(connection)) // { // g_dbus_connection_close_sync(connection, nullptr, nullptr); // } g_clear_object(&connection); } } struct MenuMatcher::Parameters::Priv { string m_busName; vector> m_actions; string m_menuObjectPath; }; MenuMatcher::Parameters::Parameters(const string& busName, const vector>& actions, const string& menuObjectPath) : p(new Priv) { p->m_busName = busName; p->m_actions = actions; p->m_menuObjectPath = menuObjectPath; } MenuMatcher::Parameters::~Parameters() { } MenuMatcher::Parameters::Parameters(const Parameters& other) : p(new Priv) { *this = other; } MenuMatcher::Parameters::Parameters(Parameters&& other) { *this = move(other); } MenuMatcher::Parameters& MenuMatcher::Parameters::operator=(const Parameters& other) { p->m_busName = other.p->m_busName; p->m_actions = other.p->m_actions; p->m_menuObjectPath = other.p->m_menuObjectPath; return *this; } MenuMatcher::Parameters& MenuMatcher::Parameters::operator=(Parameters&& other) { p = move(other.p); return *this; } struct MenuMatcher::Priv { Priv(const Parameters& parameters) : m_parameters(parameters) { } Parameters m_parameters; vector m_items; shared_ptr m_system; shared_ptr m_session; shared_ptr m_menu; map> m_actions; }; MenuMatcher::MenuMatcher(const Parameters& parameters) : p(new Priv(parameters)) { p->m_system.reset(g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, nullptr), &gdbus_connection_deleter); g_dbus_connection_set_exit_on_close(p->m_system.get(), false); p->m_session.reset(g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr), &gdbus_connection_deleter); g_dbus_connection_set_exit_on_close(p->m_session.get(), false); p->m_menu.reset( G_MENU_MODEL( g_dbus_menu_model_get( p->m_session.get(), p->m_parameters.p->m_busName.c_str(), p->m_parameters.p->m_menuObjectPath.c_str())), &g_object_deleter); for (const auto& action : p->m_parameters.p->m_actions) { shared_ptr actionGroup( G_ACTION_GROUP( g_dbus_action_group_get( p->m_session.get(), p->m_parameters.p->m_busName.c_str(), action.second.c_str())), &g_object_deleter); p->m_actions[action.first] = actionGroup; } } MenuMatcher::~MenuMatcher() { } MenuMatcher& MenuMatcher::item(const MenuItemMatcher& item) { p->m_items.emplace_back(item); return *this; } void MenuMatcher::match(MatchResult& matchResult) const { vector location; while (true) { MatchResult childMatchResult(matchResult.createChild()); int menuSize = g_menu_model_get_n_items(p->m_menu.get()); if (p->m_items.size() > (unsigned int) menuSize) { childMatchResult.failure( location, "Row count mismatch, expected " + to_string(p->m_items.size()) + " but found " + to_string(menuSize)); } else { for (size_t i = 0; i < p->m_items.size(); ++i) { const auto& matcher = p->m_items.at(i); matcher.match(childMatchResult, location, p->m_menu, p->m_actions, i); } } if (childMatchResult.success()) { matchResult.merge(childMatchResult); break; } else { if (matchResult.hasTimedOut()) { matchResult.merge(childMatchResult); break; } menuWaitForItems(p->m_menu); } } } MatchResult MenuMatcher::match() const { MatchResult matchResult; match(matchResult); return matchResult; } } // namespace gmenuharness } // namespace unity gmenuharness-0.1+16.04.20151119.3/src/MatchResult.cpp0000644000015300001610000000744112623327216022307 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser 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 warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authored by: Pete Woods */ #include #include #include #include #include using namespace std; namespace unity { namespace gmenuharness { namespace { static void printLocation(ostream& ss, const vector& location, bool first) { for (auto i : location) { ss << " "; if (first) { ss << i; } else { ss << " "; } } ss << " "; } struct compare_vector { bool operator()(const vector& a, const vector& b) const { auto p1 = a.begin(); auto p2 = b.begin(); while (p1 != a.end()) { if (p2 == b.end()) { return false; } if (*p2 > *p1) { return true; } if (*p1 > *p2) { return false; } ++p1; ++p2; } if (p2 != b.end()) { return true; } return false; } }; } struct MatchResult::Priv { bool m_success = true; map, vector, compare_vector> m_failures; chrono::time_point m_timeout = chrono::system_clock::now() + chrono::seconds(10); }; MatchResult::MatchResult() : p(new Priv) { } MatchResult::MatchResult(MatchResult&& other) { *this = move(other); } MatchResult::MatchResult(const MatchResult& other) : p(new Priv) { *this = other; } MatchResult& MatchResult::operator=(const MatchResult& other) { p->m_success = other.p->m_success; p->m_failures= other.p->m_failures; return *this; } MatchResult& MatchResult::operator=(MatchResult&& other) { p = move(other.p); return *this; } MatchResult MatchResult::createChild() const { MatchResult child; child.p->m_timeout = p->m_timeout; return child; } void MatchResult::failure(const vector& location, const string& message) { p->m_success = false; auto it = p->m_failures.find(location); if (it == p->m_failures.end()) { it = p->m_failures.insert(make_pair(location, vector())).first; } it->second.emplace_back(message); } void MatchResult::merge(const MatchResult& other) { p->m_success &= other.p->m_success; for (const auto& e : other.p->m_failures) { p->m_failures.insert(make_pair(e.first, e.second)); } } bool MatchResult::success() const { return p->m_success; } bool MatchResult::hasTimedOut() const { auto now = chrono::system_clock::now(); return (now >= p->m_timeout); } string MatchResult::concat_failures() const { stringstream ss; ss << "Failed expectations:" << endl; for (const auto& failure : p->m_failures) { bool first = true; for (const string& s: failure.second) { printLocation(ss, failure.first, first); first = false; ss << s << endl; } } return ss.str(); } } // namespace gmenuharness } // namespace unity gmenuharness-0.1+16.04.20151119.3/src/libgmenuharness.pc.in0000644000015300001610000000202012623327216023453 0ustar pbuserpbgroup00000000000000# # Copyright (C) 2015 Canonical Ltd # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser 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 warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . # # Authored by: Xavi Garcia Mena # prefix=@CMAKE_INSTALL_PREFIX@ includedir=${prefix}/@GMENU_HARNESS_HDR_INSTALL_BASE_DIR@ libdir=${prefix}/@LIBDIR@ Name: libgmenuharness Description: GMenu harness library Version: @GMENU_HARNESS_SO_VERSION_MAJOR@.@GMENU_HARNESS_SO_VERSION_MINOR@.@GMENU_HARNESS_SO_VERSION_MICRO@ Libs: -L${libdir} -l@GMENU_HARNESS@ Cflags: -I${includedir} gmenuharness-0.1+16.04.20151119.3/TODO0000644000015300001610000000002012623327216017233 0ustar pbuserpbgroup00000000000000Add unit tests. gmenuharness-0.1+16.04.20151119.3/CMakeLists.txt0000644000015300001610000000222512623327223021312 0ustar pbuserpbgroup00000000000000project(gmenu-harness C CXX) cmake_minimum_required(VERSION 2.8.9) set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}") find_package(PkgConfig REQUIRED) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 ${COMMON_FLAGS} -fno-strict-aliasing -fvisibility-inlines-hidden") set(CMAKE_INCLUDE_CURRENT_DIR ON) # version set(GMENU_HARNESS gmenuharness) set(GMENU_HARNESS_SO_VERSION_MAJOR "0") set(GMENU_HARNESS_SO_VERSION_MINOR "1") set(GMENU_HARNESS_SO_VERSION_MICRO "0") set(GMENU_HARNESS_SO_VERSION ${GMENU_HARNESS_SO_VERSION_MAJOR}.${GMENU_HARNESS_SO_VERSION_MINOR}) set(GMENU_HARNESS_HDR_INSTALL_BASE_DIR include/${GMENU_HARNESS}-${GMENU_HARNESS_SO_VERSION}) set(GMENU_HARNESS_HDR_INSTALL_DIR ${GMENU_HARNESS_HDR_INSTALL_BASE_DIR}/unity/${GMENU_HARNESS}) include_directories(include) set(GLIB_REQUIRED_VERSION 2.26) pkg_check_modules( GLIB REQUIRED glib-2.0>=${GLIB_REQUIRED_VERSION} gio-2.0>=${GLIB_REQUIRED_VERSION} ) include_directories(${GLIB_INCLUDE_DIRS}) pkg_check_modules( UNITY_API REQUIRED libunity-api ) include_directories(${UNITY_API_INCLUDE_DIRS}) add_subdirectory(src) add_subdirectory(include) add_subdirectory(tests) gmenuharness-0.1+16.04.20151119.3/cmake/0000755000015300001610000000000012623330006017622 5ustar pbuserpbgroup00000000000000gmenuharness-0.1+16.04.20151119.3/cmake/FindValgrind.cmake0000644000015300001610000000164512623327216023212 0ustar pbuserpbgroup00000000000000 option( ENABLE_MEMCHECK_OPTION "If set to ON, enables automatic creation of memcheck targets" OFF ) find_program( VALGRIND_PROGRAM NAMES valgrind ) if(VALGRIND_PROGRAM) set(VALGRIND_PROGRAM_OPTIONS "--suppressions=${CMAKE_SOURCE_DIR}/tests/data/valgrind.suppression" "--error-exitcode=1" "--leak-check=full" "--gen-suppressions=all" "--quiet" ) endif() find_package_handle_standard_args( VALGRIND DEFAULT_MSG VALGRIND_PROGRAM ) function(add_valgrind_test) foreach(_arg ${ARGN}) if ("VALGRIND" STREQUAL ${_arg}) if(ENABLE_MEMCHECK_OPTION AND VALGRIND_PROGRAM) list(APPEND _vgargs ${VALGRIND_PROGRAM} ${VALGRIND_PROGRAM_OPTIONS}) endif() else() list(APPEND _vgargs ${_arg}) endif() endforeach() add_test(${_vgargs}) endfunction() gmenuharness-0.1+16.04.20151119.3/cmake/COPYING-CMAKE-SCRIPTS0000644000015300001610000000245712623327216022641 0ustar pbuserpbgroup00000000000000Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. gmenuharness-0.1+16.04.20151119.3/include/0000755000015300001610000000000012623330006020165 5ustar pbuserpbgroup00000000000000gmenuharness-0.1+16.04.20151119.3/include/CMakeLists.txt0000644000015300001610000000003012623327216022727 0ustar pbuserpbgroup00000000000000add_subdirectory(unity) gmenuharness-0.1+16.04.20151119.3/include/unity/0000755000015300001610000000000012623330006021335 5ustar pbuserpbgroup00000000000000gmenuharness-0.1+16.04.20151119.3/include/unity/CMakeLists.txt0000644000015300001610000000003712623327216024106 0ustar pbuserpbgroup00000000000000add_subdirectory(gmenuharness) gmenuharness-0.1+16.04.20151119.3/include/unity/gmenuharness/0000755000015300001610000000000012623330006024034 5ustar pbuserpbgroup00000000000000gmenuharness-0.1+16.04.20151119.3/include/unity/gmenuharness/MatchResult.h0000644000015300001610000000270312623327216026453 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser 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 warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authored by: Pete Woods */ #pragma once #include #include #include namespace unity { namespace gmenuharness { class MatchResult { public: MatchResult(); MatchResult(MatchResult&& other); MatchResult(const MatchResult& other); MatchResult& operator=(const MatchResult& other); MatchResult& operator=(MatchResult&& other); ~MatchResult() = default; MatchResult createChild() const; void failure(const std::vector& location, const std::string& message); void merge(const MatchResult& other); bool success() const; bool hasTimedOut() const; std::string concat_failures() const; protected: struct Priv; std::shared_ptr p; }; } // namespace gmenuharness } // namespace unity gmenuharness-0.1+16.04.20151119.3/include/unity/gmenuharness/CMakeLists.txt0000644000015300001610000000021312623327216026601 0ustar pbuserpbgroup00000000000000install(FILES MatchResult.h MatchUtils.h MenuItemMatcher.h MenuMatcher.h DESTINATION ${GMENU_HARNESS_HDR_INSTALL_DIR}) gmenuharness-0.1+16.04.20151119.3/include/unity/gmenuharness/MenuMatcher.h0000644000015300001610000000432112623327216026426 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser 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 warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authored by: Pete Woods */ #pragma once #define EXPECT_MATCHRESULT(statement) \ do {\ auto result = (statement);\ GTEST_TEST_BOOLEAN_(result.success(), #statement, false, true, \ GTEST_NONFATAL_FAILURE_) << result.concat_failures().c_str(); \ } while (0) #include #include #include #include namespace unity { namespace gmenuharness { class MenuMatcher { public: class Parameters { public: Parameters( const std::string& busName, const std::vector>& actions, const std::string& menuObjectPath); ~Parameters(); Parameters(const Parameters& other); Parameters(Parameters&& other); Parameters& operator=(const Parameters& other); Parameters& operator=(Parameters&& other); protected: friend MenuMatcher; struct Priv; std::shared_ptr p; }; MenuMatcher(const Parameters& parameters); ~MenuMatcher(); MenuMatcher(const MenuMatcher& other) = delete; MenuMatcher(MenuMatcher&& other) = delete; MenuMatcher& operator=(const MenuMatcher& other) = delete; MenuMatcher& operator=(MenuMatcher&& other) = delete; MenuMatcher& item(const MenuItemMatcher& item); MatchResult match() const; void match(MatchResult& matchResult) const; protected: struct Priv; std::shared_ptr p; }; } // gmenuharness } // unity gmenuharness-0.1+16.04.20151119.3/include/unity/gmenuharness/MatchUtils.h0000644000015300001610000000216612623327216026300 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser 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 warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authored by: Pete Woods */ #pragma once #include #include #include namespace unity { namespace gmenuharness { void waitForCore(GObject* obj, const std::string& signalName, unsigned int timeout = 10); void menuWaitForItems(const std::shared_ptr& menu, unsigned int timeout = 10); void g_object_deleter(gpointer object); void gvariant_deleter(GVariant* varptr); } //namespace gmenuharness } // namespace unity gmenuharness-0.1+16.04.20151119.3/include/unity/gmenuharness/MenuItemMatcher.h0000644000015300001610000000765312623327216027260 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser 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 warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authored by: Pete Woods */ #pragma once #include #include #include #include namespace unity { namespace gmenuharness { class MatchResult; class MenuItemMatcher { public: enum class Mode { all, starts_with, ends_with }; enum class Type { plain, checkbox, radio }; static MenuItemMatcher checkbox(); static MenuItemMatcher radio(); MenuItemMatcher(); ~MenuItemMatcher(); MenuItemMatcher(const MenuItemMatcher& other); MenuItemMatcher(MenuItemMatcher&& other); MenuItemMatcher& operator=(const MenuItemMatcher& other); MenuItemMatcher& operator=(MenuItemMatcher&& other); MenuItemMatcher& type(Type type); MenuItemMatcher& label(const std::string& label); MenuItemMatcher& action(const std::string& action); MenuItemMatcher& state_icons(const std::vector& state); MenuItemMatcher& icon(const std::string& icon); MenuItemMatcher& themed_icon(const std::string& iconName, const std::vector& icons); MenuItemMatcher& widget(const std::string& widget); MenuItemMatcher& pass_through_attribute(const std::string& actionName, const std::shared_ptr& value); MenuItemMatcher& pass_through_boolean_attribute(const std::string& actionName, bool value); MenuItemMatcher& pass_through_string_attribute(const std::string& actionName, const std::string& value); MenuItemMatcher& pass_through_double_attribute(const std::string& actionName, double value); MenuItemMatcher& round_doubles(double maxDifference); MenuItemMatcher& attribute(const std::string& name, const std::shared_ptr& value); MenuItemMatcher& boolean_attribute(const std::string& name, bool value); MenuItemMatcher& string_attribute(const std::string& name, const std::string& value); MenuItemMatcher& int32_attribute(const std::string& name, int value); MenuItemMatcher& int64_attribute(const std::string& name, int value); MenuItemMatcher& double_attribute(const std::string& name, double value); MenuItemMatcher& attribute_not_set(const std::string& name); MenuItemMatcher& toggled(bool toggled); MenuItemMatcher& mode(Mode mode); MenuItemMatcher& submenu(); MenuItemMatcher& section(); MenuItemMatcher& is_empty(); MenuItemMatcher& has_exactly(unsigned int children); MenuItemMatcher& item(const MenuItemMatcher& item); MenuItemMatcher& item(MenuItemMatcher&& item); MenuItemMatcher& pass_through_activate(const std::string& action, const std::shared_ptr& parameter = nullptr); MenuItemMatcher& activate(const std::shared_ptr& parameter = nullptr); MenuItemMatcher& set_pass_through_action_state(const std::string& action, const std::shared_ptr& state); MenuItemMatcher& set_action_state(const std::shared_ptr& state); void match(MatchResult& matchResult, const std::vector& location, const std::shared_ptr& menu, std::map>& actions, unsigned int index) const; protected: struct Priv; std::shared_ptr p; }; } // namespace gmenuharness } // namespace unity gmenuharness-0.1+16.04.20151119.3/INSTALL0000644000015300001610000000221412623327216017603 0ustar pbuserpbgroup00000000000000# # Copyright © 2015 Canonical Ltd. # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU Lesser 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 warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . # # Authored by: Pete Woods # Xavi Garcia # Build dependencies ------------------ See debian/control for the list of packages required to build and test the code. Building the code ----------------- The simplest case is: $ mkdir build $ cd build $ cmake .. $ make By default, the code is built in release mode. To build a debug version, use $ mkdir builddebug $ cd builddebug $ cmake -DCMAKE_BUILD_TYPE=debug .. $ make gmenuharness-0.1+16.04.20151119.3/COPYING0000644000015300001610000001674312623327216017621 0ustar pbuserpbgroup00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. gmenuharness-0.1+16.04.20151119.3/README0000644000015300001610000000154012623327216017433 0ustar pbuserpbgroup00000000000000# # Copyright © 2015 Canonical Ltd. # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU Lesser 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 warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . # # Authored by: Pete Woods # Xavi Garcia # This is a library to test GMenuModel structures. For instructions on how to build the code, see the INSTALL file. gmenuharness-0.1+16.04.20151119.3/tests/0000755000015300001610000000000012623330006017704 5ustar pbuserpbgroup00000000000000gmenuharness-0.1+16.04.20151119.3/tests/utils/0000755000015300001610000000000012623330006021044 5ustar pbuserpbgroup00000000000000gmenuharness-0.1+16.04.20151119.3/tests/utils/CMakeLists.txt0000644000015300001610000000020412623327223023607 0ustar pbuserpbgroup00000000000000 add_library( test-main STATIC TestMain.cpp ) target_link_libraries( test-main Qt5::Core ${GTEST_LIBRARIES} ) gmenuharness-0.1+16.04.20151119.3/tests/utils/TestMain.cpp0000644000015300001610000000170012623327223023301 0ustar pbuserpbgroup00000000000000/* * 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(); } gmenuharness-0.1+16.04.20151119.3/tests/functional/0000755000015300001610000000000012623330006022046 5ustar pbuserpbgroup00000000000000gmenuharness-0.1+16.04.20151119.3/tests/functional/menus/0000755000015300001610000000000012623330006023175 5ustar pbuserpbgroup00000000000000gmenuharness-0.1+16.04.20151119.3/tests/functional/menus/CMakeLists.txt0000644000015300001610000000050312623327223025742 0ustar pbuserpbgroup00000000000000 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) gmenuharness-0.1+16.04.20151119.3/tests/functional/menus/Simple.cpp0000644000015300001610000000462512623327223025150 0ustar pbuserpbgroup00000000000000/* * 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); } gmenuharness-0.1+16.04.20151119.3/tests/functional/menus/Deeper.cpp0000644000015300001610000001630312623327223025117 0ustar pbuserpbgroup00000000000000/* * 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); } gmenuharness-0.1+16.04.20151119.3/tests/functional/menus/MenuMain.cpp0000644000015300001610000000542012623327223025422 0ustar pbuserpbgroup00000000000000/* * 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; } gmenuharness-0.1+16.04.20151119.3/tests/functional/CMakeLists.txt0000644000015300001610000000003112623327223024607 0ustar pbuserpbgroup00000000000000 add_subdirectory(menus) gmenuharness-0.1+16.04.20151119.3/tests/functional/FunctionalTests.cpp0000644000015300001610000001220512623327223025706 0ustar pbuserpbgroup00000000000000/* * 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()); } } gmenuharness-0.1+16.04.20151119.3/tests/CMakeLists.txt0000644000015300001610000000150212623327223022451 0ustar pbuserpbgroup00000000000000 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 ) gmenuharness-0.1+16.04.20151119.3/tests/unit/0000755000015300001610000000000012623330006020663 5ustar pbuserpbgroup00000000000000gmenuharness-0.1+16.04.20151119.3/tests/unit/TestMatchResult.cpp0000644000015300001610000000572312623327223024500 0ustar pbuserpbgroup00000000000000/* * 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()); } } }