aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2014-11-05 09:29:40 -0600
committerTed Gould <ted@gould.cx>2014-11-05 09:29:40 -0600
commit629fb9872de0626e957489b177f36e025f996abe (patch)
treef3cd4b293a8bc3f04e4ca6c86a17c9512d248a0b
parentad16588f7734f0086d8cfa8ee10aaaa4961de23d (diff)
downloadayatana-indicator-sound-629fb9872de0626e957489b177f36e025f996abe.tar.gz
ayatana-indicator-sound-629fb9872de0626e957489b177f36e025f996abe.tar.bz2
ayatana-indicator-sound-629fb9872de0626e957489b177f36e025f996abe.zip
Flesh out the action functions
-rw-r--r--tests/indicator-fixture.h84
1 files changed, 81 insertions, 3 deletions
diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h
index 6b3963a..02dd885 100644
--- a/tests/indicator-fixture.h
+++ b/tests/indicator-fixture.h
@@ -168,18 +168,96 @@ class IndicatorFixture : public ::testing::Test
agWaitForActions(_actions);
}
- void expectActionExists (const std::string& name) {
+ bool expectActionExists (const std::string& name) {
+ bool hasit = g_action_group_has_action(_actions.get(), name.c_str());
+ if (!hasit) {
+ std::cout <<
+ " Action: " << name << std::endl <<
+ " Expected: " << "Exists" << std::endl <<
+ " Actual: " << "No action found" << std::endl;
+ }
+
+ return hasit;
}
- void expectActionStateType (const std::string& name, const GVariantType * type) {
+ bool expectActionStateType (const std::string& name, const GVariantType * type) {
+ auto atype = g_action_group_get_action_state_type(_actions.get(), name.c_str());
+ bool same = false;
+ if (atype != nullptr) {
+ same = g_variant_type_equal(atype, type);
+ }
+
+ if (!same) {
+ std::cout <<
+ " Action: " << name << std::endl <<
+ " Expected: " << g_variant_type_peek_string(type) << std::endl <<
+ " Actual: " << g_variant_type_peek_string(atype) << std::endl;
+ }
+
+ return same;
}
- void expectActionStateIs (const std::string& name, const GVariant * value) {
+ bool expectActionStateIs (const std::string& name, GVariant * value) {
+ auto varref = std::shared_ptr<GVariant>(g_variant_ref_sink(value), [](GVariant * varptr) {
+ if (varptr != nullptr)
+ g_variant_unref(varptr);
+ });
+ auto aval = std::shared_ptr<GVariant>(g_action_group_get_action_state(_actions.get(), name.c_str()), [] (GVariant * varptr) {
+ if (varptr != nullptr)
+ g_variant_unref(varptr);
+ });
+ bool match = false;
+
+ if (aval != nullptr) {
+ match = g_variant_equal(aval.get(), varref.get());
+ }
+ if (!match) {
+ gchar * valstr = nullptr;
+ gchar * attstr = nullptr;
+
+ if (aval != nullptr) {
+ attstr = g_variant_print(aval.get(), TRUE);
+ } else {
+ attstr = g_strdup("nullptr");
+ }
+
+ if (varref != nullptr) {
+ valstr = g_variant_print(varref.get(), TRUE);
+ } else {
+ valstr = g_strdup("nullptr");
+ }
+
+ std::cout <<
+ " Action: " << name << std::endl <<
+ " Expected: " << valstr << std::endl <<
+ " Actual: " << attstr << std::endl;
+
+ g_free(valstr);
+ g_free(attstr);
+ }
+
+ return match;
+ }
+
+ bool expectActionStateIs (const std::string& name, bool value) {
+ GVariant * var = g_variant_new_boolean(value);
+ return expectActionStateIs(name, var);
+ }
+
+ bool expectActionStateIs (const std::string& name, std::string value) {
+ GVariant * var = g_variant_new_string(value.c_str());
+ return expectActionStateIs(name, var);
+ }
+
+ bool expectActionStateIs (const std::string& name, const char * value) {
+ GVariant * var = g_variant_new_string(value);
+ return expectActionStateIs(name, var);
}
+
private:
std::shared_ptr<GVariant> getMenuAttributeVal (int location, std::shared_ptr<GMenuModel>& menu, const std::string& attribute, std::shared_ptr<GVariant>& value) {
if (!(location < g_menu_model_get_n_items(menu.get()))) {