[glib/wip/resources] Add a test for resources in modules



commit c84fe0d3eff721147ea4fd48bfdf564589d6cc7c
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Jan 10 16:24:05 2012 +0100

    Add a test for resources in modules

 gio/tests/Makefile.am         |    9 ++++++
 gio/tests/resourceplugin.c    |   18 +++++++++++
 gio/tests/resources.c         |   63 +++++++++++++++++++++++++++++++++++++++++
 gio/tests/test4.gresource.xml |    6 ++++
 4 files changed, 96 insertions(+), 0 deletions(-)
---
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index 16c4802..73eb046 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -585,9 +585,18 @@ test_resources2.c: test3.gresource.xml test1.txt
 test_resources2.h: test3.gresource.xml
 	$(top_builddir)/gio/glib-compile-resources --target=$@ --generate-header --c-name _g_test2 --manual-register $(srcdir)/test3.gresource.xml
 
+plugin_resources.c: test4.gresource.xml test1.txt
+	$(top_builddir)/gio/glib-compile-resources --target=$@ --generate-source --c-name _g_plugin $(srcdir)/test4.gresource.xml
+
 test.gresource: test.gresource.xml test1.txt test2.txt test3.txt
 	$(top_builddir)/gio/glib-compile-resources --target=$@ --sourcedir=$(srcdir) $(srcdir)/test.gresource.xml
 
+noinst_LTLIBRARIES = libresourceplugin.la
+
+libresourceplugin_la_SOURCES = resourceplugin.c plugin_resources.c
+libresourceplugin_la_LDFLAGS = $(G_MODULE_LDFLAGS) -avoid-version -module $(no_undefined) -rpath $(libdir)
+libresourceplugin_la_LIBADD = $(G_MODULE_LIBS)
+
 CLEANFILES = gdbus-test-codegen-generated.[ch] gdbus-test-codegen-generated-doc-*.xml
 
 DISTCLEANFILES = \
diff --git a/gio/tests/resourceplugin.c b/gio/tests/resourceplugin.c
new file mode 100644
index 0000000..b66d541
--- /dev/null
+++ b/gio/tests/resourceplugin.c
@@ -0,0 +1,18 @@
+#include <gio/gio.h>
+
+void
+g_io_module_load (GIOModule *module)
+{
+}
+
+void
+g_io_module_unload (GIOModule   *module)
+{
+}
+
+char **
+g_io_module_query (void)
+{
+  return NULL;
+}
+
diff --git a/gio/tests/resources.c b/gio/tests/resources.c
index 3ff569e..586bafa 100644
--- a/gio/tests/resources.c
+++ b/gio/tests/resources.c
@@ -388,6 +388,67 @@ test_resource_manual (void)
   g_bytes_unref (data);
 }
 
+static void
+test_resource_module (void)
+{
+  GIOModule *module;
+  gboolean found;
+  gsize size;
+  guint32 flags;
+  GBytes *data;
+  GError *error;
+
+  if (g_module_supported ())
+    {
+      char *dir, *path;
+
+      dir = g_get_current_dir ();
+
+      path = g_strconcat (dir, G_DIR_SEPARATOR_S "libresourceplugin",  NULL);
+      module = g_io_module_new (path);
+      g_free (path);
+
+      error = NULL;
+
+      found = g_resources_get_info ("/resourceplugin/test1.txt",
+				    G_RESOURCE_LOOKUP_FLAGS_NONE,
+				    &size, &flags, &error);
+      g_assert (!found);
+      g_assert (error != NULL);
+      g_clear_error (&error);
+
+      g_type_module_use (G_TYPE_MODULE (module));
+
+      found = g_resources_get_info ("/resourceplugin/test1.txt",
+				    G_RESOURCE_LOOKUP_FLAGS_NONE,
+				    &size, &flags, &error);
+      g_assert (found);
+      g_assert (error == NULL);
+      g_assert (size == 6);
+      g_assert (flags == 0);
+
+      data = g_resources_lookup_data ("/resourceplugin/test1.txt",
+				      G_RESOURCE_LOOKUP_FLAGS_NONE,
+				      &error);
+      g_assert (data != NULL);
+      g_assert (error == NULL);
+      size = g_bytes_get_size (data);
+      g_assert (size == 6);
+      g_assert_cmpstr (g_bytes_get_data (data, NULL), ==, "test1\n");
+      g_bytes_unref (data);
+
+      g_type_module_unuse (G_TYPE_MODULE (module));
+
+      found = g_resources_get_info ("/resourceplugin/test1.txt",
+				    G_RESOURCE_LOOKUP_FLAGS_NONE,
+				    &size, &flags, &error);
+      g_assert (!found);
+      g_assert (error != NULL);
+      g_clear_error (&error);
+    }
+}
+
+
 int
 main (int   argc,
       char *argv[])
@@ -403,6 +464,8 @@ main (int   argc,
   g_test_add_func ("/resource/manual", test_resource_manual);
 #ifdef G_HAS_CONSTRUCTORS
   g_test_add_func ("/resource/automatic", test_resource_automatic);
+  /* This only uses automatic resources too, so it tests the constructors and destructors */
+  g_test_add_func ("/resource/module", test_resource_module);
 #endif
 
   return g_test_run();
diff --git a/gio/tests/test4.gresource.xml b/gio/tests/test4.gresource.xml
new file mode 100644
index 0000000..ddd7304
--- /dev/null
+++ b/gio/tests/test4.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/resourceplugin">
+    <file>test1.txt</file>
+  </gresource>
+</gresources>



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