Some final g_test_build_filename() porting
authorRyan Lortie <desrt@desrt.ca>
Thu, 30 May 2013 03:49:30 +0000 (23:49 -0400)
committerRyan Lortie <desrt@desrt.ca>
Sat, 1 Jun 2013 03:03:19 +0000 (23:03 -0400)
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
gio/tests/desktop-app-info.c
glib/tests/keyfile.c
glib/tests/spawn-singlethread.c
tests/iochannel-test.c
tests/module-test.c
tests/unicode-caseconv.c
tests/unicode-encoding.c

index 9d6a5ff..d8aee25 100644 (file)
@@ -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;
 }
index bcda49f..26e4e9e 100644 (file)
@@ -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"));
index 2556826..5abe738 100644 (file)
@@ -1309,7 +1309,7 @@ test_load (void)
   /* Uses the value of $XDG_DATA_HOME we set in main() */
   loaded = g_key_file_load_from_data_dirs (file, "keyfiletest.ini", NULL, 0, &error);
 #else
-  loaded = g_key_file_load_from_file (file, SRCDIR "/keyfiletest.ini", 0, &error);
+  loaded = g_key_file_load_from_file (file, g_test_get_filename (G_TEST_DIST, "keyfiletest.ini", NULL), 0, &error);
 #endif
   g_assert_no_error (error);
   g_assert (loaded);
index 4ad91a7..d205822 100644 (file)
@@ -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);
 
index 57d31c9..92fcc34 100644 (file)
@@ -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);
index 3e648a6..f54a015 100644 (file)
@@ -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 */
   
index 467a3a0..affb558 100644 (file)
@@ -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)
index e120a72..a231f10 100644 (file)
@@ -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);