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

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2019 Canonical Limited
       3                 :            :  *
       4                 :            :  * SPDX-License-Identifier: LGPL-2.1-or-later
       5                 :            :  *
       6                 :            :  * This library is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU Lesser General Public
       8                 :            :  * License as published by the Free Software Foundation; either
       9                 :            :  * version 2.1 of the License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This library 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.  See the GNU
      14                 :            :  * Lesser General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU Lesser General
      17                 :            :  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
      18                 :            :  *
      19                 :            :  * Authors: James Henstridge <james.henstridge@canonical.com>
      20                 :            :  */
      21                 :            : 
      22                 :            : /* A stub implementation of xdg-document-portal covering enough to
      23                 :            :  * support g_document_portal_add_documents */
      24                 :            : 
      25                 :            : #include <glib.h>
      26                 :            : #include <gio/gio.h>
      27                 :            : #include <gio/gunixfdlist.h>
      28                 :            : 
      29                 :            : #include "fake-document-portal-generated.h"
      30                 :            : 
      31                 :            : static gboolean
      32                 :          0 : on_handle_get_mount_point (FakeDocuments         *object,
      33                 :            :                            GDBusMethodInvocation *invocation,
      34                 :            :                            gpointer               user_data)
      35                 :            : {
      36                 :          0 :   fake_documents_complete_get_mount_point (object,
      37                 :            :                                            invocation,
      38                 :            :                                            "/document-portal");
      39                 :          0 :   return TRUE;
      40                 :            : }
      41                 :            : 
      42                 :            : static gboolean
      43                 :          0 : on_handle_add_full (FakeDocuments         *object,
      44                 :            :                     GDBusMethodInvocation *invocation,
      45                 :            :                     GUnixFDList           *o_path_fds,
      46                 :            :                     guint                  flags,
      47                 :            :                     const gchar           *app_id,
      48                 :            :                     const gchar * const   *permissions,
      49                 :            :                     gpointer               user_data)
      50                 :            : {
      51                 :          0 :   const gchar **doc_ids = NULL;
      52                 :          0 :   GVariant *extra_out = NULL;
      53                 :            :   gsize length, i;
      54                 :            : 
      55         [ #  # ]:          0 :   if (o_path_fds != NULL)
      56                 :          0 :     length = g_unix_fd_list_get_length (o_path_fds);
      57                 :            :   else
      58                 :          0 :     length = 0;
      59                 :            : 
      60                 :          0 :   doc_ids = g_new0 (const gchar *, length + 1  /* NULL terminator */);
      61         [ #  # ]:          0 :   for (i = 0; i < length; i++)
      62                 :            :     {
      63                 :          0 :       doc_ids[i] = "document-id";
      64                 :            :     }
      65                 :          0 :   extra_out = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
      66                 :            : 
      67                 :          0 :   fake_documents_complete_add_full (object,
      68                 :            :                                     invocation,
      69                 :            :                                     NULL,
      70                 :            :                                     doc_ids,
      71                 :            :                                     extra_out);
      72                 :            : 
      73                 :          0 :   g_free (doc_ids);
      74                 :            : 
      75                 :          0 :   return TRUE;
      76                 :            : }
      77                 :            : 
      78                 :            : static void
      79                 :          0 : on_bus_acquired (GDBusConnection *connection,
      80                 :            :                  const gchar     *name,
      81                 :            :                  gpointer         user_data)
      82                 :            : {
      83                 :            :   FakeDocuments *interface;
      84                 :          0 :   GError *error = NULL;
      85                 :            : 
      86                 :          0 :   g_test_message ("Acquired a message bus connection");
      87                 :            : 
      88                 :          0 :   interface = fake_documents_skeleton_new ();
      89                 :          0 :   g_signal_connect (interface,
      90                 :            :                     "handle-get-mount-point",
      91                 :            :                     G_CALLBACK (on_handle_get_mount_point),
      92                 :            :                     NULL);
      93                 :          0 :   g_signal_connect (interface,
      94                 :            :                     "handle-add-full",
      95                 :            :                     G_CALLBACK (on_handle_add_full),
      96                 :            :                     NULL);
      97                 :            : 
      98                 :          0 :   g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (interface),
      99                 :            :                                     connection,
     100                 :            :                                     "/org/freedesktop/portal/documents",
     101                 :            :                                     &error);
     102                 :          0 :   g_assert_no_error (error);
     103                 :          0 : }
     104                 :            : 
     105                 :            : static void
     106                 :          0 : on_name_acquired (GDBusConnection *connection,
     107                 :            :                   const gchar     *name,
     108                 :            :                   gpointer         user_data)
     109                 :            : {
     110                 :          0 :   g_test_message ("Acquired the name %s", name);
     111                 :          0 : }
     112                 :            : 
     113                 :            : static void
     114                 :          0 : on_name_lost (GDBusConnection *connection,
     115                 :            :               const gchar     *name,
     116                 :            :               gpointer         user_data)
     117                 :            : {
     118                 :          0 :   g_test_message ("Lost the name %s", name);
     119                 :          0 : }
     120                 :            : 
     121                 :            : 
     122                 :            : gint
     123                 :          0 : main (gint argc, gchar *argv[])
     124                 :            : {
     125                 :            :   GMainLoop *loop;
     126                 :            :   guint id;
     127                 :            : 
     128                 :          0 :   g_log_writer_default_set_use_stderr (TRUE);
     129                 :            : 
     130                 :          0 :   loop = g_main_loop_new (NULL, FALSE);
     131                 :            : 
     132                 :          0 :   id = g_bus_own_name (G_BUS_TYPE_SESSION,
     133                 :            :                        "org.freedesktop.portal.Documents",
     134                 :            :                        G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
     135                 :            :                        G_BUS_NAME_OWNER_FLAGS_REPLACE,
     136                 :            :                        on_bus_acquired,
     137                 :            :                        on_name_acquired,
     138                 :            :                        on_name_lost,
     139                 :            :                        loop,
     140                 :            :                        NULL);
     141                 :            : 
     142                 :          0 :   g_main_loop_run (loop);
     143                 :            : 
     144                 :          0 :   g_bus_unown_name (id);
     145                 :          0 :   g_main_loop_unref (loop);
     146                 :            : 
     147                 :          0 :   return 0;
     148                 :            : }

Generated by: LCOV version 1.14