aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2014-11-24 10:16:40 -0600
committerTed Gould <ted@gould.cx>2014-11-24 10:16:40 -0600
commit12bcb367c0fe067b2b3475d09a08e09e63757a48 (patch)
treedefeaeab1f0c8d3faf58912cd9794b39458610b3
parent5b061aac08bfb1931b1a52eb8439937ff66d8d80 (diff)
downloadayatana-indicator-sound-12bcb367c0fe067b2b3475d09a08e09e63757a48.tar.gz
ayatana-indicator-sound-12bcb367c0fe067b2b3475d09a08e09e63757a48.tar.bz2
ayatana-indicator-sound-12bcb367c0fe067b2b3475d09a08e09e63757a48.zip
Switching to using a results object for the menu attribute checking
-rw-r--r--tests/indicator-fixture.h49
-rw-r--r--tests/indicator-test.cc2
2 files changed, 21 insertions, 30 deletions
diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h
index 3115fae..a05f7bb 100644
--- a/tests/indicator-fixture.h
+++ b/tests/indicator-fixture.h
@@ -357,7 +357,7 @@ class IndicatorFixture : public ::testing::Test
}
protected:
- bool expectMenuAttribute (const std::vector<int> menuLocation, const std::string& attribute, GVariant * value) {
+ testing::AssertionResult expectMenuAttribute (const char * menuLocationStr, const gchar * attributeStr, const char * valueStr, const std::vector<int> menuLocation, const std::string& attribute, GVariant * value) {
auto varref = std::shared_ptr<GVariant>(g_variant_ref_sink(value), [](GVariant * varptr) {
if (varptr != nullptr)
g_variant_unref(varptr);
@@ -371,7 +371,6 @@ class IndicatorFixture : public ::testing::Test
}
if (!same) {
- gchar * valstr = nullptr;
gchar * attstr = nullptr;
if (attrib != nullptr) {
@@ -380,50 +379,42 @@ class IndicatorFixture : public ::testing::Test
attstr = g_strdup("nullptr");
}
- if (varref != nullptr) {
- valstr = g_variant_print(varref.get(), TRUE);
- } else {
- valstr = g_strdup("nullptr");
- }
-
- std::string menuprint("{ ");
- std::for_each(menuLocation.begin(), menuLocation.end(), [&menuprint](int i) {
- menuprint.append(std::to_string(i));
- menuprint.append(", ");
- });
- menuprint += "}";
-
- std::cout <<
- " Menu: " << menuprint << std::endl <<
- " Attribute: " << attribute << std::endl <<
- " Expected: " << valstr << std::endl <<
+ auto result = testing::AssertionFailure();
+ result <<
+ " Menu: " << menuLocationStr << std::endl <<
+ " Attribute: " << attributeStr << std::endl <<
+ " Expected: " << valueStr << std::endl <<
" Actual: " << attstr << std::endl;
- g_free(valstr);
g_free(attstr);
- }
- return same;
+ return result;
+ } else {
+ auto result = testing::AssertionSuccess();
+ return result;
+ }
}
- bool expectMenuAttribute (const std::vector<int> menuLocation, const std::string& attribute, bool value) {
+ testing::AssertionResult expectMenuAttribute (const char * menuLocationStr, const gchar * attributeStr, const char * valueStr, const std::vector<int> menuLocation, const std::string& attribute, bool value) {
GVariant * var = g_variant_new_boolean(value);
- return expectMenuAttribute(menuLocation, attribute, var);
+ return expectMenuAttribute(menuLocationStr, attributeStr, valueStr, menuLocation, attribute, var);
}
- bool expectMenuAttribute (const std::vector<int> menuLocation, const std::string& attribute, std::string value) {
+ testing::AssertionResult expectMenuAttribute (const char * menuLocationStr, const gchar * attributeStr, const char * valueStr, const std::vector<int> menuLocation, const std::string& attribute, std::string value) {
GVariant * var = g_variant_new_string(value.c_str());
- return expectMenuAttribute(menuLocation, attribute, var);
+ return expectMenuAttribute(menuLocationStr, attributeStr, valueStr, menuLocation, attribute, var);
}
- bool expectMenuAttribute (const std::vector<int> menuLocation, const std::string& attribute, const char * value) {
+ testing::AssertionResult expectMenuAttribute (const char * menuLocationStr, const gchar * attributeStr, const char * valueStr, const std::vector<int> menuLocation, const std::string& attribute, const char * value) {
GVariant * var = g_variant_new_string(value);
- return expectMenuAttribute(menuLocation, attribute, var);
+ return expectMenuAttribute(menuLocationStr, attributeStr, valueStr, menuLocation, attribute, var);
}
};
-#define EXPECT_MENU_ATTRIB(menu, attrib, value) expectMenuAttribute(menu, attrib, value)
+#define EXPECT_MENU_ATTRIB(menu, attrib, value) \
+ EXPECT_PRED_FORMAT3(IndicatorFixture::expectMenuAttribute, menu, attrib, value)
+
#define ASSERT_MENU_ATTRIB(menu, attrib, value) \
if (!expectMenuAttribute(menu, attrib, value)) \
return;
diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc
index 725a5c8..ee9a722 100644
--- a/tests/indicator-test.cc
+++ b/tests/indicator-test.cc
@@ -51,7 +51,7 @@ TEST_F(IndicatorTest, PhoneMenu) {
EXPECT_MENU_ATTRIB({0}, "action", "indicator.root");
EXPECT_MENU_ATTRIB({0}, "x-canonical-type", "com.canonical.indicator.root");
- expectMenuAttribute({0, 0, 0}, "action", "indicator.silent-mode");
+ //expectMenuAttribute({0, 0, 0}, "action", "indicator.silent-mode");
}
TEST_F(IndicatorTest, DesktopMenu) {