[glib/resources] Test compressed resource files



commit d40f31280c8befa18be8179ba08f14d596a97a26
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Dec 22 10:10:54 2011 +0100

    Test compressed resource files

 gio/tests/resources.c        |   52 +++++++++++++++++++++++++++++++++++------
 gio/tests/test.gresource.xml |    2 +-
 2 files changed, 45 insertions(+), 9 deletions(-)
---
diff --git a/gio/tests/resources.c b/gio/tests/resources.c
index e7b975f..466a12c 100644
--- a/gio/tests/resources.c
+++ b/gio/tests/resources.c
@@ -24,11 +24,13 @@ static void
 test_resource (GResource *resource)
 {
   GError *error = NULL;
-  gboolean found;
+  gboolean found, success;
   gsize size;
   guint32 flags;
   const void *data;
   char **children;
+  GInputStream *in;
+  char buffer[128];
 
   found = g_resource_get_info (resource,
 			       "/not/there",
@@ -43,7 +45,7 @@ test_resource (GResource *resource)
   g_assert (found);
   g_assert (error == NULL);
   g_assert (size == 6);
-  g_assert (flags == G_RESOURCE_FLAGS_LOCALIZED);
+  g_assert (flags == (G_RESOURCE_FLAGS_LOCALIZED | G_RESOURCE_FLAGS_COMPRESSED));
 
   found = g_resource_get_info (resource,
 			       "/a_prefix/test2.txt",
@@ -69,13 +71,29 @@ test_resource (GResource *resource)
   g_assert (size == 6);
   g_assert (flags == 0);
 
+  /* This will fail due to compression */
   data = g_resource_lookup_data (resource,
 				 "/test1.txt",
 				 &size, &error);
-  g_assert (data != NULL);
+  g_assert (data == NULL);
+  g_assert (error != NULL);
+  g_clear_error (&error);
+
+  in = g_resource_open_stream (resource,
+			       "/test1.txt",
+			       &error);
+  g_assert (in != NULL);
+  g_assert (error == NULL);
+
+  success = g_input_stream_read_all (in, buffer, sizeof (buffer) - 1,
+				     &size,
+				     NULL, &error);
+  g_assert (success);
   g_assert (error == NULL);
   g_assert (size == 6);
-  g_assert_cmpstr (data, ==, "test1\n");
+  g_assert_cmpstr (buffer, ==, "test1\n");
+
+  g_input_stream_close (in, NULL, NULL);
 
   data = g_resource_lookup_data (resource,
 				 "/a_prefix/test2.txt",
@@ -162,11 +180,13 @@ test_resource_registred (void)
 {
   GResource *resource;
   GError *error = NULL;
-  gboolean found;
+  gboolean found, success;
   gsize size;
   guint32 flags;
   const void *data;
   char **children;
+  GInputStream *in;
+  char buffer[128];
 
   resource = g_resource_load ("test.gresource", &error);
   g_assert (resource != NULL);
@@ -185,7 +205,7 @@ test_resource_registred (void)
   g_assert (found);
   g_assert (error == NULL);
   g_assert (size == 6);
-  g_assert (flags == G_RESOURCE_FLAGS_LOCALIZED);
+  g_assert (flags == (G_RESOURCE_FLAGS_LOCALIZED | G_RESOURCE_FLAGS_COMPRESSED));
 
   found = g_resources_get_info ("/a_prefix/test2.txt",
 				&size, &flags, &error);
@@ -208,12 +228,28 @@ test_resource_registred (void)
   g_assert (size == 6);
   g_assert (flags == 0);
 
+  /* This will fail due to compression */
   data = g_resources_lookup_data ("/test1.txt",
 				  &size, &error);
-  g_assert (data != NULL);
+  g_assert (data == NULL);
+  g_assert (error != NULL);
+  g_clear_error (&error);
+
+  in = g_resources_open_stream ("/test1.txt",
+				&error);
+  g_assert (in != NULL);
+  g_assert (error == NULL);
+
+  success = g_input_stream_read_all (in, buffer, sizeof (buffer) - 1,
+				     &size,
+				     NULL, &error);
+  g_assert (success);
   g_assert (error == NULL);
   g_assert (size == 6);
-  g_assert_cmpstr (data, ==, "test1\n");
+  g_assert_cmpstr (buffer, ==, "test1\n");
+
+  g_input_stream_close (in, NULL, NULL);
+
 
   data = g_resources_lookup_data ("/a_prefix/test2.txt",
 				  &size, &error);
diff --git a/gio/tests/test.gresource.xml b/gio/tests/test.gresource.xml
index 2db9327..c9885e5 100644
--- a/gio/tests/test.gresource.xml
+++ b/gio/tests/test.gresource.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
   <gresource>
-    <file>test1.txt</file>
+    <file compressed="true">test1.txt</file>
   </gresource>
   <gresource prefix="/a_prefix">
     <file alias="test2-alias.txt">test2.txt</file>



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