LCOV - code coverage report
Current view: top level - libglib-testing - dbus-queue.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 1 1 100.0 %
Date: 2022-03-10 11:32:37 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 2 100.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
       2                 :            :  *
       3                 :            :  * Copyright © 2018 Endless Mobile, Inc.
       4                 :            :  *
       5                 :            :  * This library is free software; you can redistribute it and/or
       6                 :            :  * modify it under the terms of the GNU Lesser General Public
       7                 :            :  * License as published by the Free Software Foundation; either
       8                 :            :  * version 2.1 of the License, or (at your option) any later version.
       9                 :            :  *
      10                 :            :  * This library is distributed in the hope that it will be useful,
      11                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      12                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13                 :            :  * Lesser General Public License for more details.
      14                 :            :  *
      15                 :            :  * You should have received a copy of the GNU Lesser General Public
      16                 :            :  * License along with this library; if not, write to the Free Software
      17                 :            :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
      18                 :            :  *
      19                 :            :  * Authors:
      20                 :            :  *  - Philip Withnall <withnall@endlessm.com>
      21                 :            :  */
      22                 :            : 
      23                 :            : #pragma once
      24                 :            : 
      25                 :            : #include <gio/gio.h>
      26                 :            : #include <glib.h>
      27                 :            : #include <glib-object.h>
      28                 :            : 
      29                 :            : G_BEGIN_DECLS
      30                 :            : 
      31                 :            : typedef struct _GtDBusQueue GtDBusQueue;
      32                 :            : 
      33                 :            : GtDBusQueue *gt_dbus_queue_new  (void);
      34                 :            : void         gt_dbus_queue_free (GtDBusQueue *self);
      35                 :            : 
      36         [ +  + ]:         14 : G_DEFINE_AUTOPTR_CLEANUP_FUNC (GtDBusQueue, gt_dbus_queue_free)
      37                 :            : 
      38                 :            : GDBusConnection *gt_dbus_queue_get_client_connection (GtDBusQueue *self);
      39                 :            : 
      40                 :            : gboolean gt_dbus_queue_connect         (GtDBusQueue         *self,
      41                 :            :                                         GError             **error);
      42                 :            : void     gt_dbus_queue_disconnect      (GtDBusQueue         *self,
      43                 :            :                                         gboolean             assert_queue_empty);
      44                 :            : 
      45                 :            : guint    gt_dbus_queue_own_name        (GtDBusQueue         *self,
      46                 :            :                                         const gchar         *name);
      47                 :            : void     gt_dbus_queue_unown_name      (GtDBusQueue         *self,
      48                 :            :                                         guint                id);
      49                 :            : 
      50                 :            : guint    gt_dbus_queue_export_object   (GtDBusQueue         *self,
      51                 :            :                                         const gchar         *object_path,
      52                 :            :                                         GDBusInterfaceInfo  *interface_info,
      53                 :            :                                         GError             **error);
      54                 :            : void     gt_dbus_queue_unexport_object (GtDBusQueue         *self,
      55                 :            :                                         guint                id);
      56                 :            : 
      57                 :            : /**
      58                 :            :  * GtDBusQueueServerFunc:
      59                 :            :  * @queue: a #GtDBusQueue
      60                 :            :  * @user_data: user data passed to gt_dbus_queue_set_server_func()
      61                 :            :  *
      62                 :            :  * Function called in the server thread to handle incoming method calls. See
      63                 :            :  * gt_dbus_queue_set_server_func() for details.
      64                 :            :  *
      65                 :            :  * Since: 0.1.0
      66                 :            :  */
      67                 :            : typedef void (*GtDBusQueueServerFunc) (GtDBusQueue *queue,
      68                 :            :                                        gpointer     user_data);
      69                 :            : 
      70                 :            : void     gt_dbus_queue_set_server_func (GtDBusQueue           *self,
      71                 :            :                                         GtDBusQueueServerFunc  func,
      72                 :            :                                         gpointer               user_data);
      73                 :            : 
      74                 :            : gsize    gt_dbus_queue_get_n_messages   (GtDBusQueue            *self);
      75                 :            : gboolean gt_dbus_queue_try_pop_message  (GtDBusQueue            *self,
      76                 :            :                                          GDBusMethodInvocation **out_invocation);
      77                 :            : gboolean gt_dbus_queue_pop_message      (GtDBusQueue            *self,
      78                 :            :                                          GDBusMethodInvocation **out_invocation);
      79                 :            : 
      80                 :            : gboolean gt_dbus_queue_match_client_message (GtDBusQueue           *self,
      81                 :            :                                              GDBusMethodInvocation *invocation,
      82                 :            :                                              const gchar           *expected_object_path,
      83                 :            :                                              const gchar           *expected_interface_name,
      84                 :            :                                              const gchar           *expected_method_name,
      85                 :            :                                              const gchar           *expected_parameters_string);
      86                 :            : 
      87                 :            : gchar   *gt_dbus_queue_format_message       (GDBusMethodInvocation *invocation);
      88                 :            : gchar   *gt_dbus_queue_format_messages      (GtDBusQueue           *self);
      89                 :            : 
      90                 :            : /**
      91                 :            :  * gt_dbus_queue_assert_no_messages:
      92                 :            :  * @self: a #GtDBusQueue
      93                 :            :  *
      94                 :            :  * Assert that there are no messages currently in the mock service’s message
      95                 :            :  * queue.
      96                 :            :  *
      97                 :            :  * If there are, an assertion fails and some debug output is printed.
      98                 :            :  *
      99                 :            :  * Since: 0.1.0
     100                 :            :  */
     101                 :            : #define gt_dbus_queue_assert_no_messages(self) \
     102                 :            :   G_STMT_START { \
     103                 :            :     if (gt_dbus_queue_get_n_messages (self) > 0) \
     104                 :            :       { \
     105                 :            :         g_autofree gchar *anm_list = gt_dbus_queue_format_messages (self); \
     106                 :            :         g_autofree gchar *anm_message = \
     107                 :            :             g_strdup_printf ("Expected no messages, but saw %" G_GSIZE_FORMAT ":\n%s", \
     108                 :            :                              gt_dbus_queue_get_n_messages (self), \
     109                 :            :                              anm_list); \
     110                 :            :         g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
     111                 :            :                              anm_message); \
     112                 :            :       } \
     113                 :            :   } G_STMT_END
     114                 :            : 
     115                 :            : /**
     116                 :            :  * gt_dbus_queue_assert_pop_message:
     117                 :            :  * @self: a #GtDBusQueue
     118                 :            :  * @expected_object_path: object path the invocation is expected to be calling
     119                 :            :  * @expected_interface_name: interface name the invocation is expected to be calling
     120                 :            :  * @expected_method_name: method name the invocation is expected to be calling
     121                 :            :  * @parameters_format: g_variant_get() format string to extract the parameters
     122                 :            :  *    from the popped #GDBusMethodInvocation into the return locations provided
     123                 :            :  *    in @...
     124                 :            :  * @...: return locations for the parameter placeholders given in @parameters_format
     125                 :            :  *
     126                 :            :  * Assert that a message can be popped off the mock service’s message queue
     127                 :            :  * (using gt_dbus_queue_pop_message(), which will block) and that it is a method
     128                 :            :  * call from the #GtDBusQueue’s client connection to the mock service, calling
     129                 :            :  * @expected_method_name on @expected_interface_name at @expected_object_path
     130                 :            :  * (as determined using gt_dbus_queue_match_client_message() with a %NULL
     131                 :            :  * parameters argument). The parameters in the method call will be returned in
     132                 :            :  * the return locations given in the varargs, according to the
     133                 :            :  * @parameters_format, using g_variant_get_va().
     134                 :            :  *
     135                 :            :  * If a timeout occurs when popping a message, or if the popped message doesn’t
     136                 :            :  * match the expected object path, interface name or method name, an assertion
     137                 :            :  * fails and some debug output is printed.
     138                 :            :  *
     139                 :            :  * Returns: (transfer full): the popped #GDBusMethodInvocation
     140                 :            :  * Since: 0.1.0
     141                 :            :  */
     142                 :            : #define gt_dbus_queue_assert_pop_message(self, expected_object_path, expected_interface_name, expected_method_name, parameters_format, ...) \
     143                 :            :   gt_dbus_queue_assert_pop_message_impl (self, G_LOG_DOMAIN, __FILE__, __LINE__, \
     144                 :            :                                          G_STRFUNC, expected_object_path, \
     145                 :            :                                          expected_interface_name, \
     146                 :            :                                          expected_method_name, \
     147                 :            :                                          parameters_format, __VA_ARGS__)
     148                 :            : 
     149                 :            : /* Private implementations of the assertion functions above. */
     150                 :            : 
     151                 :            : /*< private >*/
     152                 :            : GDBusMethodInvocation *gt_dbus_queue_assert_pop_message_impl (GtDBusQueue *self,
     153                 :            :                                                               const gchar *macro_log_domain,
     154                 :            :                                                               const gchar *macro_file,
     155                 :            :                                                               gint         macro_line,
     156                 :            :                                                               const gchar *macro_function,
     157                 :            :                                                               const gchar *object_path,
     158                 :            :                                                               const gchar *interface_name,
     159                 :            :                                                               const gchar *method_name,
     160                 :            :                                                               const gchar *parameters_format,
     161                 :            :                                                               ...);
     162                 :            : 
     163                 :            : G_END_DECLS

Generated by: LCOV version 1.14