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.
This commit is contained in:
Tim-Philipp Müller 2017-03-12 18:36:21 +00:00 committed by Emmanuele Bassi
parent 08153c3854
commit d276cd47a5
9 changed files with 48 additions and 3 deletions

View File

@ -137,12 +137,16 @@ if x11_enabled
gtk_tests += [['testerrors']] gtk_tests += [['testerrors']]
endif endif
# TODO: need to pass source dir so progs can find .ui files and such # Pass the source dir here so programs can change into the source directory
# (with autotools this only works in the builddir == srcdir case) # 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 foreach t : gtk_tests
test_name = t.get(0) test_name = t.get(0)
test_srcs = ['@0@.c'.format(test_name), t.get(1, [])] 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 endforeach
subdir('visuals') subdir('visuals')

View File

@ -1,4 +1,5 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib/gstdio.h>
static void static void
show_message_dialog1 (GtkWindow *parent) show_message_dialog1 (GtkWindow *parent)
@ -316,6 +317,10 @@ main (int argc, char *argv[])
GtkWidget *box; GtkWidget *box;
GtkWidget *button; GtkWidget *button;
#ifdef GTK_SRCDIR
g_chdir (GTK_SRCDIR);
#endif
gtk_init (); gtk_init ();
window = gtk_window_new (GTK_WINDOW_TOPLEVEL); window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

View File

@ -17,6 +17,7 @@
*/ */
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib/gstdio.h>
int int
main (int argc, main (int argc,
@ -28,6 +29,10 @@ main (int argc,
GEmblem *emblem; GEmblem *emblem;
gchar *str; gchar *str;
#ifdef GTK_SRCDIR
g_chdir (GTK_SRCDIR);
#endif
gtk_init (); gtk_init ();
pixbuf = gdk_pixbuf_new_from_file ("apple-red.png", NULL); pixbuf = gdk_pixbuf_new_from_file ("apple-red.png", NULL);

View File

@ -37,6 +37,8 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <glib/gstdio.h>
#include "gtk/gtk.h" #include "gtk/gtk.h"
#include "gdk/gdk.h" #include "gdk/gdk.h"
#include "gdk/gdkkeysyms.h" #include "gdk/gdkkeysyms.h"
@ -8805,6 +8807,10 @@ main (int argc, char *argv[])
g_set_application_name ("GTK+ Test Program"); g_set_application_name ("GTK+ Test Program");
#ifdef GTK_SRCDIR
g_chdir (GTK_SRCDIR);
#endif
gtk_init (); gtk_init ();
provider = gtk_css_provider_new (); provider = gtk_css_provider_new ();

View File

@ -16,6 +16,7 @@
*/ */
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib/gstdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <string.h> #include <string.h>
@ -420,6 +421,10 @@ main (gint argc, gchar **argv)
GtkCellRenderer *cell; GtkCellRenderer *cell;
GtkTreeViewColumn *tvc; GtkTreeViewColumn *tvc;
#ifdef GTK_SRCDIR
g_chdir (GTK_SRCDIR);
#endif
gtk_init (); gtk_init ();
/* to test rtl layout, set RTL=1 in the environment */ /* to test rtl layout, set RTL=1 in the environment */

View File

@ -1,4 +1,5 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib/gstdio.h>
static void static void
activate (GSimpleAction *action, activate (GSimpleAction *action,
@ -48,6 +49,10 @@ main (int argc, char *argv[])
GtkWidget *check; GtkWidget *check;
GtkWidget *combo; GtkWidget *combo;
#ifdef GTK_SRCDIR
g_chdir (GTK_SRCDIR);
#endif
gtk_init (); gtk_init ();
win = gtk_window_new (GTK_WINDOW_TOPLEVEL); win = gtk_window_new (GTK_WINDOW_TOPLEVEL);

View File

@ -1,4 +1,5 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib/gstdio.h>
typedef struct { typedef struct {
GtkListBoxRow parent; GtkListBoxRow parent;
@ -179,6 +180,10 @@ main (int argc, char *argv[])
GSimpleActionGroup *group; GSimpleActionGroup *group;
GSimpleAction *action; GSimpleAction *action;
#ifdef GTK_SRCDIR
g_chdir (GTK_SRCDIR);
#endif
gtk_init (); gtk_init ();
builder = gtk_builder_new_from_file ("selectionmode.ui"); builder = gtk_builder_new_from_file ("selectionmode.ui");

View File

@ -1,4 +1,5 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib/gstdio.h>
static void static void
split_decorations (GtkSettings *settings, split_decorations (GtkSettings *settings,
@ -42,6 +43,10 @@ main (int argc, char *argv[])
GtkWidget *check; GtkWidget *check;
GtkWidget *header; GtkWidget *header;
#ifdef GTK_SRCDIR
g_chdir (GTK_SRCDIR);
#endif
gtk_init (); gtk_init ();
builder = gtk_builder_new_from_file ("testsplitheaders.ui"); builder = gtk_builder_new_from_file ("testsplitheaders.ui");

View File

@ -1,4 +1,5 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib/gstdio.h>
static GtkWidget *header_stack; static GtkWidget *header_stack;
static GtkWidget *page_stack; static GtkWidget *page_stack;
@ -23,6 +24,10 @@ main (int argc, char *argv[])
GtkBuilder *builder; GtkBuilder *builder;
GtkWidget *win; GtkWidget *win;
#ifdef GTK_SRCDIR
g_chdir (GTK_SRCDIR);
#endif
gtk_init (); gtk_init ();
builder = gtk_builder_new (); builder = gtk_builder_new ();