diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 15:59:36 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 15:59:36 +0000 |
commit | ec52555862913a23417735f9f7f5402f5230da13 (patch) | |
tree | 5e43a30d289a3daa69dddfbb060216ff6332f197 /test/automated/display | |
parent | Initial commit. (diff) | |
download | nautilus-ec52555862913a23417735f9f7f5402f5230da13.tar.xz nautilus-ec52555862913a23417735f9f7f5402f5230da13.zip |
Adding upstream version 3.38.2.upstream/3.38.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/automated/display')
-rw-r--r-- | test/automated/display/meson.build | 23 | ||||
-rw-r--r-- | test/automated/display/test-nautilus-directory-async.c | 101 | ||||
-rw-r--r-- | test/automated/display/test-nautilus-mime-actions-set.c | 187 | ||||
-rw-r--r-- | test/automated/display/test-nautilus-mime-actions.c | 145 |
4 files changed, 456 insertions, 0 deletions
diff --git a/test/automated/display/meson.build b/test/automated/display/meson.build new file mode 100644 index 0000000..a7e2e0b --- /dev/null +++ b/test/automated/display/meson.build @@ -0,0 +1,23 @@ +test_env += [ + 'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()), + 'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir()) +] + +tests = [ + ['test-nautilus-directory-async', [ + 'test-nautilus-directory-async.c' + ]], +] + +foreach t: tests + test( + t[0], + executable(t[0], t[1], dependencies: libnautilus_dep), + env: [ + test_env, + 'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()), + 'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir()) + ], + timeout: 480 + ) +endforeach diff --git a/test/automated/display/test-nautilus-directory-async.c b/test/automated/display/test-nautilus-directory-async.c new file mode 100644 index 0000000..a4dc24e --- /dev/null +++ b/test/automated/display/test-nautilus-directory-async.c @@ -0,0 +1,101 @@ +#include <src/nautilus-directory.h> +#include <src/nautilus-file-utilities.h> +#include <src/nautilus-search-directory.h> +#include <src/nautilus-file.h> +#include <unistd.h> + +static GMainLoop *main_loop; +void *client1, *client2; + +static void +files_added (NautilusDirectory *directory, + GList *added_files) +{ +#if 0 + GList *list; + + for (list = added_files; list != NULL; list = list->next) + { + NautilusFile *file = list->data; + + g_print (" - %s\n", nautilus_file_get_uri (file)); + } +#endif + + g_print ("files added: %d files\n", + g_list_length (added_files)); +} + +static void +files_changed (NautilusDirectory *directory, + GList *changed_files) +{ +#if 0 + GList *list; + + for (list = changed_files; list != NULL; list = list->next) + { + NautilusFile *file = list->data; + + g_print (" - %s\n", nautilus_file_get_uri (file)); + } +#endif + g_print ("files changed: %d\n", + g_list_length (changed_files)); +} + +static void +done_loading (NautilusDirectory *directory) +{ + g_print ("done loading\n"); + g_main_loop_quit (main_loop); +} + +int +main (int argc, + char **argv) +{ + NautilusDirectory *directory; + NautilusFileAttributes attributes; + const char *uri; + + client1 = g_new0 (int, 1); + client2 = g_new0 (int, 1); + + main_loop = g_main_loop_new (NULL, FALSE); + + nautilus_ensure_extension_points (); + + if (argv[1] == NULL) + { + uri = "file:///tmp"; + } + else + { + uri = argv[1]; + } + g_print ("loading %s", uri); + directory = nautilus_directory_get_by_uri (uri); + + g_signal_connect (directory, "files-added", G_CALLBACK (files_added), NULL); + g_signal_connect (directory, "files-changed", G_CALLBACK (files_changed), NULL); + g_signal_connect (directory, "done-loading", G_CALLBACK (done_loading), NULL); + + attributes = + NAUTILUS_FILE_ATTRIBUTES_FOR_ICON | + NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT | + NAUTILUS_FILE_ATTRIBUTE_INFO | + NAUTILUS_FILE_ATTRIBUTE_MOUNT | + NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO; + + nautilus_directory_file_monitor_add (directory, client1, TRUE, + attributes, + NULL, NULL); + + + g_main_loop_run (main_loop); + + g_main_loop_unref (main_loop); + + return 0; +} diff --git a/test/automated/display/test-nautilus-mime-actions-set.c b/test/automated/display/test-nautilus-mime-actions-set.c new file mode 100644 index 0000000..a08f817 --- /dev/null +++ b/test/automated/display/test-nautilus-mime-actions-set.c @@ -0,0 +1,187 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* test-mime.c - Test for the mime handler detection features of the GNOME + * Virtual File System Library + * + * Copyright (C) 2000 Eazel + * + * The Gnome Library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * The Gnome Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with the Gnome Library; see the file COPYING.LIB. If not, + * see <http://www.gnu.org/licenses/>. + * + * Author: Maciej Stachowiak <mjs@eazel.com> + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include <src/nautilus-mime-actions.h> +#include <stdio.h> + +static gboolean ready = FALSE; + +static void +usage (const char *name) +{ + fprintf (stderr, "Usage: %s uri field value\n", name); + fprintf (stderr, "Valid field values are: \n"); + fprintf (stderr, "\tdefault_action_type\n"); + fprintf (stderr, "\tdefault_application\n"); + fprintf (stderr, "\tdefault_component\n"); + fprintf (stderr, "\tshort_list_applicationss\n"); + fprintf (stderr, "\tshort_list_components\n"); + fprintf (stderr, "\tadd_to_all_applicationss\n"); + fprintf (stderr, "\tremove_from_all_applications\n"); + exit (1); +} + +static GnomeVFSMimeActionType +str_to_action_type (const char *str) +{ + if (g_ascii_strcasecmp (str, "component") == 0) + { + return GNOME_VFS_MIME_ACTION_TYPE_COMPONENT; + } + else if (g_ascii_strcasecmp (str, "application") == 0) + { + return GNOME_VFS_MIME_ACTION_TYPE_APPLICATION; + } + else + { + return GNOME_VFS_MIME_ACTION_TYPE_NONE; + } +} + +static char ** +strsplit_handle_null (const char *str, + const char *delim, + int max) +{ + return g_strsplit ((str == NULL ? "" : str), delim, max); +} + + +static GList * +strsplit_to_list (const char *str, + const char *delim, + int max) +{ + char **strv; + GList *retval; + int i; + + strv = strsplit_handle_null (str, delim, max); + + retval = NULL; + + for (i = 0; strv[i] != NULL; i++) + { + retval = g_list_prepend (retval, strv[i]); + } + + retval = g_list_reverse (retval); + /* Don't strfreev, since we didn't copy the individual strings. */ + g_free (strv); + + return retval; +} + +static GList * +comma_separated_str_to_str_list (const char *str) +{ + return strsplit_to_list (str, ",", 0); +} + +static void +ready_callback (NautilusFile *file, + gpointer callback_data) +{ + ready = TRUE; +} + +int +main (int argc, + char **argv) +{ + const char *uri; + const char *field; + const char *value; + NautilusFile *file; + NautilusFileAttributes attributes; + + gtk_init (&argc, &argv); + + if (argc < 3) + { + usage (argv[0]); + } + + uri = argv[1]; + field = argv[2]; + value = argv[3]; + + file = nautilus_file_get_by_uri (uri); + + attributes = nautilus_mime_actions_get_full_file_attributes (); + nautilus_file_call_when_ready (file, attributes, ready_callback, NULL); + + while (!ready) + { + gtk_main_iteration (); + } + + if (strcmp (field, "default_action_type") == 0) + { + puts ("default_action_type"); + nautilus_mime_set_default_action_type_for_file (file, str_to_action_type (value)); + } + else if (strcmp (field, "default_application") == 0) + { + puts ("default_application"); + nautilus_mime_set_default_application_for_file (file, value); + } + else if (strcmp (field, "default_component") == 0) + { + puts ("default_component"); + nautilus_mime_set_default_component_for_file (file, value); + } + else if (strcmp (field, "short_list_applicationss") == 0) + { + puts ("short_list_applications"); + nautilus_mime_set_short_list_applications_for_file + (file, comma_separated_str_to_str_list (value)); + } + else if (strcmp (field, "short_list_components") == 0) + { + puts ("short_list_components"); + nautilus_mime_set_short_list_components_for_file + (file, comma_separated_str_to_str_list (value)); + } + else if (strcmp (field, "add_to_all_applicationss") == 0) + { + puts ("add_to_all_applications"); + nautilus_mime_extend_all_applications_for_file + (file, comma_separated_str_to_str_list (value)); + } + else if (strcmp (field, "remove_from_all_applications") == 0) + { + puts ("remove_from_all_applications"); + nautilus_mime_remove_from_all_applications_for_file + (file, comma_separated_str_to_str_list (value)); + } + else + { + usage (argv[0]); + } + + return 0; +} diff --git a/test/automated/display/test-nautilus-mime-actions.c b/test/automated/display/test-nautilus-mime-actions.c new file mode 100644 index 0000000..38e140f --- /dev/null +++ b/test/automated/display/test-nautilus-mime-actions.c @@ -0,0 +1,145 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* test-mime.c - Test for the mime handler detection features of the GNOME + * Virtual File System Library + * + * Copyright (C) 2000 Eazel + * + * The Gnome Library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * The Gnome Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with the Gnome Library; see the file COPYING.LIB. If not, + * see <http://www.gnu.org/licenses/>. + * + * Author: Maciej Stachowiak <mjs@eazel.com> + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include <src/nautilus-mime-actions.h> +#include <stdio.h> + +static gboolean ready = FALSE; + + +static void +append_comma_and_scheme (gpointer scheme, + gpointer user_data) +{ + char **string; + + string = (char **) user_data; + if (strlen (*string) > 0) + { + *string = g_strconcat (*string, ", ", scheme, NULL); + } + else + { + *string = g_strdup (scheme); + } +} + + +static char * +format_supported_uri_schemes_for_display (GList *supported_uri_schemes) +{ + char *string; + + string = g_strdup (""); + g_list_foreach (supported_uri_schemes, + append_comma_and_scheme, + &string); + return string; +} + +static void +print_application (GAppInfo *application) +{ + if (application == NULL) + { + puts ("(none)"); + } + else + { + printf ("name: %s\ncommand: %s\nexpects_uris: %s\n", + g_application_get_name (application), + g_application_get_executable (application), + (g_app_info_supports_uris (application) ? "TRUE" : "FALSE")); + } +} + +static void +print_application_list (GList *applications) +{ + GList *p; + + if (applications == NULL) + { + puts ("(none)"); + } + else + { + for (p = applications; p != NULL; p = p->next) + { + print_application (p->data); + puts ("------"); + } + } +} + +static void +ready_callback (NautilusFile *file, + gpointer callback_data) +{ + ready = TRUE; +} + +int +main (int argc, + char **argv) +{ + const char *uri; + GAppInfo *default_application; + GList *all_applications; + NautilusFile *file; + NautilusFileAttributes attributes; + + gtk_init (&argc, &argv); + + if (argc != 2) + { + fprintf (stderr, "Usage: %s uri\n", *argv); + return 1; + } + + uri = argv[1]; + file = nautilus_file_get_by_uri (uri); + + attributes = nautilus_mime_actions_get_full_file_attributes (); + nautilus_file_call_when_ready (file, attributes, ready_callback, NULL); + + while (!ready) + { + gtk_main_iteration (); + } + + default_application = nautilus_mime_get_default_application_for_file (file); + puts ("Default Application"); + print_application (default_application); + puts (""); + + all_applications = nautilus_mime_get_applications_for_file (file); + puts ("All Applications"); + print_application_list (all_applications); + puts (""); + + return 0; +} |