[glib/wip/meson: 49/53] meson: gio/tests: add more gio tests



commit 44979f30c26dc96a836d48e03446c810c05fe092
Author: Tim-Philipp Müller <tim centricular com>
Date:   Fri Feb 24 09:46:36 2017 +0000

    meson: gio/tests: add more gio tests
    
    Need to fix up some of the tests a little, because the
    test binary will not necessarily be run from the current
    build sub-directory, and the build directory structure
    might not always be a mirror of the source directory
    structure, so pass location of glib-mkenums and
    glib-compile-scheme and such directly.

 gio/meson.build              |    2 +-
 gio/tests/appinfo.c          |    9 +++++++
 gio/tests/desktop-app-info.c |    8 ++++++
 gio/tests/gschema-compile.c  |    7 +++++-
 gio/tests/gsettings.c        |   30 ++++++++++++++++++++----
 gio/tests/meson.build        |   51 ++++++++++++++++++++++++++++++++++++++---
 6 files changed, 96 insertions(+), 11 deletions(-)
---
diff --git a/gio/meson.build b/gio/meson.build
index 80284e6..b04e511 100644
--- a/gio/meson.build
+++ b/gio/meson.build
@@ -773,7 +773,7 @@ executable('gio-querymodules', 'gio-querymodules.c',
   link_args : noseh_link_args,
   dependencies : [libgio_dep, libgobject_dep, libgmodule_dep, libglib_dep])
 
-executable('glib-compile-schemas',
+glib_compile_schemas = executable('glib-compile-schemas',
   [gconstructor_as_data_h, 'gvdb/gvdb-builder.c', 'glib-compile-schemas.c'],
   install : true,
   c_args : ['-DHAVE_CONFIG_H=1'],
diff --git a/gio/tests/appinfo.c b/gio/tests/appinfo.c
index b1a60f0..1902053 100644
--- a/gio/tests/appinfo.c
+++ b/gio/tests/appinfo.c
@@ -2,6 +2,7 @@
 #include <locale.h>
 #include <string.h>
 
+#include <glib/gstdio.h>
 #include <gio/gio.h>
 #include <gio/gdesktopappinfo.h>
 
@@ -474,10 +475,18 @@ test_from_keyfile (void)
 int
 main (int argc, char *argv[])
 {
+  const gchar *build_dir;
+
   g_setenv ("XDG_CURRENT_DESKTOP", "GNOME", TRUE);
 
   g_test_init (&argc, &argv, NULL);
 
+  /* With Meson build we need to change into right directory, so that the
+   * appinfo-test binary can be found. */
+  build_dir = g_getenv ("G_TEST_BUILDDIR");
+  if (build_dir)
+    g_chdir (build_dir);
+
   g_test_add_func ("/appinfo/basic", test_basic);
   g_test_add_func ("/appinfo/text", test_text);
   g_test_add_func ("/appinfo/launch", test_launch);
diff --git a/gio/tests/desktop-app-info.c b/gio/tests/desktop-app-info.c
index 5f34ed1..dd0dd4d 100644
--- a/gio/tests/desktop-app-info.c
+++ b/gio/tests/desktop-app-info.c
@@ -18,6 +18,7 @@
  */
 
 #include <glib/glib.h>
+#include <glib/gstdio.h>
 #include <gio/gio.h>
 #include <gio/gdesktopappinfo.h>
 #include <stdlib.h>
@@ -759,8 +760,15 @@ int
 main (int   argc,
       char *argv[])
 {
+  const gchar *build_dir;
   gint result;
 
+  /* With Meson build we need to change into right directory, so that the
+   * appinfo-test binary can be found. */
+  build_dir = g_getenv ("G_TEST_BUILDDIR");
+  if (build_dir)
+    g_chdir (build_dir);
+
   g_test_init (&argc, &argv, NULL);
 
   basedir = g_get_current_dir ();
diff --git a/gio/tests/gschema-compile.c b/gio/tests/gschema-compile.c
index a215a84..79eab97 100644
--- a/gio/tests/gschema-compile.c
+++ b/gio/tests/gschema-compile.c
@@ -11,6 +11,11 @@ typedef struct {
   const gchar *err;
 } SchemaTest;
 
+/* Meson build defines this, autotools build does not */
+#ifndef GLIB_COMPILE_SCHEMAS
+#define GLIB_COMPILE_SCHEMAS "../glib-compile-schemas"
+#endif
+
 static void
 test_schema_do_compile (gpointer data)
 {
@@ -18,7 +23,7 @@ test_schema_do_compile (gpointer data)
   gchar *filename = g_strconcat (test->name, ".gschema.xml", NULL);
   gchar *path = g_test_build_filename (G_TEST_DIST, "schema-tests", filename, NULL);
   gchar *argv[] = {
-    "../glib-compile-schemas",
+    GLIB_COMPILE_SCHEMAS,
     "--strict",
     "--dry-run",
     "--schema-file", path,
diff --git a/gio/tests/gsettings.c b/gio/tests/gsettings.c
index b1bbd4e..aa8e4c8 100644
--- a/gio/tests/gsettings.c
+++ b/gio/tests/gsettings.c
@@ -8,6 +8,8 @@
 
 #include "testenum.h"
 
+static const gchar *locale_dir = ".";
+
 static gboolean backend_set;
 
 /* These tests rely on the schemas in org.gtk.test.gschema.xml
@@ -732,7 +734,7 @@ test_l10n (void)
   gchar *str;
   gchar *locale;
 
-  bindtextdomain ("test", ".");
+  bindtextdomain ("test", locale_dir);
   bind_textdomain_codeset ("test", "UTF-8");
 
   locale = g_strdup (setlocale (LC_MESSAGES, NULL));
@@ -779,7 +781,7 @@ test_l10n_context (void)
   gchar *str;
   gchar *locale;
 
-  bindtextdomain ("test", ".");
+  bindtextdomain ("test", locale_dir);
   bind_textdomain_codeset ("test", "UTF-8");
 
   locale = g_strdup (setlocale (LC_MESSAGES, NULL));
@@ -2604,6 +2606,14 @@ main (int argc, char *argv[])
   gchar *enums;
   gint result;
 
+/* Meson build sets this */
+#ifdef TEST_LOCALE_PATH
+  if (g_str_has_suffix (TEST_LOCALE_PATH, "LC_MESSAGES"))
+    {
+      locale_dir = TEST_LOCALE_PATH G_DIR_SEPARATOR_S ".." G_DIR_SEPARATOR_S "..";
+    }
+#endif
+
   setlocale (LC_ALL, "");
 
   g_test_init (&argc, &argv, NULL);
@@ -2618,8 +2628,13 @@ main (int argc, char *argv[])
       if (!backend_set)
         g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
 
+/* Meson build defines this, autotools build does not */
+#ifndef GLIB_MKENUMS
+#define GLIB_MKENUMS "../../gobject/glib-mkenums"
+#endif
+
       g_remove ("org.gtk.test.enums.xml");
-      g_assert (g_spawn_command_line_sync ("../../gobject/glib-mkenums "
+      g_assert (g_spawn_command_line_sync (GLIB_MKENUMS " "
                                            "--template " SRCDIR "/enums.xml.template "
                                            SRCDIR "/testenum.h",
                                            &enums, NULL, &result, NULL));
@@ -2631,8 +2646,13 @@ main (int argc, char *argv[])
       g_assert (g_file_set_contents ("org.gtk.test.gschema.xml", schema_text, -1, NULL));
       g_free (schema_text);
 
+/* Meson build defines this, autotools build does not */
+#ifndef GLIB_COMPILE_SCHEMAS
+#define GLIB_COMPILE_SCHEMAS "../glib-compile-schemas"
+#endif
+
       g_remove ("gschemas.compiled");
-      g_assert (g_spawn_command_line_sync ("../glib-compile-schemas --targetdir=. "
+      g_assert (g_spawn_command_line_sync (GLIB_COMPILE_SCHEMAS " --targetdir=. "
                                            "--schema-file=org.gtk.test.enums.xml "
                                            "--schema-file=org.gtk.test.gschema.xml",
                                            NULL, NULL, &result, NULL));
@@ -2640,7 +2660,7 @@ main (int argc, char *argv[])
 
       g_remove ("schema-source/gschemas.compiled");
       g_mkdir ("schema-source", 0777);
-      g_assert (g_spawn_command_line_sync ("../glib-compile-schemas --targetdir=schema-source "
+      g_assert (g_spawn_command_line_sync (GLIB_COMPILE_SCHEMAS " --targetdir=schema-source "
                                            "--schema-file=" SRCDIR "/org.gtk.schemasourcecheck.gschema.xml",
                                            NULL, NULL, &result, NULL));
       g_assert (result == 0);
diff --git a/gio/tests/meson.build b/gio/tests/meson.build
index 7e6eede..d70b5b3 100644
--- a/gio/tests/meson.build
+++ b/gio/tests/meson.build
@@ -71,6 +71,8 @@ test_c_args = [
   '-DHAVE_CONFIG_H=1',
   '-DG_LOG_DOMAIN="GLib-GIO"',
   '-DTEST_SERVICES="@0@/gio/tests/services"'.format(meson.build_root()),
+  '-DGLIB_MKENUMS="@0@"'.format(glib_mkenums),
+  '-DGLIB_COMPILE_SCHEMAS="@0@"'.format(glib_compile_schemas.full_path()),
 ]
 
 # Check for libdbus1 - Optional - is only used in the GDBus test cases
@@ -99,6 +101,14 @@ if host_machine.system() != 'windows'
     'unix-fd',
     'unix-streams',
     'mimeapps',
+    'gschema-compile',
+  ]
+
+  # Uninstalled because of the check-for-executable logic in DesktopAppInfo
+  # unable to find the installed executable
+  gio_tests += [
+    'appinfo',
+    'desktop-app-info',
   ]
 
   test_extra_programs += [
@@ -186,11 +196,44 @@ if host_machine.system() != 'windows'
           dependencies : [libglib_dep, libgmodule_dep, libgio_dep])
     test('gapplication', exe, env : test_env)
 
-    if host_machine.system() != 'windows'
-      gio_tests += ['gdbus-unix-addresses']
-    endif
+    gio_tests += ['gdbus-unix-addresses']
+  endif # have_dbus_daemon
+
+  # This test is currently unreliable
+  executable('gdbus-overflow', 'gdbus-overflow.c',
+      install : false,
+      c_args : test_c_args,
+      dependencies : [libglib_dep, libgmodule_dep, libgio_dep])
+
+  exe = executable('gdbus-connection-flush', 'gdbus-connection-flush.c',
+      'test-io-stream.c', 'test-pipe-unix.c',
+      install : false,
+      c_args : test_c_args,
+      dependencies : [libglib_dep, libgmodule_dep, libgio_dep])
+  test('gdbus-connection-flush', exe, env : test_env)
+
+  exe = executable('gdbus-non-socket', 'gdbus-non-socket.c',
+      'gdbus-tests.c', 'test-io-stream.c', 'test-pipe-unix.c',
+      install : false,
+      c_args : test_c_args,
+      dependencies : [libglib_dep, libgmodule_dep, libgio_dep])
+  test('gdbus-non-socket', exe, env : test_env)
+
+  # Generate test.mo from de.po using msgfmt
+  msgfmt = find_program('msgfmt', required : false)
+  if msgfmt.found()
+    subdir('de/LC_MESSAGES')
+    # gsettings target exe already exists in gio directory
+    exe = executable('gsettings-test', 'gsettings.c', test_mo,
+        install : false,
+        c_args : test_c_args + [
+                   '-DSRCDIR="@0@"'.format(meson.current_source_dir()),
+                   '-DTEST_LOCALE_PATH="@0@"'.format(test_mo_dir),
+                 ],
+        dependencies : [libglib_dep, libgmodule_dep, libgio_dep])
+    test('gsettings', exe, env : test_env)
   endif
-endif
+endif # unix
 
 #  Test programs buildable on Windows only
 if host_machine.system() == 'windows'


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