LCOV - code coverage report
Current view: top level - glib/gio/tests - permission.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 50 50 100.0 %
Date: 2024-04-23 05:16:05 Functions: 4 4 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Unit tests for GPermission
       2                 :            :  * Copyright (C) 2012 Red Hat, Inc
       3                 :            :  * Author: Matthias Clasen
       4                 :            :  *
       5                 :            :  * SPDX-License-Identifier: LicenseRef-old-glib-tests
       6                 :            :  *
       7                 :            :  * This work is provided "as is"; redistribution and modification
       8                 :            :  * in whole or in part, in any medium, physical or electronic is
       9                 :            :  * permitted without restriction.
      10                 :            :  *
      11                 :            :  * This work is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
      14                 :            :  *
      15                 :            :  * In no event shall the authors or contributors be liable for any
      16                 :            :  * direct, indirect, incidental, special, exemplary, or consequential
      17                 :            :  * damages (including, but not limited to, procurement of substitute
      18                 :            :  * goods or services; loss of use, data, or profits; or business
      19                 :            :  * interruption) however caused and on any theory of liability, whether
      20                 :            :  * in contract, strict liability, or tort (including negligence or
      21                 :            :  * otherwise) arising in any way out of the use of this software, even
      22                 :            :  * if advised of the possibility of such damage.
      23                 :            :  */
      24                 :            : 
      25                 :            : #include <gio/gio.h>
      26                 :            : 
      27                 :            : static void
      28                 :          1 : acquired (GObject      *source,
      29                 :            :           GAsyncResult *res,
      30                 :            :           gpointer      user_data)
      31                 :            : {
      32                 :          1 :   GPermission *p = G_PERMISSION (source);
      33                 :          1 :   GMainLoop *loop = user_data;
      34                 :          1 :   GError *error = NULL;
      35                 :            :   gboolean ret;
      36                 :            : 
      37                 :          1 :   ret = g_permission_acquire_finish (p, res, &error);
      38                 :          1 :   g_assert (!ret);
      39                 :          1 :   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED);
      40                 :          1 :   g_clear_error (&error);
      41                 :            : 
      42                 :          1 :   g_main_loop_quit (loop);
      43                 :          1 : }
      44                 :            : 
      45                 :            : static void
      46                 :          1 : released (GObject      *source,
      47                 :            :           GAsyncResult *res,
      48                 :            :           gpointer      user_data)
      49                 :            : {
      50                 :          1 :   GPermission *p = G_PERMISSION (source);
      51                 :          1 :   GMainLoop *loop = user_data;
      52                 :          1 :   GError *error = NULL;
      53                 :            :   gboolean ret;
      54                 :            : 
      55                 :          1 :   ret = g_permission_release_finish (p, res, &error);
      56                 :          1 :   g_assert (!ret);
      57                 :          1 :   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED);
      58                 :          1 :   g_clear_error (&error);
      59                 :            : 
      60                 :          1 :   g_main_loop_quit (loop);
      61                 :          1 : }
      62                 :            : 
      63                 :            : static void
      64                 :          1 : test_simple (void)
      65                 :            : {
      66                 :            :   GPermission *p;
      67                 :            :   gboolean allowed;
      68                 :            :   gboolean can_acquire;
      69                 :            :   gboolean can_release;
      70                 :            :   gboolean ret;
      71                 :          1 :   GError *error = NULL;
      72                 :            :   GMainLoop *loop;
      73                 :            : 
      74                 :          1 :   p = g_simple_permission_new (TRUE);
      75                 :            : 
      76                 :          1 :   g_assert (g_permission_get_allowed (p));
      77                 :          1 :   g_assert (!g_permission_get_can_acquire (p));
      78                 :          1 :   g_assert (!g_permission_get_can_release (p));
      79                 :            : 
      80                 :          1 :   g_object_get (p,
      81                 :            :                 "allowed", &allowed,
      82                 :            :                 "can-acquire", &can_acquire,
      83                 :            :                 "can-release", &can_release,
      84                 :            :                 NULL);
      85                 :            : 
      86                 :          1 :   g_assert (allowed);
      87                 :          1 :   g_assert (!can_acquire);
      88                 :          1 :   g_assert (!can_release);
      89                 :            : 
      90                 :          1 :   ret = g_permission_acquire (p, NULL, &error);
      91                 :          1 :   g_assert (!ret);
      92                 :          1 :   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED);
      93                 :          1 :   g_clear_error (&error);
      94                 :            : 
      95                 :          1 :   ret = g_permission_release (p, NULL, &error);
      96                 :          1 :   g_assert (!ret);
      97                 :          1 :   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED);
      98                 :          1 :   g_clear_error (&error);
      99                 :            : 
     100                 :          1 :   loop = g_main_loop_new (NULL, FALSE);
     101                 :          1 :   g_permission_acquire_async (p, NULL, acquired, loop);
     102                 :          1 :   g_main_loop_run (loop);
     103                 :          1 :   g_permission_release_async (p, NULL, released, loop);
     104                 :          1 :   g_main_loop_run (loop);
     105                 :            : 
     106                 :          1 :   g_main_loop_unref (loop);
     107                 :            : 
     108                 :          1 :   g_object_unref (p);
     109                 :          1 : }
     110                 :            : 
     111                 :            : int
     112                 :          1 : main (int argc, char *argv[])
     113                 :            : {
     114                 :          1 :   g_test_init (&argc, &argv, NULL);
     115                 :            : 
     116                 :          1 :   g_test_add_func ("/permission/simple", test_simple);
     117                 :            : 
     118                 :          1 :   return g_test_run ();
     119                 :            : }

Generated by: LCOV version 1.14