aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt9
-rw-r--r--tests/device-provider-mock.c107
-rw-r--r--tests/device-provider-mock.h79
-rw-r--r--tests/indicator-power-service-cmdline-battery.cc127
-rw-r--r--tests/manual38
5 files changed, 27 insertions, 333 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index a0d24af..02ecb1b 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -50,12 +50,3 @@ endfunction()
add_test_by_name(test-notify)
add_test(NAME dear-reader-the-next-test-takes-80-seconds COMMAND true)
add_test_by_name(test-device)
-
-###
-###
-
-set (APP_NAME indicator-power-service-cmdline-battery)
-add_executable (${APP_NAME} ${APP_NAME}.cc device-provider-mock.c)
-add_dependencies (${APP_NAME} libindicatorpowerservice)
-target_link_libraries (${APP_NAME} indicatorpowerservice ${SERVICE_DEPS_LIBRARIES})
-
diff --git a/tests/device-provider-mock.c b/tests/device-provider-mock.c
deleted file mode 100644
index afca178..0000000
--- a/tests/device-provider-mock.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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);
-}
diff --git a/tests/device-provider-mock.h b/tests/device-provider-mock.h
deleted file mode 100644
index 4d06924..0000000
--- a/tests/device-provider-mock.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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>
- */
-
-#ifndef __INDICATOR_POWER_DEVICE_PROVIDER_MOCK__H__
-#define __INDICATOR_POWER_DEVICE_PROVIDER_MOCK__H__
-
-#include <glib-object.h> /* parent class */
-
-#include "device.h"
-#include "device-provider.h"
-
-G_BEGIN_DECLS
-
-#define INDICATOR_TYPE_POWER_DEVICE_PROVIDER_MOCK \
- (indicator_power_device_provider_mock_get_type())
-
-#define INDICATOR_POWER_DEVICE_PROVIDER_MOCK(o) \
- (G_TYPE_CHECK_INSTANCE_CAST ((o), \
- INDICATOR_TYPE_POWER_DEVICE_PROVIDER_MOCK, \
- IndicatorPowerDeviceProviderMock))
-
-#define INDICATOR_POWER_DEVICE_PROVIDER_MOCK_GET_CLASS(o) \
- (G_TYPE_INSTANCE_GET_CLASS ((o), \
- INDICATOR_TYPE_POWER_DEVICE_PROVIDER_MOCK, \
- IndicatorPowerDeviceProviderMockClass))
-
-#define INDICATOR_IS_POWER_DEVICE_PROVIDER_MOCK(o) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((o), \
- INDICATOR_TYPE_POWER_DEVICE_PROVIDER_MOCK))
-
-typedef struct _IndicatorPowerDeviceProviderMock
- IndicatorPowerDeviceProviderMock;
-typedef struct _IndicatorPowerDeviceProviderMockPriv
- IndicatorPowerDeviceProviderMockPriv;
-typedef struct _IndicatorPowerDeviceProviderMockClass
- IndicatorPowerDeviceProviderMockClass;
-
-/**
- * An IndicatorPowerDeviceProvider which gets its devices from Mock.
- */
-struct _IndicatorPowerDeviceProviderMock
-{
- GObject parent_instance;
-
- /*< private >*/
- GList * devices;
-};
-
-struct _IndicatorPowerDeviceProviderMockClass
-{
- GObjectClass parent_class;
-};
-
-GType indicator_power_device_provider_mock_get_type (void);
-
-IndicatorPowerDeviceProvider * indicator_power_device_provider_mock_new (void);
-
-void indicator_power_device_provider_add_device (IndicatorPowerDeviceProviderMock * provider,
- IndicatorPowerDevice * device);
-
-G_END_DECLS
-
-#endif /* __INDICATOR_POWER_DEVICE_PROVIDER_MOCK__H__ */
diff --git a/tests/indicator-power-service-cmdline-battery.cc b/tests/indicator-power-service-cmdline-battery.cc
deleted file mode 100644
index 50ed2bb..0000000
--- a/tests/indicator-power-service-cmdline-battery.cc
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * 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 <cstdlib>
-
-#include <locale.h> // setlocale()
-#include <libintl.h> // bindtextdomain()
-#include <unistd.h> // STDIN_FILENO
-
-#include <gio/gio.h>
-
-#include "device-provider-mock.h"
-
-#include "service.h"
-
-/***
-****
-***/
-
-static void
-on_name_lost (gpointer instance G_GNUC_UNUSED, gpointer loop)
-{
- g_message ("exiting: service couldn't acquire or lost ownership of busname");
- g_main_loop_quit (static_cast<GMainLoop*>(loop));
-}
-
-static IndicatorPowerDevice * battery = nullptr;
-
-static GMainLoop * loop = nullptr;
-
-static gboolean on_command_stream_available (GIOChannel *source,
- GIOCondition /*condition*/,
- gpointer /*user_data*/)
-{
- gchar * str = nullptr;
- GError * error = nullptr;
- auto status = g_io_channel_read_line (source, &str, nullptr, nullptr, &error);
- g_assert_no_error (error);
-
- if (status == G_IO_STATUS_NORMAL)
- {
- g_strstrip (str);
-
- if (!g_strcmp0 (str, "charging"))
- {
- g_object_set (battery, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING, nullptr);
- }
- else if (!g_strcmp0 (str, "discharging"))
- {
- g_object_set (battery, INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING, nullptr);
- }
- else
- {
- g_object_set (battery, INDICATOR_POWER_DEVICE_PERCENTAGE, atof(str), nullptr);
- }
- }
- else if (status == G_IO_STATUS_EOF)
- {
- g_main_loop_quit (loop);
- }
-
- g_free (str);
- return G_SOURCE_CONTINUE;
-}
-
-/* this is basically indicator-power-service with a custom provider */
-int
-main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED)
-{
- g_print("This test app has the same code as indicator-power-service\n"
- "except instead of listening to UPower, it has a fake battery\n"
- "which you can edit with keyboard inputs. Supported commands:\n"
- "1. A number in [0..100] to set battery level\n"
- "2. 'charging'\n"
- "3. 'discharging'\n"
- "4. ctrl-c to exit\n");
-
- IndicatorPowerDeviceProvider * device_provider;
- IndicatorPowerService * service;
-
- g_assert(g_setenv("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, true));
- g_assert(g_setenv("GSETTINGS_BACKEND", "memory", true));
-
- /* boilerplate i18n */
- setlocale (LC_ALL, "");
- bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
- textdomain (GETTEXT_PACKAGE);
-
- /* read lines from the command line */
- auto channel = g_io_channel_unix_new (STDIN_FILENO);
- auto watch_tag = g_io_add_watch (channel, G_IO_IN, on_command_stream_available, nullptr);
-
- /* run */
- battery = indicator_power_device_new ("/some/path", UP_DEVICE_KIND_BATTERY, 50.0, UP_DEVICE_STATE_DISCHARGING, 30*60);
- device_provider = indicator_power_device_provider_mock_new ();
- indicator_power_device_provider_add_device (INDICATOR_POWER_DEVICE_PROVIDER_MOCK(device_provider), battery);
- service = indicator_power_service_new (device_provider);
- loop = g_main_loop_new (NULL, FALSE);
- g_signal_connect (service, INDICATOR_POWER_SERVICE_SIGNAL_NAME_LOST,
- G_CALLBACK(on_name_lost), loop);
- g_main_loop_run (loop);
-
- /* cleanup */
- g_main_loop_unref (loop);
- g_source_remove (watch_tag);
- g_io_channel_unref (channel);
- g_clear_object (&service);
- g_clear_object (&device_provider);
- g_clear_object (&battery);
- return 0;
-}
diff --git a/tests/manual b/tests/manual
index 1ec1524..1e6febd 100644
--- a/tests/manual
+++ b/tests/manual
@@ -1,21 +1,37 @@
Notes on Battery Testing
-When building from source, an executable 'indicator-power-service-cmdline-battery' will be built in the tests/ directory. This has the same code as indicator-power-service, except instead of listening to UPower it has a single fake battery that can be set from the command line to set its charge level and whether it's charging or discharging.
+Mock battery propreties are available for testing purposes.
-You'll need to stop the current indicator-power-service before starting the test one. After that, you enter in a number, or 'charging', or 'discharging', to set the fake battery. ctrl-c exits.
+The testing properties are DBus properties published on busname "com.canonical.indicator.power", object path "/com/canonical/indicator/power/Testing", and interface "com.canonical.indicator.power.Testing". The four properties are "MockBatteryEnabled" (boolean, default false), "MockBatteryLevel" (uint32 [0-100], default 50), "MockBatteryState" (string, default 'discharging'), "MockBatteryMinutesLeft" (minutes remaining to charge/discharge, uint32, default 30).
-Example:
+Example use:
-$ stop indicator-power # stop the real indicator-power service
-$ build/tests/indicator-power-service-cmdline-battery # start the test service
-50 # sets the fake battery level to 50%
-30 # sets the fake battery level to 30%
-charging # sets the fake battery to charging
-discharging # sets the fake battery to discharging
-ctrl-c # exits the test service
-$ start indicator-power # restart the real service
+Show the testing properties:
+$ gdbus call --session --dest "com.canonical.indicator.power" \
+ --object-path /com/canonical/indicator/power/Testing \
+ --method org.freedesktop.DBus.Properties.GetAll \
+ com.canonical.indicator.power.Testing
+({'MockBatteryEnabled': <false>, 'MockBatteryLevel': <uint32 50>, 'MockBatteryState': <'discharging'>, 'MockBatteryMinutesLeft': <uint32 30>},)
+
+Enable the mock battery:
+
+$ gdbus call --session --dest "com.canonical.indicator.power" \
+ --object-path /com/canonical/indicator/power/Testing \
+ --method org.freedesktop.DBus.Properties.Set \
+ com.canonical.indicator.power.Testing \
+ MockBatteryEnabled \
+ "<true>"
+
+Set the mock battery's charge to 10%
+
+$ gdbus call --session --dest "com.canonical.indicator.power" \
+ --object-path /com/canonical/indicator/power/Testing \
+ --method org.freedesktop.DBus.Properties.Set \
+ com.canonical.indicator.power.Testing \
+ MockBatteryLevel \
+ "<uint32 10>"
Test-case indicator-power/unity7-items-check