diff options
author | Matthias Clasen <mclasen@redhat.com> | 2023-05-14 14:11:12 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2023-05-15 00:20:24 -0400 |
commit | 37345670c8c932e2338376fc8b1e47d8bb8bf40e (patch) | |
tree | e12aea747c1842656eb15328405a266a063fafe3 /tests | |
parent | 89d993b6ecb30c76df9b948b80444c871b20a253 (diff) | |
download | gtk+-37345670c8c932e2338376fc8b1e47d8bb8bf40e.tar.gz |
Add testfilelauncherexport-handles-properly
This is a test to use GtkFileLauncher a bit
more intensively than usual.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/meson.build | 1 | ||||
-rw-r--r-- | tests/testfilelauncher.c | 47 |
2 files changed, 48 insertions, 0 deletions
diff --git a/tests/meson.build b/tests/meson.build index c2d08c26de..c9c6e6a4cd 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,5 +1,6 @@ gtk_tests = [ # testname, optional extra sources + ['testfilelauncher'], ['input'], ['testpopup'], ['testupload'], diff --git a/tests/testfilelauncher.c b/tests/testfilelauncher.c new file mode 100644 index 0000000000..3a44037d51 --- /dev/null +++ b/tests/testfilelauncher.c @@ -0,0 +1,47 @@ +#include <gtk/gtk.h> + +static void +launched_cb (GObject *source, + GAsyncResult *result, + gpointer data) +{ + GtkFileLauncher *launcher = GTK_FILE_LAUNCHER (source); + GError *error = NULL; + + if (!gtk_file_launcher_launch_finish (launcher, result, &error)) + { + g_print ("Launching failed: %s\n", error->message); + g_error_free (error); + } +} + +int +main (int argc, char *argv[]) +{ + GtkWidget *window; + GtkFileLauncher *launcher; + + gtk_init (); + + window = gtk_window_new (); + + launcher = gtk_file_launcher_new (NULL); + + gtk_window_present (GTK_WINDOW (window)); + + for (int i = 1; i < argc; i++) + { + GFile *file = g_file_new_for_commandline_arg (argv[i]); + + g_print ("launching %s\n", argv[i]); + + gtk_file_launcher_set_file (launcher, file); + gtk_file_launcher_launch (launcher, GTK_WINDOW (window), NULL, launched_cb, NULL); + g_object_unref (file); + } + + while (g_list_model_get_n_items (gtk_window_get_toplevels ()) > 0) + g_main_context_iteration (NULL, FALSE); + + return 0; +} |