[glib] live-g-file: test hidden files



commit 605c4ca24ef0cbfdee5775526399f217f659faea
Author: Emilio Pozuelo Monfort <pochu27 gmail com>
Date:   Mon Mar 4 20:03:26 2013 +0100

    live-g-file: test hidden files
    
    We test for traditional Unix dot-leading files as well as
    for files listed in the .hidden file.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=695147

 gio/tests/live-g-file.c |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/gio/tests/live-g-file.c b/gio/tests/live-g-file.c
index a9a9c03..6edc99a 100644
--- a/gio/tests/live-g-file.c
+++ b/gio/tests/live-g-file.c
@@ -23,6 +23,7 @@
 #include <glib/glib.h>
 #include <gio/gio.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <string.h>
@@ -53,6 +54,8 @@ enum StructureExtraFlags
   TEST_OPEN = 1 << 15,
   TEST_OVERWRITE = 1 << 16,
   TEST_INVALID_SYMLINK = 1 << 17,
+  TEST_HIDDEN = 1 << 18,
+  TEST_DOT_HIDDEN = 1 << 19,
 };
 
 struct StructureItem
@@ -100,6 +103,11 @@ static const struct StructureItem sample_struct[] = {
     {"not_exists4",                    NULL,   G_FILE_TYPE_REGULAR,    G_FILE_CREATE_NONE, 0, 
TEST_HANDLE_SPECIAL, TEST_NOT_EXISTS | TEST_APPEND},
     {"dir_no-execute/file",    NULL,   G_FILE_TYPE_REGULAR,    G_FILE_CREATE_NONE, 0, TEST_HANDLE_SPECIAL, 
TEST_DELETE_NORMAL | TEST_DELETE_FAILURE | TEST_NOT_EXISTS | TEST_OPEN},
        {"lost_symlink",                "nowhere",      G_FILE_TYPE_SYMBOLIC_LINK, G_FILE_CREATE_NONE, 0, 0, 
TEST_COPY | TEST_DELETE_NORMAL | TEST_OPEN | TEST_INVALID_SYMLINK},
+    {"dir_hidden",             NULL,   G_FILE_TYPE_DIRECTORY,  G_FILE_CREATE_NONE, 0, 0, 0},
+    {"dir_hidden/.hidden",             NULL,   G_FILE_TYPE_REGULAR,    G_FILE_CREATE_NONE, 0, 
TEST_HANDLE_SPECIAL, 0},
+    {"dir_hidden/.a-hidden-file",      NULL,   G_FILE_TYPE_REGULAR,    G_FILE_CREATE_NONE, 0, 0, 
TEST_HIDDEN},
+    {"dir_hidden/file-in-.hidden1",    NULL,   G_FILE_TYPE_REGULAR,    G_FILE_CREATE_NONE, 0, 0, TEST_HIDDEN 
| TEST_DOT_HIDDEN},
+    {"dir_hidden/file-in-.hidden2",    NULL,   G_FILE_TYPE_REGULAR,    G_FILE_CREATE_NONE, 0, 0, TEST_HIDDEN 
| TEST_DOT_HIDDEN},
   };
 
 static gboolean test_suite;
@@ -243,6 +251,24 @@ test_create_structure (gconstpointer test_data)
          g_assert_no_error (error);
        }
 
+      if ((item.extra_flags & TEST_DOT_HIDDEN) == TEST_DOT_HIDDEN)
+       {
+         gchar *dir, *path, *basename;
+         FILE *f;
+
+         dir = g_path_get_dirname (item.filename);
+         basename = g_path_get_basename (item.filename);
+         path = g_build_filename (test_data, dir, ".hidden", NULL);
+
+         f = fopen (path, "a");
+         fprintf (f, "%s\n", basename);
+         fclose (f);
+
+         g_free (dir);
+         g_free (path);
+         g_free (basename);
+       }
+
       g_object_unref (child);
     }
 
@@ -303,6 +329,7 @@ test_attributes (struct StructureItem item, GFileInfo * info)
   gboolean utf8_valid;
   gboolean has_attr;
   gboolean is_symlink;
+  gboolean is_hidden;
   gboolean can_read, can_write;
 
   /*  standard::type  */
@@ -381,6 +408,15 @@ test_attributes (struct StructureItem item, GFileInfo * info)
       symlink_target = g_file_info_get_symlink_target (info);
       g_assert_cmpstr (symlink_target, ==, item.link_to);
     }
+
+  /*  standard::is-hidden  */
+  if ((item.extra_flags & TEST_HIDDEN) == TEST_HIDDEN)
+    {
+      is_hidden =
+       g_file_info_get_attribute_boolean (info,
+                                          G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
+      g_assert_cmpint (is_hidden, ==, TRUE);
+    }
 }
 
 static void


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