2018-09-03 14:37:55 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright 2002-2008 Red Hat Inc.
|
|
|
|
|
* Copyright 2011-2017 Collabora Ltd.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
|
* obtaining a copy of this software and associated documentation files
|
|
|
|
|
* (the "Software"), to deal in the Software without restriction,
|
|
|
|
|
* including without limitation the rights to use, copy, modify, merge,
|
|
|
|
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
|
|
* and to permit persons to whom the Software is furnished to do so,
|
|
|
|
|
* subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-03-19 12:36:49 +01:00
|
|
|
#include <config.h>
|
2003-04-07 15:42:22 +00:00
|
|
|
#include "test-utils.h"
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
DBusLoop *loop;
|
|
|
|
|
DBusConnection *connection;
|
|
|
|
|
|
|
|
|
|
} CData;
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
add_watch (DBusWatch *watch,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
CData *cd = data;
|
|
|
|
|
|
2011-01-21 18:54:33 +00:00
|
|
|
return _dbus_loop_add_watch (cd->loop, watch);
|
2003-04-07 15:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
remove_watch (DBusWatch *watch,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
CData *cd = data;
|
|
|
|
|
|
2011-01-21 18:54:33 +00:00
|
|
|
_dbus_loop_remove_watch (cd->loop, watch);
|
2003-04-07 15:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
2011-01-24 17:11:52 +00:00
|
|
|
static void
|
|
|
|
|
toggle_watch (DBusWatch *watch,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
CData *cd = data;
|
|
|
|
|
|
|
|
|
|
_dbus_loop_toggle_watch (cd->loop, watch);
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-07 15:42:22 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
add_timeout (DBusTimeout *timeout,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
CData *cd = data;
|
|
|
|
|
|
2011-01-21 18:54:09 +00:00
|
|
|
return _dbus_loop_add_timeout (cd->loop, timeout);
|
2003-04-07 15:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
remove_timeout (DBusTimeout *timeout,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
CData *cd = data;
|
|
|
|
|
|
2011-01-21 18:54:09 +00:00
|
|
|
_dbus_loop_remove_timeout (cd->loop, timeout);
|
2003-04-07 15:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
2003-04-09 22:15:05 +00:00
|
|
|
static void
|
|
|
|
|
dispatch_status_function (DBusConnection *connection,
|
|
|
|
|
DBusDispatchStatus new_status,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
DBusLoop *loop = data;
|
|
|
|
|
|
|
|
|
|
if (new_status != DBUS_DISPATCH_COMPLETE)
|
|
|
|
|
{
|
|
|
|
|
while (!_dbus_loop_queue_dispatch (loop, connection))
|
|
|
|
|
_dbus_wait_for_memory ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-07 15:42:22 +00:00
|
|
|
static void
|
|
|
|
|
cdata_free (void *data)
|
|
|
|
|
{
|
|
|
|
|
CData *cd = data;
|
|
|
|
|
|
|
|
|
|
dbus_connection_unref (cd->connection);
|
|
|
|
|
_dbus_loop_unref (cd->loop);
|
|
|
|
|
|
|
|
|
|
dbus_free (cd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static CData*
|
|
|
|
|
cdata_new (DBusLoop *loop,
|
|
|
|
|
DBusConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
CData *cd;
|
|
|
|
|
|
|
|
|
|
cd = dbus_new0 (CData, 1);
|
|
|
|
|
if (cd == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
cd->loop = loop;
|
|
|
|
|
cd->connection = connection;
|
|
|
|
|
|
|
|
|
|
dbus_connection_ref (cd->connection);
|
|
|
|
|
_dbus_loop_ref (cd->loop);
|
|
|
|
|
|
|
|
|
|
return cd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
2017-11-27 19:26:03 +00:00
|
|
|
test_connection_try_setup (TestMainContext *ctx,
|
|
|
|
|
DBusConnection *connection)
|
2003-04-07 15:42:22 +00:00
|
|
|
{
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
DBusLoop *loop = ctx;
|
2003-04-07 15:42:22 +00:00
|
|
|
CData *cd;
|
|
|
|
|
|
2003-04-09 22:15:05 +00:00
|
|
|
cd = NULL;
|
|
|
|
|
|
|
|
|
|
dbus_connection_set_dispatch_status_function (connection, dispatch_status_function,
|
|
|
|
|
loop, NULL);
|
2017-11-27 19:23:10 +00:00
|
|
|
/* ownership of cd taken */
|
|
|
|
|
|
2003-04-07 15:42:22 +00:00
|
|
|
cd = cdata_new (loop, connection);
|
|
|
|
|
if (cd == NULL)
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_set_watch_functions (connection,
|
|
|
|
|
add_watch,
|
|
|
|
|
remove_watch,
|
2011-01-24 17:11:52 +00:00
|
|
|
toggle_watch,
|
2003-04-07 15:42:22 +00:00
|
|
|
cd, cdata_free))
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cd = cdata_new (loop, connection);
|
|
|
|
|
if (cd == NULL)
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_set_timeout_functions (connection,
|
|
|
|
|
add_timeout,
|
|
|
|
|
remove_timeout,
|
|
|
|
|
NULL,
|
|
|
|
|
cd, cdata_free))
|
2003-04-09 22:15:05 +00:00
|
|
|
goto nomem;
|
|
|
|
|
|
2017-11-27 19:23:10 +00:00
|
|
|
/* ownership taken */
|
|
|
|
|
cd = NULL;
|
|
|
|
|
|
2003-04-09 22:15:05 +00:00
|
|
|
if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE)
|
2003-04-07 15:42:22 +00:00
|
|
|
{
|
2003-04-09 22:15:05 +00:00
|
|
|
if (!_dbus_loop_queue_dispatch (loop, connection))
|
|
|
|
|
goto nomem;
|
2003-04-07 15:42:22 +00:00
|
|
|
}
|
2003-04-09 22:15:05 +00:00
|
|
|
|
2003-04-07 15:42:22 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
nomem:
|
|
|
|
|
if (cd)
|
|
|
|
|
cdata_free (cd);
|
2003-04-09 22:15:05 +00:00
|
|
|
|
|
|
|
|
dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
|
|
|
|
|
dbus_connection_set_watch_functions (connection, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
|
2003-04-07 15:42:22 +00:00
|
|
|
return FALSE;
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
}
|
|
|
|
|
|
2016-10-07 19:45:48 +01:00
|
|
|
static void die (const char *message) _DBUS_GNUC_NORETURN;
|
|
|
|
|
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
static void
|
|
|
|
|
die (const char *message)
|
|
|
|
|
{
|
2017-11-21 12:10:01 +00:00
|
|
|
printf ("Bail out! %s\n", message);
|
|
|
|
|
fflush (stdout);
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
exit (1);
|
2003-04-07 15:42:22 +00:00
|
|
|
}
|
2003-04-07 23:28:16 +00:00
|
|
|
|
2017-11-27 19:26:03 +00:00
|
|
|
void
|
|
|
|
|
test_connection_setup (TestMainContext *ctx,
|
|
|
|
|
DBusConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
if (!test_connection_try_setup (ctx, connection))
|
|
|
|
|
die ("Not enough memory to set up connection");
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-07 23:28:16 +00:00
|
|
|
void
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
test_connection_shutdown (TestMainContext *ctx,
|
2003-04-07 23:28:16 +00:00
|
|
|
DBusConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
if (!dbus_connection_set_watch_functions (connection,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL, NULL))
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
die ("setting watch functions to NULL failed");
|
2003-04-07 23:28:16 +00:00
|
|
|
|
|
|
|
|
if (!dbus_connection_set_timeout_functions (connection,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL, NULL))
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
die ("setting timeout functions to NULL failed");
|
2003-04-07 23:28:16 +00:00
|
|
|
|
2003-04-09 22:15:05 +00:00
|
|
|
dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
|
2003-04-07 23:28:16 +00:00
|
|
|
}
|
2008-05-30 10:33:18 -04:00
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
DBusLoop *loop;
|
|
|
|
|
DBusServer *server;
|
|
|
|
|
} ServerData;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
serverdata_free (void *data)
|
|
|
|
|
{
|
|
|
|
|
ServerData *sd = data;
|
|
|
|
|
|
|
|
|
|
dbus_server_unref (sd->server);
|
|
|
|
|
_dbus_loop_unref (sd->loop);
|
|
|
|
|
|
|
|
|
|
dbus_free (sd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ServerData*
|
|
|
|
|
serverdata_new (DBusLoop *loop,
|
|
|
|
|
DBusServer *server)
|
|
|
|
|
{
|
|
|
|
|
ServerData *sd;
|
|
|
|
|
|
|
|
|
|
sd = dbus_new0 (ServerData, 1);
|
|
|
|
|
if (sd == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
sd->loop = loop;
|
|
|
|
|
sd->server = server;
|
|
|
|
|
|
|
|
|
|
dbus_server_ref (sd->server);
|
|
|
|
|
_dbus_loop_ref (sd->loop);
|
|
|
|
|
|
|
|
|
|
return sd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
add_server_watch (DBusWatch *watch,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
ServerData *context = data;
|
|
|
|
|
|
2011-01-21 18:54:33 +00:00
|
|
|
return _dbus_loop_add_watch (context->loop, watch);
|
2008-05-30 10:33:18 -04:00
|
|
|
}
|
|
|
|
|
|
2011-01-24 17:11:52 +00:00
|
|
|
static void
|
|
|
|
|
toggle_server_watch (DBusWatch *watch,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
ServerData *context = data;
|
|
|
|
|
|
|
|
|
|
_dbus_loop_toggle_watch (context->loop, watch);
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-30 10:33:18 -04:00
|
|
|
static void
|
|
|
|
|
remove_server_watch (DBusWatch *watch,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
ServerData *context = data;
|
|
|
|
|
|
2011-01-21 18:54:33 +00:00
|
|
|
_dbus_loop_remove_watch (context->loop, watch);
|
2008-05-30 10:33:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
add_server_timeout (DBusTimeout *timeout,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
ServerData *context = data;
|
|
|
|
|
|
2011-01-21 18:54:09 +00:00
|
|
|
return _dbus_loop_add_timeout (context->loop, timeout);
|
2008-05-30 10:33:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
remove_server_timeout (DBusTimeout *timeout,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
ServerData *context = data;
|
|
|
|
|
|
2011-01-21 18:54:09 +00:00
|
|
|
_dbus_loop_remove_timeout (context->loop, timeout);
|
2008-05-30 10:33:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
2017-11-27 19:26:03 +00:00
|
|
|
test_server_try_setup (TestMainContext *ctx,
|
|
|
|
|
DBusServer *server)
|
2008-05-30 10:33:18 -04:00
|
|
|
{
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
DBusLoop *loop = ctx;
|
2008-05-30 10:33:18 -04:00
|
|
|
ServerData *sd;
|
|
|
|
|
|
|
|
|
|
sd = serverdata_new (loop, server);
|
|
|
|
|
if (sd == NULL)
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
if (!dbus_server_set_watch_functions (server,
|
|
|
|
|
add_server_watch,
|
|
|
|
|
remove_server_watch,
|
2011-01-24 17:11:52 +00:00
|
|
|
toggle_server_watch,
|
2008-05-30 10:33:18 -04:00
|
|
|
sd,
|
|
|
|
|
serverdata_free))
|
|
|
|
|
{
|
2011-01-19 17:28:58 +00:00
|
|
|
goto nomem;
|
2008-05-30 10:33:18 -04:00
|
|
|
}
|
|
|
|
|
|
2011-01-19 17:33:31 +00:00
|
|
|
sd = serverdata_new (loop, server);
|
|
|
|
|
if (sd == NULL)
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
2008-05-30 10:33:18 -04:00
|
|
|
if (!dbus_server_set_timeout_functions (server,
|
|
|
|
|
add_server_timeout,
|
|
|
|
|
remove_server_timeout,
|
|
|
|
|
NULL,
|
|
|
|
|
sd, serverdata_free))
|
|
|
|
|
{
|
2011-01-19 17:28:58 +00:00
|
|
|
goto nomem;
|
2008-05-30 10:33:18 -04:00
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
nomem:
|
|
|
|
|
if (sd)
|
|
|
|
|
serverdata_free (sd);
|
|
|
|
|
|
|
|
|
|
test_server_shutdown (loop, server);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 19:26:03 +00:00
|
|
|
void
|
|
|
|
|
test_server_setup (TestMainContext *ctx,
|
|
|
|
|
DBusServer *server)
|
|
|
|
|
{
|
|
|
|
|
if (!test_server_try_setup (ctx, server))
|
|
|
|
|
die ("Not enough memory to set up server");
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-30 10:33:18 -04:00
|
|
|
void
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
test_server_shutdown (TestMainContext *ctx,
|
2008-05-30 10:33:18 -04:00
|
|
|
DBusServer *server)
|
|
|
|
|
{
|
2011-01-19 17:34:10 +00:00
|
|
|
dbus_server_disconnect (server);
|
|
|
|
|
|
2008-05-30 10:33:18 -04:00
|
|
|
if (!dbus_server_set_watch_functions (server,
|
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL))
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
die ("setting watch functions to NULL failed");
|
2008-05-30 10:33:18 -04:00
|
|
|
|
|
|
|
|
if (!dbus_server_set_timeout_functions (server,
|
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL))
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
die ("setting timeout functions to NULL failed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestMainContext *
|
|
|
|
|
test_main_context_get (void)
|
2017-11-27 19:26:03 +00:00
|
|
|
{
|
|
|
|
|
TestMainContext *ret = _dbus_loop_new ();
|
|
|
|
|
|
|
|
|
|
if (ret == NULL)
|
|
|
|
|
die ("Out of memory");
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestMainContext *
|
|
|
|
|
test_main_context_try_get (void)
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
{
|
|
|
|
|
return _dbus_loop_new ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestMainContext *
|
|
|
|
|
test_main_context_ref (TestMainContext *ctx)
|
|
|
|
|
{
|
|
|
|
|
return _dbus_loop_ref (ctx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void test_main_context_unref (TestMainContext *ctx)
|
|
|
|
|
{
|
|
|
|
|
_dbus_loop_unref (ctx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void test_main_context_iterate (TestMainContext *ctx,
|
|
|
|
|
dbus_bool_t may_block)
|
|
|
|
|
{
|
|
|
|
|
_dbus_loop_iterate (ctx, may_block);
|
2008-05-30 10:33:18 -04:00
|
|
|
}
|
2015-01-26 19:02:59 +00:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
test_pending_call_store_reply (DBusPendingCall *pc,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage **message_p = data;
|
|
|
|
|
|
|
|
|
|
*message_p = dbus_pending_call_steal_reply (pc);
|
2015-02-20 15:07:23 +00:00
|
|
|
_dbus_assert (*message_p != NULL);
|
2015-01-26 19:02:59 +00:00
|
|
|
}
|