[gnome-settings-daemon/wip/benzea/backlight: 17/18] power: Test backlight steps and rounding



commit 4e5405eb39c492c6165ab642fcdfbf4872882309
Author: Benjamin Berg <bberg redhat com>
Date:   Fri Apr 20 18:37:22 2018 +0200

    power: Test backlight steps and rounding
    
    This adds a test for the step size and rounding including cases where
    the backlight only has very few steps.

 plugins/power/gsd-backlight.c |  2 ++
 plugins/power/test.py         | 63 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 63 insertions(+), 2 deletions(-)
---
diff --git a/plugins/power/gsd-backlight.c b/plugins/power/gsd-backlight.c
index 62e061c7..84b86915 100644
--- a/plugins/power/gsd-backlight.c
+++ b/plugins/power/gsd-backlight.c
@@ -682,6 +682,8 @@ gsd_backlight_constructed (GObject *object)
 done:
         priv->brightness_target = priv->brightness_val;
         priv->brightness_step = MAX(priv->brightness_step, BRIGHTNESS_STEP_AMOUNT(priv->brightness_max - 
priv->brightness_min + 1));
+
+        g_debug ("Step size for backlight is %i.", priv->brightness_step);
 }
 
 static void
diff --git a/plugins/power/test.py b/plugins/power/test.py
index 988577c0..3b5d7f1e 100755
--- a/plugins/power/test.py
+++ b/plugins/power/test.py
@@ -53,6 +53,8 @@ class PowerPluginTest(gsdtestcase.GSDTestCase):
         os.environ['UMOCKDEV_DIR'] = self.testbed.get_root_dir()
 
         # Create a mock backlight device
+        # Note that this function creates a different backlight device based on
+        # the name of the test.
         self.add_backlight()
 
         # start mock upowerd
@@ -211,7 +213,17 @@ class PowerPluginTest(gsdtestcase.GSDTestCase):
     def get_status(self):
         return self.obj_session_presence_props.Get('org.gnome.SessionManager.Presence', 'status')
 
-    def add_backlight(self, _type="raw", brightness=50, max_brightness=100, enabled="enabled"):
+    def backlight_defaults(self):
+        # Hack to modify the brightness defaults before starting gsd-power.
+        # The alternative would be to create two separate test files.
+        if 'legacy_brightness' in self.id():
+            return 15, 15
+        else:
+            return 100, 50
+
+    def add_backlight(self, _type="raw", enabled="enabled"):
+        max_brightness, brightness = self.backlight_defaults()
+
         # Undo mangling done in GSD
         if max_brightness >= 99:
             max_brightness += 1
@@ -224,7 +236,9 @@ class PowerPluginTest(gsdtestcase.GSDTestCase):
                                                   'brightness', str(brightness)],
                                                  [])
 
-    def get_brightness(self, max_brightness=100):
+    def get_brightness(self):
+        max_brightness = int(open(os.path.join(self.testbed.get_root_dir() + self.backlight, 
'max_brightness')).read())
+
         # self.backlight contains the leading slash, so os.path.join doesn't quite work
         res = int(open(os.path.join(self.testbed.get_root_dir() + self.backlight, 'brightness')).read())
         # Undo mangling done in GSD
@@ -1105,5 +1119,50 @@ class PowerPluginTest(gsdtestcase.GSDTestCase):
         time.sleep(1.0)
         self.assertEqual(self.get_brightness(), 90)
 
+    def test_brightness_step(self):
+        # We cannot use check_plugin_log here because the startup check already
+        # read the relevant message.
+        log = open(self.plugin_log_write.name, 'rb').read()
+        self.assertIn('Step size for backlight is 5.', log)
+
+    def test_legacy_brightness_step(self):
+        # We cannot use check_plugin_log here because the startup check already
+        # read the relevant message.
+        log = open(self.plugin_log_write.name, 'rb').read()
+        self.assertIn('Step size for backlight is 1.', log)
+
+    def test_legacy_brightness_rounding(self):
+        obj_gsd_power = self.session_bus_con.get_object(
+            'org.gnome.SettingsDaemon.Power', '/org/gnome/SettingsDaemon/Power')
+        obj_gsd_power_prop_iface = dbus.Interface(obj_gsd_power, dbus.PROPERTIES_IFACE)
+
+        obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 0)
+        time.sleep(0.2)
+        self.assertEqual(self.get_brightness(), 0)
+        obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 10)
+        time.sleep(0.2)
+        self.assertEqual(self.get_brightness(), 1)
+        obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 20)
+        time.sleep(0.2)
+        self.assertEqual(self.get_brightness(), 3)
+        obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 25)
+        time.sleep(0.2)
+        self.assertEqual(self.get_brightness(), 4)
+        obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 50)
+        time.sleep(0.2)
+        self.assertEqual(self.get_brightness(), 7)
+        obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 52)
+        time.sleep(0.2)
+        self.assertEqual(self.get_brightness(), 8)
+        obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 56)
+        time.sleep(0.2)
+        self.assertEqual(self.get_brightness(), 8)
+        obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 57)
+        time.sleep(0.2)
+        self.assertEqual(self.get_brightness(), 9)
+        obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 98)
+        time.sleep(0.2)
+        self.assertEqual(self.get_brightness(), 15)
+
 # avoid writing to stderr
 unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]