mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-23 04:36:17 +01:00
gresources: Add a test with resources > 64kb
This is to ensure that the generated code is still compilable by the running compiler, and see whether we can read the things in there properly. See issue #1580.
This commit is contained in:
parent
4501807d73
commit
cd30faae1f
1
gio/tests/.gitignore
vendored
1
gio/tests/.gitignore
vendored
@ -146,3 +146,4 @@ xdgdatadir
|
|||||||
xdgdatahome
|
xdgdatahome
|
||||||
xgen-gio
|
xgen-gio
|
||||||
xgen-giosrc.c
|
xgen-giosrc.c
|
||||||
|
gresource-big-test.txt
|
||||||
|
@ -589,9 +589,12 @@ test-generated.txt: test1.txt
|
|||||||
$(AM_V_GEN) echo "Generated" > $@ && \
|
$(AM_V_GEN) echo "Generated" > $@ && \
|
||||||
cat $< >> $@
|
cat $< >> $@
|
||||||
|
|
||||||
|
gresource-big-test.txt: gen-big-test-resource.py
|
||||||
|
$(AM_V_GEN) $(PYTHON) $< $@
|
||||||
|
|
||||||
resources.o: test_resources2.h
|
resources.o: test_resources2.h
|
||||||
test_resources.c: test2.gresource.xml Makefile $(shell $(glib_compile_resources) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/test2.gresource.xml)
|
test_resources.c: test2.gresource.xml Makefile $(shell $(glib_compile_resources) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/test2.gresource.xml)
|
||||||
$(AM_V_GEN) $(glib_compile_resources) --target=$@ --sourcedir=$(srcdir) --generate-source --c-name _g_test1 $<
|
$(AM_V_GEN) $(glib_compile_resources) --target=$@ --sourcedir=. --sourcedir=$(srcdir) --generate-source --c-name _g_test1 $<
|
||||||
|
|
||||||
test_resources2.h test_resources2.c: test3.gresource.xml Makefile $(shell $(glib_compile_resources) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/test3.gresource.xml)
|
test_resources2.h test_resources2.c: test3.gresource.xml Makefile $(shell $(glib_compile_resources) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/test3.gresource.xml)
|
||||||
$(AM_V_GEN) $(glib_compile_resources) --target=$@ --sourcedir=$(srcdir) --generate --c-name _g_test2 --manual-register $<
|
$(AM_V_GEN) $(glib_compile_resources) --target=$@ --sourcedir=$(srcdir) --generate --c-name _g_test2 --manual-register $<
|
||||||
@ -602,8 +605,8 @@ plugin_resources.c: test4.gresource.xml Makefile $(shell $(glib_compile_resource
|
|||||||
test.gresource: test.gresource.xml Makefile $(shell $(glib_compile_resources) --sourcedir=. --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/test.gresource.xml)
|
test.gresource: test.gresource.xml Makefile $(shell $(glib_compile_resources) --sourcedir=. --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/test.gresource.xml)
|
||||||
$(AM_V_GEN) $(glib_compile_resources) --target=$@ --sourcedir=. --sourcedir=$(srcdir) $<
|
$(AM_V_GEN) $(glib_compile_resources) --target=$@ --sourcedir=. --sourcedir=$(srcdir) $<
|
||||||
|
|
||||||
EXTRA_DIST += test.gresource.xml test1.txt test2.gresource.xml test2.txt test3.gresource.xml test3.txt test4.gresource.xml
|
EXTRA_DIST += test.gresource.xml test1.txt test2.gresource.xml test2.txt test3.gresource.xml test3.txt test4.gresource.xml gen-big-test-resource.py
|
||||||
CLEANFILES += test-generated.txt test_resources.c test_resources2.[ch] plugin_resources.c test.gresource
|
CLEANFILES += test-generated.txt test_resources.c test_resources2.[ch] plugin_resources.c test.gresource gresource-big-test.txt
|
||||||
endif # !CROSS_COMPILING
|
endif # !CROSS_COMPILING
|
||||||
|
|
||||||
BUILT_SOURCES += giotypefuncs.inc
|
BUILT_SOURCES += giotypefuncs.inc
|
||||||
|
27
gio/tests/gen-big-test-resource.py
Normal file
27
gio/tests/gen-big-test-resource.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Generate a large text file to test compile
|
||||||
|
# the resulting code that contains a large (>65536 bytes)
|
||||||
|
# resource entry. Just have 12 iterations of the following:
|
||||||
|
#
|
||||||
|
# -100 of each of the lowercase letters
|
||||||
|
# -100 of each of the uppercase letters
|
||||||
|
# -100 of the numbers 0 to 9
|
||||||
|
#
|
||||||
|
# See issue #1580
|
||||||
|
|
||||||
|
import io
|
||||||
|
import string
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
raise SystemExit('Usage: %s <output-file>' % sys.argv[0])
|
||||||
|
|
||||||
|
with open(sys.argv[1], 'w', newline='\n') as f:
|
||||||
|
for count in range(12):
|
||||||
|
for c in string.ascii_lowercase:
|
||||||
|
f.write("%s\n" % (c * 100))
|
||||||
|
|
||||||
|
for c in string.ascii_uppercase:
|
||||||
|
f.write("%s\n" % (c * 100))
|
||||||
|
|
||||||
|
for i in range(10):
|
||||||
|
f.write("%s\n" % (str(i) * 100))
|
@ -411,6 +411,13 @@ if not meson.is_cross_build() or meson.has_exe_wrapper()
|
|||||||
install : installed_tests_enabled
|
install : installed_tests_enabled
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# referenced by test2.gresource.xml
|
||||||
|
big_test_resource = custom_target(
|
||||||
|
'gresource-big-test.txt',
|
||||||
|
input : ['gen-big-test-resource.py'],
|
||||||
|
output : ['gresource-big-test.txt'],
|
||||||
|
command : [python, '@INPUT0@', '@OUTPUT@'])
|
||||||
|
|
||||||
test_gresource = custom_target('test.gresource',
|
test_gresource = custom_target('test.gresource',
|
||||||
input : 'test.gresource.xml',
|
input : 'test.gresource.xml',
|
||||||
output : 'test.gresource',
|
output : 'test.gresource',
|
||||||
@ -446,10 +453,12 @@ if not meson.is_cross_build() or meson.has_exe_wrapper()
|
|||||||
|
|
||||||
test_resources_c = custom_target('test_resources.c',
|
test_resources_c = custom_target('test_resources.c',
|
||||||
input : 'test2.gresource.xml',
|
input : 'test2.gresource.xml',
|
||||||
|
depends : big_test_resource,
|
||||||
output : 'test_resources.c',
|
output : 'test_resources.c',
|
||||||
command : [glib_compile_resources,
|
command : [glib_compile_resources,
|
||||||
'--target=@OUTPUT@',
|
'--target=@OUTPUT@',
|
||||||
'--sourcedir=' + meson.current_source_dir(),
|
'--sourcedir=' + meson.current_source_dir(),
|
||||||
|
'--sourcedir=' + meson.current_build_dir(),
|
||||||
'--generate-source',
|
'--generate-source',
|
||||||
'--c-name', '_g_test1',
|
'--c-name', '_g_test1',
|
||||||
'@INPUT@'])
|
'@INPUT@'])
|
||||||
|
@ -812,6 +812,50 @@ test_uri_file (void)
|
|||||||
g_resource_unref (resource);
|
g_resource_unref (resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_resource_64k (void)
|
||||||
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
gboolean found;
|
||||||
|
gsize size;
|
||||||
|
guint32 flags;
|
||||||
|
GBytes *data;
|
||||||
|
gchar **tokens;
|
||||||
|
|
||||||
|
found = g_resources_get_info ("/big_prefix/gresource-big-test.txt",
|
||||||
|
G_RESOURCE_LOOKUP_FLAGS_NONE,
|
||||||
|
&size, &flags, &error);
|
||||||
|
g_assert_true (found);
|
||||||
|
g_assert_no_error (error);
|
||||||
|
|
||||||
|
/* Check size: 100 of all lower case letters + newline char +
|
||||||
|
* 100 all upper case letters + newline char +
|
||||||
|
* 100 of all numbers between 0 to 9 + newline char
|
||||||
|
* (for 12 iterations)
|
||||||
|
*/
|
||||||
|
|
||||||
|
g_assert_cmpint (size, ==, (26 + 26 + 10) * (100 + 1) * 12);
|
||||||
|
g_assert_cmpuint (flags, ==, 0);
|
||||||
|
data = g_resources_lookup_data ("/big_prefix/gresource-big-test.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, ==, (26 + 26 + 10) * (100 + 1) * 12);
|
||||||
|
tokens = g_strsplit ((const gchar *) g_bytes_get_data (data, NULL), "\n", -1);
|
||||||
|
|
||||||
|
/* check tokens[x] == entry at gresource-big-test.txt's line, where x = line - 1 */
|
||||||
|
g_assert_cmpstr (tokens[0], ==, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
||||||
|
g_assert_cmpstr (tokens[27], ==, "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB");
|
||||||
|
g_assert_cmpstr (tokens[183], ==, "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777");
|
||||||
|
g_assert_cmpstr (tokens[600], ==, "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ");
|
||||||
|
g_assert_cmpstr (tokens[742], ==, "8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888");
|
||||||
|
g_strfreev (tokens);
|
||||||
|
g_bytes_unref (data);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char *argv[])
|
char *argv[])
|
||||||
@ -836,6 +880,7 @@ main (int argc,
|
|||||||
#endif
|
#endif
|
||||||
g_test_add_func ("/resource/uri/query-info", test_uri_query_info);
|
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/uri/file", test_uri_file);
|
||||||
|
g_test_add_func ("/resource/64k", test_resource_64k);
|
||||||
|
|
||||||
return g_test_run();
|
return g_test_run();
|
||||||
}
|
}
|
||||||
|
@ -3,4 +3,9 @@
|
|||||||
<gresource prefix="/auto_loaded">
|
<gresource prefix="/auto_loaded">
|
||||||
<file>test1.txt</file>
|
<file>test1.txt</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
|
<!-- Test compiling the generated GResource C-code
|
||||||
|
that has a resouce entry size over 65536 bytes -->
|
||||||
|
<gresource prefix="/big_prefix">
|
||||||
|
<file>gresource-big-test.txt</file>
|
||||||
|
</gresource>
|
||||||
</gresources>
|
</gresources>
|
||||||
|
Loading…
Reference in New Issue
Block a user