aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/unity/gmenuharness/MenuItemMatcher.h4
-rw-r--r--src/gmenuharness/MenuItemMatcher.cpp70
-rw-r--r--tests/integration/indicator-sound-test-base.cpp2
3 files changed, 76 insertions, 0 deletions
diff --git a/include/unity/gmenuharness/MenuItemMatcher.h b/include/unity/gmenuharness/MenuItemMatcher.h
index 6f7f94c..8f6deaf 100644
--- a/include/unity/gmenuharness/MenuItemMatcher.h
+++ b/include/unity/gmenuharness/MenuItemMatcher.h
@@ -75,6 +75,8 @@ public:
MenuItemMatcher& icon(const std::string& icon);
+ MenuItemMatcher& themed_icon(const std::string& iconName, const std::vector<std::string>& icons);
+
MenuItemMatcher& widget(const std::string& widget);
MenuItemMatcher& pass_through_attribute(const std::string& actionName, const std::shared_ptr<GVariant>& value);
@@ -95,6 +97,8 @@ public:
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& toggled(bool toggled);
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)
{
diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp
index a839fbc..bbede82 100644
--- a/tests/integration/indicator-sound-test-base.cpp
+++ b/tests/integration/indicator-sound-test-base.cpp
@@ -276,6 +276,8 @@ unity::gmenuharness::MenuItemMatcher IndicatorSoundTestBase::volumeSlider(double
.double_attribute("max-value", 1.0)
.double_attribute("step", 0.01)
.string_attribute("x-canonical-type", "com.canonical.unity.slider")
+ .themed_icon("max-icon", {"audio-volume-high-panel", "audio-volume-high", "audio-volume", "audio"})
+ .themed_icon("min-icon", {"audio-volume-low-zero-panel", "audio-volume-low-zero", "audio-volume-low", "audio-volume", "audio"})
.pass_through_double_attribute("action", volume);
}