[gtksourceview/wip/loader-saver: 2/2] Unit tests for the FileSaver (unfinished!)



commit 50a4b8df35a116b9b1f108b301c54ae3158ff980
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Dec 13 17:47:08 2013 +0100

    Unit tests for the FileSaver (unfinished!)

 tests/Makefile.am       |    7 +
 tests/test-file-saver.c |  706 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 713 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b2835fe..65856f6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -86,6 +86,13 @@ test_completion_words_LDADD =                                        \
        $(DEP_LIBS)                                             \
        $(TESTS_LIBS)
 
+UNIT_TEST_PROGS += test-file-saver
+test_file_saver_SOURCES = test-file-saver.c
+test_file_saver_LDADD =                                                \
+       $(top_builddir)/gtksourceview/libgtksourceview-3.0.la   \
+       $(DEP_LIBS)                                             \
+       $(TESTS_LIBS)
+
 UNIT_TEST_PROGS += test-language
 test_language_SOURCES =                \
        test-language.c
diff --git a/tests/test-file-saver.c b/tests/test-file-saver.c
new file mode 100644
index 0000000..18e395e
--- /dev/null
+++ b/tests/test-file-saver.c
@@ -0,0 +1,706 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
+/* test-file-saver.c
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2010 - Jesse van den Kieboom
+ * Copyright (C) 2013 - Sébastien Wilmet
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <gio/gio.h>
+#include <gtk/gtk.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <gtksourceview/gtksource.h>
+
+/* linux/bsd has it. others such as Solaris, do not */
+#ifndef ACCESSPERMS
+#define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO)
+#endif
+
+#define DEFAULT_LOCAL_URI "/tmp/gtksourceview-file-saver-test.txt"
+#define DEFAULT_REMOTE_URI "sftp://localhost/tmp/gtksourceview-file-saver-test.txt";
+#define DEFAULT_CONTENT "hello world!"
+#define DEFAULT_CONTENT_RESULT "hello world!\n"
+
+#define UNOWNED_LOCAL_DIRECTORY "/tmp/gtksourceview-file-saver-unowned"
+#define UNOWNED_LOCAL_URI "/tmp/gtksourceview-file-saver-unowned/gtksourceview-file-saver-test.txt"
+
+#define UNOWNED_REMOTE_DIRECTORY "sftp://localhost/tmp/gtksourceview-file-saver-unowned";
+#define UNOWNED_REMOTE_URI 
"sftp://localhost/tmp/gtksourceview-file-saver-unowned/gtksourceview-file-saver-test.txt";
+
+#define UNOWNED_GROUP_LOCAL_URI "/tmp/gtksourceview-file-saver-unowned-group.txt"
+#define UNOWNED_GROUP_REMOTE_URI "sftp://localhost/tmp/gtksourceview-file-saver-unowned-group.txt";
+
+typedef struct
+{
+       GtkSourceFile *file;
+       GFile *location;
+       const gchar *expected_file_contents;
+       GtkSourceFileSaveFlags save_flags;
+       GCallback saved_callback;
+       gpointer userdata;
+
+       guint file_existed : 1;
+} SaverTestData;
+
+static const gchar *
+read_file (GFile *location)
+{
+       /* TODO use g_file_load_contents() */
+       GError *error = NULL;
+       static gchar buffer[4096];
+       gsize read;
+
+       GInputStream *stream = G_INPUT_STREAM (g_file_read (location, NULL, &error));
+
+       g_assert_no_error (error);
+
+       g_input_stream_read_all (stream, buffer, sizeof (buffer) - 1, &read, NULL, &error);
+       g_assert_no_error (error);
+
+       buffer[read] = '\0';
+
+       g_input_stream_close (stream, NULL, NULL);
+
+       g_object_unref (stream);
+
+       return buffer;
+}
+
+static void
+save_file_cb (GtkSourceFile *file,
+             GAsyncResult  *result,
+             SaverTestData *data)
+{
+       GError *error = NULL;
+
+       gtk_source_file_save_finish (file, result, &error);
+
+       g_assert_no_error (error);
+
+       g_assert_cmpstr (data->expected_file_contents, ==, read_file (data->location));
+
+       if (data->saved_callback != NULL)
+       {
+               data->saved_callback (data);
+       }
+
+       if (!data->file_existed)
+       {
+               g_file_delete (data->location, NULL, NULL);
+       }
+
+       /* finished */
+       g_object_unref (data->file);
+       g_object_unref (data->location);
+       g_slice_free (SaverTestData, data);
+}
+
+static void
+save_file (SaverTestData *data)
+{
+       data->file_existed = g_file_query_exists (data->location, NULL);
+
+       gtk_source_file_save_async (data->file,
+                                   data->save_flags,
+                                   G_PRIORITY_DEFAULT,
+                                   NULL,
+                                   NULL,
+                                   NULL,
+                                   (GAsyncReadyCallback) save_file_cb,
+                                   data);
+}
+
+static void
+mount_cb (GFile         *location,
+         GAsyncResult  *result,
+         SaverTestData *data)
+{
+       GError *error = NULL;
+
+       g_file_mount_enclosing_volume_finish (location, result, &error);
+
+       if (error != NULL && error->code == G_IO_ERROR_ALREADY_MOUNTED)
+       {
+               g_error_free (error);
+       }
+       else if (error != NULL && error->code == G_IO_ERROR_NOT_SUPPORTED)
+       {
+               g_error_free (error);
+       }
+       else
+       {
+               g_assert_no_error (error);
+       }
+
+       save_file (data);
+}
+
+static void
+check_mounted (SaverTestData *data)
+{
+       GMountOperation *mount_operation;
+
+       if (g_file_is_native (data->location))
+       {
+               save_file (data);
+               return;
+       }
+
+       mount_operation = gtk_mount_operation_new (NULL);
+
+       g_file_mount_enclosing_volume (data->location,
+                                      G_MOUNT_MOUNT_NONE,
+                                      mount_operation,
+                                      NULL,
+                                      (GAsyncReadyCallback) mount_cb,
+                                      data);
+
+       g_object_unref (mount_operation);
+}
+
+static void
+test_saver (const gchar            *filename_or_uri,
+           const gchar            *buffer_contents,
+           const gchar            *expected_file_contents,
+           GtkSourceNewlineType    newline_type,
+           GtkSourceFileSaveFlags  save_flags,
+           GCallback               saved_callback,
+           gpointer                userdata)
+{
+       GFile *location;
+       GtkSourceBuffer *buffer;
+       GtkSourceFile *file;
+       SaverTestData *data;
+
+       location = g_file_new_for_commandline_arg (filename_or_uri);
+
+       buffer = gtk_source_buffer_new (NULL);
+       gtk_text_buffer_set_text (GTK_TEXT_BUFFER (buffer), buffer_contents, -1);
+
+       file = gtk_source_file_new (location, buffer);
+       g_object_unref (buffer);
+
+       gtk_source_file_set_newline_type (file, newline_type);
+       gtk_source_file_set_encoding (file, gtk_source_encoding_get_utf8 ());
+
+       data = g_slice_new (SaverTestData);
+       data->file = file;
+       data->location = location;
+       data->expected_file_contents = expected_file_contents;
+       data->save_flags = save_flags;
+       data->saved_callback = saved_callback;
+       data->userdata = userdata;
+
+       check_mounted (data);
+}
+
+typedef struct
+{
+       GeditDocumentNewlineType type;
+       const gchar *text;
+       const gchar *result;
+} NewLineTestData;
+
+static NewLineTestData newline_test_data[] = {
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_LF, "\nhello\nworld", "\nhello\nworld\n"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_LF, "\nhello\nworld\n", "\nhello\nworld\n\n"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_LF, "\nhello\nworld\n\n", "\nhello\nworld\n\n\n"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_LF, "\r\nhello\r\nworld", "\nhello\nworld\n"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_LF, "\r\nhello\r\nworld\r\n", "\nhello\nworld\n\n"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_LF, "\rhello\rworld", "\nhello\nworld\n"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_LF, "\rhello\rworld\r", "\nhello\nworld\n\n"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_LF, "\nhello\r\nworld", "\nhello\nworld\n"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_LF, "\nhello\r\nworld\r", "\nhello\nworld\n\n"},
+
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF, "\nhello\nworld", "\r\nhello\r\nworld\r\n"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF, "\nhello\nworld\n", "\r\nhello\r\nworld\r\n\r\n"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF, "\nhello\nworld\n\n", "\r\nhello\r\nworld\r\n\r\n\r\n"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF, "\r\nhello\r\nworld", "\r\nhello\r\nworld\r\n"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF, "\r\nhello\r\nworld\r\n", "\r\nhello\r\nworld\r\n\r\n"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF, "\rhello\rworld", "\r\nhello\r\nworld\r\n"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF, "\rhello\rworld\r", "\r\nhello\r\nworld\r\n\r\n"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF, "\nhello\r\nworld", "\r\nhello\r\nworld\r\n"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF, "\nhello\r\nworld\r", "\r\nhello\r\nworld\r\n\r\n"},
+
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR, "\nhello\nworld", "\rhello\rworld\r"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR, "\nhello\nworld\n", "\rhello\rworld\r\r"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR, "\nhello\nworld\n\n", "\rhello\rworld\r\r\r"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR, "\r\nhello\r\nworld", "\rhello\rworld\r"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR, "\r\nhello\r\nworld\r\n", "\rhello\rworld\r\r"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR, "\rhello\rworld", "\rhello\rworld\r"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR, "\rhello\rworld\r", "\rhello\rworld\r\r"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR, "\nhello\r\nworld", "\rhello\rworld\r"},
+       {GEDIT_DOCUMENT_NEWLINE_TYPE_CR, "\nhello\r\nworld\r", "\rhello\rworld\r\r"}
+};
+
+static void
+test_new_line (const gchar *filename, GeditDocumentSaveFlags save_flags)
+{
+       gint i;
+       gint num = sizeof (newline_test_data) / sizeof (NewLineTestData);
+
+       for (i = 0; i < num; ++i)
+       {
+               NewLineTestData *nt = &(newline_test_data[i]);
+
+               test_saver (filename,
+                           nt->text,
+                           nt->result,
+                           nt->type,
+                           save_flags,
+                           NULL,
+                           NULL);
+       }
+}
+
+static void
+test_local_newline ()
+{
+       test_new_line (DEFAULT_LOCAL_URI, 0);
+}
+
+static void
+test_local ()
+{
+       test_saver (DEFAULT_LOCAL_URI,
+                   "hello world",
+                   "hello world\n",
+                   GEDIT_DOCUMENT_NEWLINE_TYPE_LF,
+                   0,
+                   NULL,
+                   NULL);
+
+       test_saver (DEFAULT_LOCAL_URI,
+                   "hello world\r\n",
+                   "hello world\n\n",
+                   GEDIT_DOCUMENT_NEWLINE_TYPE_LF,
+                   0,
+                   NULL,
+                   NULL);
+
+       test_saver (DEFAULT_LOCAL_URI,
+                   "hello world\n",
+                   "hello world\n\n",
+                   GEDIT_DOCUMENT_NEWLINE_TYPE_LF,
+                   0,
+                   NULL,
+                   NULL);
+}
+
+static void
+test_remote_newline ()
+{
+       test_new_line (DEFAULT_REMOTE_URI, 0);
+}
+
+static void
+test_remote ()
+{
+       test_saver (DEFAULT_REMOTE_URI,
+                   "hello world",
+                   "hello world\n",
+                   GEDIT_DOCUMENT_NEWLINE_TYPE_LF,
+                   0,
+                   NULL,
+                   NULL);
+
+       test_saver (DEFAULT_REMOTE_URI,
+                   "hello world\r\n",
+                   "hello world\n\n",
+                   GEDIT_DOCUMENT_NEWLINE_TYPE_LF,
+                   0,
+                   NULL,
+                   NULL);
+
+       test_saver (DEFAULT_REMOTE_URI,
+                   "hello world\n",
+                   "hello world\n\n",
+                   GEDIT_DOCUMENT_NEWLINE_TYPE_LF,
+                   0,
+                   NULL,
+                   NULL);
+}
+
+#ifndef G_OS_WIN32
+static void
+check_permissions (GFile *location,
+                   guint  permissions)
+{
+       GError *error = NULL;
+       GFileInfo *info;
+
+       info = g_file_query_info (location,
+                                 G_FILE_ATTRIBUTE_UNIX_MODE,
+                                 G_FILE_QUERY_INFO_NONE,
+                                 NULL,
+                                 &error);
+
+       g_assert_no_error (error);
+
+       g_assert_cmpint (permissions,
+                        ==,
+                        g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE) & ACCESSPERMS);
+
+       g_object_unref (info);
+}
+
+static void
+check_permissions_saved (SaverTestData *data)
+{
+       guint permissions = (guint)GPOINTER_TO_INT (data->userdata);
+
+       check_permissions (data->location, permissions);
+}
+
+static void
+test_permissions (const gchar *uri,
+                  guint        permissions)
+{
+       GError *error = NULL;
+       GFile *file = g_file_new_for_commandline_arg (uri);
+       GFileOutputStream *stream;
+       GFileInfo *info;
+       guint mode;
+
+       g_file_delete (file, NULL, NULL);
+       stream = g_file_create (file, 0, NULL, &error);
+
+       if (error && error->code == G_IO_ERROR_NOT_SUPPORTED)
+       {
+               g_error_free (error);
+               return;
+       }
+
+       g_assert_no_error (error);
+
+       g_output_stream_close (G_OUTPUT_STREAM (stream), NULL, NULL);
+       g_object_unref (stream);
+
+       info = g_file_query_info (file,
+                                 G_FILE_ATTRIBUTE_UNIX_MODE,
+                                 G_FILE_QUERY_INFO_NONE,
+                                 NULL,
+                                 &error);
+
+       g_assert_no_error (error);
+
+       mode = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE);
+       g_object_unref (info);
+
+       g_file_set_attribute_uint32 (file,
+                                    G_FILE_ATTRIBUTE_UNIX_MODE,
+                                    (mode & ~ACCESSPERMS) | permissions,
+                                    G_FILE_QUERY_INFO_NONE,
+                                    NULL,
+                                    &error);
+       g_assert_no_error (error);
+
+       check_permissions (file, permissions);
+
+       test_saver (uri,
+                   DEFAULT_CONTENT,
+                   DEFAULT_CONTENT_RESULT,
+                   GEDIT_DOCUMENT_NEWLINE_TYPE_LF,
+                   0,
+                   G_CALLBACK (check_permissions_saved),
+                   GINT_TO_POINTER ((gint)permissions));
+
+       g_file_delete (file, NULL, NULL);
+       g_object_unref (file);
+}
+
+static void
+test_local_permissions ()
+{
+       test_permissions (DEFAULT_LOCAL_URI, 0600);
+       test_permissions (DEFAULT_LOCAL_URI, 0660);
+       test_permissions (DEFAULT_LOCAL_URI, 0666);
+       test_permissions (DEFAULT_LOCAL_URI, 0760);
+}
+#endif
+
+static void
+test_local_unowned_directory ()
+{
+       test_saver (UNOWNED_LOCAL_URI,
+                   DEFAULT_CONTENT,
+                   DEFAULT_CONTENT_RESULT,
+                   GEDIT_DOCUMENT_NEWLINE_TYPE_LF,
+                   0,
+                   NULL,
+                   NULL);
+}
+
+static void
+test_remote_unowned_directory ()
+{
+       test_saver (UNOWNED_REMOTE_URI,
+                   DEFAULT_CONTENT,
+                   DEFAULT_CONTENT_RESULT,
+                   GEDIT_DOCUMENT_NEWLINE_TYPE_LF,
+                   0,
+                   NULL,
+                   NULL);
+}
+
+#ifndef G_OS_WIN32
+static void
+test_remote_permissions ()
+{
+       test_permissions (DEFAULT_REMOTE_URI, 0600);
+       test_permissions (DEFAULT_REMOTE_URI, 0660);
+       test_permissions (DEFAULT_REMOTE_URI, 0666);
+       test_permissions (DEFAULT_REMOTE_URI, 0760);
+}
+
+static void
+test_unowned_group_permissions (SaverTestData *data)
+{
+       GError *error = NULL;
+       const gchar *group;
+       guint32 mode;
+
+       GFileInfo *info = g_file_query_info (data->location,
+                                            G_FILE_ATTRIBUTE_OWNER_GROUP ","
+                                            G_FILE_ATTRIBUTE_UNIX_MODE,
+                                            G_FILE_QUERY_INFO_NONE,
+                                            NULL,
+                                            &error);
+
+       g_assert_no_error (error);
+
+       group = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_GROUP);
+       g_assert_cmpstr (group, ==, "root");
+
+       mode = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE);
+
+       g_assert_cmpint (mode & ACCESSPERMS, ==, 0660);
+
+       g_object_unref (info);
+}
+
+static void
+test_unowned_group (const gchar *uri)
+{
+       test_saver (uri,
+                   DEFAULT_CONTENT,
+                   DEFAULT_CONTENT_RESULT,
+                   GEDIT_DOCUMENT_NEWLINE_TYPE_LF,
+                   0,
+                   G_CALLBACK (test_unowned_group_permissions),
+                   NULL);
+}
+
+static void
+test_local_unowned_group ()
+{
+       test_unowned_group (UNOWNED_GROUP_LOCAL_URI);
+}
+
+static void
+test_remote_unowned_group ()
+{
+       test_unowned_group (UNOWNED_GROUP_REMOTE_URI);
+}
+
+#endif
+
+static gboolean
+check_unowned_directory ()
+{
+       GFile *unowned = g_file_new_for_path (UNOWNED_LOCAL_DIRECTORY);
+       GFile *unowned_file;
+       GFileInfo *info;
+       GError *error = NULL;
+
+       g_printf ("*** Checking for unowned directory test... ");
+
+       info = g_file_query_info (unowned,
+                                 G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
+                                 G_FILE_QUERY_INFO_NONE,
+                                 NULL,
+                                 &error);
+
+       if (error)
+       {
+               g_object_unref (unowned);
+               g_printf ("NO: directory does not exist\n");
+
+               g_error_free (error);
+               return FALSE;
+       }
+
+       if (g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
+       {
+               g_object_unref (unowned);
+
+               g_printf ("NO: directory is writable\n");
+               g_object_unref (info);
+               return FALSE;
+       }
+
+       g_object_unref (info);
+       g_object_unref (unowned);
+
+       unowned_file = g_file_new_for_commandline_arg (UNOWNED_LOCAL_URI);
+
+       info = g_file_query_info (unowned_file,
+                                 G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
+                                 G_FILE_QUERY_INFO_NONE,
+                                 NULL,
+                                 &error);
+
+       if (error)
+       {
+               g_object_unref (unowned_file);
+               g_error_free (error);
+
+               g_printf ("NO: file does not exist\n");
+               return FALSE;
+       }
+
+       if (!g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
+       {
+               g_object_unref (unowned_file);
+
+               g_printf ("NO: file is not writable\n");
+               g_object_unref (info);
+               return FALSE;
+       }
+
+       g_object_unref (info);
+       g_object_unref (unowned_file);
+
+       g_printf ("YES\n");
+       return TRUE;
+}
+
+static gboolean
+check_unowned_group ()
+{
+       GFile *unowned = g_file_new_for_path (UNOWNED_GROUP_LOCAL_URI);
+       GFileInfo *info;
+       GError *error = NULL;
+
+       g_printf ("*** Checking for unowned group test... ");
+
+       info = g_file_query_info (unowned,
+                                 G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE ","
+                                 G_FILE_ATTRIBUTE_OWNER_GROUP ","
+                                 G_FILE_ATTRIBUTE_UNIX_MODE,
+                                 G_FILE_QUERY_INFO_NONE,
+                                 NULL,
+                                 &error);
+
+       if (error)
+       {
+               g_object_unref (unowned);
+               g_printf ("NO: file does not exist\n");
+
+               g_error_free (error);
+               return FALSE;
+       }
+
+       if (!g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
+       {
+               g_object_unref (unowned);
+
+               g_printf ("NO: file is not writable\n");
+               g_object_unref (info);
+               return FALSE;
+       }
+
+       if (g_strcmp0 (g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_GROUP),
+                      "root") != 0)
+       {
+               g_object_unref (unowned);
+
+               g_printf ("NO: group is not root (%s)\n", g_file_info_get_attribute_string (info, 
G_FILE_ATTRIBUTE_OWNER_GROUP));
+               g_object_unref (info);
+               return FALSE;
+       }
+
+#ifndef G_OS_WIN32
+       if ((g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE) & ACCESSPERMS) != 0660)
+       {
+               g_object_unref (unowned);
+
+               g_printf ("NO: file has wrong permissions\n");
+               g_object_unref (info);
+               return FALSE;
+       }
+#endif
+
+       g_object_unref (info);
+       g_object_unref (unowned);
+
+       g_printf ("YES\n");
+       return TRUE;
+}
+
+gint
+main (gint   argc,
+      gchar *argv[])
+{
+       gboolean have_unowned;
+       gboolean have_unowned_group;
+
+       g_test_init (&argc, &argv, NULL);
+       gtk_init (&argc, &argv);
+
+       g_printf ("\n***\n");
+       have_unowned = check_unowned_directory ();
+       have_unowned_group = check_unowned_group ();
+       g_printf ("***\n\n");
+
+       g_test_add_func ("/file-saver/local", test_local);
+       g_test_add_func ("/file-saver/local-new-line", test_local_newline);
+
+       if (have_unowned)
+       {
+               g_test_add_func ("/file-saver/local-unowned-directory", test_local_unowned_directory);
+       }
+
+       g_test_add_func ("/file-saver/remote", test_remote);
+       g_test_add_func ("/file-saver/remote-new-line", test_remote_newline);
+
+
+       if (have_unowned)
+       {
+               g_test_add_func ("/file-saver/remote-unowned-directory", test_remote_unowned_directory);
+       }
+
+       if (have_unowned_group)
+       {
+               /* FIXME: there is a bug in gvfs sftp which doesn't pass this test */
+               /* g_test_add_func ("/file-saver/remote-unowned-group", test_remote_unowned_group); */
+       }
+
+#ifndef G_OS_WIN32
+       g_test_add_func ("/file-saver/local-permissions", test_local_permissions);
+
+       if (have_unowned_group)
+       {
+               g_test_add_func ("/file-saver/local-unowned-group", test_local_unowned_group);
+       }
+
+       g_test_add_func ("/file-saver/remote-permissions", test_remote_permissions);
+#endif
+
+       return g_test_run ();
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]