[glib: 1/2] glib-compile-resources: Fixes #1675



commit 45655b8265349d8e94b7472b6deb54adb3a63f38
Author: Felix Potthast <mail ninjakoa la>
Date:   Wed Feb 20 10:38:29 2019 +0000

    glib-compile-resources: Fixes #1675

 gio/glib-compile-resources.c           |  2 +-
 gio/tests/111_digit_test.gresource.xml |  6 ++++++
 gio/tests/meson.build                  | 25 ++++++++++++++++++++++--
 gio/tests/resources.c                  | 35 ++++++++++++++++++++++++++++++++++
 4 files changed, 65 insertions(+), 3 deletions(-)
---
diff --git a/gio/glib-compile-resources.c b/gio/glib-compile-resources.c
index 60ccdbf81..f04ea488b 100644
--- a/gio/glib-compile-resources.c
+++ b/gio/glib-compile-resources.c
@@ -992,7 +992,7 @@ main (int argc, char **argv)
            {
              const char *first = G_CSET_A_2_Z G_CSET_a_2_z "_";
              const char *rest = G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "_";
-             if (strchr ((i == 0) ? first : rest, base[i]) != NULL)
+             if (strchr ((s->len == 0) ? first : rest, base[i]) != NULL)
                g_string_append_c (s, base[i]);
              else if (base[i] == '-')
                g_string_append_c (s, '_');
diff --git a/gio/tests/111_digit_test.gresource.xml b/gio/tests/111_digit_test.gresource.xml
new file mode 100644
index 000000000..00efcc315
--- /dev/null
+++ b/gio/tests/111_digit_test.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/digit_test">
+    <file>test1.txt</file>
+  </gresource>
+</gresources>
diff --git a/gio/tests/meson.build b/gio/tests/meson.build
index a1b41872d..b5b41bb7c 100644
--- a/gio/tests/meson.build
+++ b/gio/tests/meson.build
@@ -525,6 +525,27 @@ if not meson.is_cross_build() or meson.has_exe_wrapper()
                '--c-name', '_g_test1',
                '@INPUT@'])
 
+  digit_test_resources_c = custom_target('digit_test_resources.c',
+    input : '111_digit_test.gresource.xml',
+    output : 'digit_test_resources.c',
+    command : [glib_compile_resources,
+               '--target=@OUTPUT@',
+               '--sourcedir=' + meson.current_source_dir(),
+               '--sourcedir=' + meson.current_build_dir(),
+               '--generate-source',
+               '--manual-register',
+               '@INPUT@'])
+
+  digit_test_resources_h = custom_target('digit_test_resources.h',
+    input : '111_digit_test.gresource.xml',
+    output : 'digit_test_resources.h',
+    command : [glib_compile_resources,
+               '--target=@OUTPUT@',
+               '--sourcedir=' + meson.current_source_dir(),
+               '--generate',
+               '--manual-register',
+               '@INPUT@'])
+
   # referenced by test.gresource.xml
   test_generated_txt = configure_file(input : 'test1.txt',
     output : 'test-generated.txt',
@@ -581,14 +602,14 @@ if not meson.is_cross_build() or meson.has_exe_wrapper()
       'resources' : {
         'extra_sources' : [test_gresource, test_resources_c, test_resources2_c,
                            test_resources2_h, test_resources_binary_c,
-                           test_resources_binary2],
+                           test_resources_binary2, digit_test_resources_c, digit_test_resources_h],
       },
     }
   else
     gio_tests += {
       'resources' : {
         'extra_sources' : [test_gresource, test_resources_c, test_resources2_c,
-                           test_resources2_h],
+                           test_resources2_h, digit_test_resources_c, digit_test_resources_h],
       },
     }
   endif
diff --git a/gio/tests/resources.c b/gio/tests/resources.c
index 6e9c7c5e6..cb2c00a48 100644
--- a/gio/tests/resources.c
+++ b/gio/tests/resources.c
@@ -20,6 +20,7 @@
 #include <gio/gio.h>
 #include "gconstructor.h"
 #include "test_resources2.h"
+#include "digit_test_resources.h"
 
 static void
 test_resource (GResource *resource)
@@ -595,6 +596,38 @@ test_resource_binary_linked (void)
   #endif /* if __linux__ */
 }
 
+/* Test resource whose xml file starts with more than one digit
+ * and where no explicit c-name is given
+ * Checks if resources are sucessfully registered and
+ * data can be found and read. */
+static void
+test_resource_digits (void)
+{
+  GError *error = NULL;
+  gboolean found;
+  gsize size;
+  guint32 flags;
+  GBytes *data;
+
+  found = g_resources_get_info ("/digit_test/test1.txt",
+                               G_RESOURCE_LOOKUP_FLAGS_NONE,
+                               &size, &flags, &error);
+  g_assert_true (found);
+  g_assert_no_error (error);
+  g_assert_cmpint (size, ==, 6);
+  g_assert_cmpuint (flags, ==, 0);
+
+  data = g_resources_lookup_data ("/digit_test/test1.txt",
+                                 G_RESOURCE_LOOKUP_FLAGS_NONE,
+                                 &error);
+  g_assert_nonnull (data);
+  g_assert_no_error (error);
+  size = g_bytes_get_size (data);
+  g_assert_cmpint (size, ==, 6);
+  g_assert_cmpstr (g_bytes_get_data (data, NULL), ==, "test1\n");
+  g_bytes_unref (data);
+}
+
 static void
 test_resource_module (void)
 {
@@ -930,6 +963,7 @@ main (int   argc,
   g_test_init (&argc, &argv, NULL);
 
   _g_test2_register_resource ();
+  _digit_test_register_resource ();
 
   g_test_add_func ("/resource/file", test_resource_file);
   g_test_add_func ("/resource/file-path", test_resource_file_path);
@@ -950,6 +984,7 @@ main (int   argc,
   g_test_add_func ("/resource/uri/file", test_uri_file);
   g_test_add_func ("/resource/64k", test_resource_64k);
   g_test_add_func ("/resource/overlay", test_overlay);
+  g_test_add_func ("/resource/digits", test_resource_digits);
 
   return g_test_run();
 }


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