aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2012-10-26 10:02:14 +0200
committerCharles Kerr <charles.kerr@canonical.com>2012-10-26 10:02:14 +0200
commitb7b7ffd56c91ae9622ffebfec4ea4400c96d2fce (patch)
treec5f5fe9fc6b005800e8a52c7c5a8f82a08e0d0b4 /tests
parenta8d3382188e2fad083a287c9656052273f91e845 (diff)
downloadayatana-indicator-power-b7b7ffd56c91ae9622ffebfec4ea4400c96d2fce.tar.gz
ayatana-indicator-power-b7b7ffd56c91ae9622ffebfec4ea4400c96d2fce.tar.bz2
ayatana-indicator-power-b7b7ffd56c91ae9622ffebfec4ea4400c96d2fce.zip
Select the primary device based on the spec's criteria. Add tests to confirm.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-device.cc75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/test-device.cc b/tests/test-device.cc
index 4c6a6f2..c310a58 100644
--- a/tests/test-device.cc
+++ b/tests/test-device.cc
@@ -19,6 +19,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <gtest/gtest.h>
#include "device.h"
+#include "indicator-power.h"
namespace
{
@@ -530,3 +531,77 @@ TEST_F(DeviceTest, Labels)
g_setenv ("LANG", real_lang, TRUE);
g_free (real_lang);
}
+
+static void
+set_device_charge_state (IndicatorPowerDevice * device, int state, int time, double pct)
+{
+ g_object_set (device, INDICATOR_POWER_DEVICE_STATE, state,
+ INDICATOR_POWER_DEVICE_PERCENTAGE, pct,
+ INDICATOR_POWER_DEVICE_TIME, guint64(time),
+ NULL);
+}
+
+
+/* The menu title should tell you at a glance what you need to know most: what
+ device will lose power soonest (and optionally when), or otherwise which
+ device will take longest to charge (and optionally how long it will take). */
+TEST_F(DeviceTest, ChoosePrimary)
+{
+ GSList * devices;
+ IndicatorPowerDevice * a;
+ IndicatorPowerDevice * b;
+
+ a = indicator_power_device_new ("/org/freedesktop/UPower/devices/mouse",
+ UP_DEVICE_KIND_MOUSE,
+ 0.0,
+ UP_DEVICE_STATE_DISCHARGING,
+ 0);
+ b = indicator_power_device_new ("/org/freedesktop/UPower/devices/battery",
+ UP_DEVICE_KIND_BATTERY,
+ 0.0,
+ UP_DEVICE_STATE_DISCHARGING,
+ 0);
+
+ devices = NULL;
+ devices = g_slist_append (devices, a);
+ devices = g_slist_append (devices, b);
+
+ /* Both discharging, same charge %, different times left before empty.
+ Confirm that the one with less time is chosen. */
+ set_device_charge_state (a, UP_DEVICE_STATE_DISCHARGING, 99, 50.0);
+ set_device_charge_state (b, UP_DEVICE_STATE_DISCHARGING, 100, 50.0);
+ ASSERT_EQ (a, indicator_power_choose_primary_device(devices));
+
+ /* Both discharging, different charge % and times left.
+ Confirm that the one with less time is chosen. */
+ set_device_charge_state (a, UP_DEVICE_STATE_DISCHARGING, 99, 50.0);
+ set_device_charge_state (b, UP_DEVICE_STATE_DISCHARGING, 100, 49.0);
+ ASSERT_EQ (a, indicator_power_choose_primary_device(devices));
+
+ /* Both discharging, different charge %, same times left.
+ Confirm that the one with less charge is chosen. */
+ set_device_charge_state (a, UP_DEVICE_STATE_DISCHARGING, 100, 49.0);
+ set_device_charge_state (b, UP_DEVICE_STATE_DISCHARGING, 100, 50.0);
+ ASSERT_EQ (a, indicator_power_choose_primary_device(devices));
+
+ /* Both are charging, have the same charge percentage, and differnt times left (to charge).
+ * Confirm that the one with the most time left is chosen. */
+ set_device_charge_state (a, UP_DEVICE_STATE_CHARGING, 49, 50.0);
+ set_device_charge_state (b, UP_DEVICE_STATE_CHARGING, 50, 50.0);
+ ASSERT_EQ (b, indicator_power_choose_primary_device(devices));
+
+ /* Both are charging, with different charges and time left.
+ Confirm that the one with the most time left is chosen. */
+ set_device_charge_state (a, UP_DEVICE_STATE_CHARGING, 49, 50.0);
+ set_device_charge_state (b, UP_DEVICE_STATE_CHARGING, 50, 49.0);
+ ASSERT_EQ (b, indicator_power_choose_primary_device(devices));
+
+ /* Both are charging, have the same time left, and different charges.
+ * Confirm that the one with less charge is chosen. */
+ set_device_charge_state (a, UP_DEVICE_STATE_CHARGING, 50, 50.0);
+ set_device_charge_state (b, UP_DEVICE_STATE_CHARGING, 50, 49.0);
+ ASSERT_EQ (b, indicator_power_choose_primary_device(devices));
+
+ // cleanup
+ g_slist_free_full (devices, g_object_unref);
+}