Back to index

indicator-power  12.10.0
Classes | Functions
test-indicator.cc File Reference
#include <gtest/gtest.h>
#include "dbus-listener.h"
#include "device.h"
#include "indicator-power.h"

Go to the source code of this file.

Classes

class  IndicatorTest

Functions

 TEST_F (IndicatorTest, GObjectNew)
 TEST_F (IndicatorTest, SetDevices)
 TEST_F (IndicatorTest, DischargingStrings)
 TEST_F (IndicatorTest, ChargingStrings)
 TEST_F (IndicatorTest, ChargedStrings)
 TEST_F (IndicatorTest, AvoidChargingBatteriesWithZeroSecondsLeft)
 TEST_F (IndicatorTest, OtherDevices)
 TEST_F (IndicatorTest, NoDevices)

Function Documentation

TEST_F ( IndicatorTest  ,
GObjectNew   
)

Definition at line 93 of file test-indicator.cc.

{
  GObject * o = G_OBJECT (g_object_new (INDICATOR_POWER_TYPE, NULL));
  ASSERT_TRUE (o != NULL);
  ASSERT_TRUE (IS_INDICATOR_POWER(o));
  g_object_run_dispose (o); // used to get coverage of both branches in the object's dispose func's g_clear_*() calls
  g_object_unref (o);
}
TEST_F ( IndicatorTest  ,
SetDevices   
)

Definition at line 102 of file test-indicator.cc.

{
  GSList * devices;
  IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL));

  devices = NULL;
  devices = g_slist_append (devices, ac_device);
  devices = g_slist_append (devices, battery_device);
  indicator_power_set_devices (power, devices);
  g_slist_free (devices); 

  g_object_unref (power);
}

Here is the call graph for this function:

TEST_F ( IndicatorTest  ,
DischargingStrings   
)

Definition at line 116 of file test-indicator.cc.

{
  IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL));
  GSList * devices = g_slist_append (NULL, battery_device);

  // give the indicator a discharging battery with 30 minutes of life left
  g_object_set (battery_device,
                INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,
                INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0,
                INDICATOR_POWER_DEVICE_TIME, guint64(60*30),
                NULL);
  indicator_power_set_devices (power, devices);
  ASSERT_STREQ (GetAccessibleDesc(power), "Battery (30 minutes left (50%))");

  // give the indicator a discharging battery with 1 hour of life left
  g_object_set (battery_device,
                INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_DISCHARGING,
                INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0,
                INDICATOR_POWER_DEVICE_TIME, guint64(60*60),
                NULL);
  indicator_power_set_devices (power, devices);
  ASSERT_STREQ (GetAccessibleDesc(power), "Battery (1 hour left (50%))");

  // give the indicator a discharging battery with 2 hours of life left
  g_object_set (battery_device,
                INDICATOR_POWER_DEVICE_PERCENTAGE, 100.0,
                INDICATOR_POWER_DEVICE_TIME, guint64(60*60*2),
                NULL);
  indicator_power_set_devices (power, devices);
  ASSERT_STREQ (GetAccessibleDesc(power), "Battery (2 hours left (100%))");

  // give the indicator a discharging battery with over 12 hours of life left
  g_object_set (battery_device,
                INDICATOR_POWER_DEVICE_TIME, guint64(60*60*12 + 1),
                NULL);
  indicator_power_set_devices (power, devices);
  ASSERT_STREQ (GetAccessibleDesc(power), "Battery");

  // give the indicator a discharging battery with 29 seconds left
  g_object_set (battery_device,
                INDICATOR_POWER_DEVICE_TIME, guint64(29),
                NULL);
  indicator_power_set_devices (power, devices);
  ASSERT_STREQ (GetAccessibleDesc(power), "Battery (Unknown time left (100%))");

  // what happens if the time estimate isn't available
  g_object_set (battery_device,
                INDICATOR_POWER_DEVICE_TIME, guint64(0),
                INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0,
                NULL);
  indicator_power_set_devices (power, devices);
  ASSERT_STREQ (GetAccessibleDesc(power), "Battery (50%)");

  // what happens if the time estimate AND percentage isn't available
  g_object_set (battery_device,
                INDICATOR_POWER_DEVICE_TIME, guint64(0),
                INDICATOR_POWER_DEVICE_PERCENTAGE, 0.0,
                NULL);
  indicator_power_set_devices (power, devices);
  ASSERT_STREQ (GetAccessibleDesc(power), "Battery (not present)");

  // cleanup
  g_slist_free (devices);
  g_object_unref (power);
}

Here is the call graph for this function:

TEST_F ( IndicatorTest  ,
ChargingStrings   
)

Definition at line 182 of file test-indicator.cc.

{
  IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL));
  GSList * devices = g_slist_prepend (NULL, battery_device);

  // give the indicator a discharging battery with 1 hour of life left
  g_object_set (battery_device,
                INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_CHARGING,
                INDICATOR_POWER_DEVICE_PERCENTAGE, 50.0,
                INDICATOR_POWER_DEVICE_TIME, guint64(60*60),
                NULL);
  indicator_power_set_devices (power, devices);
  ASSERT_STREQ (GetAccessibleDesc(power), "Battery (1 hour to charge (50%))");

  // give the indicator a discharging battery with 2 hours of life left
  g_object_set (battery_device,
                INDICATOR_POWER_DEVICE_TIME, guint64(60*60*2),
                NULL);
  indicator_power_set_devices (power, devices);
  ASSERT_STREQ (GetAccessibleDesc(power), "Battery (2 hours to charge (50%))");

  // cleanup
  g_slist_free (devices);
  g_object_unref (power);
}

Here is the call graph for this function:

TEST_F ( IndicatorTest  ,
ChargedStrings   
)

Definition at line 208 of file test-indicator.cc.

{
  IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL));
  GSList * devices = g_slist_append (NULL, battery_device);

  // give the indicator a discharging battery with 1 hour of life left
  g_object_set (battery_device,
                INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_FULLY_CHARGED,
                INDICATOR_POWER_DEVICE_PERCENTAGE, 100.0,
                INDICATOR_POWER_DEVICE_TIME, guint64(0),
                NULL);
  indicator_power_set_devices (power, devices);
  ASSERT_STREQ (GetAccessibleDesc(power), "Battery (charged)");

  // cleanup
  g_slist_free (devices);
  g_object_unref (power);
}

Here is the call graph for this function:

TEST_F ( IndicatorTest  ,
AvoidChargingBatteriesWithZeroSecondsLeft   
)

Definition at line 227 of file test-indicator.cc.

{
  IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL));

  g_object_set (battery_device,
                INDICATOR_POWER_DEVICE_STATE, UP_DEVICE_STATE_FULLY_CHARGED,
                INDICATOR_POWER_DEVICE_PERCENTAGE, 100.0,
                INDICATOR_POWER_DEVICE_TIME, guint64(0),
                NULL);
  IndicatorPowerDevice * bad_battery_device  = indicator_power_device_new (
    "/org/freedesktop/UPower/devices/battery_BAT0",
    UP_DEVICE_KIND_BATTERY,
    53, UP_DEVICE_STATE_CHARGING, 0);

  GSList * devices = NULL;
  devices = g_slist_append (devices, battery_device);
  devices = g_slist_append (devices, bad_battery_device);
  indicator_power_set_devices (power, devices);
  ASSERT_STREQ (GetAccessibleDesc(power), "Battery (53%)");

  // cleanup
  g_slist_free (devices);
  g_object_unref (power);
  g_object_unref (bad_battery_device);
}

Here is the call graph for this function:

TEST_F ( IndicatorTest  ,
OtherDevices   
)

Definition at line 253 of file test-indicator.cc.

{
  IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL));

  g_object_ref (battery_device);
  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,
    0, UP_DEVICE_STATE_UNKNOWN, 0));
  devices = g_slist_append (devices, indicator_power_device_new (
    "/org/freedesktop/UPower/devices/ups", UP_DEVICE_KIND_UPS,
    0, UP_DEVICE_STATE_UNKNOWN, 0));
  devices = g_slist_append (devices, indicator_power_device_new (
    "/org/freedesktop/UPower/devices/keyboard", UP_DEVICE_KIND_KEYBOARD,
    0, UP_DEVICE_STATE_UNKNOWN, 0));
  devices = g_slist_append (devices, indicator_power_device_new (
    "/org/freedesktop/UPower/devices/pda", UP_DEVICE_KIND_PDA,
    0, UP_DEVICE_STATE_UNKNOWN, 0));
  devices = g_slist_append (devices, indicator_power_device_new (
    "/org/freedesktop/UPower/devices/phone", UP_DEVICE_KIND_PHONE,
    0, UP_DEVICE_STATE_UNKNOWN, 0));
  devices = g_slist_append (devices, indicator_power_device_new (
    "/org/freedesktop/UPower/devices/monitor", UP_DEVICE_KIND_MONITOR,
    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,
    0, UP_DEVICE_STATE_UNKNOWN, 0));
  devices = g_slist_append (devices, indicator_power_device_new (
    "/org/freedesktop/UPower/devices/tablet", UP_DEVICE_KIND_TABLET,
    0, UP_DEVICE_STATE_UNKNOWN, 0));
  devices = g_slist_append (devices, indicator_power_device_new (
    "/org/freedesktop/UPower/devices/computer", UP_DEVICE_KIND_COMPUTER,
    0, UP_DEVICE_STATE_UNKNOWN, 0));
  devices = g_slist_append (devices, indicator_power_device_new (
    "/org/freedesktop/UPower/devices/unknown", UP_DEVICE_KIND_UNKNOWN,
    0, UP_DEVICE_STATE_UNKNOWN, 0));

  indicator_power_set_devices (power, devices);

  // FIXME: this tests to confirm the code doesn't crash,
  // but further tests would be helpful

  // cleanup
  g_slist_free_full (devices, g_object_unref);
  g_object_unref (power);
}

Here is the call graph for this function:

TEST_F ( IndicatorTest  ,
NoDevices   
)

Definition at line 301 of file test-indicator.cc.

{
  IndicatorPower * power = INDICATOR_POWER(g_object_new (INDICATOR_POWER_TYPE, NULL));

  indicator_power_set_devices (power, NULL);

  // FIXME: this tests to confirm the code doesn't crash,
  // but further tests would be helpful

  // cleanup
  g_object_unref (power);
}

Here is the call graph for this function: