GTestDBus

## GTestDBus GTestDBus — D-Bus testing helper |

## Synopsis

    #include <gio/gio.h>

                        GTestDBus;
    enum                GTestDBusFlags;
    GTestDBus *         g_test_dbus_new                     (GTestDBusFlags flags);
    GTestDBusFlags      g_test_dbus_get_flags               (GTestDBus *self);
    const gchar *       g_test_dbus_get_bus_address         (GTestDBus *self);
    void                g_test_dbus_add_service_dir         (GTestDBus *self,
                                                             const gchar *path);
    void                g_test_dbus_up                      (GTestDBus *self);
    void                g_test_dbus_stop                    (GTestDBus *self);
    void                g_test_dbus_down                    (GTestDBus *self);
    void                g_test_dbus_unset                   (void);

## Object Hierarchy

      GObject
       +----GTestDBus

      GFlags
       +----GTestDBusFlags

## Properties

      "flags"                    GTestDBusFlags        : Read / Write / Construct Only

## Description

Helper to test D-Bus code wihtout messing up with user' session bus.

## Details

### GTestDBus

    typedef struct _GTestDBus GTestDBus;

The GTestDBus structure contains only private data and should only be accessed using the provided API.

Since 2.34

### enum GTestDBusFlags

    typedef enum {
      G_TEST_DBUS_NONE = 0
    } GTestDBusFlags;

Flags to define future GTestDBus behaviour.

`G_TEST_DBUS_NONE` | No flags.

Since 2.34

### g_test_dbus_new ()

    GTestDBus *         g_test_dbus_new                     (GTestDBusFlags flags);

Create a new GTestDBus object.

`flags` : | a GTestDBusFlags
Returns : | a new GTestDBus. [transfer full]

### g_test_dbus_get_flags ()

    GTestDBusFlags      g_test_dbus_get_flags               (GTestDBus *self);

Gets the flags of the GTestDBus object.

`self` : | a GTestDBus
Returns : | the value of "flags" property

### g_test_dbus_get_bus_address ()

    const gchar *       g_test_dbus_get_bus_address         (GTestDBus *self);

Get the address on which dbus-daemon is running. if `g_test_dbus_up()` has not been called yet, `NULL` is returned. This can be used with `g_dbus_connection_new_for_address()`

`self` : | a GTestDBus
Returns : | the address of the bus, or `NULL`.

### g_test_dbus_add_service_dir ()

    void                g_test_dbus_add_service_dir         (GTestDBus *self,
                                                             const gchar *path);

Add a path where dbus-daemon will lookup for .services files. This can't be called after `g_test_dbus_up()`.

`self` : | a GTestDBus
`path` : | path to a directory containing .service files

### g_test_dbus_up ()

    void                g_test_dbus_up                      (GTestDBus *self);

Start a dbus-daemon instance and set DBUS_SESSION_BUS_ADDRESS. After this call, it is safe for unit tests to start sending messages on the session bug.

If this function is called from setup callback of `g_test_add()`, `g_test_dbus_down()` must be called in its teardown callback.

If this function is called from unit test's `main()`, then `g_test_dbus_down()` must be called after `g_test_run()`.

`self` : | a GTestDBus

### g_test_dbus_stop ()

    void                g_test_dbus_stop                    (GTestDBus *self);

Stop the session bus started by `g_test_dbus_up()`.

Unlike `g_test_dbus_down()`, this won't verify the GDBusConnection singleton returned by `g_bus_get()` or `g_bus_get_sync()` is destroyed. Unit tests wanting to verify behaviour after the session bus has been stopped can use this function but should still call `g_test_dbus_down()` when done.

`self` : | a GTestDBus

### g_test_dbus_down ()

    void                g_test_dbus_down                    (GTestDBus *self);

Stop the session bus started by `g_test_dbus_up()`.

This will wait for the singleton returned by `g_bus_get()` or `g_bus_get_sync()` is destroyed. This is done to ensure that the next unit test won't get a leaked singleton from this test.

`self` : | a GTestDBus

### g_test_dbus_unset ()

    void                g_test_dbus_unset                   (void);

Unset DISPLAY and DBUS_SESSION_BUS_ADDRESS env variables to ensure the test won't use user's session bus.

This is useful for unit tests that want to verify behaviour when no session bus is running. It is not necessary to call this if unit test already calls `g_test_dbus_up()` before acquiring the session bus.

## Property Details

### The `"flags"` property

      "flags"                    GTestDBusFlags        : Read / Write / Construct Only

GTestDBusFlags specifying the behaviour of the dbus session

Since 2.34