aboutsummaryrefslogtreecommitdiff
path: root/src/gmenuharness/MenuItemMatcher.cpp
diff options
context:
space:
mode:
authorXavi Garcia Mena <xavi.garcia.mena@canonical.com>2015-09-22 11:52:43 +0200
committerXavi Garcia Mena <xavi.garcia.mena@canonical.com>2015-09-22 11:52:43 +0200
commitb9ef4f6abdefb7b1d31d34f35b742016f1b5b87f (patch)
treeb30c8ee756d20e4469bd6a739d2d7f4dd24162ca /src/gmenuharness/MenuItemMatcher.cpp
parent22de41f3cc382adbf06be8642af5cfa7ec664c8e (diff)
downloadayatana-indicator-sound-b9ef4f6abdefb7b1d31d34f35b742016f1b5b87f.tar.gz
ayatana-indicator-sound-b9ef4f6abdefb7b1d31d34f35b742016f1b5b87f.tar.bz2
ayatana-indicator-sound-b9ef4f6abdefb7b1d31d34f35b742016f1b5b87f.zip
Added themed_icon to integration tests
Diffstat (limited to 'src/gmenuharness/MenuItemMatcher.cpp')
-rw-r--r--src/gmenuharness/MenuItemMatcher.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/gmenuharness/MenuItemMatcher.cpp b/src/gmenuharness/MenuItemMatcher.cpp
index ab22364..dae9e7d 100644
--- a/src/gmenuharness/MenuItemMatcher.cpp
+++ b/src/gmenuharness/MenuItemMatcher.cpp
@@ -22,6 +22,7 @@
#include <iostream>
#include <vector>
+#include <map>
using namespace std;
@@ -182,6 +183,8 @@ struct MenuItemMatcher::Priv
shared_ptr<string> m_icon;
+ map<shared_ptr<string>, vector<std::string>> m_themed_icons;
+
shared_ptr<string> m_action;
vector<std::string> m_state_icons;
@@ -242,6 +245,7 @@ MenuItemMatcher& MenuItemMatcher::operator=(const MenuItemMatcher& other)
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;
@@ -291,6 +295,12 @@ MenuItemMatcher& MenuItemMatcher::icon(const string& icon)
return *this;
}
+MenuItemMatcher& MenuItemMatcher::themed_icon(const std::string& iconName, const std::vector<std::string>& icons)
+{
+ p->m_themed_icons[make_shared<string>(iconName)] = icons;
+ return *this;
+}
+
MenuItemMatcher& MenuItemMatcher::widget(const string& widget)
{
return string_attribute("x-canonical-type", widget);
@@ -362,6 +372,14 @@ MenuItemMatcher& MenuItemMatcher::int32_attribute(const std::string& name, int v
&gvariant_deleter));
}
+MenuItemMatcher& MenuItemMatcher::int64_attribute(const std::string& name, int value)
+{
+ return attribute(
+ name,
+ shared_ptr<GVariant>(g_variant_new_int64 (value),
+ &gvariant_deleter));
+}
+
MenuItemMatcher& MenuItemMatcher::double_attribute(const std::string& name, double value)
{
return attribute(
@@ -503,6 +521,58 @@ void MenuItemMatcher::match(
+ type_to_string(actualType));
}
+ // check themed icons
+ map<shared_ptr<string>, vector<string>>::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 = g_icon_deserialize(icon_val);
+ if (!gicon || !G_IS_THEMED_ICON(gicon))
+ {
+ matchResult.failure(
+ location,
+ "Expected attribute " + (*(*iter).first) + " is not a themed icon");
+ }
+ auto iconNames = g_themed_icon_get_names(G_THEMED_ICON(gicon));
+ 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 (string(iconNames[i]) != (*iter).second[i])
+ {
+ matchResult.failure(
+ location,
+ "Icon at position " + to_string(i) +
+ " for themed icon [" + (*(*iter).first) +
+ "], mismatchs. Expected: " + iconNames[i] + " but found " + (*iter).second[i]);
+ }
+ }
+ }
+ g_object_unref(gicon);
+ }
+
string label = get_string_attribute(menuItem, G_MENU_ATTRIBUTE_LABEL);
if (p->m_label && (*p->m_label) != label)
{