LCOV - code coverage report
Current view: top level - libmogwai-schedule-client/tests - client-schedule-entry.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 42 42 100.0 %
Date: 2022-06-30 20:59:16 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 26 53.8 %

           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                 :            : #include "config.h"
      24                 :            : 
      25                 :            : #include <glib.h>
      26                 :            : #include <gio/gio.h>
      27                 :            : #include <libmogwai-schedule-client/schedule-entry.h>
      28                 :            : #include <locale.h>
      29                 :            : 
      30                 :            : 
      31                 :            : typedef struct
      32                 :            : {
      33                 :            :   GTestDBus *bus;  /* (owned) */
      34                 :            :   GDBusConnection *connection;  /* (owned) */
      35                 :            : } Fixture;
      36                 :            : 
      37                 :            : static void
      38                 :          3 : setup (Fixture       *fixture,
      39                 :            :        gconstpointer  test_data)
      40                 :            : {
      41                 :          2 :   g_autoptr(GError) error = NULL;
      42                 :            : 
      43                 :          3 :   fixture->bus = g_test_dbus_new (G_TEST_DBUS_NONE);
      44                 :          3 :   g_test_dbus_up (fixture->bus);
      45                 :            : 
      46                 :          2 :   fixture->connection = g_dbus_connection_new_for_address_sync (g_test_dbus_get_bus_address (fixture->bus),
      47                 :            :                                                                 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
      48                 :            :                                                                 G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
      49                 :            :                                                                 NULL,
      50                 :            :                                                                 NULL,
      51                 :            :                                                                 &error);
      52         [ -  + ]:          2 :   g_assert_no_error (error);
      53                 :          2 : }
      54                 :            : 
      55                 :            : static void
      56                 :          2 : teardown (Fixture       *fixture,
      57                 :            :           gconstpointer  test_data)
      58                 :            : {
      59         [ +  - ]:          2 :   if (fixture->connection != NULL)
      60                 :          2 :     g_dbus_connection_close_sync (fixture->connection, NULL, NULL);
      61         [ +  - ]:          2 :   g_clear_object (&fixture->connection);
      62                 :            : 
      63                 :          2 :   g_test_dbus_down (fixture->bus);
      64         [ +  - ]:          2 :   g_clear_object (&fixture->bus);
      65                 :          2 : }
      66                 :            : 
      67                 :            : static void
      68                 :          1 : async_result_cb (GObject      *obj,
      69                 :            :                  GAsyncResult *result,
      70                 :            :                  gpointer      user_data)
      71                 :            : {
      72                 :          1 :   GAsyncResult **result_out = user_data;
      73                 :          1 :   *result_out = g_object_ref (result);
      74                 :          1 : }
      75                 :            : 
      76                 :            : /* Test asynchronously constructing an #MwscScheduleEntry object with invalid
      77                 :            :  * arguments. */
      78                 :            : static void
      79                 :          1 : test_service_construction_async_error (Fixture       *fixture,
      80                 :            :                                        gconstpointer  test_data)
      81                 :            : {
      82                 :          1 :   g_autoptr(GAsyncResult) result = NULL;
      83                 :          1 :   g_autoptr(GError) error = NULL;
      84                 :            : 
      85                 :          1 :   mwsc_schedule_entry_new_full_async (fixture->connection,
      86                 :            :                                       "com.endlessm.MogwaiSchedule1.Nonexistent",
      87                 :            :                                       "/com/endlessm/DownloadManager1/Nonexistent",
      88                 :            :                                       NULL,  /* cancellable */
      89                 :            :                                       async_result_cb,
      90                 :            :                                       &result);
      91                 :            : 
      92         [ +  + ]:          4 :   while (result == NULL)
      93                 :          3 :     g_main_context_iteration (NULL, TRUE);
      94                 :            : 
      95                 :          1 :   g_autoptr(MwscScheduleEntry) entry = NULL;
      96                 :          1 :   entry = mwsc_schedule_entry_new_full_finish (result, &error);
      97   [ +  -  +  -  :          1 :   g_assert_error (error, MWSC_SCHEDULE_ENTRY_ERROR,
                   -  + ]
      98                 :            :                   MWSC_SCHEDULE_ENTRY_ERROR_UNKNOWN_ENTRY);
      99         [ -  + ]:          1 :   g_assert_null (entry);
     100                 :          1 : }
     101                 :            : 
     102                 :            : /* Test synchronously constructing an #MwscScheduleEntry object with invalid
     103                 :            :  * arguments. */
     104                 :            : static void
     105                 :          1 : test_service_construction_sync_error (Fixture       *fixture,
     106                 :            :                                       gconstpointer  test_data)
     107                 :            : {
     108                 :          1 :   g_autoptr(MwscScheduleEntry) entry = NULL;
     109                 :          1 :   g_autoptr(GError) error = NULL;
     110                 :            : 
     111                 :          1 :   entry = mwsc_schedule_entry_new_full (fixture->connection,
     112                 :            :                                         "com.endlessm.MogwaiSchedule1.Nonexistent",
     113                 :            :                                         "/com/endlessm/DownloadManager1/Nonexistent",
     114                 :            :                                         NULL,  /* cancellable */
     115                 :            :                                         &error);
     116   [ +  -  +  -  :          1 :   g_assert_error (error, MWSC_SCHEDULE_ENTRY_ERROR,
                   -  + ]
     117                 :            :                   MWSC_SCHEDULE_ENTRY_ERROR_UNKNOWN_ENTRY);
     118         [ -  + ]:          1 :   g_assert_null (entry);
     119                 :          1 : }
     120                 :            : 
     121                 :            : int
     122                 :          2 : main (int    argc,
     123                 :            :       char **argv)
     124                 :            : {
     125                 :          2 :   setlocale (LC_ALL, "");
     126                 :          2 :   g_test_init (&argc, &argv, NULL);
     127                 :            : 
     128                 :          2 :   g_test_add ("/schedule-entry/construction/async/error", Fixture, NULL, setup,
     129                 :            :               test_service_construction_async_error, teardown);
     130                 :          2 :   g_test_add ("/schedule-entry/construction/sync/error", Fixture, NULL, setup,
     131                 :            :               test_service_construction_sync_error, teardown);
     132                 :            : 
     133                 :          2 :   return g_test_run ();
     134                 :            : }

Generated by: LCOV version 1.16