LCOV - code coverage report
Current view: top level - libmogwai-schedule/tests - schedule-service.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 185 185 100.0 %
Date: 2022-06-30 20:59:16 Functions: 15 15 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 80 148 54.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
       2                 :            :  *
       3                 :            :  * Copyright © 2017, 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/connection-monitor.h>
      28                 :            : #include <libmogwai-schedule/peer-manager.h>
      29                 :            : #include <libmogwai-schedule/scheduler.h>
      30                 :            : #include <libmogwai-schedule/schedule-service.h>
      31                 :            : #include <libmogwai-schedule/service.h>
      32                 :            : #include <libmogwai-schedule/tests/clock-dummy.h>
      33                 :            : #include <libmogwai-schedule/tests/connection-monitor-dummy.h>
      34                 :            : #include <libmogwai-schedule/tests/peer-manager-dummy.h>
      35                 :            : #include <locale.h>
      36                 :            : 
      37                 :            : 
      38                 :            : static void
      39                 :         13 : async_result_cb (GObject      *obj,
      40                 :            :                  GAsyncResult *result,
      41                 :            :                  gpointer      user_data)
      42                 :            : {
      43                 :         13 :   GAsyncResult **result_out = user_data;
      44                 :         13 :   *result_out = g_object_ref (result);
      45                 :         13 : }
      46                 :            : 
      47                 :            : /* A test fixture which creates an in-process #MwsScheduleService and all the
      48                 :            :  * associated state management, a #GDBusConnection for it, and a
      49                 :            :  * #GDBusConnection for the client. Both connections are on a private
      50                 :            :  * #GTestDBus instance. */
      51                 :            : typedef struct
      52                 :            : {
      53                 :            :   GTestDBus *bus;  /* (owned) */
      54                 :            :   GDBusConnection *server_connection;  /* (owned) */
      55                 :            :   GDBusConnection *client_connection;  /* (owned) */
      56                 :            :   MwsConnectionMonitor *connection_monitor;  /* (owned) */
      57                 :            :   MwsPeerManager *peer_manager;  /* (owned) */
      58                 :            :   MwsClock *clock;  /* (owned) */
      59                 :            :   MwsScheduler *scheduler;  /* (owned) */
      60                 :            :   MwsScheduleService *service;  /* (owned) */
      61                 :            : } BusFixture;
      62                 :            : 
      63                 :            : static void
      64                 :         12 : bus_setup (BusFixture    *fixture,
      65                 :            :            gconstpointer  test_data)
      66                 :            : {
      67                 :         11 :   g_autoptr(GError) local_error = NULL;
      68                 :            : 
      69                 :            :   /* Set up a dummy bus and two connections to it. */
      70                 :         12 :   fixture->bus = g_test_dbus_new (G_TEST_DBUS_NONE);
      71                 :         12 :   g_test_dbus_up (fixture->bus);
      72                 :            : 
      73                 :         11 :   fixture->server_connection = g_dbus_connection_new_for_address_sync (g_test_dbus_get_bus_address (fixture->bus),
      74                 :            :                                                                        G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION |
      75                 :            :                                                                        G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
      76                 :            :                                                                        NULL, NULL,
      77                 :            :                                                                        &local_error);
      78         [ -  + ]:         11 :   g_assert_no_error (local_error);
      79                 :            : 
      80                 :         11 :   fixture->client_connection = g_dbus_connection_new_for_address_sync (g_test_dbus_get_bus_address (fixture->bus),
      81                 :            :                                                                        G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION |
      82                 :            :                                                                        G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
      83                 :            :                                                                        NULL, NULL,
      84                 :            :                                                                        &local_error);
      85         [ -  + ]:         11 :   g_assert_no_error (local_error);
      86                 :            : 
      87                 :         11 :   fixture->connection_monitor = MWS_CONNECTION_MONITOR (mws_connection_monitor_dummy_new ());
      88                 :         11 :   fixture->peer_manager = MWS_PEER_MANAGER (mws_peer_manager_dummy_new (FALSE));
      89                 :         11 :   fixture->clock = MWS_CLOCK (mws_clock_dummy_new ());
      90                 :            : 
      91                 :            :   /* Set some credentials for the first peer so calls don’t fail by default. We
      92                 :            :    * can override this later by calling set_fail(). */
      93                 :         11 :   mws_peer_manager_dummy_set_peer_credentials (MWS_PEER_MANAGER_DUMMY (fixture->peer_manager),
      94                 :            :                                                ":1.1", "/some/peer/path");
      95                 :            : 
      96                 :            :   /* Construct the scheduler manually so we can set max-entries. */
      97                 :         11 :   fixture->scheduler = g_object_new (MWS_TYPE_SCHEDULER,
      98                 :            :                                      "connection-monitor", fixture->connection_monitor,
      99                 :            :                                      "peer-manager", fixture->peer_manager,
     100                 :            :                                      "clock", fixture->clock,
     101                 :            :                                      "max-entries", 10,
     102                 :            :                                      NULL);
     103                 :            : 
     104                 :         11 :   fixture->service = mws_schedule_service_new (fixture->server_connection, "/test",
     105                 :            :                                                fixture->scheduler);
     106                 :            : 
     107         [ -  + ]:         11 :   g_assert_true (mws_schedule_service_register (fixture->service, &local_error));
     108         [ -  + ]:         11 :   g_assert_no_error (local_error);
     109                 :         11 : }
     110                 :            : 
     111                 :            : static void
     112                 :         11 : bus_teardown (BusFixture    *fixture,
     113                 :            :               gconstpointer  test_data)
     114                 :            : {
     115                 :         11 :   g_autoptr(GError) local_error = NULL;
     116                 :            : 
     117                 :         11 :   mws_schedule_service_unregister (fixture->service);
     118         [ +  - ]:         11 :   g_clear_object (&fixture->service);
     119                 :            : 
     120         [ +  - ]:         11 :   g_clear_object (&fixture->scheduler);
     121         [ +  - ]:         11 :   g_clear_object (&fixture->clock);
     122         [ +  - ]:         11 :   g_clear_object (&fixture->peer_manager);
     123         [ +  - ]:         11 :   g_clear_object (&fixture->connection_monitor);
     124                 :            : 
     125                 :         11 :   g_dbus_connection_close_sync (fixture->client_connection, NULL, &local_error);
     126         [ -  + ]:         11 :   g_assert_no_error (local_error);
     127         [ +  - ]:         11 :   g_clear_object (&fixture->client_connection);
     128                 :            : 
     129                 :         11 :   g_dbus_connection_close_sync (fixture->server_connection, NULL, &local_error);
     130         [ -  + ]:         11 :   g_assert_no_error (local_error);
     131         [ +  - ]:         11 :   g_clear_object (&fixture->server_connection);
     132                 :            : 
     133                 :         11 :   g_test_dbus_down (fixture->bus);
     134         [ +  - ]:         11 :   g_clear_object (&fixture->bus);
     135                 :         11 : }
     136                 :            : 
     137                 :            : /* Helper function to synchronously call a D-Bus method on the scheduler using
     138                 :            :  * the #BusFixture.client_connection. */
     139                 :            : static GVariant *
     140                 :         13 : scheduler_call_method (BusFixture    *fixture,
     141                 :            :                        const gchar   *method_name,
     142                 :            :                        GVariant      *parameters,
     143                 :            :                        GVariantType  *reply_type,
     144                 :            :                        GError       **error)
     145                 :            : {
     146         [ -  + ]:         13 :   g_assert (reply_type != NULL);
     147                 :            : 
     148                 :         13 :   g_autoptr(GAsyncResult) result = NULL;
     149                 :         13 :   g_dbus_connection_call (fixture->client_connection,
     150                 :            :                           g_dbus_connection_get_unique_name (fixture->server_connection),
     151                 :            :                           "/test",
     152                 :            :                           "com.endlessm.DownloadManager1.Scheduler",
     153                 :            :                           method_name, parameters, reply_type,
     154                 :            :                           G_DBUS_CALL_FLAGS_NO_AUTO_START,
     155                 :            :                           1000, NULL, async_result_cb, &result);
     156                 :            : 
     157         [ +  + ]:         72 :   while (result == NULL)
     158                 :         59 :     g_main_context_iteration (NULL, TRUE);
     159                 :            : 
     160                 :         13 :   return g_dbus_connection_call_finish (fixture->client_connection,
     161                 :            :                                         result, error);
     162                 :            : }
     163                 :            : 
     164                 :            : /* Test a normal call to Schedule() succeeds. */
     165                 :            : static void
     166                 :          1 : test_service_dbus_schedule (BusFixture    *fixture,
     167                 :            :                             gconstpointer  test_data)
     168                 :            : {
     169                 :          1 :   g_autoptr(GError) local_error = NULL;
     170                 :          1 :   g_autoptr(GVariant) entry_path_variant = NULL;
     171                 :            : 
     172                 :          1 :   entry_path_variant = scheduler_call_method (fixture, "Schedule",
     173                 :            :                                               g_variant_new ("(a{sv})", NULL),
     174                 :          1 :                                               G_VARIANT_TYPE ("(o)"),
     175                 :            :                                               &local_error);
     176         [ -  + ]:          1 :   g_assert_no_error (local_error);
     177         [ -  + ]:          1 :   g_assert_nonnull (entry_path_variant);
     178                 :            : 
     179                 :            :   const gchar *entry_path;
     180                 :          1 :   g_variant_get (entry_path_variant, "(&o)", &entry_path);
     181                 :            : 
     182         [ -  + ]:          1 :   g_assert_cmpstr (entry_path, !=, "");
     183                 :          1 : }
     184                 :            : 
     185                 :            : /* Test that invalid parameters to Schedule() return an error. */
     186                 :            : static void
     187                 :          1 : test_service_dbus_schedule_invalid_parameters (BusFixture    *fixture,
     188                 :            :                                                gconstpointer  test_data)
     189                 :            : {
     190                 :          1 :   g_autoptr(GError) local_error = NULL;
     191                 :          1 :   g_autoptr(GVariant) entry_path_variant = NULL;
     192                 :            : 
     193                 :          1 :   entry_path_variant = scheduler_call_method (fixture, "Schedule",
     194                 :            :                                               g_variant_new_parsed ("({ 'resumable': <'not a boolean'> },)"),
     195                 :          1 :                                               G_VARIANT_TYPE ("(o)"),
     196                 :            :                                               &local_error);
     197   [ +  -  +  -  :          1 :   g_assert_error (local_error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
                   -  + ]
     198         [ -  + ]:          1 :   g_assert_null (entry_path_variant);
     199                 :          1 : }
     200                 :            : 
     201                 :            : /* Test that an invalid peer is rejected when it calls Schedule(). */
     202                 :            : static void
     203                 :          1 : test_service_dbus_schedule_invalid_peer (BusFixture    *fixture,
     204                 :            :                                          gconstpointer  test_data)
     205                 :            : {
     206                 :          1 :   g_autoptr(GError) local_error = NULL;
     207                 :          1 :   g_autoptr(GVariant) entry_path_variant = NULL;
     208                 :            : 
     209                 :            :   /* Tell the dummy peer manager to fail to get the details for any peer. */
     210                 :          1 :   mws_peer_manager_dummy_set_fail (MWS_PEER_MANAGER_DUMMY (fixture->peer_manager), TRUE);
     211                 :            : 
     212                 :          1 :   entry_path_variant = scheduler_call_method (fixture, "Schedule",
     213                 :            :                                               g_variant_new ("(a{sv})", NULL),
     214                 :          1 :                                               G_VARIANT_TYPE ("(o)"),
     215                 :            :                                               &local_error);
     216   [ +  -  +  -  :          1 :   g_assert_error (local_error, MWS_SCHEDULER_ERROR, MWS_SCHEDULER_ERROR_IDENTIFYING_PEER);
                   -  + ]
     217         [ -  + ]:          1 :   g_assert_null (entry_path_variant);
     218                 :          1 : }
     219                 :            : 
     220                 :            : /* Test a normal call to ScheduleEntries() succeeds. The number of entries to
     221                 :            :  * create is passed in @test_data. */
     222                 :            : static void
     223                 :          2 : test_service_dbus_schedule_entries (BusFixture    *fixture,
     224                 :            :                                     gconstpointer  test_data)
     225                 :            : {
     226                 :          2 :   gsize n_entries = GPOINTER_TO_UINT (test_data);
     227                 :          2 :   g_autoptr(GError) local_error = NULL;
     228                 :          2 :   g_autoptr(GVariant) entry_paths_variant = NULL;
     229                 :            : 
     230                 :          4 :   g_auto(GVariantBuilder) builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("aa{sv}"));
     231                 :            : 
     232         [ -  + ]:          2 :   g_assert (n_entries > 0);
     233         [ +  + ]:          6 :   for (gsize i = 0; i < n_entries; i++)
     234                 :          4 :     g_variant_builder_add (&builder, "a{sv}", NULL);
     235                 :            : 
     236                 :          2 :   entry_paths_variant = scheduler_call_method (fixture, "ScheduleEntries",
     237                 :            :                                                g_variant_new ("(aa{sv})",
     238                 :            :                                                               &builder),
     239                 :          2 :                                                G_VARIANT_TYPE ("(ao)"),
     240                 :            :                                                &local_error);
     241         [ -  + ]:          2 :   g_assert_no_error (local_error);
     242         [ -  + ]:          2 :   g_assert_nonnull (entry_paths_variant);
     243                 :            : 
     244                 :          2 :   g_autoptr(GVariantIter) entries_paths_iter = NULL;
     245                 :            :   const gchar *entry_path;
     246                 :          4 :   g_autoptr(GHashTable) entries_paths_set = g_hash_table_new_full (g_str_hash,
     247                 :            :                                                                    g_str_equal,
     248                 :            :                                                                    NULL, NULL);
     249                 :            : 
     250                 :          2 :   g_variant_get (entry_paths_variant, "(ao)", &entries_paths_iter);
     251         [ +  + ]:          6 :   while (g_variant_iter_loop (entries_paths_iter, "&o", &entry_path))
     252                 :            :     {
     253         [ -  + ]:          4 :       g_assert_cmpstr (entry_path, !=, "");
     254         [ -  + ]:          4 :       g_assert_false (g_hash_table_contains (entries_paths_set, entry_path));
     255                 :          4 :       g_hash_table_add (entries_paths_set, entry_path);
     256                 :            :     }
     257                 :            : 
     258         [ -  + ]:          2 :   g_assert_cmpuint (g_hash_table_size (entries_paths_set), ==, n_entries);
     259                 :          2 : }
     260                 :            : 
     261                 :            : /* Test that ScheduleEntries() rejects entries with invalid parameters. The
     262                 :            :  * number of entries to create is passed in @test_data. */
     263                 :            : static void
     264                 :          1 : test_service_dbus_schedule_entries_invalid_parameters (BusFixture    *fixture,
     265                 :            :                                                        gconstpointer  test_data)
     266                 :            : {
     267                 :          1 :   gsize n_entries = GPOINTER_TO_UINT (test_data);
     268                 :          1 :   g_autoptr(GError) local_error = NULL;
     269                 :          1 :   g_autoptr(GVariant) entry_paths_variant = NULL;
     270                 :            : 
     271                 :          2 :   g_auto(GVariantBuilder) builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("aa{sv}"));
     272                 :            : 
     273         [ -  + ]:          1 :   g_assert (n_entries > 0);
     274         [ +  + ]:          4 :   for (gsize i = 0; i < n_entries; i++)
     275                 :          3 :     g_variant_builder_add_parsed (&builder, "{ 'priority': <'not a uint32'> }");
     276                 :            : 
     277                 :          1 :   entry_paths_variant = scheduler_call_method (fixture, "ScheduleEntries",
     278                 :            :                                                g_variant_new ("(aa{sv})",
     279                 :            :                                                               &builder),
     280                 :          1 :                                                G_VARIANT_TYPE ("(ao)"),
     281                 :            :                                                &local_error);
     282   [ +  -  +  -  :          1 :   g_assert_error (local_error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
                   -  + ]
     283         [ -  + ]:          1 :   g_assert_null (entry_paths_variant);
     284                 :          1 : }
     285                 :            : 
     286                 :            : /* Test that ScheduleEntries() rejects entries from peers it can’t identify. The
     287                 :            :  * number of entries to create is passed in @test_data. */
     288                 :            : static void
     289                 :          1 : test_service_dbus_schedule_entries_invalid_peer (BusFixture    *fixture,
     290                 :            :                                                  gconstpointer  test_data)
     291                 :            : {
     292                 :          1 :   gsize n_entries = GPOINTER_TO_UINT (test_data);
     293                 :          1 :   g_autoptr(GError) local_error = NULL;
     294                 :          1 :   g_autoptr(GVariant) entry_paths_variant = NULL;
     295                 :            : 
     296                 :            :   /* Tell the dummy peer manager to fail to get the details for any peer. */
     297                 :          1 :   mws_peer_manager_dummy_set_fail (MWS_PEER_MANAGER_DUMMY (fixture->peer_manager), TRUE);
     298                 :            : 
     299                 :          2 :   g_auto(GVariantBuilder) builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("aa{sv}"));
     300                 :            : 
     301         [ -  + ]:          1 :   g_assert (n_entries > 0);
     302         [ +  + ]:          4 :   for (gsize i = 0; i < n_entries; i++)
     303                 :          3 :     g_variant_builder_add (&builder, "a{sv}", NULL);
     304                 :            : 
     305                 :          1 :   entry_paths_variant = scheduler_call_method (fixture, "ScheduleEntries",
     306                 :            :                                                g_variant_new ("(aa{sv})",
     307                 :            :                                                               &builder),
     308                 :          1 :                                                G_VARIANT_TYPE ("(ao)"),
     309                 :            :                                                &local_error);
     310   [ +  -  +  -  :          1 :   g_assert_error (local_error, MWS_SCHEDULER_ERROR, MWS_SCHEDULER_ERROR_IDENTIFYING_PEER);
                   -  + ]
     311         [ -  + ]:          1 :   g_assert_null (entry_paths_variant);
     312                 :          1 : }
     313                 :            : 
     314                 :            : /* Test that ScheduleEntries() rejects entries which would take it over the
     315                 :            :  * scheduler’s limit on entries. */
     316                 :            : static void
     317                 :          1 : test_service_dbus_schedule_entries_full (BusFixture    *fixture,
     318                 :            :                                          gconstpointer  test_data)
     319                 :            : {
     320                 :            :   guint max_entries;
     321                 :          1 :   g_autoptr(GError) local_error = NULL;
     322                 :          1 :   g_autoptr(GVariant) entry_paths_variant = NULL;
     323                 :            : 
     324                 :            :   /* bus_setup() already sets a low limit on the number of entries. */
     325                 :          1 :   g_object_get (G_OBJECT (fixture->scheduler), "max-entries", &max_entries, NULL);
     326                 :          1 :   g_test_message ("max-entries: %u", max_entries);
     327                 :            : 
     328                 :          2 :   g_auto(GVariantBuilder) builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("aa{sv}"));
     329                 :            : 
     330         [ +  + ]:         12 :   for (gsize i = 0; i <= max_entries; i++)
     331                 :         11 :     g_variant_builder_add (&builder, "a{sv}", NULL);
     332                 :            : 
     333                 :          1 :   entry_paths_variant = scheduler_call_method (fixture, "ScheduleEntries",
     334                 :            :                                                g_variant_new ("(aa{sv})",
     335                 :            :                                                               &builder),
     336                 :          1 :                                                G_VARIANT_TYPE ("(ao)"),
     337                 :            :                                                &local_error);
     338   [ +  -  +  -  :          1 :   g_assert_error (local_error, MWS_SCHEDULER_ERROR, MWS_SCHEDULER_ERROR_FULL);
                   -  + ]
     339         [ -  + ]:          1 :   g_assert_null (entry_paths_variant);
     340                 :          1 : }
     341                 :            : 
     342                 :            : /* Test that Hold() and Release() affect mws_schedule_service_get_busy(). */
     343                 :            : static void
     344                 :          1 : test_service_dbus_hold_normal (BusFixture    *fixture,
     345                 :            :                                gconstpointer  test_data)
     346                 :            : {
     347                 :          1 :   g_autoptr(GError) local_error = NULL;
     348                 :            : 
     349                 :            :   /* The schedule service shouldn’t be busy to begin with. */
     350         [ -  + ]:          1 :   g_assert_false (mws_schedule_service_get_busy (fixture->service));
     351                 :            : 
     352                 :            :   /* Hold it. */
     353                 :          1 :   g_autoptr(GVariant) unit_variant1 = NULL;
     354                 :          1 :   unit_variant1 = scheduler_call_method (fixture, "Hold",
     355                 :            :                                          g_variant_new ("(s)", "Test reason"),
     356                 :            :                                          G_VARIANT_TYPE_UNIT,
     357                 :            :                                          &local_error);
     358         [ -  + ]:          1 :   g_assert_no_error (local_error);
     359         [ -  + ]:          1 :   g_assert_nonnull (unit_variant1);
     360                 :            : 
     361                 :            :   /* Should be busy now. */
     362         [ -  + ]:          1 :   g_assert_true (mws_schedule_service_get_busy (fixture->service));
     363                 :            : 
     364                 :            :   /* Release it. */
     365                 :          1 :   g_autoptr(GVariant) unit_variant2 = NULL;
     366                 :          1 :   unit_variant2 = scheduler_call_method (fixture, "Release",
     367                 :            :                                          NULL,  /* no arguments */
     368                 :            :                                          G_VARIANT_TYPE_UNIT,
     369                 :            :                                          &local_error);
     370         [ -  + ]:          1 :   g_assert_no_error (local_error);
     371         [ -  + ]:          1 :   g_assert_nonnull (unit_variant2);
     372                 :            : 
     373                 :            :   /* Should not be busy again. */
     374         [ -  + ]:          1 :   g_assert_false (mws_schedule_service_get_busy (fixture->service));
     375                 :          1 : }
     376                 :            : 
     377                 :            : /* Test that calling Hold() twice results in an error. */
     378                 :            : static void
     379                 :          1 : test_service_dbus_hold_twice (BusFixture    *fixture,
     380                 :            :                               gconstpointer  test_data)
     381                 :            : {
     382                 :          1 :   g_autoptr(GError) local_error = NULL;
     383                 :            : 
     384                 :            :   /* The schedule service shouldn’t be busy to begin with. */
     385         [ -  + ]:          1 :   g_assert_false (mws_schedule_service_get_busy (fixture->service));
     386                 :            : 
     387                 :            :   /* Hold it. */
     388                 :          1 :   g_autoptr(GVariant) unit_variant1 = NULL;
     389                 :          1 :   unit_variant1 = scheduler_call_method (fixture, "Hold",
     390                 :            :                                          g_variant_new ("(s)", "Test reason"),
     391                 :            :                                          G_VARIANT_TYPE_UNIT,
     392                 :            :                                          &local_error);
     393         [ -  + ]:          1 :   g_assert_no_error (local_error);
     394         [ -  + ]:          1 :   g_assert_nonnull (unit_variant1);
     395                 :            : 
     396                 :            :   /* Should be busy now. */
     397         [ -  + ]:          1 :   g_assert_true (mws_schedule_service_get_busy (fixture->service));
     398                 :            : 
     399                 :            :   /* Hold it again; this should error. */
     400                 :          1 :   g_autoptr(GVariant) unit_variant2 = NULL;
     401                 :          1 :   unit_variant2 = scheduler_call_method (fixture, "Hold",
     402                 :            :                                          g_variant_new ("(s)", "Test reason 2"),
     403                 :            :                                          G_VARIANT_TYPE_UNIT,
     404                 :            :                                          &local_error);
     405   [ +  -  +  -  :          1 :   g_assert_error (local_error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED);
                   -  + ]
     406         [ -  + ]:          1 :   g_assert_null (unit_variant2);
     407                 :            : 
     408                 :            :   /* Should still be busy now. */
     409         [ -  + ]:          1 :   g_assert_true (mws_schedule_service_get_busy (fixture->service));
     410                 :          1 : }
     411                 :            : 
     412                 :            : /* Test that calling Release() twice (or once without calling Hold() results in
     413                 :            :  * an error. */
     414                 :            : static void
     415                 :          1 : test_service_dbus_release_twice (BusFixture    *fixture,
     416                 :            :                                  gconstpointer  test_data)
     417                 :            : {
     418                 :          1 :   g_autoptr(GError) local_error = NULL;
     419                 :            : 
     420                 :            :   /* The schedule service shouldn’t be busy to begin with. */
     421         [ -  + ]:          1 :   g_assert_false (mws_schedule_service_get_busy (fixture->service));
     422                 :            : 
     423                 :            :   /* Release it. */
     424                 :          1 :   g_autoptr(GVariant) unit_variant1 = NULL;
     425                 :          1 :   unit_variant1 = scheduler_call_method (fixture, "Release",
     426                 :            :                                          NULL,  /* no arguments */
     427                 :            :                                          G_VARIANT_TYPE_UNIT,
     428                 :            :                                          &local_error);
     429   [ +  -  +  -  :          1 :   g_assert_error (local_error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED);
                   -  + ]
     430         [ -  + ]:          1 :   g_assert_null (unit_variant1);
     431                 :            : 
     432                 :            :   /* Should still not be busy. */
     433         [ -  + ]:          1 :   g_assert_false (mws_schedule_service_get_busy (fixture->service));
     434                 :          1 : }
     435                 :            : 
     436                 :            : int
     437                 :          2 : main (int    argc,
     438                 :            :       char **argv)
     439                 :            : {
     440                 :          2 :   setlocale (LC_ALL, "");
     441                 :          2 :   g_test_init (&argc, &argv, NULL);
     442                 :            : 
     443                 :          2 :   g_test_add ("/schedule-service/dbus/schedule", BusFixture, NULL, bus_setup,
     444                 :            :               test_service_dbus_schedule, bus_teardown);
     445                 :          2 :   g_test_add ("/schedule-service/dbus/schedule/invalid-parameters",
     446                 :            :               BusFixture, NULL, bus_setup,
     447                 :            :               test_service_dbus_schedule_invalid_parameters, bus_teardown);
     448                 :          2 :   g_test_add ("/schedule-service/dbus/schedule/invalid-peer",
     449                 :            :               BusFixture, NULL, bus_setup,
     450                 :            :               test_service_dbus_schedule_invalid_peer, bus_teardown);
     451                 :          2 :   g_test_add ("/schedule-service/dbus/schedule-entries/single", BusFixture, GUINT_TO_POINTER (1),
     452                 :            :               bus_setup, test_service_dbus_schedule_entries, bus_teardown);
     453                 :          2 :   g_test_add ("/schedule-service/dbus/schedule-entries/three", BusFixture, GUINT_TO_POINTER (3),
     454                 :            :               bus_setup, test_service_dbus_schedule_entries, bus_teardown);
     455                 :          2 :   g_test_add ("/schedule-service/dbus/schedule-entries/invalid-parameters",
     456                 :            :               BusFixture, GUINT_TO_POINTER (3),
     457                 :            :               bus_setup, test_service_dbus_schedule_entries_invalid_parameters,
     458                 :            :               bus_teardown);
     459                 :          2 :   g_test_add ("/schedule-service/dbus/schedule-entries/invalid-peer",
     460                 :            :               BusFixture, GUINT_TO_POINTER (3),
     461                 :            :               bus_setup, test_service_dbus_schedule_entries_invalid_peer,
     462                 :            :               bus_teardown);
     463                 :          2 :   g_test_add ("/schedule-service/dbus/schedule-entries/full", BusFixture, NULL,
     464                 :            :               bus_setup, test_service_dbus_schedule_entries_full, bus_teardown);
     465                 :          2 :   g_test_add ("/schedule-service/dbus/hold/normal", BusFixture, NULL,
     466                 :            :               bus_setup, test_service_dbus_hold_normal, bus_teardown);
     467                 :          2 :   g_test_add ("/schedule-service/dbus/hold/twice", BusFixture, NULL,
     468                 :            :               bus_setup, test_service_dbus_hold_twice, bus_teardown);
     469                 :          2 :   g_test_add ("/schedule-service/dbus/release/twice", BusFixture, NULL,
     470                 :            :               bus_setup, test_service_dbus_release_twice, bus_teardown);
     471                 :            : 
     472                 :          2 :   return g_test_run ();
     473                 :            : }

Generated by: LCOV version 1.16