(root)/
glib-2.79.0/
gio/
tests/
gdbus-sessionbus.c
       1  /* GLib testing framework examples and tests
       2   *
       3   * Copyright (C) 2012 Collabora Ltd. <http://www.collabora.co.uk/>
       4   *
       5   * SPDX-License-Identifier: LGPL-2.1-or-later
       6   *
       7   * This library is free software; you can redistribute it and/or
       8   * modify it under the terms of the GNU Lesser General Public
       9   * License as published by the Free Software Foundation; either
      10   * version 2.1 of the License, or (at your option) any later version.
      11   *
      12   * This library is distributed in the hope that it will be useful,
      13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15   * Lesser General Public License for more details.
      16   *
      17   * You should have received a copy of the GNU Lesser General
      18   * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
      19   *
      20   * Author: Xavier Claessens <xavier.claessens@collabora.co.uk>
      21   */
      22  
      23  #include "gdbus-sessionbus.h"
      24  
      25  static GTestDBus *singleton = NULL;
      26  
      27  void
      28  session_bus_up (void)
      29  {
      30    gchar *relative, *servicesdir;
      31    g_assert (singleton == NULL);
      32    singleton = g_test_dbus_new (G_TEST_DBUS_NONE);
      33  
      34    /* We ignore deprecations here so that gdbus-test-codegen-old can
      35     * build successfully despite these two functions not being
      36     * available in GLib 2.36 */
      37    G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      38    relative = g_test_build_filename (G_TEST_BUILT, "services", NULL);
      39    servicesdir = g_canonicalize_filename (relative, NULL);
      40    G_GNUC_END_IGNORE_DEPRECATIONS
      41    g_free (relative);
      42  
      43    g_test_dbus_add_service_dir (singleton, servicesdir);
      44    g_free (servicesdir);
      45    g_test_dbus_up (singleton);
      46  }
      47  
      48  void
      49  session_bus_stop (void)
      50  {
      51    g_assert (singleton != NULL);
      52    g_test_dbus_stop (singleton);
      53  }
      54  
      55  void
      56  session_bus_down (void)
      57  {
      58    g_assert (singleton != NULL);
      59    g_test_dbus_down (singleton);
      60    g_clear_object (&singleton);
      61  }
      62  
      63  gint
      64  session_bus_run (void)
      65  {
      66    gint ret;
      67  
      68    session_bus_up ();
      69    ret = g_test_run ();
      70    session_bus_down ();
      71  
      72    return ret;
      73  }