gdbus-auth: Fix leaks in tests
[platform/upstream/glib.git] / gio / tests / resources.c
index 63ace3d..5cad1e4 100644 (file)
@@ -23,8 +23,6 @@
 #include "gconstructor.h"
 #include "test_resources2.h"
 
-const gchar *datapath;
-
 static void
 test_resource (GResource *resource)
 {
@@ -145,18 +143,15 @@ test_resource_file (void)
 {
   GResource *resource;
   GError *error = NULL;
-  gchar *path;
 
   resource = g_resource_load ("not-there", &error);
   g_assert (resource == NULL);
   g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
   g_clear_error (&error);
 
-  path = g_build_filename (datapath, "test.gresource", NULL);
-  resource = g_resource_load (path, &error);
+  resource = g_resource_load (g_test_get_filename (G_TEST_BUILT, "test.gresource", NULL), &error);
   g_assert (resource != NULL);
   g_assert_no_error (error);
-  g_free (path);
 
   test_resource (resource);
   g_resource_unref (resource);
@@ -171,12 +166,10 @@ test_resource_data (void)
   char *content;
   gsize content_size;
   GBytes *data;
-  gchar *path;
 
-  path = g_build_filename (datapath, "test.gresource", NULL);
-  loaded_file = g_file_get_contents (path, &content, &content_size, NULL);
+  loaded_file = g_file_get_contents (g_test_get_filename (G_TEST_BUILT, "test.gresource", NULL),
+                                     &content, &content_size, NULL);
   g_assert (loaded_file);
-  g_free (path);
 
   data = g_bytes_new_take (content, content_size);
   resource = g_resource_new_from_data (data, &error);
@@ -201,13 +194,10 @@ test_resource_registered (void)
   char **children;
   GInputStream *in;
   char buffer[128];
-  gchar *path;
 
-  path = g_build_filename (datapath, "test.gresource", NULL);
-  resource = g_resource_load (path, &error);
+  resource = g_resource_load (g_test_get_filename (G_TEST_BUILT, "test.gresource", NULL), &error);
   g_assert (resource != NULL);
   g_assert_no_error (error);
-  g_free (path);
 
   found = g_resources_get_info ("/test1.txt",
                                G_RESOURCE_LOOKUP_FLAGS_NONE,
@@ -406,11 +396,8 @@ test_resource_module (void)
 
   if (g_module_supported ())
     {
-      char *path;
-
-      path = g_build_filename (datapath, "libresourceplugin",  NULL);
-      module = g_io_module_new (path);
-      g_free (path);
+      /* For in-tree, this will find the .la file and use it to get to the .so in .libs/ */
+      module = g_io_module_new (g_test_get_filename (G_TEST_BUILT, "libresourceplugin",  NULL));
 
       error = NULL;
 
@@ -463,13 +450,11 @@ test_uri_query_info (void)
   GBytes *data;
   GFile *file;
   GFileInfo *info;
-  gchar *path;
-  const char *content_type;
+  const char *content_type, *mime_type;
 
-  path = g_build_filename (datapath, "test.gresource", NULL);
-  loaded_file = g_file_get_contents (path, &content, &content_size, NULL);
+  loaded_file = g_file_get_contents (g_test_get_filename (G_TEST_BUILT, "test.gresource", NULL),
+                                     &content, &content_size, NULL);
   g_assert (loaded_file);
-  g_free (path);
 
   data = g_bytes_new_take (content, content_size);
   resource = g_resource_new_from_data (data, &error);
@@ -486,7 +471,9 @@ test_uri_query_info (void)
 
   content_type = g_file_info_get_content_type (info);
   g_assert (content_type);
-  g_assert_cmpstr (content_type, ==, "text/plain");
+  mime_type = g_content_type_get_mime_type (content_type);
+  g_assert (mime_type);
+  g_assert_cmpstr (mime_type, ==, "text/plain");
 
   g_object_unref (info);
 
@@ -516,12 +503,10 @@ test_uri_file (void)
   gchar buf[1024];
   gboolean ret;
   gssize skipped;
-  gchar *path;
 
-  path = g_build_filename (datapath, "test.gresource", NULL);
-  loaded_file = g_file_get_contents (path, &content, &content_size, NULL);
+  loaded_file = g_file_get_contents (g_test_get_filename (G_TEST_BUILT, "test.gresource", NULL),
+                                     &content, &content_size, NULL);
   g_assert (loaded_file);
-  g_free (path);
 
   data = g_bytes_new_take (content, content_size);
   resource = g_resource_new_from_data (data, &error);
@@ -641,11 +626,6 @@ int
 main (int   argc,
       char *argv[])
 {
-  if (g_getenv ("G_TEST_DATA"))
-    datapath = g_getenv ("G_TEST_DATA");
-  else
-    datapath = SRCDIR;
-
   g_test_init (&argc, &argv, NULL);
 
   _g_test2_register_resource ();