[glib/resource-overlay-info: 2/2] Add a test for resource overlays



commit be5637ebe329a9818591571e6665b0371f25fa24
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jan 9 18:11:45 2019 -0500

    Add a test for resource overlays
    
    Add a test that checks that g_resources_get_info()
    respects the G_RESOURCE_OVERLAYS environment variable.

 gio/tests/resources.c   | 29 ++++++++++++++++++++++++++++-
 gio/tests/test1.overlay |  1 +
 2 files changed, 29 insertions(+), 1 deletion(-)
---
diff --git a/gio/tests/resources.c b/gio/tests/resources.c
index 70d8c03a6..c4514a265 100644
--- a/gio/tests/resources.c
+++ b/gio/tests/resources.c
@@ -642,7 +642,6 @@ test_uri_query_info (void)
   g_resources_register (resource);
 
   file = g_file_new_for_uri ("resource://" "/a_prefix/test2-alias.txt");
-
   info = g_file_query_info (file, "*", 0, NULL, &error);
   g_assert_no_error (error);
 
@@ -812,6 +811,33 @@ test_uri_file (void)
   g_resource_unref (resource);
 }
 
+/* Check that g_resources_get_info() respects G_RESOURCE_OVERLAYS */
+static void
+test_overlay (void)
+{
+  if (g_test_subprocess ())
+    {
+       GError *error = NULL;
+       gboolean res;
+       gsize size;
+       char *overlay;
+       char *path;
+
+       path = g_test_build_filename (G_TEST_DIST, "test1.overlay", NULL);
+       overlay = g_strconcat ("/auto_loaded/test1.txt=", path, NULL);
+
+       g_setenv ("G_RESOURCE_OVERLAYS", overlay, TRUE);
+       res = g_resources_get_info ("/auto_loaded/test1.txt", 0, &size, NULL, &error);
+       g_assert_true (res);
+       g_assert_no_error (error);
+       /* test1.txt is 6 bytes, test1.overlay is 23 */
+       g_assert_cmpint (size, ==, 23);
+
+       g_free (overlay);
+       g_free (path);
+    }
+}
+
 int
 main (int   argc,
       char *argv[])
@@ -836,6 +862,7 @@ main (int   argc,
 #endif
   g_test_add_func ("/resource/uri/query-info", test_uri_query_info);
   g_test_add_func ("/resource/uri/file", test_uri_file);
+  g_test_add_func ("/resource/overlay", test_overlay);
 
   return g_test_run();
 }
diff --git a/gio/tests/test1.overlay b/gio/tests/test1.overlay
new file mode 100644
index 000000000..687d69b2a
--- /dev/null
+++ b/gio/tests/test1.overlay
@@ -0,0 +1 @@
+It is a beautiful day!


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