[glib] Improve GResource test coverage



commit 3e1b972c933bc4a01e8d05f1bb6c6df1ad816579
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Jun 4 06:00:45 2012 -0400

    Improve GResource test coverage

 gio/tests/resources.c |  112 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 109 insertions(+), 3 deletions(-)
---
diff --git a/gio/tests/resources.c b/gio/tests/resources.c
index 0687e38..aec6a97 100644
--- a/gio/tests/resources.c
+++ b/gio/tests/resources.c
@@ -182,7 +182,7 @@ test_resource_data (void)
 }
 
 static void
-test_resource_registred (void)
+test_resource_registered (void)
 {
   GResource *resource;
   GError *error = NULL;
@@ -449,7 +449,6 @@ test_uri_query_info (void)
 
   info = g_file_query_info (file, "*", 0, NULL, &error);
   g_assert_no_error (error);
-  g_object_unref (file);
 
   content_type = g_file_info_get_content_type (info);
   g_assert (content_type);
@@ -457,6 +456,112 @@ test_uri_query_info (void)
 
   g_object_unref (info);
 
+  g_object_unref (file);
+
+  g_resources_unregister (resource);
+  g_resource_unref (resource);
+}
+
+void
+test_uri_file (void)
+{
+  GResource *resource;
+  GError *error = NULL;
+  gboolean loaded_file;
+  char *content;
+  gsize content_size;
+  GBytes *data;
+  GFile *file;
+  GFileInfo *info;
+  gchar *name;
+  GFile *file2, *parent;
+  GFileEnumerator *enumerator;
+  gchar *scheme;
+  GFileAttributeInfoList *attrs;
+
+  loaded_file = g_file_get_contents ("test.gresource", &content, &content_size,
+                                     NULL);
+  g_assert (loaded_file);
+
+  data = g_bytes_new_take (content, content_size);
+  resource = g_resource_new_from_data (data, &error);
+  g_bytes_unref (data);
+  g_assert (resource != NULL);
+  g_assert_no_error (error);
+
+  g_resources_register (resource);
+
+  file = g_file_new_for_uri ("resource://" "/a_prefix/test2-alias.txt");
+
+  g_assert (g_file_get_path (file) == NULL);
+
+  name = g_file_get_parse_name (file);
+  g_assert_cmpstr (name, ==, "resource:///a_prefix/test2-alias.txt");
+  g_free (name);
+
+  name = g_file_get_uri (file);
+  g_assert_cmpstr (name, ==, "resource:///a_prefix/test2-alias.txt");
+  g_free (name);
+
+  g_assert (!g_file_is_native (file));
+  g_assert (!g_file_has_uri_scheme (file, "http"));
+  g_assert (g_file_has_uri_scheme (file, "resource"));
+  scheme = g_file_get_uri_scheme (file);
+  g_assert_cmpstr (scheme, ==, "resource");
+  g_free (scheme);
+
+  file2 = g_file_dup (file);
+  g_assert (g_file_equal (file, file2));
+  g_object_unref (file2);
+
+  parent = g_file_get_parent (file);
+  enumerator = g_file_enumerate_children (parent, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &error);
+  g_assert_no_error (error);
+
+  file2 = g_file_get_child_for_display_name (parent, "test2-alias.txt", &error);
+  g_assert_no_error (error);
+  g_assert (g_file_equal (file, file2));
+  g_object_unref (file2);
+
+  info = g_file_enumerator_next_file (enumerator, NULL, &error);
+  g_assert_no_error (error);
+  g_assert (info != NULL);
+  g_object_unref (info);
+
+  info = g_file_enumerator_next_file (enumerator, NULL, &error);
+  g_assert_no_error (error);
+  g_assert (info != NULL);
+  g_object_unref (info);
+
+  info = g_file_enumerator_next_file (enumerator, NULL, &error);
+  g_assert_no_error (error);
+  g_assert (info == NULL);
+
+  g_file_enumerator_close (enumerator, NULL, &error);
+  g_assert_no_error (error);
+  g_object_unref (enumerator);
+
+  file2 = g_file_new_for_uri ("resource://" "a_prefix/../a_prefix//test2-alias.txt");
+  g_assert (g_file_equal (file, file2));
+
+  g_assert (g_file_has_prefix (file, parent));
+
+  name = g_file_get_relative_path (parent, file);
+  g_assert_cmpstr (name, ==, "test2-alias.txt");
+  g_free (name);
+
+  g_object_unref (parent);
+
+  attrs = g_file_query_settable_attributes (file, NULL, &error);
+  g_assert_no_error (error);
+  g_file_attribute_info_list_unref (attrs);
+
+  attrs = g_file_query_writable_namespaces (file, NULL, &error);
+  g_assert_no_error (error);
+  g_file_attribute_info_list_unref (attrs);
+
+  g_object_unref (file);
+
   g_resources_unregister (resource);
   g_resource_unref (resource);
 }
@@ -472,7 +577,7 @@ main (int   argc,
 
   g_test_add_func ("/resource/file", test_resource_file);
   g_test_add_func ("/resource/data", test_resource_data);
-  g_test_add_func ("/resource/registred", test_resource_registred);
+  g_test_add_func ("/resource/registered", test_resource_registered);
   g_test_add_func ("/resource/manual", test_resource_manual);
 #ifdef G_HAS_CONSTRUCTORS
   g_test_add_func ("/resource/automatic", test_resource_automatic);
@@ -480,6 +585,7 @@ main (int   argc,
   g_test_add_func ("/resource/module", test_resource_module);
 #endif
   g_test_add_func ("/resource/uri/query-info", test_uri_query_info);
+  g_test_add_func ("/resource/uri/file", test_uri_file);
 
   return g_test_run();
 }



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