Blame gio/tests/gdbus-proxy.c

Packit ae235b
/* GLib testing framework examples and tests
Packit ae235b
 *
Packit ae235b
 * Copyright (C) 2008-2010 Red Hat, Inc.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 *
Packit ae235b
 * Author: David Zeuthen <davidz@redhat.com>
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include <gio/gio.h>
Packit ae235b
#include <unistd.h>
Packit ae235b
#include <string.h>
Packit ae235b
Packit ae235b
#include "gdbus-tests.h"
Packit ae235b
Packit ae235b
/* all tests rely on a shared mainloop */
Packit ae235b
static GMainLoop *loop = NULL;
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
/* Test that the method aspects of GDBusProxy works */
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_methods (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  GVariant *result;
Packit ae235b
  GError *error;
Packit ae235b
  const gchar *str;
Packit ae235b
  gchar *dbus_error_name;
Packit ae235b
Packit ae235b
  /* check that we can invoke a method */
Packit ae235b
  error = NULL;
Packit ae235b
  result = g_dbus_proxy_call_sync (proxy,
Packit ae235b
                                   "HelloWorld",
Packit ae235b
                                   g_variant_new ("(s)", "Hey"),
Packit ae235b
                                   G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                                   -1,
Packit ae235b
                                   NULL,
Packit ae235b
                                   &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert (result != NULL);
Packit ae235b
  g_assert_cmpstr (g_variant_get_type_string (result), ==, "(s)");
Packit ae235b
  g_variant_get (result, "(&s)", &str);
Packit ae235b
  g_assert_cmpstr (str, ==, "You greeted me with 'Hey'. Thanks!");
Packit ae235b
  g_variant_unref (result);
Packit ae235b
Packit ae235b
  /* Check that we can completely recover the returned error */
Packit ae235b
  result = g_dbus_proxy_call_sync (proxy,
Packit ae235b
                                   "HelloWorld",
Packit ae235b
                                   g_variant_new ("(s)", "Yo"),
Packit ae235b
                                   G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                                   -1,
Packit ae235b
                                   NULL,
Packit ae235b
                                   &error);
Packit ae235b
  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR);
Packit ae235b
  g_assert (g_dbus_error_is_remote_error (error));
Packit ae235b
  g_assert (g_dbus_error_is_remote_error (error));
Packit ae235b
  g_assert (result == NULL);
Packit ae235b
  dbus_error_name = g_dbus_error_get_remote_error (error);
Packit ae235b
  g_assert_cmpstr (dbus_error_name, ==, "com.example.TestException");
Packit ae235b
  g_free (dbus_error_name);
Packit ae235b
  g_assert (g_dbus_error_strip_remote_error (error));
Packit ae235b
  g_assert_cmpstr (error->message, ==, "Yo is not a proper greeting");
Packit ae235b
  g_clear_error (&error);
Packit ae235b
Packit ae235b
  /* Check that we get a timeout if the method handling is taking longer than
Packit ae235b
   * timeout. We use such a long sleep because on slow machines, if the
Packit ae235b
   * sleep isn't much longer than the timeout and we're doing a parallel
Packit ae235b
   * build, there's no guarantee we'll be scheduled in the window between
Packit ae235b
   * the timeout being hit and the sleep finishing. */
Packit ae235b
  error = NULL;
Packit ae235b
  result = g_dbus_proxy_call_sync (proxy,
Packit ae235b
                                   "Sleep",
Packit ae235b
                                   g_variant_new ("(i)", 10000 /* msec */),
Packit ae235b
                                   G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                                   100 /* msec */,
Packit ae235b
                                   NULL,
Packit ae235b
                                   &error);
Packit ae235b
  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT);
Packit ae235b
  g_assert (!g_dbus_error_is_remote_error (error));
Packit ae235b
  g_assert (result == NULL);
Packit ae235b
  g_clear_error (&error);
Packit ae235b
Packit ae235b
  /* Check that proxy-default timeouts work. */
Packit ae235b
  g_assert_cmpint (g_dbus_proxy_get_default_timeout (proxy), ==, -1);
Packit ae235b
Packit ae235b
  /* the default timeout is 25000 msec so this should work */
Packit ae235b
  result = g_dbus_proxy_call_sync (proxy,
Packit ae235b
                                   "Sleep",
Packit ae235b
                                   g_variant_new ("(i)", 500 /* msec */),
Packit ae235b
                                   G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                                   -1, /* use proxy default (e.g. -1 -> e.g. 25000 msec) */
Packit ae235b
                                   NULL,
Packit ae235b
                                   &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert (result != NULL);
Packit ae235b
  g_assert_cmpstr (g_variant_get_type_string (result), ==, "()");
Packit ae235b
  g_variant_unref (result);
Packit ae235b
Packit ae235b
  /* Now set the proxy-default timeout to 250 msec and try the 10000 msec
Packit ae235b
   * call - this should FAIL. Again, we use such a long sleep because on slow
Packit ae235b
   * machines there's no guarantee we'll be scheduled when we want to be. */
Packit ae235b
  g_dbus_proxy_set_default_timeout (proxy, 250);
Packit ae235b
  g_assert_cmpint (g_dbus_proxy_get_default_timeout (proxy), ==, 250);
Packit ae235b
  result = g_dbus_proxy_call_sync (proxy,
Packit ae235b
                                   "Sleep",
Packit ae235b
                                   g_variant_new ("(i)", 10000 /* msec */),
Packit ae235b
                                   G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                                   -1, /* use proxy default (e.g. 250 msec) */
Packit ae235b
                                   NULL,
Packit ae235b
                                   &error);
Packit ae235b
  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT);
Packit ae235b
  g_assert (!g_dbus_error_is_remote_error (error));
Packit ae235b
  g_assert (result == NULL);
Packit ae235b
  g_clear_error (&error);
Packit ae235b
Packit ae235b
  /* clean up after ourselves */
Packit ae235b
  g_dbus_proxy_set_default_timeout (proxy, -1);
Packit ae235b
}
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
strv_equal (gchar **strv, ...)
Packit ae235b
{
Packit ae235b
  gint count;
Packit ae235b
  va_list list;
Packit ae235b
  const gchar *str;
Packit ae235b
  gboolean res;
Packit ae235b
Packit ae235b
  res = TRUE;
Packit ae235b
  count = 0;
Packit ae235b
  va_start (list, strv);
Packit ae235b
  while (1)
Packit ae235b
    {
Packit ae235b
      str = va_arg (list, const gchar *);
Packit ae235b
      if (str == NULL)
Packit ae235b
        break;
Packit ae235b
      if (g_strcmp0 (str, strv[count]) != 0)
Packit ae235b
        {
Packit ae235b
          res = FALSE;
Packit ae235b
          break;
Packit ae235b
        }
Packit ae235b
      count++;
Packit ae235b
    }
Packit ae235b
  va_end (list);
Packit ae235b
Packit ae235b
  if (res)
Packit ae235b
    res = g_strv_length (strv) == count;
Packit ae235b
Packit ae235b
  return res;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
/* Test that the property aspects of GDBusProxy works */
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_properties (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  GError *error;
Packit ae235b
  GVariant *variant;
Packit ae235b
  GVariant *variant2;
Packit ae235b
  GVariant *result;
Packit ae235b
  gchar **names;
Packit ae235b
  gchar *name_owner;
Packit ae235b
  GDBusProxy *proxy2;
Packit ae235b
Packit ae235b
  error = NULL;
Packit ae235b
Packit ae235b
  if (g_dbus_proxy_get_flags (proxy) & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES)
Packit ae235b
    {
Packit ae235b
       g_assert (g_dbus_proxy_get_cached_property_names (proxy) == NULL);
Packit ae235b
       return;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  /*
Packit ae235b
   * Check that we can list all cached properties.
Packit ae235b
   */
Packit ae235b
  names = g_dbus_proxy_get_cached_property_names (proxy);
Packit ae235b
Packit ae235b
  g_assert (strv_equal (names,
Packit ae235b
                        "PropertyThatWillBeInvalidated",
Packit ae235b
                        "ab",
Packit ae235b
                        "ad",
Packit ae235b
                        "ai",
Packit ae235b
                        "an",
Packit ae235b
                        "ao",
Packit ae235b
                        "aq",
Packit ae235b
                        "as",
Packit ae235b
                        "at",
Packit ae235b
                        "au",
Packit ae235b
                        "ax",
Packit ae235b
                        "ay",
Packit ae235b
                        "b",
Packit ae235b
                        "d",
Packit ae235b
                        "foo",
Packit ae235b
                        "i",
Packit ae235b
                        "n",
Packit ae235b
                        "o",
Packit ae235b
                        "q",
Packit ae235b
                        "s",
Packit ae235b
                        "t",
Packit ae235b
                        "u",
Packit ae235b
                        "x",
Packit ae235b
                        "y",
Packit ae235b
                        NULL));
Packit ae235b
Packit ae235b
  g_strfreev (names);
Packit ae235b
Packit ae235b
  /*
Packit ae235b
   * Check that we can read cached properties.
Packit ae235b
   *
Packit ae235b
   * No need to test all properties - GVariant has already been tested
Packit ae235b
   */
Packit ae235b
  variant = g_dbus_proxy_get_cached_property (proxy, "y");
Packit ae235b
  g_assert (variant != NULL);
Packit ae235b
  g_assert_cmpint (g_variant_get_byte (variant), ==, 1);
Packit ae235b
  g_variant_unref (variant);
Packit ae235b
  variant = g_dbus_proxy_get_cached_property (proxy, "o");
Packit ae235b
  g_assert (variant != NULL);
Packit ae235b
  g_assert_cmpstr (g_variant_get_string (variant, NULL), ==, "/some/path");
Packit ae235b
  g_variant_unref (variant);
Packit ae235b
Packit ae235b
  /*
Packit ae235b
   * Now ask the service to change a property and check that #GDBusProxy::g-property-changed
Packit ae235b
   * is received. Also check that the cache is updated.
Packit ae235b
   */
Packit ae235b
  variant2 = g_variant_new_byte (42);
Packit ae235b
  result = g_dbus_proxy_call_sync (proxy,
Packit ae235b
                                   "FrobSetProperty",
Packit ae235b
                                   g_variant_new ("(sv)",
Packit ae235b
                                                  "y",
Packit ae235b
                                                  variant2),
Packit ae235b
                                   G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                                   -1,
Packit ae235b
                                   NULL,
Packit ae235b
                                   &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert (result != NULL);
Packit ae235b
  g_assert_cmpstr (g_variant_get_type_string (result), ==, "()");
Packit ae235b
  g_variant_unref (result);
Packit ae235b
  _g_assert_signal_received (proxy, "g-properties-changed");
Packit ae235b
  variant = g_dbus_proxy_get_cached_property (proxy, "y");
Packit ae235b
  g_assert (variant != NULL);
Packit ae235b
  g_assert_cmpint (g_variant_get_byte (variant), ==, 42);
Packit ae235b
  g_variant_unref (variant);
Packit ae235b
Packit ae235b
  g_dbus_proxy_set_cached_property (proxy, "y", g_variant_new_byte (142));
Packit ae235b
  variant = g_dbus_proxy_get_cached_property (proxy, "y");
Packit ae235b
  g_assert (variant != NULL);
Packit ae235b
  g_assert_cmpint (g_variant_get_byte (variant), ==, 142);
Packit ae235b
  g_variant_unref (variant);
Packit ae235b
Packit ae235b
  g_dbus_proxy_set_cached_property (proxy, "y", NULL);
Packit ae235b
  variant = g_dbus_proxy_get_cached_property (proxy, "y");
Packit ae235b
  g_assert (variant == NULL);
Packit ae235b
Packit ae235b
  /* Check that the invalidation feature of the PropertiesChanged()
Packit ae235b
   * signal works... First, check that we have a cached value of the
Packit ae235b
   * property (from the initial GetAll() call)
Packit ae235b
   */
Packit ae235b
  variant = g_dbus_proxy_get_cached_property (proxy, "PropertyThatWillBeInvalidated");
Packit ae235b
  g_assert (variant != NULL);
Packit ae235b
  g_assert_cmpstr (g_variant_get_string (variant, NULL), ==, "InitialValue");
Packit ae235b
  g_variant_unref (variant);
Packit ae235b
  /* now ask to invalidate the property - this causes a
Packit ae235b
   *
Packit ae235b
   *   PropertiesChanaged("com.example.Frob",
Packit ae235b
   *                      {},
Packit ae235b
   *                      ["PropertyThatWillBeInvalidated")
Packit ae235b
   *
Packit ae235b
   * signal to be emitted. This is received before the method reply
Packit ae235b
   * for FrobInvalidateProperty *but* since the proxy was created in
Packit ae235b
   * the same thread as we're doing this synchronous call, we'll get
Packit ae235b
   * the method reply before...
Packit ae235b
   */
Packit ae235b
  result = g_dbus_proxy_call_sync (proxy,
Packit ae235b
                                   "FrobInvalidateProperty",
Packit ae235b
                                   g_variant_new ("(s)", "OMGInvalidated"),
Packit ae235b
                                   G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                                   -1,
Packit ae235b
                                   NULL,
Packit ae235b
                                   &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert (result != NULL);
Packit ae235b
  g_assert_cmpstr (g_variant_get_type_string (result), ==, "()");
Packit ae235b
  g_variant_unref (result);
Packit ae235b
  /* ... hence we wait for the g-properties-changed signal to be delivered */
Packit ae235b
  _g_assert_signal_received (proxy, "g-properties-changed");
Packit ae235b
  /* ... and now we finally, check that the cached value has been invalidated */
Packit ae235b
  variant = g_dbus_proxy_get_cached_property (proxy, "PropertyThatWillBeInvalidated");
Packit ae235b
  g_assert (variant == NULL);
Packit ae235b
Packit ae235b
  /* Now test that G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES works - we need a new proxy for that */
Packit ae235b
  error = NULL;
Packit ae235b
  proxy2 = g_dbus_proxy_new_sync (g_dbus_proxy_get_connection (proxy),
Packit ae235b
                                  G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
Packit ae235b
                                  NULL,                      /* GDBusInterfaceInfo */
Packit ae235b
                                  "com.example.TestService", /* name */
Packit ae235b
                                  "/com/example/TestObject", /* object path */
Packit ae235b
                                  "com.example.Frob",        /* interface */
Packit ae235b
                                  NULL, /* GCancellable */
Packit ae235b
                                  &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
Packit ae235b
  name_owner = g_dbus_proxy_get_name_owner (proxy2);
Packit ae235b
  g_assert (name_owner != NULL);
Packit ae235b
  g_free (name_owner);
Packit ae235b
Packit ae235b
  variant = g_dbus_proxy_get_cached_property (proxy2, "PropertyThatWillBeInvalidated");
Packit ae235b
  g_assert (variant != NULL);
Packit ae235b
  g_assert_cmpstr (g_variant_get_string (variant, NULL), ==, "OMGInvalidated"); /* from previous test */
Packit ae235b
  g_variant_unref (variant);
Packit ae235b
Packit ae235b
  result = g_dbus_proxy_call_sync (proxy2,
Packit ae235b
                                   "FrobInvalidateProperty",
Packit ae235b
                                   g_variant_new ("(s)", "OMGInvalidated2"),
Packit ae235b
                                   G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                                   -1,
Packit ae235b
                                   NULL,
Packit ae235b
                                   &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert (result != NULL);
Packit ae235b
  g_assert_cmpstr (g_variant_get_type_string (result), ==, "()");
Packit ae235b
  g_variant_unref (result);
Packit ae235b
Packit ae235b
  /* this time we should get the ::g-properties-changed _with_ the value */
Packit ae235b
  _g_assert_signal_received (proxy2, "g-properties-changed");
Packit ae235b
Packit ae235b
  variant = g_dbus_proxy_get_cached_property (proxy2, "PropertyThatWillBeInvalidated");
Packit ae235b
  g_assert (variant != NULL);
Packit ae235b
  g_assert_cmpstr (g_variant_get_string (variant, NULL), ==, "OMGInvalidated2");
Packit ae235b
  g_variant_unref (variant);
Packit ae235b
Packit ae235b
  g_object_unref (proxy2);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
/* Test that the signal aspects of GDBusProxy works */
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_proxy_signals_on_signal (GDBusProxy  *proxy,
Packit ae235b
                              const gchar *sender_name,
Packit ae235b
                              const gchar *signal_name,
Packit ae235b
                              GVariant    *parameters,
Packit ae235b
                              gpointer     user_data)
Packit ae235b
{
Packit ae235b
  GString *s = user_data;
Packit ae235b
Packit ae235b
  g_assert_cmpstr (signal_name, ==, "TestSignal");
Packit ae235b
  g_assert_cmpstr (g_variant_get_type_string (parameters), ==, "(sov)");
Packit ae235b
Packit ae235b
  g_variant_print_string (parameters, s, TRUE);
Packit ae235b
}
Packit ae235b
Packit ae235b
typedef struct
Packit ae235b
{
Packit ae235b
  GMainLoop *internal_loop;
Packit ae235b
  GString *s;
Packit ae235b
} TestSignalData;
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_proxy_signals_on_emit_signal_cb (GDBusProxy   *proxy,
Packit ae235b
                                      GAsyncResult *res,
Packit ae235b
                                      gpointer      user_data)
Packit ae235b
{
Packit ae235b
  TestSignalData *data = user_data;
Packit ae235b
  GError *error;
Packit ae235b
  GVariant *result;
Packit ae235b
Packit ae235b
  error = NULL;
Packit ae235b
  result = g_dbus_proxy_call_finish (proxy,
Packit ae235b
                                     res,
Packit ae235b
                                     &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert (result != NULL);
Packit ae235b
  g_assert_cmpstr (g_variant_get_type_string (result), ==, "()");
Packit ae235b
  g_variant_unref (result);
Packit ae235b
Packit ae235b
  /* check that the signal was recieved before we got the method result */
Packit ae235b
  g_assert (strlen (data->s->str) > 0);
Packit ae235b
Packit ae235b
  /* break out of the loop */
Packit ae235b
  g_main_loop_quit (data->internal_loop);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_signals (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  GError *error;
Packit ae235b
  GString *s;
Packit ae235b
  gulong signal_handler_id;
Packit ae235b
  TestSignalData data;
Packit ae235b
  GVariant *result;
Packit ae235b
Packit ae235b
  error = NULL;
Packit ae235b
Packit ae235b
  /*
Packit ae235b
   * Ask the service to emit a signal and check that we receive it.
Packit ae235b
   *
Packit ae235b
   * Note that blocking calls don't block in the mainloop so wait for the signal (which
Packit ae235b
   * is dispatched before the method reply)
Packit ae235b
   */
Packit ae235b
  s = g_string_new (NULL);
Packit ae235b
  signal_handler_id = g_signal_connect (proxy,
Packit ae235b
                                        "g-signal",
Packit ae235b
                                        G_CALLBACK (test_proxy_signals_on_signal),
Packit ae235b
                                        s);
Packit ae235b
Packit ae235b
  result = g_dbus_proxy_call_sync (proxy,
Packit ae235b
                                   "EmitSignal",
Packit ae235b
                                   g_variant_new ("(so)",
Packit ae235b
                                                  "Accept the next proposition you hear",
Packit ae235b
                                                  "/some/path"),
Packit ae235b
                                   G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                                   -1,
Packit ae235b
                                   NULL,
Packit ae235b
                                   &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert (result != NULL);
Packit ae235b
  g_assert_cmpstr (g_variant_get_type_string (result), ==, "()");
Packit ae235b
  g_variant_unref (result);
Packit ae235b
  /* check that we haven't received the signal just yet */
Packit ae235b
  g_assert (strlen (s->str) == 0);
Packit ae235b
  /* and now wait for the signal */
Packit ae235b
  _g_assert_signal_received (proxy, "g-signal");
Packit ae235b
  g_assert_cmpstr (s->str,
Packit ae235b
                   ==,
Packit ae235b
                   "('Accept the next proposition you hear .. in bed!', objectpath '/some/path/in/bed', <'a variant'>)");
Packit ae235b
  g_signal_handler_disconnect (proxy, signal_handler_id);
Packit ae235b
  g_string_free (s, TRUE);
Packit ae235b
Packit ae235b
  /*
Packit ae235b
   * Now do this async to check the signal is received before the method returns.
Packit ae235b
   */
Packit ae235b
  s = g_string_new (NULL);
Packit ae235b
  data.internal_loop = g_main_loop_new (NULL, FALSE);
Packit ae235b
  data.s = s;
Packit ae235b
  signal_handler_id = g_signal_connect (proxy,
Packit ae235b
                                        "g-signal",
Packit ae235b
                                        G_CALLBACK (test_proxy_signals_on_signal),
Packit ae235b
                                        s);
Packit ae235b
  g_dbus_proxy_call (proxy,
Packit ae235b
                     "EmitSignal",
Packit ae235b
                     g_variant_new ("(so)",
Packit ae235b
                                    "You will make a great programmer",
Packit ae235b
                                    "/some/other/path"),
Packit ae235b
                     G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                     -1,
Packit ae235b
                     NULL,
Packit ae235b
                     (GAsyncReadyCallback) test_proxy_signals_on_emit_signal_cb,
Packit ae235b
                     &data);
Packit ae235b
  g_main_loop_run (data.internal_loop);
Packit ae235b
  g_main_loop_unref (data.internal_loop);
Packit ae235b
  g_assert_cmpstr (s->str,
Packit ae235b
                   ==,
Packit ae235b
                   "('You will make a great programmer .. in bed!', objectpath '/some/other/path/in/bed', <'a variant'>)");
Packit ae235b
  g_signal_handler_disconnect (proxy, signal_handler_id);
Packit ae235b
  g_string_free (s, TRUE);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_bogus_method_return (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  GError *error = NULL;
Packit ae235b
  GVariant *result;
Packit ae235b
Packit ae235b
  result = g_dbus_proxy_call_sync (proxy,
Packit ae235b
                                   "PairReturn",
Packit ae235b
                                   NULL,
Packit ae235b
                                   G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                                   -1,
Packit ae235b
                                   NULL,
Packit ae235b
                                   &error);
Packit ae235b
  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
Packit ae235b
  g_error_free (error);
Packit ae235b
  g_assert (result == NULL);
Packit ae235b
}
Packit ae235b
Packit ae235b
#if 0 /* Disabled: see https://bugzilla.gnome.org/show_bug.cgi?id=658999 */
Packit ae235b
static void
Packit ae235b
test_bogus_signal (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  GError *error = NULL;
Packit ae235b
  GVariant *result;
Packit ae235b
  GDBusInterfaceInfo *old_iface_info;
Packit ae235b
Packit ae235b
  result = g_dbus_proxy_call_sync (proxy,
Packit ae235b
                                   "EmitSignal2",
Packit ae235b
                                   NULL,
Packit ae235b
                                   G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                                   -1,
Packit ae235b
                                   NULL,
Packit ae235b
                                   &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert (result != NULL);
Packit ae235b
  g_assert_cmpstr (g_variant_get_type_string (result), ==, "()");
Packit ae235b
  g_variant_unref (result);
Packit ae235b
Packit ae235b
  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
Packit ae235b
    {
Packit ae235b
      /* and now wait for the signal that will never arrive */
Packit ae235b
      _g_assert_signal_received (proxy, "g-signal");
Packit ae235b
    }
Packit ae235b
  g_test_trap_assert_stderr ("*Dropping signal TestSignal2 of type (i) since the type from the expected interface is (u)*");
Packit ae235b
  g_test_trap_assert_failed();
Packit ae235b
Packit ae235b
  /* Our main branch will also do g_warning() when running the mainloop so
Packit ae235b
   * temporarily remove the expected interface
Packit ae235b
   */
Packit ae235b
  old_iface_info = g_dbus_proxy_get_interface_info (proxy);
Packit ae235b
  g_dbus_proxy_set_interface_info (proxy, NULL);
Packit ae235b
  _g_assert_signal_received (proxy, "g-signal");
Packit ae235b
  g_dbus_proxy_set_interface_info (proxy, old_iface_info);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_bogus_property (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  GError *error = NULL;
Packit ae235b
  GVariant *result;
Packit ae235b
  GDBusInterfaceInfo *old_iface_info;
Packit ae235b
Packit ae235b
  /* Make the service emit a PropertiesChanged signal for property 'i' of type 'i' - since
Packit ae235b
   * our introspection data has this as type 'u' we should get a warning on stderr.
Packit ae235b
   */
Packit ae235b
  result = g_dbus_proxy_call_sync (proxy,
Packit ae235b
                                   "FrobSetProperty",
Packit ae235b
                                   g_variant_new ("(sv)",
Packit ae235b
                                                  "i", g_variant_new_int32 (42)),
Packit ae235b
                                   G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                                   -1,
Packit ae235b
                                   NULL,
Packit ae235b
                                   &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert (result != NULL);
Packit ae235b
  g_assert_cmpstr (g_variant_get_type_string (result), ==, "()");
Packit ae235b
  g_variant_unref (result);
Packit ae235b
Packit ae235b
  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
Packit ae235b
    {
Packit ae235b
      /* and now wait for the signal that will never arrive */
Packit ae235b
      _g_assert_signal_received (proxy, "g-properties-changed");
Packit ae235b
    }
Packit ae235b
  g_test_trap_assert_stderr ("*Received property i with type i does not match expected type u in the expected interface*");
Packit ae235b
  g_test_trap_assert_failed();
Packit ae235b
Packit ae235b
  /* Our main branch will also do g_warning() when running the mainloop so
Packit ae235b
   * temporarily remove the expected interface
Packit ae235b
   */
Packit ae235b
  old_iface_info = g_dbus_proxy_get_interface_info (proxy);
Packit ae235b
  g_dbus_proxy_set_interface_info (proxy, NULL);
Packit ae235b
  _g_assert_signal_received (proxy, "g-properties-changed");
Packit ae235b
  g_dbus_proxy_set_interface_info (proxy, old_iface_info);
Packit ae235b
}
Packit ae235b
#endif /* Disabled: see https://bugzilla.gnome.org/show_bug.cgi?id=658999 */
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static const gchar *frob_dbus_interface_xml =
Packit ae235b
  "<node>"
Packit ae235b
  "  <interface name='com.example.Frob'>"
Packit ae235b
  /* PairReturn() is deliberately different from gdbus-testserver's definition */
Packit ae235b
  "    <method name='PairReturn'>"
Packit ae235b
  "      <arg type='u' name='somenumber' direction='in'/>"
Packit ae235b
  "      <arg type='s' name='somestring' direction='out'/>"
Packit ae235b
  "    </method>"
Packit ae235b
  "    <method name='HelloWorld'>"
Packit ae235b
  "      <arg type='s' name='somestring' direction='in'/>"
Packit ae235b
  "      <arg type='s' name='somestring' direction='out'/>"
Packit ae235b
  "    </method>"
Packit ae235b
  "    <method name='Sleep'>"
Packit ae235b
  "      <arg type='i' name='timeout' direction='in'/>"
Packit ae235b
  "    </method>"
Packit ae235b
  /* We deliberately only mention a single property here */
Packit ae235b
  "    <property name='y' type='y' access='readwrite'/>"
Packit ae235b
  /* The 'i' property is deliberately different from gdbus-testserver's definition */
Packit ae235b
  "    <property name='i' type='u' access='readwrite'/>"
Packit ae235b
  /* ::TestSignal2 is deliberately different from gdbus-testserver's definition */
Packit ae235b
  "    <signal name='TestSignal2'>"
Packit ae235b
  "      <arg type='u' name='somenumber'/>"
Packit ae235b
  "    </signal>"
Packit ae235b
  "  </interface>"
Packit ae235b
  "</node>";
Packit ae235b
static GDBusInterfaceInfo *frob_dbus_interface_info;
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_expected_interface (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  GVariant *value;
Packit ae235b
  GError *error;
Packit ae235b
Packit ae235b
  /* This is obviously wrong but expected interface is not set so we don't fail... */
Packit ae235b
  g_dbus_proxy_set_cached_property (proxy, "y", g_variant_new_string ("error_me_out!"));
Packit ae235b
  g_dbus_proxy_set_cached_property (proxy, "y", g_variant_new_byte (42));
Packit ae235b
  g_dbus_proxy_set_cached_property (proxy, "does-not-exist", g_variant_new_string ("something"));
Packit ae235b
  g_dbus_proxy_set_cached_property (proxy, "does-not-exist", NULL);
Packit ae235b
Packit ae235b
  /* Now repeat the method tests, with an expected interface set */
Packit ae235b
  g_dbus_proxy_set_interface_info (proxy, frob_dbus_interface_info);
Packit ae235b
  test_methods (proxy);
Packit ae235b
  test_signals (proxy);
Packit ae235b
Packit ae235b
  /* And also where we deliberately set the expected interface definition incorrectly */
Packit ae235b
  test_bogus_method_return (proxy);
Packit ae235b
  /* Disabled: see https://bugzilla.gnome.org/show_bug.cgi?id=658999
Packit ae235b
  test_bogus_signal (proxy);
Packit ae235b
  test_bogus_property (proxy);
Packit ae235b
  */
Packit ae235b
Packit ae235b
  if (g_test_undefined ())
Packit ae235b
    {
Packit ae235b
      /* Also check that we complain if setting a cached property of the wrong type */
Packit ae235b
      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
Packit ae235b
                             "*Trying to set property y of type s but according to the expected interface the type is y*");
Packit ae235b
      g_dbus_proxy_set_cached_property (proxy, "y", g_variant_new_string ("error_me_out!"));
Packit ae235b
      g_test_assert_expected_messages ();
Packit ae235b
    }
Packit ae235b
Packit ae235b
  /* this should work, however (since the type is correct) */
Packit ae235b
  g_dbus_proxy_set_cached_property (proxy, "y", g_variant_new_byte (42));
Packit ae235b
Packit ae235b
  if (g_test_undefined ())
Packit ae235b
    {
Packit ae235b
      /* Try to get the value of a property where the type we expect is different from
Packit ae235b
       * what we have in our cache (e.g. what the service returned)
Packit ae235b
       */
Packit ae235b
      g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
Packit ae235b
                             "*Trying to get property i with type i but according to the expected interface the type is u*");
Packit ae235b
      value = g_dbus_proxy_get_cached_property (proxy, "i");
Packit ae235b
      g_test_assert_expected_messages ();
Packit ae235b
    }
Packit ae235b
Packit ae235b
  /* Even if a property does not exist in expected_interface, looking it
Packit ae235b
   * up, or setting it, should never fail. Because it could be that the
Packit ae235b
   * property has been added to the service but the GDBusInterfaceInfo*
Packit ae235b
   * passed to g_dbus_proxy_set_interface_info() just haven't been updated.
Packit ae235b
   *
Packit ae235b
   * See https://bugzilla.gnome.org/show_bug.cgi?id=660886
Packit ae235b
   */
Packit ae235b
  value = g_dbus_proxy_get_cached_property (proxy, "d");
Packit ae235b
  g_assert (value != NULL);
Packit ae235b
  g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE_DOUBLE));
Packit ae235b
  g_assert_cmpfloat (g_variant_get_double (value), ==, 7.5);
Packit ae235b
  g_variant_unref (value);
Packit ae235b
  /* update it via the cached property... */
Packit ae235b
  g_dbus_proxy_set_cached_property (proxy, "d", g_variant_new_double (75.0));
Packit ae235b
  /* ... and finally check that it has changed */
Packit ae235b
  value = g_dbus_proxy_get_cached_property (proxy, "d");
Packit ae235b
  g_assert (value != NULL);
Packit ae235b
  g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE_DOUBLE));
Packit ae235b
  g_assert_cmpfloat (g_variant_get_double (value), ==, 75.0);
Packit ae235b
  g_variant_unref (value);
Packit ae235b
  /* now update it via the D-Bus interface... */
Packit ae235b
  error = NULL;
Packit ae235b
  value = g_dbus_proxy_call_sync (proxy, "FrobSetProperty",
Packit ae235b
                                  g_variant_new ("(sv)", "d", g_variant_new_double (85.0)),
Packit ae235b
                                  G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                                  -1, NULL, &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert (value != NULL);
Packit ae235b
  g_assert_cmpstr (g_variant_get_type_string (value), ==, "()");
Packit ae235b
  g_variant_unref (value);
Packit ae235b
  /* ...ensure we receive the ::PropertiesChanged signal... */
Packit ae235b
  _g_assert_signal_received (proxy, "g-properties-changed");
Packit ae235b
  /* ... and finally check that it has changed */
Packit ae235b
  value = g_dbus_proxy_get_cached_property (proxy, "d");
Packit ae235b
  g_assert (value != NULL);
Packit ae235b
  g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE_DOUBLE));
Packit ae235b
  g_assert_cmpfloat (g_variant_get_double (value), ==, 85.0);
Packit ae235b
  g_variant_unref (value);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_basic (GDBusProxy *proxy)
Packit ae235b
{
Packit ae235b
  GDBusConnection *connection;
Packit ae235b
  GDBusConnection *conn;
Packit ae235b
  GDBusProxyFlags flags;
Packit ae235b
  GDBusInterfaceInfo *info;
Packit ae235b
  gchar *name;
Packit ae235b
  gchar *path;
Packit ae235b
  gchar *interface;
Packit ae235b
  gint timeout;
Packit ae235b
Packit ae235b
  connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
Packit ae235b
Packit ae235b
  g_assert (g_dbus_proxy_get_connection (proxy) == connection);
Packit ae235b
  g_assert (g_dbus_proxy_get_flags (proxy) == G_DBUS_PROXY_FLAGS_NONE);
Packit ae235b
  g_assert (g_dbus_proxy_get_interface_info (proxy) == NULL);
Packit ae235b
  g_assert_cmpstr (g_dbus_proxy_get_name (proxy), ==, "com.example.TestService");
Packit ae235b
  g_assert_cmpstr (g_dbus_proxy_get_object_path (proxy), ==, "/com/example/TestObject");
Packit ae235b
  g_assert_cmpstr (g_dbus_proxy_get_interface_name (proxy), ==, "com.example.Frob");
Packit ae235b
  g_assert_cmpint (g_dbus_proxy_get_default_timeout (proxy), ==, -1);
Packit ae235b
Packit ae235b
  g_object_get (proxy,
Packit ae235b
                "g-connection", &conn,
Packit ae235b
                "g-interface-info", &info,
Packit ae235b
                "g-flags", &flags,
Packit ae235b
                "g-name", &name,
Packit ae235b
                "g-object-path", &path,
Packit ae235b
                "g-interface-name", &interface,
Packit ae235b
                "g-default-timeout", &timeout,
Packit ae235b
                NULL);
Packit ae235b
Packit ae235b
  g_assert (conn == connection);
Packit ae235b
  g_assert (info == NULL);
Packit ae235b
  g_assert_cmpint (flags, ==, G_DBUS_PROXY_FLAGS_NONE);
Packit ae235b
  g_assert_cmpstr (name, ==, "com.example.TestService");
Packit ae235b
  g_assert_cmpstr (path, ==, "/com/example/TestObject");
Packit ae235b
  g_assert_cmpstr (interface, ==, "com.example.Frob");
Packit ae235b
  g_assert_cmpint (timeout, ==, -1);
Packit ae235b
Packit ae235b
  g_object_unref (conn);
Packit ae235b
  g_free (name);
Packit ae235b
  g_free (path);
Packit ae235b
  g_free (interface);
Packit ae235b
Packit ae235b
  g_object_unref (connection);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
kill_test_service (GDBusConnection *connection)
Packit ae235b
{
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
  guint pid;
Packit ae235b
  GVariant *ret;
Packit ae235b
  GError *error = NULL;
Packit ae235b
  const gchar *name = "com.example.TestService";
Packit ae235b
Packit ae235b
  ret = g_dbus_connection_call_sync (connection,
Packit ae235b
                                     "org.freedesktop.DBus",
Packit ae235b
                                     "/org/freedesktop/DBus",
Packit ae235b
                                     "org.freedesktop.DBus",
Packit ae235b
                                     "GetConnectionUnixProcessID",
Packit ae235b
                                     g_variant_new ("(s)", name),
Packit ae235b
                                     NULL,
Packit ae235b
                                     G_DBUS_CALL_FLAGS_NONE,
Packit ae235b
                                     -1,
Packit ae235b
                                     NULL,
Packit ae235b
                                     &error);
Packit ae235b
  g_variant_get (ret, "(u)", &pid;;
Packit ae235b
  g_variant_unref (ret);
Packit ae235b
  kill (pid, SIGTERM);
Packit ae235b
#else
Packit ae235b
  g_warning ("Can't kill com.example.TestService");
Packit ae235b
#endif
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_proxy (void)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy;
Packit ae235b
  GDBusConnection *connection;
Packit ae235b
  GError *error;
Packit ae235b
Packit ae235b
  error = NULL;
Packit ae235b
  connection = g_bus_get_sync (G_BUS_TYPE_SESSION,
Packit ae235b
                               NULL,
Packit ae235b
                               &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  error = NULL;
Packit ae235b
  proxy = g_dbus_proxy_new_sync (connection,
Packit ae235b
                                 G_DBUS_PROXY_FLAGS_NONE,
Packit ae235b
                                 NULL,                      /* GDBusInterfaceInfo */
Packit ae235b
                                 "com.example.TestService", /* name */
Packit ae235b
                                 "/com/example/TestObject", /* object path */
Packit ae235b
                                 "com.example.Frob",        /* interface */
Packit ae235b
                                 NULL, /* GCancellable */
Packit ae235b
                                 &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
Packit ae235b
  /* this is safe; testserver will exit once the bus goes away */
Packit ae235b
  g_assert (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL));
Packit ae235b
Packit ae235b
  _g_assert_property_notify (proxy, "g-name-owner");
Packit ae235b
Packit ae235b
  test_basic (proxy);
Packit ae235b
  test_methods (proxy);
Packit ae235b
  test_properties (proxy);
Packit ae235b
  test_signals (proxy);
Packit ae235b
  test_expected_interface (proxy);
Packit ae235b
Packit ae235b
  g_object_unref (proxy);
Packit ae235b
  kill_test_service (connection);
Packit ae235b
  g_object_unref (connection);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static void
Packit ae235b
proxy_ready (GObject      *source,
Packit ae235b
             GAsyncResult *result,
Packit ae235b
             gpointer      user_data)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy;
Packit ae235b
  GError *error;
Packit ae235b
Packit ae235b
  error = NULL;
Packit ae235b
  proxy = g_dbus_proxy_new_for_bus_finish (result, &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
Packit ae235b
  _g_assert_property_notify (proxy, "g-name-owner");
Packit ae235b
Packit ae235b
  test_basic (proxy);
Packit ae235b
  test_methods (proxy);
Packit ae235b
  test_properties (proxy);
Packit ae235b
  test_signals (proxy);
Packit ae235b
  test_expected_interface (proxy);
Packit ae235b
Packit ae235b
  kill_test_service (g_dbus_proxy_get_connection (proxy));
Packit ae235b
  g_object_unref (proxy);
Packit ae235b
  g_main_loop_quit (loop);
Packit ae235b
}
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
fail_test (gpointer user_data)
Packit ae235b
{
Packit ae235b
  g_assert_not_reached ();
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_async (void)
Packit ae235b
{
Packit ae235b
  guint id;
Packit ae235b
Packit ae235b
  g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
Packit ae235b
                            G_DBUS_PROXY_FLAGS_NONE,
Packit ae235b
                            NULL,                      /* GDBusInterfaceInfo */
Packit ae235b
                            "com.example.TestService", /* name */
Packit ae235b
                            "/com/example/TestObject", /* object path */
Packit ae235b
                            "com.example.Frob",        /* interface */
Packit ae235b
                            NULL, /* GCancellable */
Packit ae235b
                            proxy_ready,
Packit ae235b
                            NULL);
Packit ae235b
Packit ae235b
  /* this is safe; testserver will exit once the bus goes away */
Packit ae235b
  g_assert (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL));
Packit ae235b
Packit ae235b
  id = g_timeout_add (10000, fail_test, NULL);
Packit ae235b
  g_main_loop_run (loop);
Packit ae235b
Packit ae235b
  g_source_remove (id);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_no_properties (void)
Packit ae235b
{
Packit ae235b
  GDBusProxy *proxy;
Packit ae235b
  GError *error;
Packit ae235b
Packit ae235b
  error = NULL;
Packit ae235b
  proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
Packit ae235b
                                         G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
Packit ae235b
                                         NULL,                      /* GDBusInterfaceInfo */
Packit ae235b
                                         "com.example.TestService", /* name */
Packit ae235b
                                         "/com/example/TestObject", /* object path */
Packit ae235b
                                         "com.example.Frob",        /* interface */
Packit ae235b
                                         NULL, /* GCancellable */
Packit ae235b
                                         &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
Packit ae235b
  test_properties (proxy);
Packit ae235b
Packit ae235b
  g_object_unref (proxy);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
check_error (GObject      *source,
Packit ae235b
             GAsyncResult *result,
Packit ae235b
             gpointer      user_data)
Packit ae235b
{
Packit ae235b
  GError *error = NULL;
Packit ae235b
  GVariant *reply;
Packit ae235b
Packit ae235b
  reply = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
Packit ae235b
  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED);
Packit ae235b
  g_assert (reply == NULL);
Packit ae235b
  g_error_free (error);
Packit ae235b
Packit ae235b
  g_main_loop_quit (loop);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_wellknown_noauto (void)
Packit ae235b
{
Packit ae235b
  GError *error = NULL;
Packit ae235b
  GDBusProxy *proxy;
Packit ae235b
  guint id;
Packit ae235b
Packit ae235b
  proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
Packit ae235b
                                         G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
Packit ae235b
                                         NULL, "some.name.that.does.not.exist",
Packit ae235b
                                         "/", "some.interface", NULL, &error);
Packit ae235b
  g_assert_no_error (error);
Packit ae235b
  g_assert (proxy != NULL);
Packit ae235b
Packit ae235b
  g_dbus_proxy_call (proxy, "method", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, check_error, NULL);
Packit ae235b
  id = g_timeout_add (10000, fail_test, NULL);
Packit ae235b
  g_main_loop_run (loop);
Packit ae235b
  g_object_unref (proxy);
Packit ae235b
  g_source_remove (id);
Packit ae235b
}
Packit ae235b
Packit ae235b
int
Packit ae235b
main (int   argc,
Packit ae235b
      char *argv[])
Packit ae235b
{
Packit ae235b
  gint ret;
Packit ae235b
  GDBusNodeInfo *introspection_data = NULL;
Packit ae235b
Packit ae235b
  g_test_init (&argc, &argv, NULL);
Packit ae235b
Packit ae235b
  introspection_data = g_dbus_node_info_new_for_xml (frob_dbus_interface_xml, NULL);
Packit ae235b
  g_assert (introspection_data != NULL);
Packit ae235b
  frob_dbus_interface_info = introspection_data->interfaces[0];
Packit ae235b
Packit ae235b
  /* all the tests rely on a shared main loop */
Packit ae235b
  loop = g_main_loop_new (NULL, FALSE);
Packit ae235b
Packit ae235b
  g_test_add_func ("/gdbus/proxy", test_proxy);
Packit ae235b
  g_test_add_func ("/gdbus/proxy/no-properties", test_no_properties);
Packit ae235b
  g_test_add_func ("/gdbus/proxy/wellknown-noauto", test_wellknown_noauto);
Packit ae235b
  g_test_add_func ("/gdbus/proxy/async", test_async);
Packit ae235b
Packit ae235b
  ret = session_bus_run();
Packit ae235b
Packit ae235b
  g_dbus_node_info_unref (introspection_data);
Packit ae235b
Packit ae235b
  return ret;
Packit ae235b
}