Merge branch 'fix_cname' into 'master'

glib-compile-resources: Fixes #1675

Closes #1675

See merge request GNOME/glib!633
This commit is contained in:
Philip Withnall 2019-02-20 10:38:29 +00:00
commit 9aab30641e
4 changed files with 65 additions and 3 deletions

View File

@ -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, '_');

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/digit_test">
<file>test1.txt</file>
</gresource>
</gresources>

View File

@ -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

View File

@ -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();
}