aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2012-05-29 17:28:15 -0500
committerCharles Kerr <charles.kerr@canonical.com>2012-05-29 17:28:15 -0500
commitab87d8f8eaf75dda49dbd6e9ef56bf94dcf98e28 (patch)
treea94d9e94a2ccbf83f038a84c2d327fe680b0d494
parent5786ecae0d9ecae7aaf2b19094474db54e53a691 (diff)
downloadayatana-indicator-power-ab87d8f8eaf75dda49dbd6e9ef56bf94dcf98e28.tar.gz
ayatana-indicator-power-ab87d8f8eaf75dda49dbd6e9ef56bf94dcf98e28.tar.bz2
ayatana-indicator-power-ab87d8f8eaf75dda49dbd6e9ef56bf94dcf98e28.zip
add a test to make sure that the listener responds to a PropertiesChanged signal
-rw-r--r--src/dbus-listener.c5
-rw-r--r--tests/test-dbus-listener.cc62
2 files changed, 67 insertions, 0 deletions
diff --git a/src/dbus-listener.c b/src/dbus-listener.c
index feaf78e..bc31ee3 100644
--- a/src/dbus-listener.c
+++ b/src/dbus-listener.c
@@ -127,6 +127,7 @@ get_devices_cb (GObject * source_object,
GSList * devices = NULL;
GVariant * devices_container;
IndicatorPowerDbusListener * self = INDICATOR_POWER_DBUS_LISTENER (user_data);
+g_message ("%s", G_STRLOC);
/* build an array of IndicatorPowerDevices from the DBus response */
error = NULL;
@@ -163,6 +164,7 @@ get_devices_cb (GObject * source_object,
static void
request_device_list (IndicatorPowerDbusListener * self)
{
+g_message ("calling GetDevices... self %p priv %p proxy %p", self, self->priv, self->priv->proxy);
g_dbus_proxy_call (self->priv->proxy,
"GetDevices",
NULL,
@@ -179,6 +181,8 @@ receive_properties_changed (GDBusProxy *proxy G_GNUC_UNUSED,
GStrv invalidated_properties G_GNUC_UNUSED,
gpointer user_data)
{
+g_message ("properties changed: %p %p %p %p", proxy, changed_properties, invalidated_properties, user_data);
+g_message ("hey someone told me the properties changed");
request_device_list (INDICATOR_POWER_DBUS_LISTENER(user_data));
}
@@ -200,6 +204,7 @@ service_proxy_cb (GObject *object,
return;
}
+g_message ("registering for g-properties-changed callback");
/* we want to change the primary device changes */
g_signal_connect (priv->proxy,
"g-properties-changed",
diff --git a/tests/test-dbus-listener.cc b/tests/test-dbus-listener.cc
index 4c6c607..8bf74bf 100644
--- a/tests/test-dbus-listener.cc
+++ b/tests/test-dbus-listener.cc
@@ -306,3 +306,65 @@ TEST_F(DbusListenerTest, GSDReturnsError)
g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls
g_object_unref (o);
}
+
+/* This test emits a PropertiesChanged signal and confirms that
+ the dbus listener asks for a fresh set of devices as a result. */
+TEST_F(DbusListenerTest, GSDPropChanged)
+{
+ gsd_power_error_string = g_strdup ("no devices for you lol");
+
+ // create an i-power dbus listener to watch for GSD
+ ASSERT_EQ (g_slist_length(devices), 0);
+ GObject * o = G_OBJECT (g_object_new (INDICATOR_POWER_DBUS_LISTENER_TYPE, NULL));
+ ASSERT_TRUE (INDICATOR_IS_POWER_DBUS_LISTENER(o));
+ g_signal_connect(o, INDICATOR_POWER_DBUS_LISTENER_DEVICES_ENUMERATED,
+ G_CALLBACK(on_devices_enumerated), this);
+ g_main_loop_run (mainloop);
+ // test the devices should have gotten
+ ASSERT_EQ (g_slist_length(devices), 0);
+
+ // build a GetDevices retval that shows an AC line and a discharging battery
+ g_clear_pointer (&gsd_power_error_string, g_free);
+ GVariantBuilder * builder = g_variant_builder_new (G_VARIANT_TYPE("a(susdut)"));
+ g_variant_builder_add (builder, "(susdut)",
+ "/org/freedesktop/UPower/devices/line_power_AC",
+ UP_DEVICE_KIND_LINE_POWER,
+ ". GThemedIcon ac-adapter-symbolic ac-adapter ",
+ 0.0,
+ UP_DEVICE_STATE_UNKNOWN,
+ 0);
+ g_variant_builder_add (builder, "(susdut)",
+ "/org/freedesktop/UPower/devices/battery_BAT0",
+ UP_DEVICE_KIND_BATTERY,
+ ". GThemedIcon battery-good-symbolic gpm-battery-060 battery-good ",
+ 52.871712,
+ UP_DEVICE_STATE_DISCHARGING,
+ 8834);
+ GVariant * value = g_variant_builder_end (builder);
+ get_devices_retval = g_variant_new_tuple (&value, 1);
+ g_variant_builder_unref (builder);
+
+ // tell the listener that some property changed
+ GVariantBuilder props_builder;
+ g_variant_builder_init (&props_builder, G_VARIANT_TYPE ("a{sv}"));
+ GVariant * props_changed = g_variant_new ("(s@a{sv}@as)", GSD_POWER_DBUS_INTERFACE,
+ g_variant_builder_end (&props_builder),
+ g_variant_new_strv (NULL, 0));
+ g_variant_ref_sink (props_changed);
+ GError * error = NULL;
+ g_dbus_connection_emit_signal (connection,
+ NULL,
+ GSD_POWER_DBUS_PATH,
+ "org.freedesktop.DBus.Properties",
+ "PropertiesChanged",
+ props_changed,
+ &error);
+ ASSERT_TRUE(error == NULL);
+
+ // give i-power's dbus listener a chance to ask for a fresh device list
+ g_main_loop_run (mainloop);
+ ASSERT_EQ (g_slist_length(devices), 2);
+
+ // cleanup
+ g_object_unref (o);
+}