[gtk+/wip/meson: 63/136] meson: tests: make tests find resources from the source dir



commit 9d48496ec91a0405d4468a9cc5434d18500c055f
Author: Tim-Philipp Müller <tim centricular com>
Date:   Sun Mar 12 18:36:21 2017 +0000

    meson: tests: make tests find resources from the source dir
    
    Should probably also do this in the autotools build, since
    the same problem exists there as well if we use srcdir != builddir.

 tests/meson.build          |   10 +++++++---
 tests/testdialog.c         |    5 +++++
 tests/testgiconpixbuf.c    |    5 +++++
 tests/testgtk.c            |    6 ++++++
 tests/testiconview.c       |    5 +++++
 tests/testpopover.c        |    5 +++++
 tests/testselectionmode.c  |    5 +++++
 tests/testsplitheaders.c   |    5 +++++
 tests/teststackedheaders.c |    5 +++++
 9 files changed, 48 insertions(+), 3 deletions(-)
---
diff --git a/tests/meson.build b/tests/meson.build
index 34bd68a..2435e3d 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -137,12 +137,16 @@ if x11_enabled
   gtk_tests += [['testerrors']]
 endif
 
-# TODO: need to pass source dir so progs can find .ui files and such
-# (with autotools this only works in the builddir == srcdir case)
+# Pass the source dir here so programs can change into the source directory
+# and find .ui files and .png files and such that they load at runtime
+test_args = ['-DGTK_SRCDIR="@0@"'.format(meson.current_source_dir())]
+
 foreach t : gtk_tests
   test_name = t.get(0)
   test_srcs = ['@0@.c'.format(test_name), t.get(1, [])]
-  executable(test_name, test_srcs, dependencies: [libgtk_dep, libm])
+  executable(test_name, test_srcs,
+    c_args : test_args,
+    dependencies : [libgtk_dep, libm])
 endforeach
 
 subdir('visuals')
diff --git a/tests/testdialog.c b/tests/testdialog.c
index 941acfd..07eba4b 100644
--- a/tests/testdialog.c
+++ b/tests/testdialog.c
@@ -1,4 +1,5 @@
 #include <gtk/gtk.h>
+#include <glib/gstdio.h>
 
 static void
 show_message_dialog1 (GtkWindow *parent)
@@ -316,6 +317,10 @@ main (int argc, char *argv[])
   GtkWidget *box;
   GtkWidget *button;
 
+#ifdef GTK_SRCDIR
+  g_chdir (GTK_SRCDIR);
+#endif
+
   gtk_init ();
 
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
diff --git a/tests/testgiconpixbuf.c b/tests/testgiconpixbuf.c
index 8e9b7af..fd9ab1d 100644
--- a/tests/testgiconpixbuf.c
+++ b/tests/testgiconpixbuf.c
@@ -17,6 +17,7 @@
  */
 
 #include <gtk/gtk.h>
+#include <glib/gstdio.h>
 
 int
 main (int argc,
@@ -28,6 +29,10 @@ main (int argc,
   GEmblem *emblem;
   gchar *str;
 
+#ifdef GTK_SRCDIR
+  g_chdir (GTK_SRCDIR);
+#endif
+
   gtk_init ();
 
   pixbuf = gdk_pixbuf_new_from_file ("apple-red.png", NULL);
diff --git a/tests/testgtk.c b/tests/testgtk.c
index 082ea55..93f8c96 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -37,6 +37,8 @@
 #include <unistd.h>
 #endif
 
+#include <glib/gstdio.h>
+
 #include "gtk/gtk.h"
 #include "gdk/gdk.h"
 #include "gdk/gdkkeysyms.h"
@@ -8805,6 +8807,10 @@ main (int argc, char *argv[])
 
   g_set_application_name ("GTK+ Test Program");
 
+#ifdef GTK_SRCDIR
+  g_chdir (GTK_SRCDIR);
+#endif
+
   gtk_init ();
 
   provider = gtk_css_provider_new ();
diff --git a/tests/testiconview.c b/tests/testiconview.c
index 0a89fa6..c35916c 100644
--- a/tests/testiconview.c
+++ b/tests/testiconview.c
@@ -16,6 +16,7 @@
  */
 
 #include <gtk/gtk.h>
+#include <glib/gstdio.h>
 #include <sys/types.h>
 #include <string.h>
 
@@ -420,6 +421,10 @@ main (gint argc, gchar **argv)
   GtkCellRenderer *cell;
   GtkTreeViewColumn *tvc;
   
+#ifdef GTK_SRCDIR
+  g_chdir (GTK_SRCDIR);
+#endif
+
   gtk_init ();
 
   /* to test rtl layout, set RTL=1 in the environment */
diff --git a/tests/testpopover.c b/tests/testpopover.c
index 6d12d6c..da5839d 100644
--- a/tests/testpopover.c
+++ b/tests/testpopover.c
@@ -1,4 +1,5 @@
 #include <gtk/gtk.h>
+#include <glib/gstdio.h>
 
 static void
 activate (GSimpleAction *action,
@@ -48,6 +49,10 @@ main (int argc, char *argv[])
   GtkWidget *check;
   GtkWidget *combo;
 
+#ifdef GTK_SRCDIR
+  g_chdir (GTK_SRCDIR);
+#endif
+
   gtk_init ();
 
   win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
diff --git a/tests/testselectionmode.c b/tests/testselectionmode.c
index c639bbe..f3b983f 100644
--- a/tests/testselectionmode.c
+++ b/tests/testselectionmode.c
@@ -1,4 +1,5 @@
 #include <gtk/gtk.h>
+#include <glib/gstdio.h>
 
 typedef struct {
   GtkListBoxRow parent;
@@ -179,6 +180,10 @@ main (int argc, char *argv[])
   GSimpleActionGroup *group;
   GSimpleAction *action;
 
+#ifdef GTK_SRCDIR
+  g_chdir (GTK_SRCDIR);
+#endif
+
   gtk_init ();
 
   builder = gtk_builder_new_from_file ("selectionmode.ui");
diff --git a/tests/testsplitheaders.c b/tests/testsplitheaders.c
index 42de06d..7d89418 100644
--- a/tests/testsplitheaders.c
+++ b/tests/testsplitheaders.c
@@ -1,4 +1,5 @@
 #include <gtk/gtk.h>
+#include <glib/gstdio.h>
 
 static void
 split_decorations (GtkSettings *settings,
@@ -42,6 +43,10 @@ main (int argc, char *argv[])
   GtkWidget *check;
   GtkWidget *header;
 
+#ifdef GTK_SRCDIR
+  g_chdir (GTK_SRCDIR);
+#endif
+
   gtk_init ();
 
   builder = gtk_builder_new_from_file ("testsplitheaders.ui");
diff --git a/tests/teststackedheaders.c b/tests/teststackedheaders.c
index 830e9da..c342d68 100644
--- a/tests/teststackedheaders.c
+++ b/tests/teststackedheaders.c
@@ -1,4 +1,5 @@
 #include <gtk/gtk.h>
+#include <glib/gstdio.h>
 
 static GtkWidget *header_stack;
 static GtkWidget *page_stack;
@@ -23,6 +24,10 @@ main (int argc, char *argv[])
   GtkBuilder *builder;
   GtkWidget *win;
 
+#ifdef GTK_SRCDIR
+  g_chdir (GTK_SRCDIR);
+#endif
+
   gtk_init ();
 
   builder = gtk_builder_new ();


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