summaryrefslogtreecommitdiff
path: root/test/automated
diff options
context:
space:
mode:
Diffstat (limited to 'test/automated')
-rw-r--r--test/automated/display/meson.build12
-rw-r--r--test/automated/display/test-nautilus-directory-async.c99
-rw-r--r--test/automated/display/test-nautilus-mime-actions-set.c187
-rw-r--r--test/automated/display/test-nautilus-mime-actions.c145
-rw-r--r--test/automated/display/test-nautilus-search-engine.c65
-rw-r--r--test/automated/displayless/meson.build12
-rw-r--r--test/automated/displayless/test-eel-string-get-common-prefix.c190
-rw-r--r--test/automated/displayless/test-file-utilities-get-common-filename-prefix.c459
-rw-r--r--test/automated/meson.build4
9 files changed, 1173 insertions, 0 deletions
diff --git a/test/automated/display/meson.build b/test/automated/display/meson.build
new file mode 100644
index 000000000..1edd7b60d
--- /dev/null
+++ b/test/automated/display/meson.build
@@ -0,0 +1,12 @@
+tests = [
+ ['test-nautilus-search-engine', [
+ 'test-nautilus-search-engine.c'
+ ]],
+ ['test-nautilus-directory-async', [
+ 'test-nautilus-directory-async.c'
+ ]]
+]
+
+foreach t: tests
+ test(t[0], executable(t[0], t[1], dependencies: libnautilus_dep))
+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 000000000..804c443cc
--- /dev/null
+++ b/test/automated/display/test-nautilus-directory-async.c
@@ -0,0 +1,99 @@
+#include <gtk/gtk.h>
+#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>
+
+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");
+ gtk_main_quit ();
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ NautilusDirectory *directory;
+ NautilusFileAttributes attributes;
+ const char *uri;
+
+ client1 = g_new0 (int, 1);
+ client2 = g_new0 (int, 1);
+
+ gtk_init (&argc, &argv);
+
+ 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_LINK_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_MOUNT |
+ NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO;
+
+ nautilus_directory_file_monitor_add (directory, client1, TRUE,
+ attributes,
+ NULL, NULL);
+
+
+ gtk_main ();
+ 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 000000000..a08f817d6
--- /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 000000000..38e140fd6
--- /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;
+}
diff --git a/test/automated/display/test-nautilus-search-engine.c b/test/automated/display/test-nautilus-search-engine.c
new file mode 100644
index 000000000..2ed8af77e
--- /dev/null
+++ b/test/automated/display/test-nautilus-search-engine.c
@@ -0,0 +1,65 @@
+#include <src/nautilus-file-utilities.h>
+#include <src/nautilus-search-provider.h>
+#include <src/nautilus-search-engine.h>
+#include <gtk/gtk.h>
+
+static void
+hits_added_cb (NautilusSearchEngine *engine,
+ GSList *hits)
+{
+ g_print ("hits added\n");
+ while (hits)
+ {
+ g_print (" - %s\n", (char *) hits->data);
+ hits = hits->next;
+ }
+}
+
+static void
+finished_cb (NautilusSearchEngine *engine,
+ NautilusSearchProviderStatus status)
+{
+ g_print ("finished!\n");
+ gtk_main_quit ();
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ NautilusSearchEngine *engine;
+ NautilusSearchEngineModel *model;
+ NautilusDirectory *directory;
+ NautilusQuery *query;
+ GFile *location;
+
+ gtk_init (&argc, &argv);
+
+ nautilus_ensure_extension_points ();
+
+ engine = nautilus_search_engine_new ();
+ g_signal_connect (engine, "hits-added",
+ G_CALLBACK (hits_added_cb), NULL);
+ g_signal_connect (engine, "finished",
+ G_CALLBACK (finished_cb), NULL);
+
+ query = nautilus_query_new ();
+ nautilus_query_set_text (query, "richard hult");
+ nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (engine), query);
+ g_object_unref (query);
+
+ location = g_file_new_for_path (g_get_home_dir ());
+ directory = nautilus_directory_get (location);
+ g_object_unref (location);
+
+ model = nautilus_search_engine_get_model_provider (engine);
+ nautilus_search_engine_model_set_model (model, directory);
+ g_object_unref (directory);
+
+ nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (engine));
+ nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (engine));
+ g_object_unref (engine);
+
+ gtk_main ();
+ return 0;
+}
diff --git a/test/automated/displayless/meson.build b/test/automated/displayless/meson.build
new file mode 100644
index 000000000..fc8570f3c
--- /dev/null
+++ b/test/automated/displayless/meson.build
@@ -0,0 +1,12 @@
+tests = [
+ ['test-file-utilities-get-common-filename-prefix', [
+ 'test-file-utilities-get-common-filename-prefix.c'
+ ]],
+ ['test-eel-string-get-common-prefix', [
+ 'test-eel-string-get-common-prefix.c'
+ ]]
+]
+
+foreach t: tests
+ test(t[0], executable(t[0], t[1], dependencies: libnautilus_dep))
+endforeach
diff --git a/test/automated/displayless/test-eel-string-get-common-prefix.c b/test/automated/displayless/test-eel-string-get-common-prefix.c
new file mode 100644
index 000000000..2dc5d9e9a
--- /dev/null
+++ b/test/automated/displayless/test-eel-string-get-common-prefix.c
@@ -0,0 +1,190 @@
+#include <glib.h>
+#include <glib/gprintf.h>
+
+#include "eel/eel-string.h"
+
+
+static void
+free_list_and_result (GList *list,
+ char *result)
+{
+ g_list_free (list);
+ g_free (result);
+}
+
+static void
+test_has_large_enough_common_prefix ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "foo-1.txt");
+ list = g_list_append (list, "foo-1.tar");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_cmpstr ("foo-1.t", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_has_common_prefix_that_equals_the_min_required_length ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "food");
+ list = g_list_append (list, "foody");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_cmpstr ("food", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_has_common_prefix_that_equals_the_min_required_length2 ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "foody");
+ list = g_list_append (list, "food");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_cmpstr ("food", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_many_strings_with_common_prefix ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "some text that matches abcde");
+ list = g_list_append (list, "some text that matches abc22");
+ list = g_list_append (list, "some text that 11");
+ list = g_list_append (list, "some text that matches---");
+ list = g_list_append (list, "some text that matches £$$");
+ list = g_list_append (list, "some text that matches.txt");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_cmpstr ("some text that ", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_strings_with_unicode_characters_that_have_common_prefix ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "ƹƱƱƬ");
+ list = g_list_append (list, "ƹƱƱƬƧƥƧ");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_cmpstr ("ƹƱƱƬ", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_no_common_prefix ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "fyod");
+ list = g_list_append (list, "completely different string");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_has_common_prefix_but_smaller_than_min_required_length ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "fyod");
+ list = g_list_append (list, "fyoa");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_first_character_differs ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "tyodaa");
+ list = g_list_append (list, "fyodaa");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_strings_with_unicode_characters_that_dont_have_common_prefix ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "ƹƱƱƬ");
+ list = g_list_append (list, "ƹƱƢƱƬƧƥƧ");
+
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+
+static void
+setup_test_suite ()
+{
+ g_test_add_func ("/get-common-prefix/1.0",
+ test_has_large_enough_common_prefix);
+ g_test_add_func ("/get-common-prefix/1.1",
+ test_has_common_prefix_that_equals_the_min_required_length);
+ g_test_add_func ("/get-common-prefix/1.2",
+ test_has_common_prefix_that_equals_the_min_required_length2);
+ g_test_add_func ("/get-common-prefix/1.3",
+ test_many_strings_with_common_prefix);
+ g_test_add_func ("/get-common-prefix/1.4",
+ test_strings_with_unicode_characters_that_have_common_prefix);
+
+ g_test_add_func ("/get-common-prefix/2.0",
+ test_no_common_prefix);
+ g_test_add_func ("/get-common-prefix/2.1",
+ test_has_common_prefix_but_smaller_than_min_required_length);
+ g_test_add_func ("/get-common-prefix/2.2",
+ test_first_character_differs);
+ g_test_add_func ("/get-common-prefix/2.3",
+ test_strings_with_unicode_characters_that_dont_have_common_prefix);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=747907");
+ g_test_set_nonfatal_assertions ();
+
+ setup_test_suite ();
+
+ return g_test_run ();
+}
diff --git a/test/automated/displayless/test-file-utilities-get-common-filename-prefix.c b/test/automated/displayless/test-file-utilities-get-common-filename-prefix.c
new file mode 100644
index 000000000..0d78b97ee
--- /dev/null
+++ b/test/automated/displayless/test-file-utilities-get-common-filename-prefix.c
@@ -0,0 +1,459 @@
+#include <glib.h>
+#include <glib/gprintf.h>
+
+#include "src/nautilus-file-utilities.h"
+
+
+static void
+free_list_and_result (GList *list,
+ char *result)
+{
+ g_list_free (list);
+ g_free (result);
+}
+
+static void
+test_has_large_enough_common_prefix ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "test");
+ list = g_list_append (list, "tests");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("test", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_has_large_enough_common_prefix_with_spaces_in_middle ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "Cpt J Yossarian r1");
+ list = g_list_append (list, "Cpt J Yossarian a1");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("Cpt J Yossarian", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_has_large_enough_common_prefix_with_punctuation_in_middle ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "Cpt-J_Yossarian r1");
+ list = g_list_append (list, "Cpt-J_Yossarian a1");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("Cpt-J_Yossarian", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_has_large_enough_common_prefix_with_punctuation_in_middle_and_extension ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "Cpt-J, Yossarian.xml");
+ list = g_list_append (list, "Cpt-J, Yossarian.xsl");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("Cpt-J, Yossarian", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_doesnt_have_large_enough_common_prefix ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "foo");
+ list = g_list_append (list, "foob");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_doesnt_have_large_enough_common_prefix_completely_different_strings ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "this string really");
+ list = g_list_append (list, "isn't the same as the other");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_doesnt_have_large_enough_common_prefix_first_character_differs ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "foo");
+ list = g_list_append (list, "roo");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_doesnt_have_large_enough_common_prefix_first_character_differs_longer_string ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "fools");
+ list = g_list_append (list, "rools");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_has_large_enough_common_prefix_until_extension_removed ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "tes.txt");
+ list = g_list_append (list, "tes.tar");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_extension_is_removed ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "nau tilus.c");
+ list = g_list_append (list, "nau tilus.cpp");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("nau tilus", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_whitespace_is_removed ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "nautilus ");
+ list = g_list_append (list, "nautilus two");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("nautilus", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_whitespace_and_extension_are_removed ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "nautilus !£ $\" foo.tar.gz");
+ list = g_list_append (list, "nautilus !£ $\" .lzma");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("nautilus !£ $\"", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_punctuation_is_preserved (void)
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "nautilus (2018!£$%^&* ()_+-={}[ ];':@#~<>?,./\".mp4");
+ list = g_list_append (list, "nautilus (2018!£$%^&* ()_+-={}[ ];':@#~<>?,./\".srt");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("nautilus (2018!£$%^&* ()_+-={}[ ];':@#~<>?,./\"", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_unicode_on_outside ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "ӶtestӶ234");
+ list = g_list_append (list, "ӶtestӶ1");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("ӶtestӶ", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_unicode_on_inside ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "QQӶtestӶabb234");
+ list = g_list_append (list, "QQӶtestӶabb1");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("QQӶtestӶabb", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_unicode_whole_string ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "ǣȸʸͻͻΎΘΛ");
+ list = g_list_append (list, "ǣȸʸͻͻΎΘ");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("ǣȸʸͻͻΎΘ", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_unicode_extension ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "test.ǣȸʸͻͻΎΘΛ");
+ list = g_list_append (list, "test.ǣȸʸͻͻΎΘ");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("test", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_unicode_with_punctuation ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "ǣȸʸ- ͻͻΎΘ$%%^");
+ list = g_list_append (list, "ǣȸʸ- ͻͻΎΘ$%%&");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("ǣȸʸ- ͻͻΎΘ$%%", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_many_strings ()
+{
+ GList *list = NULL;
+ char *actual;
+ char *filename;
+ int i;
+
+ for (i = 0; i < 500; ++i)
+ {
+ filename = g_strdup_printf ("we are no longer the knights who say nii%d", i);
+ list = g_list_append (list, filename);
+ }
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("we are no longer the knights who say nii", ==, actual);
+
+ g_free (actual);
+ g_list_free_full (list, g_free);
+}
+
+static void
+test_many_strings_last_differs ()
+{
+ GList *list = NULL;
+ char *actual;
+ char *filename;
+ int i;
+
+ for (i = 0; i < 500; ++i)
+ {
+ filename = g_strdup_printf ("we are no longer the knights who say nii%d", i);
+
+ if (i == 499)
+ {
+ filename[2] = 'X';
+ }
+
+ list = g_list_append (list, filename);
+ }
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
+
+ g_free (actual);
+ g_list_free_full (list, g_free);
+}
+
+static void
+test_many_strings_first_differs ()
+{
+ GList *list = NULL;
+ char *actual;
+ char *filename;
+ int i;
+
+ for (i = 0; i < 500; ++i)
+ {
+ filename = g_strdup_printf ("we are no longer the knights who say nii%d", i);
+
+ if (i == 0)
+ {
+ filename[2] = 'X';
+ }
+
+ list = g_list_append (list, filename);
+ }
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
+
+ g_free (actual);
+ g_list_free_full (list, g_free);
+}
+
+static void
+test_smaller_min_length_and_does_have_common_prefix ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "CA");
+ list = g_list_append (list, "CB");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 1);
+ g_assert_cmpstr ("C", ==, actual);
+
+ free_list_and_result (list, actual);
+}
+
+static void
+test_smaller_min_length_and_doesnt_have_common_prefix ()
+{
+ GList *list = NULL;
+ char *actual;
+
+ list = g_list_append (list, "CA");
+ list = g_list_append (list, "BB");
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 1);
+ g_assert_null (actual);
+
+ free_list_and_result (list, actual);
+}
+
+
+static void
+setup_test_suite ()
+{
+ g_test_add_func ("/get-common-filename-prefix/1.0",
+ test_has_large_enough_common_prefix);
+ g_test_add_func ("/get-common-filename-prefix/1.1",
+ test_has_large_enough_common_prefix_with_spaces_in_middle);
+ g_test_add_func ("/get-common-filename-prefix/1.2",
+ test_has_large_enough_common_prefix_with_punctuation_in_middle);
+ g_test_add_func ("/get-common-filename-prefix/1.3",
+ test_has_large_enough_common_prefix_with_punctuation_in_middle_and_extension);
+
+ g_test_add_func ("/get-common-filename-prefix/2.0",
+ test_doesnt_have_large_enough_common_prefix);
+ g_test_add_func ("/get-common-filename-prefix/2.1",
+ test_doesnt_have_large_enough_common_prefix_completely_different_strings);
+ g_test_add_func ("/get-common-filename-prefix/2.2",
+ test_doesnt_have_large_enough_common_prefix_first_character_differs);
+ g_test_add_func ("/get-common-filename-prefix/2.3",
+ test_doesnt_have_large_enough_common_prefix_first_character_differs_longer_string);
+
+ g_test_add_func ("/get-common-filename-prefix/3.0",
+ test_has_large_enough_common_prefix_until_extension_removed);
+
+ g_test_add_func ("/get-common-filename-prefix/4.0",
+ test_extension_is_removed);
+ g_test_add_func ("/get-common-filename-prefix/4.1",
+ test_whitespace_is_removed);
+ g_test_add_func ("/get-common-filename-prefix/4.2",
+ test_whitespace_and_extension_are_removed);
+ g_test_add_func ("/get-common-filename-prefix/4.3",
+ test_punctuation_is_preserved);
+
+ g_test_add_func ("/get-common-filename-prefix/5.0",
+ test_unicode_on_inside);
+ g_test_add_func ("/get-common-filename-prefix/5.1",
+ test_unicode_on_outside);
+ g_test_add_func ("/get-common-filename-prefix/5.2",
+ test_unicode_whole_string);
+ g_test_add_func ("/get-common-filename-prefix/5.3",
+ test_unicode_extension);
+ g_test_add_func ("/get-common-filename-prefix/5.4",
+ test_unicode_with_punctuation);
+
+ g_test_add_func ("/get-common-filename-prefix/6.0",
+ test_many_strings);
+ g_test_add_func ("/get-common-filename-prefix/6.1",
+ test_many_strings_last_differs);
+ g_test_add_func ("/get-common-filename-prefix/6.2",
+ test_many_strings_first_differs);
+
+ g_test_add_func ("/get-common-filename-prefix/7.0",
+ test_smaller_min_length_and_does_have_common_prefix);
+ g_test_add_func ("/get-common-filename-prefix/7.1",
+ test_smaller_min_length_and_doesnt_have_common_prefix);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=747907");
+ g_test_set_nonfatal_assertions ();
+
+ setup_test_suite ();
+
+ return g_test_run ();
+}
diff --git a/test/automated/meson.build b/test/automated/meson.build
new file mode 100644
index 000000000..f71d0e884
--- /dev/null
+++ b/test/automated/meson.build
@@ -0,0 +1,4 @@
+subdir('displayless')
+if get_option('display-tests')
+ subdir('display')
+endif