[glib/wip/test-cleanup: 2/4] Some final g_test_build_filename() porting
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/test-cleanup: 2/4] Some final g_test_build_filename() porting
- Date: Thu, 30 May 2013 04:16:58 +0000 (UTC)
commit ce3bbede16cb6aedc8456cc03e0bc6df72caadc5
Author: Ryan Lortie <desrt desrt ca>
Date: Wed May 29 23:49:30 2013 -0400
Some final g_test_build_filename() porting
This should be the last users that need to be ported.
For some of the oldschool non-gtester-ified tests, we call g_test_init()
from main() because it is necessary in order to use
g_test_build_filename().
gio/tests/appinfo-test.c | 2 +-
gio/tests/desktop-app-info.c | 2 +-
glib/tests/spawn-singlethread.c | 2 +-
tests/iochannel-test.c | 11 +++--------
tests/module-test.c | 17 ++++++-----------
tests/unicode-caseconv.c | 10 +++-------
tests/unicode-encoding.c | 12 ++++--------
7 files changed, 19 insertions(+), 37 deletions(-)
---
diff --git a/gio/tests/appinfo-test.c b/gio/tests/appinfo-test.c
index 9d6a5ff..d8aee25 100644
--- a/gio/tests/appinfo-test.c
+++ b/gio/tests/appinfo-test.c
@@ -13,7 +13,7 @@ main (int argc, char *argv[])
g_assert_cmpint (pid_from_env, ==, getpid ());
envvar = g_getenv ("GIO_LAUNCHED_DESKTOP_FILE");
- g_assert_cmpstr (envvar, ==, SRCDIR "/appinfo-test.desktop");
+ g_assert_cmpstr (envvar, ==, g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL));
return 0;
}
diff --git a/gio/tests/desktop-app-info.c b/gio/tests/desktop-app-info.c
index bcda49f..26e4e9e 100644
--- a/gio/tests/desktop-app-info.c
+++ b/gio/tests/desktop-app-info.c
@@ -357,7 +357,7 @@ test_extra_getters (void)
gchar *s;
gboolean b;
- appinfo = g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test.desktop");
+ appinfo = g_desktop_app_info_new_from_filename (g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop",
NULL));
g_assert (appinfo != NULL);
g_assert (g_desktop_app_info_has_key (appinfo, "Terminal"));
diff --git a/glib/tests/spawn-singlethread.c b/glib/tests/spawn-singlethread.c
index 4ad91a7..d205822 100644
--- a/glib/tests/spawn-singlethread.c
+++ b/glib/tests/spawn-singlethread.c
@@ -204,7 +204,7 @@ main (int argc,
if (!g_file_test (echo_script_path, G_FILE_TEST_EXISTS))
{
g_free (echo_script_path);
- echo_script_path = g_build_filename (SRCDIR, "echo-script", NULL);
+ echo_script_path = g_test_build_filename (G_TEST_DIST, "echo-script", NULL);
}
g_free (dirname);
diff --git a/tests/iochannel-test.c b/tests/iochannel-test.c
index 57d31c9..92fcc34 100644
--- a/tests/iochannel-test.c
+++ b/tests/iochannel-test.c
@@ -11,8 +11,6 @@
#define BUFFER_SIZE 1024
-static const gchar *datapath;
-
static void
test_small_writes (void)
{
@@ -66,13 +64,10 @@ gint main (gint argc, gchar * argv[])
const gchar encoding[] = "EUC-JP";
GIOStatus status;
- if (g_getenv ("G_TEST_DATA"))
- datapath = g_getenv ("G_TEST_DATA");
- else
- datapath = SRCDIR;
+ g_test_init (&argc, &argv, NULL);
+
+ filename = g_test_build_filename (G_TEST_DIST, "iochannel-test-infile", NULL);
- filename = g_build_filename (datapath, "iochannel-test-infile", NULL);
-
setbuf (stdout, NULL); /* For debugging */
gio_r = g_io_channel_new_file (filename, "r", &gerr);
diff --git a/tests/module-test.c b/tests/module-test.c
index 3e648a6..f54a015 100644
--- a/tests/module-test.c
+++ b/tests/module-test.c
@@ -30,8 +30,6 @@
#include <gmodule.h>
#include <string.h>
-static const gchar *datapath;
-
gchar* global_state;
G_MODULE_EXPORT void g_clash_func (void);
@@ -75,24 +73,21 @@ test_states (const gchar *global, const gchar *gplugin_a,
static SimpleFunc plugin_clash_func = NULL;
int
-main (int arg,
- char *argv[])
+main (int argc,
+ char **argv)
{
GModule *module_self, *module_a, *module_b;
gchar *plugin_a, *plugin_b;
SimpleFunc f_a, f_b, f_self;
GModuleFunc gmod_f;
+ g_test_init (&argc, &argv, NULL);
+
if (!g_module_supported ())
g_error ("dynamic modules not supported");
- if (g_getenv ("G_TEST_DATA"))
- datapath = g_getenv ("G_TEST_DATA");
- else
- datapath = ".";
-
- plugin_a = g_build_filename (datapath, "libmoduletestplugin_a", NULL);
- plugin_b = g_build_filename (datapath, "libmoduletestplugin_b", NULL);
+ plugin_a = g_test_build_filename (G_TEST_BUILT, "libmoduletestplugin_a", NULL);
+ plugin_b = g_test_build_filename (G_TEST_BUILT, "libmoduletestplugin_b", NULL);
/* module handles */
diff --git a/tests/unicode-caseconv.c b/tests/unicode-caseconv.c
index 467a3a0..affb558 100644
--- a/tests/unicode-caseconv.c
+++ b/tests/unicode-caseconv.c
@@ -12,7 +12,6 @@ int main (int argc, char **argv)
FILE *infile;
char buffer[1024];
char **strings;
- const char *srcdir;
char *filename;
const char *locale;
const char *test;
@@ -21,12 +20,9 @@ int main (int argc, char **argv)
char *current_locale = setlocale (LC_CTYPE, NULL);
gint result = 0;
- if (g_getenv ("G_TEST_DATA"))
- srcdir = g_getenv ("G_TEST_DATA");
- else
- srcdir = SRCDIR;
+ g_test_init (&argc, &argv, NULL);
- filename = g_strconcat (srcdir, G_DIR_SEPARATOR_S, "casemap.txt", NULL);
+ filename = g_test_build_filename (G_TEST_DIST, "casemap.txt", NULL);
infile = fopen (filename, "r");
if (!infile)
@@ -96,7 +92,7 @@ int main (int argc, char **argv)
fclose (infile);
g_free (filename);
- filename = g_strconcat (srcdir, G_DIR_SEPARATOR_S, "casefold.txt", NULL);
+ filename = g_test_build_filename (G_TEST_DIST, "casefold.txt", NULL);
infile = fopen (filename, "r");
if (!infile)
diff --git a/tests/unicode-encoding.c b/tests/unicode-encoding.c
index e120a72..a231f10 100644
--- a/tests/unicode-encoding.c
+++ b/tests/unicode-encoding.c
@@ -308,7 +308,6 @@ process (gint line,
int
main (int argc, char **argv)
{
- const gchar *srcdir;
gchar *testfile;
gchar *contents;
GError *error = NULL;
@@ -321,13 +320,10 @@ main (int argc, char **argv)
GArray *ucs4;
Status status = VALID; /* Quiet GCC */
- if (g_getenv ("G_TEST_DATA"))
- srcdir = g_getenv ("G_TEST_DATA");
- else
- srcdir = SRCDIR;
-
- testfile = g_strconcat (srcdir, G_DIR_SEPARATOR_S "utf8.txt", NULL);
-
+ g_test_init (&argc, &argv, NULL);
+
+ testfile = g_test_build_filename (G_TEST_DIST, "utf8.txt", NULL);
+
g_file_get_contents (testfile, &contents, NULL, &error);
if (error)
croak ("Cannot open utf8.txt: %s", error->message);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]