mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-14 19:55:12 +01:00
GApplication test: test remote commandline
Also, a few small fixes/tweaks to other places in the test.
This commit is contained in:
parent
3e6eee806c
commit
582638d7ad
@ -19,6 +19,7 @@ open (GApplication *application,
|
|||||||
{
|
{
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
|
g_application_hold (application);
|
||||||
g_print ("open");
|
g_print ("open");
|
||||||
|
|
||||||
for (i = 0; i < n_files; i++)
|
for (i = 0; i < n_files; i++)
|
||||||
@ -27,10 +28,33 @@ open (GApplication *application,
|
|||||||
g_print (" %s", uri);
|
g_print (" %s", uri);
|
||||||
g_free (uri);
|
g_free (uri);
|
||||||
}
|
}
|
||||||
|
g_application_release (application);
|
||||||
|
|
||||||
g_print ("\n");
|
g_print ("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
command_line (GApplication *application,
|
||||||
|
GApplicationCommandLine *cmdline)
|
||||||
|
{
|
||||||
|
gchar **argv;
|
||||||
|
gint argc;
|
||||||
|
|
||||||
|
g_application_command_line_get_argc_argv (cmdline, &argc, &argv);
|
||||||
|
|
||||||
|
g_application_command_line_print (cmdline, "%d + %d = %d\n", 40, 2, 42);
|
||||||
|
|
||||||
|
g_assert_cmpint (argc, ==, 3);
|
||||||
|
g_assert_cmpstr (argv[0], ==, "./cmd");
|
||||||
|
g_assert_cmpstr (argv[1], ==, "40 +");
|
||||||
|
g_assert_cmpstr (argv[2], ==, "2");
|
||||||
|
g_assert (argv[3] == NULL);
|
||||||
|
g_print ("cmdline '%s' '%s'\n", argv[1], argv[2]);
|
||||||
|
g_strfreev (argv);
|
||||||
|
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
app_main (int argc, char **argv)
|
app_main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -38,16 +62,31 @@ app_main (int argc, char **argv)
|
|||||||
int status;
|
int status;
|
||||||
|
|
||||||
app = g_application_new ("org.gtk.TestApplication",
|
app = g_application_new ("org.gtk.TestApplication",
|
||||||
G_APPLICATION_FLAGS_HANDLES_OPEN);
|
G_APPLICATION_HANDLES_OPEN |
|
||||||
|
(strcmp (argv[0], "./cmd") == 0 ?
|
||||||
|
G_APPLICATION_HANDLES_COMMAND_LINE
|
||||||
|
: 0));
|
||||||
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
||||||
g_signal_connect (app, "open", G_CALLBACK (open), NULL);
|
g_signal_connect (app, "open", G_CALLBACK (open), NULL);
|
||||||
|
g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
|
||||||
|
#ifdef STANDALONE
|
||||||
|
g_application_set_inactivity_timeout (app, 10000);
|
||||||
|
#else
|
||||||
g_application_set_inactivity_timeout (app, 1000);
|
g_application_set_inactivity_timeout (app, 1000);
|
||||||
|
#endif
|
||||||
status = g_application_run (app, argc, argv);
|
status = g_application_run (app, argc, argv);
|
||||||
g_object_unref (app);
|
g_object_unref (app);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef STANDALONE
|
||||||
|
int
|
||||||
|
main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
return app_main (argc - 1, argv + 1);
|
||||||
|
}
|
||||||
|
#else
|
||||||
static gint outstanding_watches;
|
static gint outstanding_watches;
|
||||||
static GMainLoop *main_loop;
|
static GMainLoop *main_loop;
|
||||||
|
|
||||||
@ -98,11 +137,14 @@ spawn (const gchar *expected_stdout,
|
|||||||
{
|
{
|
||||||
gint pipefd[2];
|
gint pipefd[2];
|
||||||
GPid pid;
|
GPid pid;
|
||||||
|
int s;
|
||||||
|
|
||||||
/* We assume that the child will not produce enough stdout
|
/* We assume that the child will not produce enough stdout
|
||||||
* to deadlock by filling the pipe.
|
* to deadlock by filling the pipe.
|
||||||
*/
|
*/
|
||||||
pipe (pipefd);
|
s = pipe (pipefd);
|
||||||
|
g_assert_cmpint (s, ==, 0);
|
||||||
|
|
||||||
pid = fork ();
|
pid = fork ();
|
||||||
|
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
@ -119,7 +161,6 @@ spawn (const gchar *expected_stdout,
|
|||||||
|
|
||||||
va_start (ap, first_arg);
|
va_start (ap, first_arg);
|
||||||
array = g_ptr_array_new ();
|
array = g_ptr_array_new ();
|
||||||
g_ptr_array_add (array, g_strdup ("./app"));
|
|
||||||
for (arg = first_arg; arg; arg = va_arg (ap, const gchar *))
|
for (arg = first_arg; arg; arg = va_arg (ap, const gchar *))
|
||||||
g_ptr_array_add (array, g_strdup (arg));
|
g_ptr_array_add (array, g_strdup (arg));
|
||||||
g_ptr_array_add (array, NULL);
|
g_ptr_array_add (array, NULL);
|
||||||
@ -131,7 +172,7 @@ spawn (const gchar *expected_stdout,
|
|||||||
g_print ("exit status: %d\n", status);
|
g_print ("exit status: %d\n", status);
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
else
|
else if (pid > 0)
|
||||||
{
|
{
|
||||||
ChildData *data;
|
ChildData *data;
|
||||||
|
|
||||||
@ -143,6 +184,8 @@ spawn (const gchar *expected_stdout,
|
|||||||
g_child_watch_add (pid, child_quit, data);
|
g_child_watch_add (pid, child_quit, data);
|
||||||
outstanding_watches++;
|
outstanding_watches++;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
g_assert_not_reached ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -153,13 +196,25 @@ basic (void)
|
|||||||
main_loop = g_main_loop_new (NULL, 0);
|
main_loop = g_main_loop_new (NULL, 0);
|
||||||
|
|
||||||
/* spawn the master */
|
/* spawn the master */
|
||||||
spawn ("activated\nopen file:///a file:///b\nexit status: 0\n", NULL);
|
spawn ("activated\n"
|
||||||
|
"open file:///a file:///b\n"
|
||||||
|
"cmdline '40 +' '2'\n"
|
||||||
|
"exit status: 0\n",
|
||||||
|
"./app", NULL);
|
||||||
|
|
||||||
/* make sure it becomes the master */
|
/* make sure it becomes the master */
|
||||||
g_usleep (100000);
|
g_usleep (100000);
|
||||||
|
|
||||||
/* send it some files */
|
/* send it some files */
|
||||||
spawn ("exit status: 0\n", "/a", "/b", NULL);
|
spawn ("exit status: 0\n",
|
||||||
|
"./app", "/a", "/b", NULL);
|
||||||
|
|
||||||
|
/* make sure the commandline arrives after the files */
|
||||||
|
g_usleep (100000);
|
||||||
|
|
||||||
|
spawn ("40 + 2 = 42\n"
|
||||||
|
"exit status: 42\n",
|
||||||
|
"./cmd", "40 +", "2", NULL);
|
||||||
|
|
||||||
g_main_loop_run (main_loop);
|
g_main_loop_run (main_loop);
|
||||||
|
|
||||||
@ -175,3 +230,4 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
return g_test_run ();
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user