4 #include "gdbus-sessionbus.h"
7 activate (GApplication *application)
9 g_application_hold (application);
10 g_print ("activated\n");
11 g_application_release (application);
15 open (GApplication *application,
24 for (i = 0; i < n_files; i++)
26 gchar *uri = g_file_get_uri (files[i]);
35 app_main (int argc, char **argv)
40 app = g_application_new ("org.gtk.TestApplication",
41 G_APPLICATION_FLAGS_HANDLES_OPEN);
42 g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
43 g_signal_connect (app, "open", G_CALLBACK (open), NULL);
44 g_application_set_inactivity_timeout (app, 1000);
45 status = g_application_run (app, argc, argv);
51 static gint outstanding_watches;
52 static GMainLoop *main_loop;
56 const gchar *expected_stdout;
65 ChildData *child = data;
66 gssize expected, actual;
69 g_assert_cmpint (status, ==, 0);
71 if (--outstanding_watches == 0)
72 g_main_loop_quit (main_loop);
74 expected = strlen (child->expected_stdout);
75 buffer = g_alloca (expected + 100);
76 actual = read (child->stdout_pipe, buffer, expected + 100);
77 close (child->stdout_pipe);
79 g_assert_cmpint (actual, >=, 0);
81 if (actual != expected ||
82 memcmp (buffer, child->expected_stdout, expected) != 0)
84 buffer[MIN(expected + 100, actual)] = '\0';
86 g_error ("\nExpected\n-----\n%s-----\nGot (%s)\n-----\n%s-----\n",
87 child->expected_stdout,
88 (actual > expected) ? "truncated" : "full", buffer);
91 g_slice_free (ChildData, child);
95 spawn (const gchar *expected_stdout,
96 const gchar *first_arg,
102 /* We assume that the child will not produce enough stdout
103 * to deadlock by filling the pipe.
120 va_start (ap, first_arg);
121 array = g_ptr_array_new ();
122 g_ptr_array_add (array, g_strdup ("./app"));
123 for (arg = first_arg; arg; arg = va_arg (ap, const gchar *))
124 g_ptr_array_add (array, g_strdup (arg));
125 g_ptr_array_add (array, NULL);
126 args = (gchar **) g_ptr_array_free (array, FALSE);
128 status = app_main (g_strv_length (args), args);
131 g_print ("exit status: %d\n", status);
138 data = g_slice_new (ChildData);
139 data->expected_stdout = expected_stdout;
140 data->stdout_pipe = pipefd[0];
143 g_child_watch_add (pid, child_quit, data);
144 outstanding_watches++;
153 main_loop = g_main_loop_new (NULL, 0);
155 /* spawn the master */
156 spawn ("activated\nopen file:///a file:///b\nexit status: 0\n", NULL);
158 /* make sure it becomes the master */
161 /* send it some files */
162 spawn ("exit status: 0\n", "/a", "/b", NULL);
164 g_main_loop_run (main_loop);
170 main (int argc, char **argv)
172 g_test_init (&argc, &argv, NULL);
174 g_test_add_func ("/gapplication/basic", basic);
176 return g_test_run ();