2010-06-07 19:25:39 +02:00
|
|
|
#include <gio/gio.h>
|
2010-06-09 03:43:16 +02:00
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
#include <fcntl.h>
|
2010-06-07 19:25:39 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <signal.h>
|
2010-06-09 03:43:16 +02:00
|
|
|
#endif
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-10 05:44:13 +02:00
|
|
|
#include "gdbus-sessionbus.h"
|
|
|
|
|
2010-06-07 19:25:39 +02:00
|
|
|
static gint appeared;
|
|
|
|
static gint disappeared;
|
|
|
|
static gint changed;
|
|
|
|
|
|
|
|
static void
|
|
|
|
name_appeared (GDBusConnection *connection,
|
|
|
|
const gchar *name,
|
|
|
|
const gchar *name_owner,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GMainLoop *loop = user_data;
|
|
|
|
|
|
|
|
appeared++;
|
|
|
|
|
|
|
|
if (loop)
|
|
|
|
g_main_loop_quit (loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
name_disappeared (GDBusConnection *connection,
|
|
|
|
const gchar *name,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GMainLoop *loop = user_data;
|
|
|
|
|
|
|
|
disappeared++;
|
|
|
|
|
|
|
|
if (loop)
|
|
|
|
g_main_loop_quit (loop);
|
|
|
|
}
|
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
void
|
|
|
|
child_setup_pipe (gpointer user_data)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-06-09 03:43:16 +02:00
|
|
|
int *fds = user_data;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
close (fds[0]);
|
|
|
|
dup2 (fds[1], 3);
|
|
|
|
g_setenv ("_G_TEST_SLAVE_FD", "3", TRUE);
|
|
|
|
close (fds[1]);
|
|
|
|
}
|
|
|
|
#endif
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
static gboolean
|
|
|
|
spawn_async_with_monitor_pipe (const gchar *argv[], GPid *pid, int *fd)
|
|
|
|
{
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
int fds[2];
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
pipe (fds);
|
|
|
|
|
|
|
|
result = g_spawn_async (NULL, (char**)argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, child_setup_pipe, &fds, pid, NULL);
|
|
|
|
close (fds[1]);
|
|
|
|
*fd = fds[0];
|
|
|
|
return result;
|
|
|
|
#else
|
|
|
|
*fd = -1;
|
|
|
|
return g_spawn_async (NULL, argv, 0, NULL, NULL, pid, NULL);
|
|
|
|
#endif
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-06-09 03:43:16 +02:00
|
|
|
start_application (GPid *pid, int *fd)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-06-09 03:43:16 +02:00
|
|
|
const gchar *argv[] = { "./testapp", NULL };
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
g_assert (spawn_async_with_monitor_pipe (argv, pid, fd));
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GMainContext *context;
|
|
|
|
GSource *child_watch;
|
|
|
|
GSource *timeout;
|
|
|
|
GPid pid;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
gboolean child_exited;
|
|
|
|
GMainLoop *loop;
|
|
|
|
} AwaitChildTerminationData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_child_termination_exited (GPid pid,
|
2010-06-12 05:21:49 +02:00
|
|
|
gint status,
|
|
|
|
gpointer user_data)
|
2010-06-09 03:43:16 +02:00
|
|
|
{
|
|
|
|
AwaitChildTerminationData *data = user_data;
|
|
|
|
data->child_exited = TRUE;
|
|
|
|
g_spawn_close_pid (data->pid);
|
|
|
|
g_main_loop_quit (data->loop);
|
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
static gboolean
|
|
|
|
on_child_termination_timeout (gpointer user_data)
|
|
|
|
{
|
|
|
|
AwaitChildTerminationData *data = user_data;
|
|
|
|
g_main_loop_quit (data->loop);
|
2010-06-07 19:25:39 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
static void
|
|
|
|
await_child_termination_init (AwaitChildTerminationData *data,
|
2010-06-12 05:21:49 +02:00
|
|
|
GPid pid,
|
|
|
|
int fd)
|
2010-06-09 03:43:16 +02:00
|
|
|
{
|
|
|
|
data->context = g_main_context_get_thread_default ();
|
|
|
|
data->child_exited = FALSE;
|
|
|
|
data->pid = pid;
|
|
|
|
data->fd = fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
await_child_termination_terminate (AwaitChildTerminationData *data)
|
|
|
|
{
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
kill (data->pid, SIGTERM);
|
|
|
|
close (data->fd);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-06-07 19:25:39 +02:00
|
|
|
static gboolean
|
2010-06-09 03:43:16 +02:00
|
|
|
await_child_termination_run (AwaitChildTerminationData *data)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-06-09 03:43:16 +02:00
|
|
|
GSource *timeout_source;
|
|
|
|
GSource *child_watch_source;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
data->loop = g_main_loop_new (data->context, FALSE);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
child_watch_source = g_child_watch_source_new (data->pid);
|
|
|
|
g_source_set_callback (child_watch_source, (GSourceFunc) on_child_termination_exited, data, NULL);
|
|
|
|
g_source_attach (child_watch_source, data->context);
|
|
|
|
|
|
|
|
timeout_source = g_timeout_source_new_seconds (5);
|
|
|
|
g_source_set_callback (timeout_source, on_child_termination_timeout, data, NULL);
|
|
|
|
g_source_attach (timeout_source, data->context);
|
|
|
|
|
|
|
|
g_main_loop_run (data->loop);
|
|
|
|
|
|
|
|
g_source_destroy (child_watch_source);
|
2010-06-22 21:31:55 +02:00
|
|
|
g_source_unref (child_watch_source);
|
2010-06-09 03:43:16 +02:00
|
|
|
g_source_destroy (timeout_source);
|
2010-06-22 21:31:55 +02:00
|
|
|
g_source_unref (timeout_source);
|
2010-06-09 03:43:16 +02:00
|
|
|
|
|
|
|
g_main_loop_unref (data->loop);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
return data->child_exited;
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-06-09 03:43:16 +02:00
|
|
|
terminate_child_sync (GPid pid, int fd)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-06-09 03:43:16 +02:00
|
|
|
AwaitChildTerminationData data;
|
|
|
|
|
|
|
|
await_child_termination_init (&data, pid, fd);
|
|
|
|
await_child_termination_terminate (&data);
|
|
|
|
await_child_termination_run (&data);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef void (*RunWithApplicationFunc) (void);
|
|
|
|
|
|
|
|
typedef struct {
|
2010-06-07 19:25:39 +02:00
|
|
|
GMainLoop *loop;
|
2010-06-09 03:43:16 +02:00
|
|
|
RunWithApplicationFunc func;
|
|
|
|
guint timeout_id;
|
|
|
|
} RunWithAppNameAppearedData;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
static void
|
|
|
|
on_run_with_application_name_appeared (GDBusConnection *connection,
|
2010-06-12 05:21:49 +02:00
|
|
|
const gchar *name,
|
|
|
|
const gchar *name_owner,
|
|
|
|
gpointer user_data)
|
2010-06-09 03:43:16 +02:00
|
|
|
{
|
|
|
|
RunWithAppNameAppearedData *data = user_data;
|
|
|
|
|
|
|
|
data->func ();
|
|
|
|
|
|
|
|
g_main_loop_quit (data->loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
on_run_with_application_timeout (gpointer user_data)
|
|
|
|
{
|
|
|
|
RunWithAppNameAppearedData *data = user_data;
|
|
|
|
data->timeout_id = 0;
|
|
|
|
g_error ("Timed out starting testapp");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
run_with_application (RunWithApplicationFunc test_func)
|
|
|
|
{
|
|
|
|
GMainLoop *loop;
|
|
|
|
RunWithAppNameAppearedData data;
|
|
|
|
gint watch;
|
|
|
|
GPid main_pid;
|
|
|
|
gint main_fd;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
|
|
|
loop = g_main_loop_new (NULL, FALSE);
|
2010-06-09 03:43:16 +02:00
|
|
|
|
|
|
|
data.timeout_id = 0;
|
|
|
|
data.func = test_func;
|
|
|
|
data.loop = loop;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
|
|
|
watch = g_bus_watch_name (G_BUS_TYPE_SESSION,
|
|
|
|
"org.gtk.test.app",
|
|
|
|
0,
|
2010-06-09 03:43:16 +02:00
|
|
|
on_run_with_application_name_appeared,
|
2010-06-07 19:25:39 +02:00
|
|
|
NULL,
|
2010-06-09 03:43:16 +02:00
|
|
|
&data,
|
2010-06-07 19:25:39 +02:00
|
|
|
NULL);
|
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
data.timeout_id = g_timeout_add_seconds (5, on_run_with_application_timeout, &data);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
start_application (&main_pid, &main_fd);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
|
|
|
g_main_loop_run (loop);
|
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
if (data.timeout_id)
|
|
|
|
{
|
|
|
|
g_source_remove (data.timeout_id);
|
|
|
|
data.timeout_id = 0;
|
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
g_main_loop_unref (loop);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
g_bus_unwatch_name (watch);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
terminate_child_sync (main_pid, main_fd);
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
/* This test starts an application, checks that its name appears
|
|
|
|
* on the bus, then starts it again and checks that the second
|
|
|
|
* instance exits right away.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
test_unique_on_app_appeared (void)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-06-09 03:43:16 +02:00
|
|
|
GPid sub_pid;
|
|
|
|
int sub_fd;
|
|
|
|
int watch;
|
|
|
|
AwaitChildTerminationData data;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
appeared = 0;
|
|
|
|
disappeared = 0;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
watch = g_bus_watch_name (G_BUS_TYPE_SESSION,
|
|
|
|
"org.gtk.test.app",
|
|
|
|
0,
|
|
|
|
name_appeared,
|
|
|
|
name_disappeared,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
start_application (&sub_pid, &sub_fd);
|
|
|
|
await_child_termination_init (&data, sub_pid, sub_fd);
|
|
|
|
await_child_termination_run (&data);
|
|
|
|
|
|
|
|
g_bus_unwatch_name (watch);
|
|
|
|
|
|
|
|
g_assert_cmpint (appeared, ==, 1);
|
|
|
|
g_assert_cmpint (disappeared, ==, 0);
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-06-09 03:43:16 +02:00
|
|
|
test_unique (void)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-06-09 03:43:16 +02:00
|
|
|
run_with_application (test_unique_on_app_appeared);
|
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
static void
|
|
|
|
on_name_disappeared_quit (GDBusConnection *connection,
|
2010-06-12 05:21:49 +02:00
|
|
|
const gchar *name,
|
|
|
|
gpointer user_data)
|
2010-06-09 03:43:16 +02:00
|
|
|
{
|
|
|
|
GMainLoop *loop = user_data;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
g_main_loop_quit (loop);
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
2010-06-08 22:25:33 +02:00
|
|
|
static GVariant *
|
|
|
|
create_empty_vardict ()
|
|
|
|
{
|
|
|
|
GVariantBuilder builder;
|
|
|
|
|
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
|
|
|
|
return g_variant_builder_end (&builder);
|
|
|
|
}
|
|
|
|
|
2010-06-12 05:21:49 +02:00
|
|
|
static gboolean
|
|
|
|
call_quit (gpointer data)
|
|
|
|
{
|
|
|
|
GDBusConnection *connection;
|
|
|
|
GError *error = NULL;
|
|
|
|
GVariant *res;
|
|
|
|
|
|
|
|
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
|
|
|
|
res = g_dbus_connection_call_sync (connection,
|
|
|
|
"org.gtk.test.app",
|
|
|
|
"/org/gtk/test/app",
|
|
|
|
"org.gtk.Application",
|
|
|
|
"Quit",
|
2010-06-08 22:25:33 +02:00
|
|
|
g_variant_new ("(@a{sv})", create_empty_vardict ()),
|
|
|
|
NULL,
|
2010-06-12 05:21:49 +02:00
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
-1,
|
|
|
|
NULL,
|
|
|
|
&error);
|
2010-06-12 07:55:25 +02:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_NO_REPLY);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
2010-06-12 05:21:49 +02:00
|
|
|
|
|
|
|
if (res)
|
|
|
|
g_variant_unref (res);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
/* This test starts an application, checks that its name appears on
|
|
|
|
* the bus, then calls Quit, and verifies that the name disappears and
|
|
|
|
* the application exits.
|
2010-06-07 19:25:39 +02:00
|
|
|
*/
|
|
|
|
static void
|
2010-06-09 03:43:16 +02:00
|
|
|
test_quit_on_app_appeared (void)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
|
|
|
GMainLoop *loop;
|
2010-06-09 03:43:16 +02:00
|
|
|
int quit_disappeared_watch;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
|
|
|
loop = g_main_loop_new (NULL, FALSE);
|
2010-06-09 03:43:16 +02:00
|
|
|
quit_disappeared_watch = g_bus_watch_name (G_BUS_TYPE_SESSION,
|
2010-06-07 19:25:39 +02:00
|
|
|
"org.gtk.test.app",
|
|
|
|
0,
|
|
|
|
NULL,
|
2010-06-09 03:43:16 +02:00
|
|
|
on_name_disappeared_quit,
|
|
|
|
loop,
|
2010-06-07 19:25:39 +02:00
|
|
|
NULL);
|
2010-06-13 00:40:45 +02:00
|
|
|
call_quit (NULL);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
|
|
|
g_main_loop_run (loop);
|
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
g_bus_unwatch_name (quit_disappeared_watch);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
|
|
|
g_main_loop_unref (loop);
|
2010-06-09 03:43:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_quit (void)
|
|
|
|
{
|
|
|
|
run_with_application (test_quit_on_app_appeared);
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_g_strv_has_string (const gchar* const * haystack,
|
|
|
|
const gchar *needle)
|
|
|
|
{
|
|
|
|
guint n;
|
|
|
|
|
|
|
|
for (n = 0; haystack != NULL && haystack[n] != NULL; n++)
|
|
|
|
{
|
|
|
|
if (g_strcmp0 (haystack[n], needle) == 0)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar **
|
|
|
|
list_actions (void)
|
|
|
|
{
|
|
|
|
GDBusConnection *connection;
|
|
|
|
GVariant *res;
|
|
|
|
gchar **strv;
|
|
|
|
gchar *str;
|
|
|
|
GVariantIter *iter;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
|
|
|
|
res = g_dbus_connection_call_sync (connection,
|
|
|
|
"org.gtk.test.app",
|
|
|
|
"/org/gtk/test/app",
|
|
|
|
"org.gtk.Application",
|
|
|
|
"ListActions",
|
|
|
|
NULL,
|
2010-06-12 05:21:49 +02:00
|
|
|
NULL,
|
2010-06-07 19:25:39 +02:00
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
-1,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
strv = g_new0 (gchar *, 32);
|
|
|
|
g_variant_get (res, "(a{s(sb)})", &iter);
|
|
|
|
i = 0;
|
|
|
|
while (g_variant_iter_loop (iter, "{s(sb)}", &str, NULL, NULL))
|
|
|
|
{
|
|
|
|
strv[i] = g_strdup (str);
|
|
|
|
i++;
|
|
|
|
g_assert (i < 32);
|
|
|
|
}
|
|
|
|
g_variant_iter_free (iter);
|
|
|
|
|
|
|
|
strv[i] = NULL;
|
|
|
|
|
|
|
|
g_variant_unref (res);
|
|
|
|
g_object_unref (connection);
|
|
|
|
|
|
|
|
return strv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-06-09 03:43:16 +02:00
|
|
|
test_list_actions_on_app_appeared (void)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
|
|
|
gchar **actions;
|
|
|
|
|
|
|
|
actions = list_actions ();
|
|
|
|
|
|
|
|
g_assert (g_strv_length (actions) == 2);
|
|
|
|
g_assert (_g_strv_has_string ((const char *const *)actions, "action1"));
|
|
|
|
g_assert (_g_strv_has_string ((const char *const *)actions, "action2"));
|
|
|
|
|
|
|
|
g_strfreev (actions);
|
2010-06-09 03:43:16 +02:00
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
/* This test start an application, waits for its name to appear on
|
|
|
|
* the bus, then calls ListActions, and verifies that it gets the expected
|
|
|
|
* actions back.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
test_list_actions (void)
|
|
|
|
{
|
|
|
|
run_with_application (test_list_actions_on_app_appeared);
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-06-09 03:43:16 +02:00
|
|
|
invoke_action (gpointer user_data)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-06-09 03:43:16 +02:00
|
|
|
const gchar *action = user_data;
|
2010-06-07 19:25:39 +02:00
|
|
|
GDBusConnection *connection;
|
|
|
|
GVariant *res;
|
|
|
|
|
|
|
|
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
|
|
|
|
res = g_dbus_connection_call_sync (connection,
|
|
|
|
"org.gtk.test.app",
|
|
|
|
"/org/gtk/test/app",
|
|
|
|
"org.gtk.Application",
|
|
|
|
"InvokeAction",
|
2010-06-08 22:25:33 +02:00
|
|
|
g_variant_new ("(s@a{sv})",
|
2010-06-07 19:25:39 +02:00
|
|
|
action,
|
2010-06-08 22:25:33 +02:00
|
|
|
create_empty_vardict ()),
|
2010-06-12 05:21:49 +02:00
|
|
|
NULL,
|
2010-06-07 19:25:39 +02:00
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
-1,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
if (res)
|
|
|
|
g_variant_unref (res);
|
|
|
|
g_object_unref (connection);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This test starts an application, waits for it to appear,
|
|
|
|
* then invokes 'action1' and checks that it causes the application
|
|
|
|
* to exit with an exit code of 1.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
test_invoke (void)
|
|
|
|
{
|
|
|
|
GMainLoop *loop;
|
2010-06-09 03:43:16 +02:00
|
|
|
int quit_disappeared_watch;
|
2010-06-07 19:25:39 +02:00
|
|
|
|
|
|
|
loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
quit_disappeared_watch = g_bus_watch_name (G_BUS_TYPE_SESSION,
|
2010-06-12 05:21:49 +02:00
|
|
|
"org.gtk.test.app",
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
on_name_disappeared_quit,
|
|
|
|
loop,
|
|
|
|
NULL);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
g_timeout_add (0, invoke_action, "action1");
|
2010-06-07 19:25:39 +02:00
|
|
|
|
|
|
|
g_main_loop_run (loop);
|
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
g_bus_unwatch_name (quit_disappeared_watch);
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-06-09 03:43:16 +02:00
|
|
|
test_remote_on_application_appeared (void)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
2010-06-09 03:43:16 +02:00
|
|
|
GPid sub_pid;
|
|
|
|
int sub_fd;
|
|
|
|
AwaitChildTerminationData data;
|
|
|
|
gchar *argv[] = { "./testapp", "--non-unique", NULL };
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
spawn_async_with_monitor_pipe ((const char **) argv, &sub_pid, &sub_fd);
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
await_child_termination_init (&data, sub_pid, sub_fd);
|
|
|
|
await_child_termination_run (&data);
|
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
static void
|
|
|
|
test_remote (void)
|
|
|
|
{
|
|
|
|
run_with_application (test_remote_on_application_appeared);
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
actions_changed (GDBusConnection *connection,
|
|
|
|
const gchar *sender_name,
|
|
|
|
const gchar *object_path,
|
|
|
|
const gchar *interface_name,
|
|
|
|
const gchar *signal_name,
|
|
|
|
GVariant *parameters,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GMainLoop *loop = user_data;
|
|
|
|
|
|
|
|
g_assert_cmpstr (interface_name, ==, "org.gtk.Application");
|
|
|
|
g_assert_cmpstr (signal_name, ==, "ActionsChanged");
|
|
|
|
|
|
|
|
changed++;
|
|
|
|
|
|
|
|
g_main_loop_quit (loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-06-09 03:43:16 +02:00
|
|
|
test_change_action_on_application_appeared (void)
|
2010-06-07 19:25:39 +02:00
|
|
|
{
|
|
|
|
GMainLoop *loop;
|
|
|
|
guint id;
|
|
|
|
GDBusConnection *connection;
|
|
|
|
|
|
|
|
loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
|
|
|
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
|
|
|
|
id = g_dbus_connection_signal_subscribe (connection,
|
|
|
|
NULL,
|
|
|
|
"org.gtk.Application",
|
|
|
|
"ActionsChanged",
|
|
|
|
"/org/gtk/test/app",
|
|
|
|
NULL,
|
|
|
|
actions_changed,
|
|
|
|
loop,
|
|
|
|
NULL);
|
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
g_timeout_add (0, invoke_action, "action2");
|
2010-06-07 19:25:39 +02:00
|
|
|
|
|
|
|
g_main_loop_run (loop);
|
|
|
|
|
|
|
|
g_assert_cmpint (changed, >, 0);
|
|
|
|
|
|
|
|
g_dbus_connection_signal_unsubscribe (connection, id);
|
|
|
|
g_object_unref (connection);
|
|
|
|
g_main_loop_unref (loop);
|
2010-06-09 03:43:16 +02:00
|
|
|
}
|
2010-06-07 19:25:39 +02:00
|
|
|
|
2010-06-09 03:43:16 +02:00
|
|
|
static void
|
|
|
|
test_change_action (void)
|
|
|
|
{
|
|
|
|
run_with_application (test_change_action_on_application_appeared);
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2010-06-10 05:44:13 +02:00
|
|
|
gint ret;
|
|
|
|
|
2010-06-07 19:25:39 +02:00
|
|
|
g_type_init ();
|
|
|
|
g_test_init (&argc, &argv, NULL);
|
|
|
|
|
2010-06-10 05:44:13 +02:00
|
|
|
g_unsetenv ("DISPLAY");
|
|
|
|
g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
|
|
|
|
|
|
|
|
session_bus_up ();
|
|
|
|
|
2010-06-07 19:25:39 +02:00
|
|
|
g_test_add_func ("/application/unique", test_unique);
|
|
|
|
g_test_add_func ("/application/quit", test_quit);
|
|
|
|
g_test_add_func ("/application/list-actions", test_list_actions);
|
|
|
|
g_test_add_func ("/application/invoke", test_invoke);
|
|
|
|
g_test_add_func ("/application/remote", test_remote);
|
|
|
|
g_test_add_func ("/application/change-action", test_change_action);
|
|
|
|
|
2010-06-10 05:44:13 +02:00
|
|
|
ret = g_test_run ();
|
|
|
|
|
|
|
|
session_bus_down ();
|
|
|
|
|
|
|
|
return ret;
|
2010-06-07 19:25:39 +02:00
|
|
|
}
|
|
|
|
|