[glib] tests: move tests to new _get_filename() API
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] tests: move tests to new _get_filename() API
- Date: Wed, 29 May 2013 13:04:06 +0000 (UTC)
commit 17ded322c5cb2cdb230233a9a020e1acdab9c0ab
Author: Ryan Lortie <desrt desrt ca>
Date: Tue May 28 14:24:47 2013 -0400
tests: move tests to new _get_filename() API
This API was introduced to save a few lines of code here and there, so
let's start by removing a bunch from our own tests.
https://bugzilla.gnome.org/show_bug.cgi?id=549783
gio/tests/file.c | 5 +--
gio/tests/g-icon.c | 7 +---
gio/tests/gdbus-connection-slow.c | 12 ++---
gio/tests/gdbus-connection.c | 5 +--
gio/tests/gdbus-introspection.c | 5 +--
gio/tests/gdbus-peer.c | 3 +-
gio/tests/gdbus-proxy-well-known-name.c | 9 +---
gio/tests/gdbus-proxy.c | 11 +----
gio/tests/resources.c | 35 ++++-----------
gio/tests/tls-certificate.c | 72 +++++++++++--------------------
glib/tests/keyfile.c | 12 +----
glib/tests/mappedfile.c | 25 ++---------
12 files changed, 56 insertions(+), 145 deletions(-)
---
diff --git a/gio/tests/file.c b/gio/tests/file.c
index 2ef037b..c2f2378 100644
--- a/gio/tests/file.c
+++ b/gio/tests/file.c
@@ -83,11 +83,8 @@ test_type (void)
GFile *file;
GFileType type;
GError *error = NULL;
- gchar *datapath;
- datapath = g_test_build_filename (G_TEST_DISTED, ".", NULL);
- datapath_f = g_file_new_for_path (datapath);
- g_free (datapath);
+ datapath_f = g_file_new_for_path (g_test_get_dir (G_TEST_DISTED));
file = g_file_get_child (datapath_f, "g-icon.c");
type = g_file_query_file_type (file, 0, NULL);
diff --git a/gio/tests/g-icon.c b/gio/tests/g-icon.c
index f339c6e..2e34d82 100644
--- a/gio/tests/g-icon.c
+++ b/gio/tests/g-icon.c
@@ -465,11 +465,8 @@ test_file_icon (void)
GError *error;
GInputStream *stream;
gchar *str;
- gchar *path;
- path = g_test_build_filename (G_TEST_DISTED, "g-icon.c", NULL);
-
- file = g_file_new_for_path (path);
+ file = g_file_new_for_path (g_test_get_filename (G_TEST_DISTED, "g-icon.c", NULL));
icon = g_file_icon_new (file);
g_object_unref (file);
@@ -487,8 +484,6 @@ test_file_icon (void)
g_object_unref (icon);
g_object_unref (icon2);
-
- g_free (path);
}
int
diff --git a/gio/tests/gdbus-connection-slow.c b/gio/tests/gdbus-connection-slow.c
index 2f943c3..981caf0 100644
--- a/gio/tests/gdbus-connection-slow.c
+++ b/gio/tests/gdbus-connection-slow.c
@@ -61,6 +61,7 @@ test_connection_flush (void)
GError *error;
guint n;
guint signal_handler_id;
+ const gchar *flush_helper;
session_bus_up ();
@@ -81,16 +82,15 @@ test_connection_flush (void)
NULL);
g_assert_cmpint (signal_handler_id, !=, 0);
+ flush_helper = g_test_get_filename (G_TEST_BUILT, "gdbus-connection-flush-helper", NULL);
for (n = 0; n < 50; n++)
{
gboolean ret;
gint exit_status;
guint timeout_mainloop_id;
- gchar *path;
error = NULL;
- path = g_test_build_filename (G_TEST_BUILT, "gdbus-connection-flush-helper", NULL);
- ret = g_spawn_command_line_sync (path,
+ ret = g_spawn_command_line_sync (flush_helper,
NULL, /* stdout */
NULL, /* stderr */
&exit_status,
@@ -99,7 +99,6 @@ test_connection_flush (void)
g_spawn_check_exit_status (exit_status, &error);
g_assert_no_error (error);
g_assert (ret);
- g_free (path);
timeout_mainloop_id = g_timeout_add (1000, test_connection_flush_on_timeout, GUINT_TO_POINTER (n));
g_main_loop_run (loop);
@@ -186,15 +185,12 @@ static void
test_connection_large_message (void)
{
guint watcher_id;
- gchar *path;
guint timeout_id;
session_bus_up ();
/* this is safe; testserver will exit once the bus goes away */
- path = g_test_build_filename (G_TEST_BUILT, "gdbus-testserver", NULL);
- g_assert (g_spawn_command_line_async (path, NULL));
- g_free (path);
+ g_assert (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL));
timeout_id = g_timeout_add_seconds (LARGE_MESSAGE_TIMEOUT_SECONDS,
large_message_timeout_cb,
diff --git a/gio/tests/gdbus-connection.c b/gio/tests/gdbus-connection.c
index 724acc0..9cd1e10 100644
--- a/gio/tests/gdbus-connection.c
+++ b/gio/tests/gdbus-connection.c
@@ -919,7 +919,6 @@ test_connection_filter (void)
FilterEffects effects;
GVariant *result;
const gchar *s;
- gchar *path;
memset (&data, '\0', sizeof (FilterData));
@@ -1002,9 +1001,7 @@ test_connection_filter (void)
g_assert_cmpint (data.num_outgoing, ==, 4);
/* this is safe; testserver will exit once the bus goes away */
- path = g_test_build_filename (G_TEST_BUILT, "gdbus-testserver", NULL);
- g_assert (g_spawn_command_line_async (path, NULL));
- g_free (path);
+ g_assert (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL));
/* wait for service to be available */
signal_handler_id = g_dbus_connection_signal_subscribe (c,
diff --git a/gio/tests/gdbus-introspection.c b/gio/tests/gdbus-introspection.c
index cbba696..3846efe 100644
--- a/gio/tests/gdbus-introspection.c
+++ b/gio/tests/gdbus-introspection.c
@@ -107,7 +107,6 @@ test_introspection_parser (void)
GDBusProxy *proxy;
GDBusConnection *connection;
GError *error;
- gchar *path;
error = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SESSION,
@@ -126,9 +125,7 @@ test_introspection_parser (void)
g_assert_no_error (error);
/* this is safe; testserver will exit once the bus goes away */
- path = g_test_build_filename (G_TEST_BUILT, "gdbus-testserver", NULL);
- g_assert (g_spawn_command_line_async (path, NULL));
- g_free (path);
+ g_assert (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL));
_g_assert_property_notify (proxy, "g-name-owner");
diff --git a/gio/tests/gdbus-peer.c b/gio/tests/gdbus-peer.c
index 1f3f330..b8f82c5 100644
--- a/gio/tests/gdbus-peer.c
+++ b/gio/tests/gdbus-peer.c
@@ -787,7 +787,7 @@ test_peer (void)
gsize len;
gchar *buf2;
gsize len2;
- char *testfile = g_test_build_filename (G_TEST_DISTED, "file.c", NULL);
+ const char *testfile = g_test_get_filename (G_TEST_DISTED, "file.c", NULL);
method_call_message = g_dbus_message_new_method_call (NULL, /* name */
"/org/gtk/GDBus/PeerTestObject",
@@ -830,7 +830,6 @@ test_peer (void)
g_assert (memcmp (buf, buf2, len) == 0);
g_free (buf2);
g_free (buf);
- g_free (testfile);
}
#else
error = NULL;
diff --git a/gio/tests/gdbus-proxy-well-known-name.c b/gio/tests/gdbus-proxy-well-known-name.c
index db2e5cc..f22aa6e 100644
--- a/gio/tests/gdbus-proxy-well-known-name.c
+++ b/gio/tests/gdbus-proxy-well-known-name.c
@@ -60,7 +60,6 @@ test_proxy_well_known_name (void)
gchar **property_names;
GVariant *variant;
GVariant *result;
- gchar *path;
session_bus_up ();
@@ -99,9 +98,7 @@ test_proxy_well_known_name (void)
g_assert (g_dbus_proxy_get_cached_property_names (ap) == NULL);
/* this is safe; testserver will exit once the bus goes away */
- path = g_test_build_filename (G_TEST_BUILT, "gdbus-testserver", NULL);
- g_assert (g_spawn_command_line_async (path, NULL));
- g_free (path);
+ g_assert (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL));
/* check that we get the notify::g-name-owner signal */
_g_assert_property_notify (p, "g-name-owner");
@@ -227,9 +224,7 @@ test_proxy_well_known_name (void)
* the 'y' property should be back at 1...
*/
/* this is safe; testserver will exit once the bus goes away */
- path = g_test_build_filename (G_TEST_BUILT, "gdbus-testserver", NULL);
- g_assert (g_spawn_command_line_async (path, NULL));
- g_free (path);
+ g_assert (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL));
/* check that we get the notify::g-name-owner signal */
_g_assert_property_notify (p, "g-name-owner");
diff --git a/gio/tests/gdbus-proxy.c b/gio/tests/gdbus-proxy.c
index 0e510af..2402f3d 100644
--- a/gio/tests/gdbus-proxy.c
+++ b/gio/tests/gdbus-proxy.c
@@ -762,7 +762,6 @@ test_proxy (void)
GDBusProxy *proxy;
GDBusConnection *connection;
GError *error;
- gchar *path;
error = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SESSION,
@@ -781,9 +780,7 @@ test_proxy (void)
g_assert_no_error (error);
/* this is safe; testserver will exit once the bus goes away */
- path = g_test_build_filename (G_TEST_BUILT, "gdbus-testserver", NULL);
- g_assert (g_spawn_command_line_async (path, NULL));
- g_free (path);
+ g_assert (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL));
_g_assert_property_notify (proxy, "g-name-owner");
@@ -834,8 +831,6 @@ fail_test (gpointer user_data)
static void
test_async (void)
{
- gchar *path;
-
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
NULL, /* GDBusInterfaceInfo */
@@ -847,9 +842,7 @@ test_async (void)
NULL);
/* this is safe; testserver will exit once the bus goes away */
- path = g_test_build_filename (G_TEST_BUILT, "gdbus-testserver", NULL);
- g_assert (g_spawn_command_line_async (path, NULL));
- g_free (path);
+ g_assert (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL));
g_timeout_add (10000, fail_test, NULL);
g_main_loop_run (loop);
diff --git a/gio/tests/resources.c b/gio/tests/resources.c
index 3a4edb8..495c05b 100644
--- a/gio/tests/resources.c
+++ b/gio/tests/resources.c
@@ -143,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_test_build_filename (G_TEST_BUILT, "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);
@@ -169,12 +166,10 @@ test_resource_data (void)
char *content;
gsize content_size;
GBytes *data;
- gchar *path;
- path = g_test_build_filename (G_TEST_BUILT, "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);
@@ -199,13 +194,10 @@ test_resource_registered (void)
char **children;
GInputStream *in;
char buffer[128];
- gchar *path;
- path = g_test_build_filename (G_TEST_BUILT, "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,
@@ -404,11 +396,8 @@ test_resource_module (void)
if (g_module_supported ())
{
- char *path;
-
- path = g_test_build_filename (G_TEST_BUILT, "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;
@@ -461,13 +450,11 @@ test_uri_query_info (void)
GBytes *data;
GFile *file;
GFileInfo *info;
- gchar *path;
const char *content_type;
- path = g_test_build_filename (G_TEST_BUILT, "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);
@@ -514,12 +501,10 @@ test_uri_file (void)
gchar buf[1024];
gboolean ret;
gssize skipped;
- gchar *path;
- path = g_test_build_filename (G_TEST_BUILT, "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);
diff --git a/gio/tests/tls-certificate.c b/gio/tests/tls-certificate.c
index a6338c0..a3a3333 100644
--- a/gio/tests/tls-certificate.c
+++ b/gio/tests/tls-certificate.c
@@ -40,15 +40,12 @@ pem_parser (const Reference *ref)
gchar *pem;
gchar *parsed_cert_pem = NULL;
const gchar *parsed_key_pem = NULL;
- gchar *path;
GError *error = NULL;
/* Check PEM parsing in certificate, private key order. */
- path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "cert-key.pem", NULL);
- g_file_get_contents (path, &pem, NULL, &error);
+ g_file_get_contents (g_test_get_filename (G_TEST_DISTED, "cert-tests", "cert-key.pem", NULL), &pem, NULL,
&error);
g_assert_no_error (error);
g_assert (pem);
- g_free (path);
cert = g_tls_certificate_new_from_pem (pem, -1, &error);
g_assert_no_error (error);
@@ -73,11 +70,9 @@ pem_parser (const Reference *ref)
g_free (pem);
/* Check PEM parsing in private key, certificate order */
- path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "key-cert.pem", NULL);
- g_file_get_contents (path, &pem, NULL, &error);
+ g_file_get_contents (g_test_get_filename (G_TEST_DISTED, "cert-tests", "key-cert.pem", NULL), &pem, NULL,
&error);
g_assert_no_error (error);
g_assert (pem);
- g_free (path);
cert = g_tls_certificate_new_from_pem (pem, -1, &error);
g_assert_no_error (error);
@@ -97,11 +92,9 @@ pem_parser (const Reference *ref)
g_object_unref (cert);
/* Check certificate only PEM */
- path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "cert1.pem", NULL);
- g_file_get_contents (path, &pem, NULL, &error);
+ g_file_get_contents (g_test_get_filename (G_TEST_DISTED, "cert-tests", "cert1.pem", NULL), &pem, NULL,
&error);
g_assert_no_error (error);
g_assert (pem);
- g_free (path);
cert = g_tls_certificate_new_from_pem (pem, -1, &error);
g_assert_no_error (error);
@@ -120,11 +113,9 @@ pem_parser (const Reference *ref)
g_object_unref (cert);
/* Check error with private key only PEM */
- path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "key.pem", NULL);
- g_file_get_contents (path, &pem, NULL, &error);
+ g_file_get_contents (g_test_get_filename (G_TEST_DISTED, "cert-tests", "key.pem", NULL), &pem, NULL,
&error);
g_assert_no_error (error);
g_assert (pem);
- g_free (path);
cert = g_tls_certificate_new_from_pem (pem, -1, &error);
g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE);
@@ -139,14 +130,12 @@ from_file (const Reference *ref)
GTlsCertificate *cert;
gchar *parsed_cert_pem = NULL;
const gchar *parsed_key_pem = NULL;
- gchar *path;
GError *error = NULL;
- path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "key-cert.pem", NULL);
- cert = g_tls_certificate_new_from_file (path, &error);
+ cert = g_tls_certificate_new_from_file (g_test_get_filename (G_TEST_DISTED, "cert-tests", "key-cert.pem",
NULL),
+ &error);
g_assert_no_error (error);
g_assert (cert);
- g_free (path);
g_object_get (cert,
"certificate-pem", &parsed_cert_pem,
@@ -167,16 +156,13 @@ from_files (const Reference *ref)
GTlsCertificate *cert;
gchar *parsed_cert_pem = NULL;
const gchar *parsed_key_pem = NULL;
- gchar *path, *path2;
GError *error = NULL;
- path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "cert1.pem", NULL);
- path2 = g_test_build_filename (G_TEST_DISTED, "cert-tests", "key.pem", NULL);
- cert = g_tls_certificate_new_from_files (path, path2, &error);
+ cert = g_tls_certificate_new_from_files (g_test_get_filename (G_TEST_DISTED, "cert-tests", "cert1.pem",
NULL),
+ g_test_get_filename (G_TEST_DISTED, "cert-tests", "key.pem",
NULL),
+ &error);
g_assert_no_error (error);
g_assert (cert);
- g_free (path);
- g_free (path2);
g_object_get (cert,
"certificate-pem", &parsed_cert_pem,
@@ -191,32 +177,30 @@ from_files (const Reference *ref)
g_object_unref (cert);
/* Missing private key */
- path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "cert1.pem", NULL);
- path2 = g_test_build_filename (G_TEST_DISTED, "cert-tests", "cert2.pem", NULL);
- cert = g_tls_certificate_new_from_files (path, path2, &error);
+ cert = g_tls_certificate_new_from_files (g_test_get_filename (G_TEST_DISTED, "cert-tests", "cert1.pem",
NULL),
+ g_test_get_filename (G_TEST_DISTED, "cert-tests", "cert2.pem",
NULL),
+ &error);
g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE);
g_clear_error (&error);
g_assert (cert == NULL);
- g_free (path);
- g_free (path2);
/* Missing certificate */
- path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "key.pem", NULL);
- cert = g_tls_certificate_new_from_files (path, path, &error);
+ cert = g_tls_certificate_new_from_files (g_test_get_filename (G_TEST_DISTED, "cert-tests", "key.pem",
NULL),
+ g_test_get_filename (G_TEST_DISTED, "cert-tests", "key.pem",
NULL),
+ &error);
g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE);
g_clear_error (&error);
g_assert (cert == NULL);
- g_free (path);
/* Using this method twice with a file containing both private key and
* certificate as a way to inforce private key presence is a fair use
*/
- path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "key-cert.pem", NULL);
- cert = g_tls_certificate_new_from_files (path, path, &error);
+ cert = g_tls_certificate_new_from_files (g_test_get_filename (G_TEST_DISTED, "cert-tests", "key-cert.pem",
NULL),
+ g_test_get_filename (G_TEST_DISTED, "cert-tests", "key-cert.pem",
NULL),
+ &error);
g_assert_no_error (error);
g_assert (cert);
g_object_unref (cert);
- g_free (path);
}
@@ -226,16 +210,13 @@ from_files_pkcs8 (const Reference *ref)
GTlsCertificate *cert;
gchar *parsed_cert_pem = NULL;
const gchar *parsed_key_pem = NULL;
- gchar *path, *path2;
GError *error = NULL;
- path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "cert1.pem", NULL);
- path2 = g_test_build_filename (G_TEST_DISTED, "cert-tests", "key8.pem", NULL);
- cert = g_tls_certificate_new_from_files (path, path2, &error);
+ cert = g_tls_certificate_new_from_files (g_test_get_filename (G_TEST_DISTED, "cert-tests", "cert1.pem",
NULL),
+ g_test_get_filename (G_TEST_DISTED, "cert-tests", "key8.pem",
NULL),
+ &error);
g_assert_no_error (error);
g_assert (cert);
- g_free (path);
- g_free (path2);
g_object_get (cert,
"certificate-pem", &parsed_cert_pem,
@@ -255,14 +236,12 @@ list_from_file (const Reference *ref)
{
GList *list, *l;
GError *error = NULL;
- gchar *path;
int i;
- path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "cert-list.pem", NULL);
- list = g_tls_certificate_list_new_from_file (path, &error);
+ list = g_tls_certificate_list_new_from_file (g_test_get_filename (G_TEST_DISTED, "cert-tests",
"cert-list.pem", NULL),
+ &error);
g_assert_no_error (error);
g_assert_cmpint (g_list_length (list), ==, 3);
- g_free (path);
l = list;
for (i = 0; i < 3; i++)
@@ -280,11 +259,10 @@ list_from_file (const Reference *ref)
g_list_free_full (list, g_object_unref);
/* Empty list is not an error */
- path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "nothing.pem", NULL);
- list = g_tls_certificate_list_new_from_file (path, &error);
+ list = g_tls_certificate_list_new_from_file (g_test_get_filename (G_TEST_DISTED, "cert-tests",
"nothing.pem", NULL),
+ &error);
g_assert_no_error (error);
g_assert_cmpint (g_list_length (list), ==, 0);
- g_free (path);
}
int
diff --git a/glib/tests/keyfile.c b/glib/tests/keyfile.c
index a0df824..170e979 100644
--- a/glib/tests/keyfile.c
+++ b/glib/tests/keyfile.c
@@ -1337,13 +1337,10 @@ test_load_fail (void)
{
GKeyFile *file;
GError *error;
- gchar *path;
file = g_key_file_new ();
error = NULL;
- path = g_test_build_filename (G_TEST_DISTED, "keyfile.c", NULL);
- g_assert (!g_key_file_load_from_file (file, path, 0, &error));
- g_free (path);
+ g_assert (!g_key_file_load_from_file (file, g_test_get_filename (G_TEST_DISTED, "keyfile.c", NULL), 0,
&error));
g_assert_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE);
g_clear_error (&error);
g_assert (!g_key_file_load_from_file (file, "/nosuchfile", 0, &error));
@@ -1398,7 +1395,6 @@ test_page_boundary (void)
GKeyFile *file;
GError *error;
gint i;
- gchar *path;
#define GROUP "main_section"
#define KEY_PREFIX "fill_abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw_"
@@ -1411,9 +1407,7 @@ test_page_boundary (void)
file = g_key_file_new ();
error = NULL;
- path = g_test_build_filename (G_TEST_DISTED, "pages.ini", NULL);
- g_key_file_load_from_file (file, path, G_KEY_FILE_NONE, &error);
- g_free (path);
+ g_key_file_load_from_file (file, g_test_get_filename (G_TEST_DISTED, "pages.ini", NULL), G_KEY_FILE_NONE,
&error);
g_assert_no_error (error);
for (i = FIRST_KEY; i <= LAST_KEY; i++)
@@ -1578,7 +1572,7 @@ main (int argc, char *argv[])
g_test_init (&argc, &argv, NULL);
#ifdef G_OS_UNIX
- g_setenv ("XDG_DATA_HOME", g_test_build_filename (G_TEST_DISTED, ".", NULL), TRUE);
+ g_setenv ("XDG_DATA_HOME", g_test_get_dir (G_TEST_DISTED), TRUE);
#endif
g_test_bug_base ("http://bugzilla.gnome.org/");
diff --git a/glib/tests/mappedfile.c b/glib/tests/mappedfile.c
index 7984da3..a812ce1 100644
--- a/glib/tests/mappedfile.c
+++ b/glib/tests/mappedfile.c
@@ -16,12 +16,9 @@ test_basic (void)
{
GMappedFile *file;
GError *error;
- gchar *path;
error = NULL;
- path = g_test_build_filename (G_TEST_DISTED, "empty", NULL);
- file = g_mapped_file_new (path, FALSE, &error);
- g_free (path);
+ file = g_mapped_file_new (g_test_get_filename (G_TEST_DISTED, "empty", NULL), FALSE, &error);
g_assert_no_error (error);
g_mapped_file_ref (file);
@@ -35,12 +32,9 @@ test_empty (void)
{
GMappedFile *file;
GError *error;
- gchar *path;
error = NULL;
- path = g_test_build_filename (G_TEST_DISTED, "empty", NULL);
- file = g_mapped_file_new (path, FALSE, &error);
- g_free (path);
+ file = g_mapped_file_new (g_test_get_filename (G_TEST_DISTED, "empty", NULL), FALSE, &error);
g_assert_no_error (error);
g_assert (g_mapped_file_get_contents (file) == NULL);
@@ -85,13 +79,11 @@ test_writable (void)
gsize len;
const gchar *old = "MMMMMMMMMMMMMMMMMMMMMMMMM";
const gchar *new = "abcdefghijklmnopqrstuvxyz";
- char *srcpath;
gchar *tmp_copy_path;
- srcpath = g_test_build_filename (G_TEST_DISTED, "4096-random-bytes", NULL);
tmp_copy_path = g_build_filename (g_get_user_runtime_dir (), "glib-test-4096-random-bytes", NULL);
- g_file_get_contents (srcpath, &contents, &len, &error);
+ g_file_get_contents (g_test_get_filename (G_TEST_DISTED, "4096-random-bytes", NULL), &contents, &len,
&error);
g_assert_no_error (error);
g_file_set_contents (tmp_copy_path, contents, len, &error);
g_assert_no_error (error);
@@ -118,7 +110,6 @@ test_writable (void)
g_mapped_file_free (file);
- g_free (srcpath);
g_free (tmp_copy_path);
}
@@ -132,13 +123,11 @@ test_writable_fd (void)
const gchar *new = "abcdefghijklmnopqrstuvxyz";
gsize len;
int fd;
- char *srcpath;
gchar *tmp_copy_path;
- srcpath = g_test_build_filename (G_TEST_DISTED, "4096-random-bytes", NULL);
tmp_copy_path = g_build_filename (g_get_user_runtime_dir (), "glib-test-4096-random-bytes", NULL);
- g_file_get_contents (srcpath, &contents, &len, &error);
+ g_file_get_contents (g_test_get_filename (G_TEST_DISTED, "4096-random-bytes", NULL), &contents, &len,
&error);
g_assert_no_error (error);
g_file_set_contents (tmp_copy_path, contents, len, &error);
g_assert_no_error (error);
@@ -170,7 +159,6 @@ test_writable_fd (void)
g_mapped_file_free (file);
- g_free (srcpath);
g_free (tmp_copy_path);
}
@@ -180,12 +168,9 @@ test_gbytes (void)
GMappedFile *file;
GBytes *bytes;
GError *error;
- gchar *path;
error = NULL;
- path = g_test_build_filename (G_TEST_DISTED, "empty", NULL);
- file = g_mapped_file_new (path, FALSE, &error);
- g_free (path);
+ file = g_mapped_file_new (g_test_get_filename (G_TEST_DISTED, "empty", NULL), FALSE, &error);
g_assert_no_error (error);
bytes = g_mapped_file_get_bytes (file);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]