aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/device.c9
-rw-r--r--tests/test-device.cc14
2 files changed, 22 insertions, 1 deletions
diff --git a/src/device.c b/src/device.c
index b163682..84af69c 100644
--- a/src/device.c
+++ b/src/device.c
@@ -515,6 +515,15 @@ indicator_power_device_get_time_details (const IndicatorPowerDevice * device,
gchar ** details,
gchar ** accessible_name)
{
+ if (!INDICATOR_IS_POWER_DEVICE(device))
+ {
+ *short_details = NULL;
+ *details = NULL;
+ *accessible_name = NULL;
+ g_warning ("%s: %p is not an IndicatorPowerDevice", G_STRFUNC, device);
+ return;
+ }
+
const time_t time = indicator_power_device_get_time (device);
const UpDeviceState state = indicator_power_device_get_state (device);
const gdouble percentage = indicator_power_device_get_percentage (device);
diff --git a/tests/test-device.cc b/tests/test-device.cc
index 525eee0..5d68880 100644
--- a/tests/test-device.cc
+++ b/tests/test-device.cc
@@ -388,8 +388,20 @@ TEST_F(DeviceTest, Labels)
char * real_lang = g_strdup(g_getenv ("LANG"));
g_setenv ("LANG", "en_US.UTF-8", TRUE);
+ /* bad args: NULL device */
+ check_strings (NULL, NULL, NULL, NULL);
+
+ /* bad args: a GObject that isn't a device */
+ GObject * o = G_OBJECT(g_cancellable_new());
+ check_strings ((IndicatorPowerDevice*)o, NULL, NULL, NULL);
+ g_object_unref (o);
+
+ /**
+ ***
+ **/
+
IndicatorPowerDevice * device = INDICATOR_POWER_DEVICE (g_object_new (INDICATOR_POWER_DEVICE_TYPE, NULL));
- GObject * o = G_OBJECT(device);
+ o = G_OBJECT(device);
/* charging */
g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_BATTERY,