1 dnl Copyright © 2019-2020 Nick Bowler
2 dnl License GPLv2+: GNU General Public License version 2 or any later version.
3 dnl This is free software: you are free to change and redistribute it.
4 dnl There is NO WARRANTY, to the extent permitted by law.
6 AT_SETUP([test.gob compilation])
8 AT_CHECK([gob2 "$abs_top_srcdir/t/test.gob"])
9 AT_CHECK([$HAVE_GTK2 || exit 77])
10 TEST_COMPILE_GOBJECT([$GTK_CFLAGS test-object.c], [0], [], [ignore])
14 AT_SETUP([test.gob C++ compilation])
16 AT_CHECK([gob2 --for-cpp "$abs_top_srcdir/t/test.gob"])
17 AT_CHECK([$HAVE_GTK2 || exit 77])
18 TEST_COMPILEXX_GOBJECT([$GTK_CFLAGS test-object.cc], [0], [], [ignore])
32 char *stupid_pointer = "ug";
34 /* This works fine. */
35 Str *test_good = (Str *) (str_new ("%d", the_answer));
36 test_good = test_good;
38 /* This gets a warning thanks to our function attribute. */
39 Str *test_bad = (Str *) (str_new ("%d", stupid_pointer));
46 str_gob=$abs_top_srcdir/t/str.gob
47 AT_CHECK([gob2 "$str_gob"])
48 TEST_COMPILE_GOBJECT([str.c], [0], [], [stderr])
51 # Check for correct diagnostic messages on the target lines...
52 AT_CHECK([awk '/want a string/ { print NR }' "$str_gob" >str_lines])
56 AS_VAR_ARITH([total], [1 + $total])
57 AT_CHECK([awk -v line="$l" -v file="$str_gob" -NF : \
58 '$1 == file && $2 == line { exit 42 }' str_stderr], [42])
61 AT_CHECK([test x"$total" = x"2"])
63 TEST_COMPILE_GOBJECT([main.c], [0], [], [stderr])
64 AT_CHECK([awk -NF : '$1 == "main.c" && $2 == "15" { exit 42 }' stderr], [42])
66 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main str.o main.o])
70 dnl Check that dynamic types are accepted and compile OK...
71 AT_SETUP([dynamic types])
72 AT_KEYWORDS([dynamic])
75 [[class :Test from G:Object (dynamic)
77 public void test(void)
82 AT_CHECK([gob2 test.gob])
88 test_register_type(NULL);
92 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
93 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
94 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main test.o main.o])
98 dnl Dynamic types: simple test case which checks that we can instantiate a
99 dnl dynamic type after registration.
100 AT_SETUP([dynamic type registration])
101 AT_KEYWORDS([dynamic runtime])
107 class :Test from G:Object (dynamic)
109 public gchar *s = { g_strdup("(nil)") };
110 property STRING s (link);
112 public void test(self)
114 printf("%s\n", self->s);
123 class :Mod from G:Type:Module
125 override (G:Type:Module) gboolean load(G:Type:Module *m)
127 test_register_type(m);
134 [[#include <stdlib.h>
138 void devnull(const char *a, GLogLevelFlags b, const char *c, gpointer d) { }
142 GTypeModule *m = g_object_new(mod_get_type(), NULL);
146 /* should fail, suppress internal glib logging... */
147 handler = g_log_set_handler("GLib-GObject", G_LOG_LEVEL_MASK, devnull, 0);
148 t = g_object_new(test_get_type(), NULL);
151 g_log_remove_handler("GLib-GObject", handler);
153 g_type_module_use(m);
154 /* should work now */
155 t = g_object_new(test_get_type(), "s", "Hello, World", (char *)NULL);
164 AT_CHECK([gob2 mod.gob])
165 AT_CHECK([gob2 test.gob])
166 TEST_COMPILE_GOBJECT([mod.c], [0], [], [ignore])
167 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
168 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
169 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main mod.o test.o main.o])
170 AT_CHECK([./main], [0], [Hello, World
175 AT_SETUP([GOB2_CHECK min-version test])
177 AT_DATA([configure.ac],
182 AT_CHECK([$AUTOCONF && test -f configure || exit 77], [0], [ignore], [ignore])
185 m4_bpatsubst(m4_dquote(m4_defn([AT_PACKAGE_VERSION])), [[^][0-9.]]))
187 m4_define([MYVER_P1], m4_dquote(m4_reverse(m4_unquote(
188 m4_split(m4_defn([MYVER]), [[.]])))))
189 m4_define([MYVER_P1], m4_join([.], m4_reverse(
190 m4_eval(m4_car(MYVER_P1)+1), m4_shift(MYVER_P1))))
192 AT_DATA([test.in], [[@GOB2@
195 cat >configure.ac <<EOF
196 [m4@&t@_include([$builddir/gob2.m4])]
197 [m4@&t@_pattern_forbid([^GOB2_])]
198 [AC_INIT([gob2_check], [0])]
199 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER]))[)]
200 GOB2=\`command -v \$GOB2\`
201 [AC_CONFIG_FILES([test])]
204 AT_CHECK([$AUTOCONF --force])
205 AT_CHECK([./configure], [0], [ignore])
207 command -v gob2 >expout
208 AT_CHECK([cat test], [0], [expout], [ignore])
211 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER_P1]))[)]' configure.ac >configure.new
212 mv -f configure.new configure.ac
213 AT_CHECK([$AUTOCONF --force])
214 AT_CHECK([./configure], [1], [ignore], [ignore])