Ejemplo n.º 1
0
/*
 * Send the given method call and wait for a reply, spinning the main
 * context as necessary.
 */
DBusMessage *
test_main_context_call_and_wait (TestMainContext *ctx,
    DBusConnection *connection,
    DBusMessage *call,
    int timeout)
{
  DBusPendingCall *pc = NULL;
  DBusMessage *reply = NULL;

  if (!dbus_connection_send_with_reply (connection, call, &pc, timeout) ||
      pc == NULL)
    test_oom ();

  if (dbus_pending_call_get_completed (pc))
    test_pending_call_store_reply (pc, &reply);
  else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
        &reply, NULL))
    test_oom ();

  while (reply == NULL)
    test_main_context_iterate (ctx, TRUE);

  dbus_clear_pending_call (&pc);
  return g_steal_pointer (&reply);
}
Ejemplo n.º 2
0
static void
test_uae (Fixture *f,
          gconstpointer context)
{
    const Config *config = context;
    DBusMessage *m;
    DBusPendingCall *pc;
    DBusMessageIter args_iter;
    DBusMessageIter arr_iter;

    if (f->skip)
        return;

    m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
                                      DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "UpdateActivationEnvironment");

    if (m == NULL)
        g_error ("OOM");

    dbus_message_iter_init_append (m, &args_iter);

    /* Append an empty a{ss} (string => string dictionary). */
    if (!dbus_message_iter_open_container (&args_iter, DBUS_TYPE_ARRAY,
                                           "{ss}", &arr_iter) ||
            !dbus_message_iter_close_container (&args_iter, &arr_iter))
        g_error ("OOM");

    if (!dbus_connection_send_with_reply (f->conn, m, &pc,
                                          DBUS_TIMEOUT_USE_DEFAULT) ||
            pc == NULL)
        g_error ("OOM");

    dbus_message_unref (m);
    m = NULL;

    if (dbus_pending_call_get_completed (pc))
        test_pending_call_store_reply (pc, &m);
    else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
                                            &m, NULL))
        g_error ("OOM");

    while (m == NULL)
        test_main_context_iterate (f->ctx, TRUE);

    if (config->expect_success)
    {
        /* it succeeds */
        g_assert_cmpint (dbus_message_get_type (m), ==,
                         DBUS_MESSAGE_TYPE_METHOD_RETURN);
    }