summaryrefslogtreecommitdiffstats
path: root/test cases/frameworks/7 gnome/resources
diff options
context:
space:
mode:
Diffstat (limited to 'test cases/frameworks/7 gnome/resources')
-rw-r--r--test cases/frameworks/7 gnome/resources/generated-main.c26
-rw-r--r--test cases/frameworks/7 gnome/resources/generated.gresource.xml9
-rw-r--r--test cases/frameworks/7 gnome/resources/generated/meson.build4
-rw-r--r--test cases/frameworks/7 gnome/resources/meson.build72
-rw-r--r--test cases/frameworks/7 gnome/resources/myresource.gresource.xml9
-rw-r--r--test cases/frameworks/7 gnome/resources/res3.txt1
-rw-r--r--test cases/frameworks/7 gnome/resources/resources.py10
-rw-r--r--test cases/frameworks/7 gnome/resources/simple-main.c27
-rw-r--r--test cases/frameworks/7 gnome/resources/simple.gresource.xml7
9 files changed, 165 insertions, 0 deletions
diff --git a/test cases/frameworks/7 gnome/resources/generated-main.c b/test cases/frameworks/7 gnome/resources/generated-main.c
new file mode 100644
index 0000000..d102604
--- /dev/null
+++ b/test cases/frameworks/7 gnome/resources/generated-main.c
@@ -0,0 +1,26 @@
+#include<stdio.h>
+#include<string.h>
+#include<gio/gio.h>
+#include"generated-resources.h"
+
+#define EXPECTED "This is a generated resource.\n"
+
+int main(int argc, char **argv) {
+ generated_resources_get_resource();
+ GError *err = NULL;
+ GBytes *data = g_resources_lookup_data("/com/example/myprog/res3.txt",
+ G_RESOURCE_LOOKUP_FLAGS_NONE, &err);
+
+ if(data == NULL) {
+ fprintf(stderr, "Data lookup failed: %s\n", err->message);
+ return 1;
+ }
+ if(strcmp(g_bytes_get_data(data, NULL), EXPECTED) != 0) {
+ fprintf(stderr, "Resource contents are wrong:\n %s\n",
+ (const char*)g_bytes_get_data(data, NULL));
+ return 1;
+ }
+ fprintf(stdout, "All ok.\n");
+ g_bytes_unref(data);
+ return 0;
+}
diff --git a/test cases/frameworks/7 gnome/resources/generated.gresource.xml b/test cases/frameworks/7 gnome/resources/generated.gresource.xml
new file mode 100644
index 0000000..7a242d7
--- /dev/null
+++ b/test cases/frameworks/7 gnome/resources/generated.gresource.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/com/example/myprog">
+ <file>res1.txt</file>
+ <file>subdir/res2.txt</file>
+ <file>res3.txt</file>
+ <file>subdir/res4.txt</file>
+ </gresource>
+</gresources>
diff --git a/test cases/frameworks/7 gnome/resources/generated/meson.build b/test cases/frameworks/7 gnome/resources/generated/meson.build
new file mode 100644
index 0000000..9805c66
--- /dev/null
+++ b/test cases/frameworks/7 gnome/resources/generated/meson.build
@@ -0,0 +1,4 @@
+ct_simple_gresource = custom_target(
+ input : '../simple.gresource.xml',
+ output : 'simple-ct.gresource.xml',
+ command : [copyfile, '@INPUT@', '@OUTPUT@'])
diff --git a/test cases/frameworks/7 gnome/resources/meson.build b/test cases/frameworks/7 gnome/resources/meson.build
new file mode 100644
index 0000000..60fc848
--- /dev/null
+++ b/test cases/frameworks/7 gnome/resources/meson.build
@@ -0,0 +1,72 @@
+# There are two tests here, because the 2nd one depends on a version of
+# GLib (2.51.1) that is very recent at the time of writing.
+
+simple_gresource = configure_file(
+ input : 'simple.gresource.xml',
+ output : 'simple-gen.gresource.xml',
+ command : [copyfile, '@INPUT@', '@OUTPUT@'])
+
+simple_resources = gnome.compile_resources('simple-resources',
+ simple_gresource,
+ install_header : true,
+ export : true,
+ source_dir : '../resources-data',
+ c_name : 'simple_resources')
+
+simple_res_exe = executable('simple-resources-test',
+ 'simple-main.c', simple_resources,
+ dependencies: gio)
+test('simple resource test', simple_res_exe)
+
+gnome.compile_resources('simple-resources',
+ 'simple.gresource.xml',
+ gresource_bundle: true,
+ install: true,
+ install_dir: get_option('datadir'),
+ source_dir : '../resources-data',
+)
+test('simple resource test (gresource)', find_program('resources.py'))
+
+if not pretend_glib_old and glib.version() >= '2.52.0'
+ # This test cannot pass if GLib version is too old. Generated resource
+ # dependencies do not work correctly and Meson will raise an error if the
+ # user tries to use either the 'dependencies' kwarg or a gresource file that
+ # is itself generated.
+ generated_resources = gnome.compile_resources('generated-resources',
+ 'generated.gresource.xml',
+ source_dir : '../resources-data',
+ c_name : 'generated_resources',
+ dependencies : [res3_txt, res4_txt])
+
+ generated_res_exe = executable('generated-resources-test',
+ 'generated-main.c', generated_resources,
+ dependencies: gio)
+ test('generated resource test', generated_res_exe)
+
+ # Test with a CustomTarget
+ subdir('generated')
+
+ ct_resources = gnome.compile_resources(
+ 'ct-resources',
+ ct_simple_gresource,
+ install_header : true,
+ export : true,
+ source_dir : '../resources-data',
+ c_name : 'simple_resources')
+
+ cti_resources = gnome.compile_resources(
+ 'cti-resources',
+ ct_simple_gresource[0],
+ install_header : true,
+ export : true,
+ source_dir : '../resources-data',
+ c_name : 'simple_resources')
+endif
+
+# Test build_by_default
+gnome.compile_resources('build-resources',
+ 'simple.gresource.xml',
+ gresource_bundle : true,
+ build_by_default : true,
+ source_dir : '../resources-data',
+)
diff --git a/test cases/frameworks/7 gnome/resources/myresource.gresource.xml b/test cases/frameworks/7 gnome/resources/myresource.gresource.xml
new file mode 100644
index 0000000..7a242d7
--- /dev/null
+++ b/test cases/frameworks/7 gnome/resources/myresource.gresource.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/com/example/myprog">
+ <file>res1.txt</file>
+ <file>subdir/res2.txt</file>
+ <file>res3.txt</file>
+ <file>subdir/res4.txt</file>
+ </gresource>
+</gresources>
diff --git a/test cases/frameworks/7 gnome/resources/res3.txt b/test cases/frameworks/7 gnome/resources/res3.txt
new file mode 100644
index 0000000..aeed4a5
--- /dev/null
+++ b/test cases/frameworks/7 gnome/resources/res3.txt
@@ -0,0 +1 @@
+This file is from the wrong directory.
diff --git a/test cases/frameworks/7 gnome/resources/resources.py b/test cases/frameworks/7 gnome/resources/resources.py
new file mode 100644
index 0000000..0855ef7
--- /dev/null
+++ b/test cases/frameworks/7 gnome/resources/resources.py
@@ -0,0 +1,10 @@
+#!/usr/bin/env python3
+import os
+from gi.repository import Gio
+
+if __name__ == '__main__':
+ res = Gio.resource_load(os.path.join('resources', 'simple-resources.gresource'))
+ Gio.Resource._register(res)
+
+ data = Gio.resources_lookup_data('/com/example/myprog/res1.txt', Gio.ResourceLookupFlags.NONE)
+ assert data.get_data() == b'This is a resource.\n'
diff --git a/test cases/frameworks/7 gnome/resources/simple-main.c b/test cases/frameworks/7 gnome/resources/simple-main.c
new file mode 100644
index 0000000..c021a54
--- /dev/null
+++ b/test cases/frameworks/7 gnome/resources/simple-main.c
@@ -0,0 +1,27 @@
+#include<stdio.h>
+#include<string.h>
+#include<gio/gio.h>
+#include"simple-resources.h"
+
+#define EXPECTED "This is a resource.\n"
+
+int main(int argc, char **argv) {
+ simple_resources_get_resource();
+
+ GError *err = NULL;
+ GBytes *data = g_resources_lookup_data("/com/example/myprog/res1.txt",
+ G_RESOURCE_LOOKUP_FLAGS_NONE, &err);
+
+ if(data == NULL) {
+ fprintf(stderr, "Data lookup failed: %s\n", err->message);
+ return 1;
+ }
+ if(strcmp(g_bytes_get_data(data, NULL), EXPECTED) != 0) {
+ fprintf(stderr, "Resource contents are wrong:\n %s\n",
+ (const char*)g_bytes_get_data(data, NULL));
+ return 1;
+ }
+ fprintf(stdout, "All ok.\n");
+ g_bytes_unref(data);
+ return 0;
+}
diff --git a/test cases/frameworks/7 gnome/resources/simple.gresource.xml b/test cases/frameworks/7 gnome/resources/simple.gresource.xml
new file mode 100644
index 0000000..6e55910
--- /dev/null
+++ b/test cases/frameworks/7 gnome/resources/simple.gresource.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/com/example/myprog">
+ <file>res1.txt</file>
+ <file>subdir/res2.txt</file>
+ </gresource>
+</gresources>