aboutsummaryrefslogtreecommitdiff
path: root/tests/indicator-fixture.h
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2014-10-29 09:36:27 -0500
committerTed Gould <ted@gould.cx>2014-10-29 09:36:27 -0500
commit3821fc9e1b07732fd1796103439b4c95b27a0138 (patch)
tree2ea579e0bc1af89d79c302bf5f778852c8a3a4cb /tests/indicator-fixture.h
parent5b7a608243729d4f9133fe092b5093ed041ba9ff (diff)
downloadayatana-indicator-sound-3821fc9e1b07732fd1796103439b4c95b27a0138.tar.gz
ayatana-indicator-sound-3821fc9e1b07732fd1796103439b4c95b27a0138.tar.bz2
ayatana-indicator-sound-3821fc9e1b07732fd1796103439b4c95b27a0138.zip
Make our ref/unrefs dependent on shared pointers
Diffstat (limited to 'tests/indicator-fixture.h')
-rw-r--r--tests/indicator-fixture.h25
1 files changed, 17 insertions, 8 deletions
diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h
index 7ae3dde..99fd7d1 100644
--- a/tests/indicator-fixture.h
+++ b/tests/indicator-fixture.h
@@ -17,6 +17,7 @@
* Ted Gould <ted@canonical.com>
*/
+#include <memory>
#include <gtest/gtest.h>
#include <gio/gio.h>
@@ -138,11 +139,14 @@ class IndicatorFixture : public ::testing::Test
if (location >= g_menu_model_get_n_items(menu))
return;
- auto menuval = g_menu_model_get_item_attribute_value(menu, location, attribute.c_str(), g_variant_get_type(value));
+ auto menuval = std::shared_ptr<GVariant>(g_menu_model_get_item_attribute_value(menu, location, attribute.c_str(), g_variant_get_type(value)), [](GVariant * varptr) {
+ if (varptr != nullptr)
+ g_variant_unref(varptr);
+ });
+
EXPECT_NE(nullptr, menuval);
if (menuval != nullptr) {
- EXPECT_TRUE(g_variant_equal(value, menuval));
- g_variant_unref(menuval);
+ EXPECT_TRUE(g_variant_equal(value, menuval.get()));
}
}
@@ -152,19 +156,24 @@ class IndicatorFixture : public ::testing::Test
if (menuLocation.size() - 1 == index)
return expectMenuAttributeVerify(menuLocation[index], menu, attribute, value);
- auto submenu = g_menu_model_get_item_link(menu, menuLocation[index], G_MENU_LINK_SUBMENU);
+ auto submenu = std::shared_ptr<GMenuModel>(g_menu_model_get_item_link(menu, menuLocation[index], G_MENU_LINK_SUBMENU), [](GMenuModel * modelptr) {
+ g_clear_object(&modelptr);
+ });
+
EXPECT_NE(nullptr, submenu);
if (submenu == nullptr)
return;
- expectMenuAttributeRecurse(menuLocation, attribute, value, index++, submenu);
- g_object_unref(submenu);
+ expectMenuAttributeRecurse(menuLocation, attribute, value, index++, submenu.get());
}
void expectMenuAttribute (const std::vector<int> menuLocation, const std::string& attribute, GVariant * value) {
- g_variant_ref_sink(value);
+ auto varref = std::shared_ptr<GVariant>(g_variant_ref_sink(value), [](GVariant * varptr) {
+ if (varptr != nullptr)
+ g_variant_unref(varptr);
+ });
+
expectMenuAttributeRecurse(menuLocation, attribute, value, 0, _menu);
- g_variant_unref(value);
}
void expectMenuAttribute (const std::vector<int> menuLocation, const std::string& attribute, bool value) {