aboutsummaryrefslogtreecommitdiff
path: root/tests/device-provider-mock.c
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-07-22 09:58:29 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-07-22 09:58:29 -0500
commit399eab24252eb7c83042de726ebbc4cf9fbb7637 (patch)
tree810442076c15cc62edde1f337afbfe7262b0de6b /tests/device-provider-mock.c
parentdd5f50b07bea7a5dec515a753cf66f060e1d79c6 (diff)
downloadayatana-indicator-power-399eab24252eb7c83042de726ebbc4cf9fbb7637.tar.gz
ayatana-indicator-power-399eab24252eb7c83042de726ebbc4cf9fbb7637.tar.bz2
ayatana-indicator-power-399eab24252eb7c83042de726ebbc4cf9fbb7637.zip
add indicator-power-service-cmdline-battery, a manual test utility to test the indicator's behavior when a battery's state changes
Diffstat (limited to 'tests/device-provider-mock.c')
-rw-r--r--tests/device-provider-mock.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/tests/device-provider-mock.c b/tests/device-provider-mock.c
new file mode 100644
index 0000000..afca178
--- /dev/null
+++ b/tests/device-provider-mock.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2014 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#include "device.h"
+#include "device-provider.h"
+#include "device-provider-mock.h"
+
+/***
+**** GObject boilerplate
+***/
+
+static void indicator_power_device_provider_interface_init (
+ IndicatorPowerDeviceProviderInterface * iface);
+
+G_DEFINE_TYPE_WITH_CODE (
+ IndicatorPowerDeviceProviderMock,
+ indicator_power_device_provider_mock,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (INDICATOR_TYPE_POWER_DEVICE_PROVIDER,
+ indicator_power_device_provider_interface_init))
+
+/***
+**** IndicatorPowerDeviceProvider virtual functions
+***/
+
+static GList *
+my_get_devices (IndicatorPowerDeviceProvider * provider)
+{
+ IndicatorPowerDeviceProviderMock * self = INDICATOR_POWER_DEVICE_PROVIDER_MOCK(provider);
+
+ return g_list_copy_deep (self->devices, (GCopyFunc)g_object_ref, NULL);
+}
+
+/***
+**** GObject virtual functions
+***/
+
+static void
+my_dispose (GObject * o)
+{
+ IndicatorPowerDeviceProviderMock * self = INDICATOR_POWER_DEVICE_PROVIDER_MOCK(o);
+
+ g_list_free_full (self->devices, g_object_unref);
+
+ G_OBJECT_CLASS (indicator_power_device_provider_mock_parent_class)->dispose (o);
+}
+
+/***
+**** Instantiation
+***/
+
+static void
+indicator_power_device_provider_mock_class_init (IndicatorPowerDeviceProviderMockClass * klass)
+{
+ GObjectClass * object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->dispose = my_dispose;
+}
+
+static void
+indicator_power_device_provider_interface_init (IndicatorPowerDeviceProviderInterface * iface)
+{
+ iface->get_devices = my_get_devices;
+}
+
+static void
+indicator_power_device_provider_mock_init (IndicatorPowerDeviceProviderMock * self)
+{
+}
+
+/***
+**** Public API
+***/
+
+IndicatorPowerDeviceProvider *
+indicator_power_device_provider_mock_new (void)
+{
+ gpointer o = g_object_new (INDICATOR_TYPE_POWER_DEVICE_PROVIDER_MOCK, NULL);
+
+ return INDICATOR_POWER_DEVICE_PROVIDER (o);
+}
+
+void
+indicator_power_device_provider_add_device (IndicatorPowerDeviceProviderMock * provider,
+ IndicatorPowerDevice * device)
+{
+ provider->devices = g_list_append (provider->devices, g_object_ref(device));
+
+ g_signal_connect_swapped (device, "notify", G_CALLBACK(indicator_power_device_provider_emit_devices_changed), provider);
+}