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])
33 char *stupid_pointer = "ug";
35 /* This works fine. */
36 Str *test_good = (Str *) (str_new ("%d", the_answer));
37 test_good = test_good;
39 /* This gets a warning thanks to our function attribute. */
40 Str *test_bad = (Str *) (str_new ("%d", stupid_pointer));
47 str_gob=$abs_top_srcdir/t/str.gob
48 AT_CHECK([gob2 "$str_gob"])
49 TEST_COMPILE_GOBJECT([str.c], [0], [], [stderr])
52 # Check for correct diagnostic messages on the target lines...
53 AT_CHECK([awk '/want a string/ { print NR }' "$str_gob" >str_lines])
57 AS_VAR_ARITH([total], [1 + $total])
58 AT_CHECK([awk -v line="$l" -v file="$str_gob" -NF : \
59 '$1 == file && $2 == line { exit 42 }' str_stderr], [42])
62 AT_CHECK([test x"$total" = x"2"])
64 TEST_COMPILE_GOBJECT([main.c], [0], [], [stderr])
65 AT_CHECK([awk -NF : '$1 == "main.c" && $2 == "16" { exit 42 }' stderr], [42])
67 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main str.o main.o])
71 dnl Check that dynamic types are accepted and compile OK...
72 AT_SETUP([dynamic types])
73 AT_KEYWORDS([dynamic])
75 AT_DATA([test.gob], [[%ctop{
78 class :Test from G:Object (dynamic)
80 public void test(void)
85 AT_CHECK([gob2 test.gob])
86 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
93 test_register_type(NULL);
96 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
98 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main test.o main.o])
102 dnl Dynamic types: simple test case which checks that we can instantiate a
103 dnl dynamic type after registration.
104 AT_SETUP([dynamic type registration])
105 AT_KEYWORDS([dynamic runtime])
107 AT_DATA([test.gob], [[%ctop{
113 class :Test from G:Object (dynamic)
115 public gchar *s = { g_strdup("(nil)") };
116 property STRING s (link);
118 public void test(self)
120 printf("%s\n", self->s);
124 AT_CHECK([gob2 test.gob])
125 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
127 TEST_TYPE_MODULE([:Test])
130 [[#include <stdlib.h>
132 #include "test-mod.h"
134 void devnull(const char *a, GLogLevelFlags b, const char *c, gpointer d) { }
141 /* should fail, suppress internal glib logging... */
142 handler = g_log_set_handler("GLib-GObject", G_LOG_LEVEL_MASK, devnull, 0);
143 t = g_object_new(test_get_type(), NULL);
146 g_log_remove_handler("GLib-GObject", handler);
148 /* Register dynamic type */
149 g_type_module_use(g_object_new(test_mod_get_type(), NULL));
151 /* should work now */
152 t = g_object_new(test_get_type(), "s", "Hello, World", (char *)NULL);
160 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
162 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
163 test.o test-mod.o main.o])
164 AT_CHECK([./main], [0], [Hello, World
169 AT_SETUP([GOB2_CHECK min-version test])
171 AT_DATA([configure.ac],
176 AT_CHECK([$AUTOCONF && test -f configure || exit 77], [0], [ignore], [ignore])
179 m4_bpatsubst(m4_dquote(m4_defn([AT_PACKAGE_VERSION])), [[^][0-9.]]))
181 m4_define([MYVER_P1], m4_dquote(m4_reverse(m4_unquote(
182 m4_split(m4_defn([MYVER]), [[.]])))))
183 m4_define([MYVER_P1], m4_join([.], m4_reverse(
184 m4_eval(m4_car(MYVER_P1)+1), m4_shift(MYVER_P1))))
186 AT_DATA([test.in], [[@GOB2@
189 cat >configure.ac <<EOF
190 [m4@&t@_include([$builddir/gob2.m4])]
191 [m4@&t@_pattern_forbid([^GOB2_])]
192 [AC_INIT([gob2_check], [0])]
193 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER]))[)]
194 GOB2=\`command -v \$GOB2\`
195 [AC_CONFIG_FILES([test])]
198 AT_CHECK([$AUTOCONF --force])
199 AT_CHECK([./configure], [0], [ignore])
201 command -v gob2 >expout
202 AT_CHECK([cat test], [0], [expout], [ignore])
205 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER_P1]))[)]' configure.ac >configure.new
206 mv -f configure.new configure.ac
207 AT_CHECK([$AUTOCONF --force])
208 AT_CHECK([./configure], [1], [ignore], [ignore])
212 AT_SETUP([private data members])
214 AT_DATA([test.gob], [[%ctop{
217 class :Test from G:Object
221 public int get_x(G:Object *go) { return TEST(go)->_priv->x; }
222 public void set_x(G:Object *go, int val) { TEST(go)->_priv->x = val; }
225 AT_CHECK([gob2 test.gob])
226 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
228 AT_DATA([main.c], [[#include <config.h>
234 GObject *go = g_object_new(test_get_type(), NULL);
236 printf("%d\n", test_get_x(go));
237 printf("%d\n", (test_set_x(go, 123), test_get_x(go)));
242 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
244 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
246 AT_CHECK([./main], [0], [42
252 AT_SETUP([private data members (dynamic)])
254 AT_DATA([test.gob], [[%ctop{
257 class :Test from G:Object (dynamic)
261 public int get_x(G:Object *go) { return TEST(go)->_priv->x; }
262 public void set_x(G:Object *go, int val) { TEST(go)->_priv->x = val; }
265 AT_CHECK([gob2 test.gob])
266 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
268 TEST_TYPE_MODULE([:Test])
270 AT_DATA([main.c], [[#include <config.h>
273 #include "test-mod.h"
279 g_type_module_use(g_object_new(test_mod_get_type(), NULL));
280 go = g_object_new(test_get_type(), NULL);
282 printf("%d\n", test_get_x(go));
283 printf("%d\n", (test_set_x(go, 123), test_get_x(go)));
288 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
290 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
291 test.o test-mod.o main.o])
292 AT_CHECK([./main], [0], [54