LCOV - code coverage report
Current view: top level - glib/gio/tests - volumemonitor.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 25 91 27.5 %
Date: 2024-04-23 05:16:05 Functions: 4 7 57.1 %
Branches: 3 26 11.5 %

           Branch data     Line data    Source code
       1                 :            : #include <gio/gio.h>
       2                 :            : 
       3                 :            : static GVolumeMonitor *monitor;
       4                 :            : 
       5                 :            : static void
       6                 :          0 : do_mount_tests (GDrive *drive, GVolume *volume, GMount *mount)
       7                 :            : {
       8                 :            :   GDrive *d;
       9                 :            :   GVolume *v;
      10                 :            :   gchar *name;
      11                 :            :   gchar *uuid;
      12                 :            : 
      13                 :          0 :   name = g_mount_get_name (mount);
      14                 :          0 :   g_assert (name != NULL);
      15                 :          0 :   g_free (name);
      16                 :            : 
      17                 :          0 :   v = g_mount_get_volume (mount);
      18                 :          0 :   g_assert (v == volume);
      19         [ #  # ]:          0 :   if (v != NULL)
      20                 :          0 :     g_object_unref (v);
      21                 :            : 
      22                 :          0 :   d = g_mount_get_drive (mount);
      23                 :          0 :   g_assert (d == drive);
      24         [ #  # ]:          0 :   if (d != NULL)
      25                 :          0 :     g_object_unref (d);
      26                 :            : 
      27                 :          0 :   uuid = g_mount_get_uuid (mount);
      28         [ #  # ]:          0 :   if (uuid)
      29                 :            :     {
      30                 :            :       GMount *m;
      31                 :          0 :       m = g_volume_monitor_get_mount_for_uuid (monitor, uuid);
      32                 :          0 :       g_assert (m == mount);
      33                 :          0 :       g_object_unref (m);
      34                 :          0 :       g_free (uuid);
      35                 :            :     }
      36                 :          0 : }
      37                 :            : 
      38                 :            : static void
      39                 :          0 : do_volume_tests (GDrive *drive, GVolume *volume)
      40                 :            : {
      41                 :            :   GDrive *d;
      42                 :            :   gchar *name;
      43                 :            :   GMount *mount;
      44                 :            :   gchar *uuid;
      45                 :            : 
      46                 :          0 :   name = g_volume_get_name (volume);
      47                 :          0 :   g_assert (name != NULL);
      48                 :          0 :   g_free (name);
      49                 :            : 
      50                 :          0 :   d = g_volume_get_drive (volume);
      51                 :          0 :   g_assert (d == drive);
      52         [ #  # ]:          0 :   if (d != NULL)
      53                 :          0 :     g_object_unref (d);
      54                 :            : 
      55                 :          0 :   mount = g_volume_get_mount (volume);
      56         [ #  # ]:          0 :   if (mount != NULL)
      57                 :            :     {
      58                 :          0 :       do_mount_tests (drive, volume, mount);
      59                 :          0 :       g_object_unref (mount);
      60                 :            :     }
      61                 :            : 
      62                 :          0 :   uuid = g_volume_get_uuid (volume);
      63         [ #  # ]:          0 :   if (uuid)
      64                 :            :     {
      65                 :            :       GVolume *v;
      66                 :          0 :       v = g_volume_monitor_get_volume_for_uuid (monitor, uuid);
      67                 :          0 :       g_assert (v == volume);
      68                 :          0 :       g_object_unref (v);
      69                 :          0 :       g_free (uuid);
      70                 :            :     }
      71                 :          0 : }
      72                 :            : 
      73                 :            : static void
      74                 :          0 : do_drive_tests (GDrive *drive)
      75                 :            : {
      76                 :            :   GList *volumes, *l;
      77                 :            :   gchar *name;
      78                 :            :   gboolean has_volumes;
      79                 :            : 
      80                 :          0 :   g_assert (G_IS_DRIVE (drive));
      81                 :          0 :   name = g_drive_get_name (drive);
      82                 :          0 :   g_assert (name != NULL);
      83                 :          0 :   g_free (name);
      84                 :            : 
      85                 :          0 :   has_volumes = g_drive_has_volumes (drive);
      86                 :          0 :   volumes = g_drive_get_volumes (drive);
      87                 :          0 :   g_assert (has_volumes == (volumes != NULL));
      88         [ #  # ]:          0 :   for (l = volumes; l; l = l->next)
      89                 :            :     {
      90                 :          0 :       GVolume *volume = l->data;
      91                 :          0 :       do_volume_tests (drive, volume);
      92                 :            :     }
      93                 :            : 
      94                 :          0 :   g_list_free_full (volumes, g_object_unref);
      95                 :          0 : }
      96                 :            : 
      97                 :            : static void
      98                 :          1 : test_connected_drives (void)
      99                 :            : {
     100                 :            :   GList *drives;
     101                 :            :   GList *l;
     102                 :            : 
     103                 :          1 :   drives = g_volume_monitor_get_connected_drives (monitor);
     104                 :            : 
     105         [ -  + ]:          1 :   for (l = drives; l; l = l->next)
     106                 :            :     {
     107                 :          0 :       GDrive *drive = l->data;
     108                 :          0 :       do_drive_tests (drive);
     109                 :            :     }
     110                 :            : 
     111                 :          1 :   g_list_free_full (drives, g_object_unref);
     112                 :          1 : }
     113                 :            : 
     114                 :            : static void
     115                 :          1 : test_volumes (void)
     116                 :            : {
     117                 :            :   GList *volumes, *l;
     118                 :            : 
     119                 :          1 :   volumes = g_volume_monitor_get_volumes (monitor);
     120                 :            : 
     121         [ -  + ]:          1 :   for (l = volumes; l; l = l->next)
     122                 :            :     {
     123                 :          0 :       GVolume *volume = l->data;
     124                 :            :       GDrive *drive;
     125                 :            : 
     126                 :          0 :       drive = g_volume_get_drive (volume);
     127                 :          0 :       do_volume_tests (drive, volume);
     128         [ #  # ]:          0 :       if (drive != NULL)
     129                 :          0 :         g_object_unref (drive);
     130                 :            :     }
     131                 :            : 
     132                 :          1 :   g_list_free_full (volumes, g_object_unref);
     133                 :          1 : }
     134                 :            : 
     135                 :            : static void
     136                 :          1 : test_mounts (void)
     137                 :            : {
     138                 :            :   GList *mounts, *l;
     139                 :            : 
     140                 :          1 :   mounts = g_volume_monitor_get_mounts (monitor);
     141                 :            : 
     142         [ -  + ]:          1 :   for (l = mounts; l; l = l->next)
     143                 :            :     {
     144                 :          0 :       GMount *mount = l->data;
     145                 :            :       GVolume *volume;
     146                 :            :       GDrive *drive;
     147                 :            : 
     148                 :          0 :       drive = g_mount_get_drive (mount);
     149                 :          0 :       volume = g_mount_get_volume (mount);
     150                 :          0 :       do_mount_tests (drive, volume, mount);
     151                 :            : 
     152         [ #  # ]:          0 :       if (drive != NULL)
     153                 :          0 :         g_object_unref (drive);
     154         [ #  # ]:          0 :       if (volume != NULL)
     155                 :          0 :         g_object_unref (volume);
     156                 :            :     }
     157                 :            : 
     158                 :          1 :   g_list_free_full (mounts, g_object_unref);
     159                 :          1 : }
     160                 :            : int
     161                 :          1 : main (int argc, char *argv[])
     162                 :            : {
     163                 :            :   gboolean ret;
     164                 :            : 
     165                 :          1 :   g_setenv ("GIO_USE_VFS", "local", FALSE);
     166                 :            : 
     167                 :          1 :   g_test_init (&argc, &argv, NULL);
     168                 :            : 
     169                 :          1 :   monitor = g_volume_monitor_get ();
     170                 :            : 
     171                 :          1 :   g_test_add_func ("/volumemonitor/connected_drives", test_connected_drives);
     172                 :          1 :   g_test_add_func ("/volumemonitor/volumes", test_volumes);
     173                 :          1 :   g_test_add_func ("/volumemonitor/mounts", test_mounts);
     174                 :            : 
     175                 :          1 :   ret = g_test_run ();
     176                 :            : 
     177                 :          1 :   g_object_unref (monitor);
     178                 :            : 
     179                 :          1 :   return ret;
     180                 :            : }

Generated by: LCOV version 1.14