aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRobert Tari <robert@tari.in>2023-04-05 13:25:10 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2023-05-05 23:37:05 +0200
commit906c021e2ebd927b512c9d52c03c17e70c01f065 (patch)
tree7c7449e858ce4a0426a1b2be7270913f5d3b6ae2 /tests
parenteeea7eab9aa5877f8e00cf3993ed088abd498427 (diff)
downloadayatana-indicator-power-906c021e2ebd927b512c9d52c03c17e70c01f065.tar.gz
ayatana-indicator-power-906c021e2ebd927b512c9d52c03c17e70c01f065.tar.bz2
ayatana-indicator-power-906c021e2ebd927b512c9d52c03c17e70c01f065.zip
Use the device model name in the menu
Diffstat (limited to 'tests')
-rw-r--r--tests/test-device.cc103
-rw-r--r--tests/test-notify.cc5
-rw-r--r--tests/test-service.cc28
3 files changed, 74 insertions, 62 deletions
diff --git a/tests/test-device.cc b/tests/test-device.cc
index 7154fcd..f2d4b8f 100644
--- a/tests/test-device.cc
+++ b/tests/test-device.cc
@@ -1,6 +1,6 @@
/*
* Copyright 2012-2016 Canonical Ltd.
- * Copyright 2022 Robert Tari
+ * Copyright 2022-2023 Robert Tari
*
* 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
@@ -83,7 +83,7 @@ class DeviceTest : public ::testing::Test
void check_label (const IndicatorPowerDevice * device,
const char * expected_label)
{
- char * label = indicator_power_device_get_readable_text (device);
+ char * label = indicator_power_device_get_readable_text (device, FALSE);
EXPECT_STREQ (expected_label, label);
g_free (label);
}
@@ -205,6 +205,7 @@ TEST_F(DeviceTest, New)
{
IndicatorPowerDevice * device = indicator_power_device_new ("/object/path",
UP_DEVICE_KIND_BATTERY,
+ "Some Model",
50.0,
UP_DEVICE_STATE_CHARGING,
30,
@@ -212,6 +213,7 @@ TEST_F(DeviceTest, New)
ASSERT_TRUE (device != NULL);
ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(device));
ASSERT_EQ (UP_DEVICE_KIND_BATTERY, indicator_power_device_get_kind(device));
+ ASSERT_STREQ ("Some Model", indicator_power_device_get_model(device));
ASSERT_EQ (UP_DEVICE_STATE_CHARGING, indicator_power_device_get_state(device));
ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));
ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));
@@ -224,9 +226,10 @@ TEST_F(DeviceTest, New)
TEST_F(DeviceTest, NewFromVariant)
{
- auto variant = g_variant_new("(susdutb)",
+ auto variant = g_variant_new("(sussdutb)",
"/object/path",
guint32(UP_DEVICE_KIND_BATTERY),
+ "Some Model",
"icon",
50.0,
guint32(UP_DEVICE_STATE_CHARGING),
@@ -237,6 +240,7 @@ TEST_F(DeviceTest, NewFromVariant)
ASSERT_TRUE (device != NULL);
ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(device));
ASSERT_EQ (UP_DEVICE_KIND_BATTERY, indicator_power_device_get_kind(device));
+ ASSERT_STREQ ("Some Model", indicator_power_device_get_model(device));
ASSERT_EQ (UP_DEVICE_STATE_CHARGING, indicator_power_device_get_state(device));
ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));
ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));
@@ -841,8 +845,10 @@ namespace
{
std::ostringstream o;
const auto path = indicator_power_device_get_object_path(device);
+ const gchar *model = indicator_power_device_get_model(device);
o << kind2str(indicator_power_device_get_kind(device))
+ << ' ' << (model ? model : "noname")
<< ' ' << state2str(indicator_power_device_get_state(device))
<< ' ' << indicator_power_device_get_time(device)<<'m'
<< ' ' << int(ceil(indicator_power_device_get_percentage(device)))<<'%'
@@ -855,14 +861,15 @@ namespace
IndicatorPowerDevice* str2device(const std::string& str)
{
auto tokens = g_strsplit(str.c_str(), " ", 0);
- g_assert(6u == g_strv_length(tokens));
+ g_assert(7u == g_strv_length(tokens));
const auto kind = str2kind(tokens[0]);
- const auto state = str2state(tokens[1]);
- const time_t time = atoi(tokens[2]);
- const double pct = strtod(tokens[3],nullptr);
- const char* path = !g_strcmp0(tokens[4],"nopath") ? nullptr : tokens[4];
- const gboolean power_supply = atoi(tokens[5]);
- auto ret = indicator_power_device_new(path, kind, pct, state, time, power_supply);
+ const char* model = !g_strcmp0(tokens[1],"noname") ? nullptr : tokens[1];
+ const auto state = str2state(tokens[2]);
+ const time_t time = atoi(tokens[3]);
+ const double pct = strtod(tokens[4],nullptr);
+ const char* path = !g_strcmp0(tokens[5],"nopath") ? nullptr : tokens[5];
+ const gboolean power_supply = atoi(tokens[6]);
+ auto ret = indicator_power_device_new(path, kind, model, pct, state, time, power_supply);
g_strfreev(tokens);
return ret;
}
@@ -885,100 +892,100 @@ TEST_F(DeviceTest, ChoosePrimary)
} tests[] = {
{
"one discharging battery",
- "battery discharging 10m 60% bat01 1",
- { "battery discharging 10m 60% bat01 1" }
+ "battery noname discharging 10m 60% bat01 1",
+ { "battery noname discharging 10m 60% bat01 1" }
},
{
"merge two discharging batteries",
- "battery discharging 20m 70% nopath 1",
- { "battery discharging 10m 60% bat01 1", "battery discharging 20m 80% bat02 1" }
+ "battery noname discharging 20m 70% nopath 1",
+ { "battery noname discharging 10m 60% bat01 1", "battery noname discharging 20m 80% bat02 1" }
},
{
"merge two other discharging batteries",
- "battery discharging 30m 90% nopath 1",
- { "battery discharging 20m 80% bat01 1", "battery discharging 30m 100% bat02 1" }
+ "battery noname discharging 30m 90% nopath 1",
+ { "battery noname discharging 20m 80% bat01 1", "battery noname discharging 30m 100% bat02 1" }
},
{
"merge three discharging batteries",
- "battery discharging 30m 80% nopath 1",
- { "battery discharging 10m 60% bat01 1", "battery discharging 20m 80% bat02 1", "battery discharging 30m 100% bat03 1" }
+ "battery noname discharging 30m 80% nopath 1",
+ { "battery noname discharging 10m 60% bat01 1", "battery noname discharging 20m 80% bat02 1", "battery noname discharging 30m 100% bat03 1" }
},
{
"one charging battery",
- "battery charging 10m 60% bat01 1",
- { "battery charging 10m 60% bat01 1" }
+ "battery noname charging 10m 60% bat01 1",
+ { "battery noname charging 10m 60% bat01 1" }
},
{
"merge two charging batteries",
- "battery charging 20m 70% nopath 1",
- { "battery charging 10m 60% bat01 1", "battery charging 20m 80% bat02 1" }
+ "battery noname charging 20m 70% nopath 1",
+ { "battery noname charging 10m 60% bat01 1", "battery noname charging 20m 80% bat02 1" }
},
{
"merge two other charging batteries",
- "battery charging 30m 90% nopath 1",
- { "battery charging 20m 80% bat01 1", "battery charging 30m 100% bat02 1" }
+ "battery noname charging 30m 90% nopath 1",
+ { "battery noname charging 20m 80% bat01 1", "battery noname charging 30m 100% bat02 1" }
},
{
"merge three charging batteries",
- "battery charging 30m 80% nopath 1",
- { "battery charging 10m 60% bat01 1", "battery charging 20m 80% bat02 1", "battery charging 30m 100% bat03 1" }
+ "battery noname charging 30m 80% nopath 1",
+ { "battery noname charging 10m 60% bat01 1", "battery noname charging 20m 80% bat02 1", "battery noname charging 30m 100% bat03 1" }
},
{
"one charged battery",
- "battery charged 0m 100% bat01 1",
- { "battery charged 0m 100% bat01 1" }
+ "battery noname charged 0m 100% bat01 1",
+ { "battery noname charged 0m 100% bat01 1" }
},
{
"merge one charged, one discharging",
- "battery discharging 10m 80% nopath 1",
- { "battery charged 0m 100% bat01 1", "battery discharging 10m 60% bat02 1" }
+ "battery noname discharging 10m 80% nopath 1",
+ { "battery noname charged 0m 100% bat01 1", "battery noname discharging 10m 60% bat02 1" }
},
{
"merged one charged, one charging",
- "battery charging 10m 80% nopath 1",
- { "battery charged 0m 100% bat01 1", "battery charging 10m 60% bat02 1" }
+ "battery noname charging 10m 80% nopath 1",
+ { "battery noname charged 0m 100% bat01 1", "battery noname charging 10m 60% bat02 1" }
},
{
"merged one charged, one charging, one discharging",
- "battery discharging 10m 74% nopath 1",
- { "battery charged 0m 100% bat01 1", "battery charging 10m 60% bat02 1", "battery discharging 10m 60% bat03 1" }
+ "battery noname discharging 10m 74% nopath 1",
+ { "battery noname charged 0m 100% bat01 1", "battery noname charging 10m 60% bat02 1", "battery noname discharging 10m 60% bat03 1" }
},
{
"one discharging mouse and one discharging battery. ignore mouse because it doesn't supply the power",
- "battery discharging 10m 60% bat01 1",
- { "battery discharging 10m 60% bat01 1", "mouse discharging 20m 80% mouse01 0" }
+ "battery noname discharging 10m 60% bat01 1",
+ { "battery noname discharging 10m 60% bat01 1", "mouse noname discharging 20m 80% mouse01 0" }
},
{
"one discharging mouse and a different discharging battery. ignore mouse because it doesn't supply the power",
- "battery discharging 30m 100% bat01 1",
- { "battery discharging 30m 100% bat01 1", "mouse discharging 20m 80% mouse01 0" }
+ "battery noname discharging 30m 100% bat01 1",
+ { "battery noname discharging 30m 100% bat01 1", "mouse noname discharging 20m 80% mouse01 0" }
},
{
"everything comes before power lines #1",
- "battery discharging 10m 60% bat01 1",
- { "battery discharging 10m 60% bat01 1", "line-power unknown 0m 0% lp01 1" }
+ "battery noname discharging 10m 60% bat01 1",
+ { "battery noname discharging 10m 60% bat01 1", "line-power noname unknown 0m 0% lp01 1" }
},
{
"everything comes before power lines #2",
- "battery charging 10m 60% bat01 1",
- { "battery charging 10m 60% bat01 1", "line-power unknown 0m 0% lp01 1" }
+ "battery noname charging 10m 60% bat01 1",
+ { "battery noname charging 10m 60% bat01 1", "line-power noname unknown 0m 0% lp01 1" }
},
{
"everything comes before power lines #3 except that the mouse doesn't supply the power",
- "line-power unknown 0m 0% lp01 1",
- { "mouse discharging 20m 80% mouse01 0", "line-power unknown 0m 0% lp01 1" }
+ "line-power noname unknown 0m 0% lp01 1",
+ { "mouse noname discharging 20m 80% mouse01 0", "line-power noname unknown 0m 0% lp01 1" }
},
{
// https://bugs.launchpad.net/ubuntu/+source/indicator-power/+bug/1470080/comments/10
"don't select a device with unknown state when we have another device with a known state...",
- "battery charged 0m 100% bat01 1",
- { "battery charged 0m 100% bat01 1", "phone unknown 0m 61% phone01 1" }
+ "battery noname charged 0m 100% bat01 1",
+ { "battery noname charged 0m 100% bat01 1", "phone noname unknown 0m 61% phone01 1" }
},
{
// https://bugs.launchpad.net/ubuntu/+source/indicator-power/+bug/1470080/comments/10
"...but do select the unknown state device if nothing else is available",
- "phone unknown 0m 61% phone01 1",
- { "phone unknown 0m 61% phone01 1" }
+ "phone noname unknown 0m 61% phone01 1",
+ { "phone noname unknown 0m 61% phone01 1" }
}
};
diff --git a/tests/test-notify.cc b/tests/test-notify.cc
index 815b5d7..12a80fb 100644
--- a/tests/test-notify.cc
+++ b/tests/test-notify.cc
@@ -1,6 +1,6 @@
/*
* Copyright 2014-2016 Canonical Ltd.
- * Copyright 2021-2022 Robert Tari
+ * Copyright 2021-2023 Robert Tari
*
* 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
@@ -236,6 +236,7 @@ TEST_F(NotifyFixture, PercentageToLevel)
{
auto battery = indicator_power_device_new ("/object/path",
UP_DEVICE_KIND_BATTERY,
+ "Some Model",
50.0,
UP_DEVICE_STATE_DISCHARGING,
30,
@@ -315,6 +316,7 @@ TEST_F(NotifyFixture, LevelsDuringBatteryDrain)
{
auto battery = indicator_power_device_new ("/object/path",
UP_DEVICE_KIND_BATTERY,
+ "Some Model",
50.0,
UP_DEVICE_STATE_DISCHARGING,
30,
@@ -388,6 +390,7 @@ TEST_F(NotifyFixture, EventsThatChangeNotifications)
auto battery = indicator_power_device_new ("/object/path",
UP_DEVICE_KIND_BATTERY,
+ "Some Model",
percent_low + 1.0,
UP_DEVICE_STATE_DISCHARGING,
30,
diff --git a/tests/test-service.cc b/tests/test-service.cc
index b2d4dc4..3db4a0e 100644
--- a/tests/test-service.cc
+++ b/tests/test-service.cc
@@ -1,8 +1,10 @@
/*
* Copyright 2013 Canonical Ltd.
+ * Copyright 2023 Robert Tari
*
* Authors:
* Charles Kerr <charles.kerr@canonical.com>
+ * Robert Tari <robert@tari.in>
*
* 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
@@ -70,12 +72,12 @@ class IndicatorTest : public ::testing::Test
ac_device = indicator_power_device_new (
"/org/freedesktop/UPower/devices/line_power_AC",
- UP_DEVICE_KIND_LINE_POWER,
+ UP_DEVICE_KIND_LINE_POWER, "Some Model",
0.0, UP_DEVICE_STATE_UNKNOWN, 0);
battery_device = indicator_power_device_new (
"/org/freedesktop/UPower/devices/battery_BAT0",
- UP_DEVICE_KIND_BATTERY,
+ UP_DEVICE_KIND_BATTERY, "Some Model",
52.871712, UP_DEVICE_STATE_DISCHARGING, 8834);
}
@@ -247,7 +249,7 @@ TEST_F(IndicatorTest, AvoidChargingBatteriesWithZeroSecondsLeft)
NULL);
IndicatorPowerDevice * bad_battery_device = indicator_power_device_new (
"/org/freedesktop/UPower/devices/battery_BAT0",
- UP_DEVICE_KIND_BATTERY,
+ UP_DEVICE_KIND_BATTERY, "Some Model",
53, UP_DEVICE_STATE_CHARGING, 0);
GSList * devices = NULL;
@@ -270,34 +272,34 @@ TEST_F(IndicatorTest, OtherDevices)
GSList * devices = g_slist_append (NULL, battery_device);
devices = g_slist_append (devices, indicator_power_device_new (
- "/org/freedesktop/UPower/devices/mouse", UP_DEVICE_KIND_MOUSE,
+ "/org/freedesktop/UPower/devices/mouse", UP_DEVICE_KIND_MOUSE, "Some Model",
0, UP_DEVICE_STATE_UNKNOWN, 0));
devices = g_slist_append (devices, indicator_power_device_new (
- "/org/freedesktop/UPower/devices/ups", UP_DEVICE_KIND_UPS,
+ "/org/freedesktop/UPower/devices/ups", UP_DEVICE_KIND_UPS, "Some Model",
0, UP_DEVICE_STATE_UNKNOWN, 0));
devices = g_slist_append (devices, indicator_power_device_new (
- "/org/freedesktop/UPower/devices/keyboard", UP_DEVICE_KIND_KEYBOARD,
+ "/org/freedesktop/UPower/devices/keyboard", UP_DEVICE_KIND_KEYBOARD, "Some Model",
0, UP_DEVICE_STATE_UNKNOWN, 0));
devices = g_slist_append (devices, indicator_power_device_new (
- "/org/freedesktop/UPower/devices/pda", UP_DEVICE_KIND_PDA,
+ "/org/freedesktop/UPower/devices/pda", UP_DEVICE_KIND_PDA, "Some Model",
0, UP_DEVICE_STATE_UNKNOWN, 0));
devices = g_slist_append (devices, indicator_power_device_new (
- "/org/freedesktop/UPower/devices/phone", UP_DEVICE_KIND_PHONE,
+ "/org/freedesktop/UPower/devices/phone", UP_DEVICE_KIND_PHONE, "Some Model",
0, UP_DEVICE_STATE_UNKNOWN, 0));
devices = g_slist_append (devices, indicator_power_device_new (
- "/org/freedesktop/UPower/devices/monitor", UP_DEVICE_KIND_MONITOR,
+ "/org/freedesktop/UPower/devices/monitor", UP_DEVICE_KIND_MONITOR, "Some Model",
0, UP_DEVICE_STATE_UNKNOWN, 0));
devices = g_slist_append (devices, indicator_power_device_new (
- "/org/freedesktop/UPower/devices/media_player", UP_DEVICE_KIND_MEDIA_PLAYER,
+ "/org/freedesktop/UPower/devices/media_player", UP_DEVICE_KIND_MEDIA_PLAYER, "Some Model",
0, UP_DEVICE_STATE_UNKNOWN, 0));
devices = g_slist_append (devices, indicator_power_device_new (
- "/org/freedesktop/UPower/devices/tablet", UP_DEVICE_KIND_TABLET,
+ "/org/freedesktop/UPower/devices/tablet", UP_DEVICE_KIND_TABLET, "Some Model",
0, UP_DEVICE_STATE_UNKNOWN, 0));
devices = g_slist_append (devices, indicator_power_device_new (
- "/org/freedesktop/UPower/devices/computer", UP_DEVICE_KIND_COMPUTER,
+ "/org/freedesktop/UPower/devices/computer", UP_DEVICE_KIND_COMPUTER, "Some Model",
0, UP_DEVICE_STATE_UNKNOWN, 0));
devices = g_slist_append (devices, indicator_power_device_new (
- "/org/freedesktop/UPower/devices/unknown", UP_DEVICE_KIND_UNKNOWN,
+ "/org/freedesktop/UPower/devices/unknown", UP_DEVICE_KIND_UNKNOWN, "Some Model",
0, UP_DEVICE_STATE_UNKNOWN, 0));
indicator_power_set_devices (power, devices);