LCOV - code coverage report
Current view: top level - glib/gio/tests - power-profile-monitor.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 11 26 42.3 %
Date: 2024-04-23 05:16:05 Functions: 2 4 50.0 %
Branches: 1 6 16.7 %

           Branch data     Line data    Source code
       1                 :            : /* GIO - GLib Input, Output and Streaming Library
       2                 :            :  *
       3                 :            :  * Copyright 2021 Igalia S.L.
       4                 :            :  *
       5                 :            :  * SPDX-License-Identifier: LGPL-2.1-or-later
       6                 :            :  *
       7                 :            :  * This library is free software; you can redistribute it and/or
       8                 :            :  * modify it under the terms of the GNU Lesser General Public
       9                 :            :  * License as published by the Free Software Foundation; either
      10                 :            :  * version 2.1 of the License, or (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This library is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15                 :            :  * Lesser General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU Lesser General
      18                 :            :  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
      19                 :            :  */
      20                 :            : 
      21                 :            : #include <gio/gio.h>
      22                 :            : 
      23                 :            : static void
      24                 :          1 : test_dup_default (void)
      25                 :            : {
      26                 :            :   GPowerProfileMonitor *monitor;
      27                 :            : 
      28                 :          1 :   monitor = g_power_profile_monitor_dup_default ();
      29                 :          1 :   g_assert_nonnull (monitor);
      30                 :          1 :   g_object_unref (monitor);
      31                 :          1 : }
      32                 :            : 
      33                 :            : static void
      34                 :          0 : power_saver_enabled_cb (GPowerProfileMonitor *monitor,
      35                 :            :                         GParamSpec           *pspec,
      36                 :            :                         gpointer              user_data)
      37                 :            : {
      38                 :            :   gboolean enabled;
      39                 :            : 
      40                 :          0 :   enabled = g_power_profile_monitor_get_power_saver_enabled (monitor);
      41         [ #  # ]:          0 :   g_debug ("Power Saver %s (%d)", enabled ? "enabled" : "disabled", enabled);
      42                 :          0 : }
      43                 :            : 
      44                 :            : static void
      45                 :          0 : do_watch_power_profile (void)
      46                 :            : {
      47                 :            :   GPowerProfileMonitor *monitor;
      48                 :            :   GMainLoop *loop;
      49                 :            :   gulong signal_id;
      50                 :            : 
      51                 :          0 :   monitor = g_power_profile_monitor_dup_default ();
      52                 :          0 :   signal_id = g_signal_connect (G_OBJECT (monitor), "notify::power-saver-enabled",
      53                 :            :                                 G_CALLBACK (power_saver_enabled_cb), NULL);
      54                 :            : 
      55                 :          0 :   loop = g_main_loop_new (NULL, TRUE);
      56                 :          0 :   g_main_loop_run (loop);
      57                 :            : 
      58                 :          0 :   g_signal_handler_disconnect (monitor, signal_id);
      59                 :          0 :   g_object_unref (monitor);
      60                 :          0 :   g_main_loop_unref (loop);
      61                 :          0 : }
      62                 :            : 
      63                 :            : int
      64                 :          1 : main (int argc, char **argv)
      65                 :            : {
      66                 :            :   int ret;
      67                 :            : 
      68   [ -  +  -  - ]:          1 :   if (argc == 2 && !strcmp (argv[1], "--watch"))
      69                 :            :     {
      70                 :          0 :       do_watch_power_profile ();
      71                 :          0 :       return 0;
      72                 :            :     }
      73                 :            : 
      74                 :          1 :   g_test_init (&argc, &argv, NULL);
      75                 :            : 
      76                 :          1 :   g_test_add_func ("/power-profile-monitor/default", test_dup_default);
      77                 :            : 
      78                 :          1 :   ret = g_test_run ();
      79                 :            : 
      80                 :          1 :   return ret;
      81                 :            : }

Generated by: LCOV version 1.14