1 dnl Copyright © 2019-2021 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 AT_CHECK([$HAVE_GOBJECT_PRIVATES || exit 77])
50 TEST_COMPILE_GOBJECT([str.c], [0], [], [stderr])
53 # Check for correct diagnostic messages on the target lines...
54 AT_CHECK([awk '/want a string/ { print NR }' "$str_gob" >str_lines])
58 AS_VAR_ARITH([total], [1 + $total])
59 AT_CHECK([awk -v line="$l" -v file="$str_gob" -NF : \
60 '$1 == file && $2 == line { exit 42 }' str_stderr], [42])
63 AT_CHECK([test x"$total" = x"2"])
65 TEST_COMPILE_GOBJECT([main.c], [0], [], [stderr])
66 AT_CHECK([awk -NF : '$1 == "main.c" && $2 == "16" { exit 42 }' stderr], [42])
68 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main str.o main.o])
72 dnl Check that dynamic types are accepted and compile OK...
73 AT_SETUP([dynamic types])
74 AT_KEYWORDS([dynamic])
76 AT_DATA([test.gob], [[%ctop{
79 class :Test from G:Object (dynamic)
81 public void test(void)
86 AT_CHECK([gob2 test.gob])
87 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
94 test_register_type(NULL);
97 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
99 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main test.o main.o])
103 dnl Dynamic types: simple test case which checks that we can instantiate a
104 dnl dynamic type after registration.
105 AT_SETUP([dynamic type registration])
106 AT_KEYWORDS([dynamic runtime])
108 AT_DATA([test.gob], [[%ctop{
114 class :Test from G:Object (dynamic)
116 public gchar *s = { g_strdup("(nil)") };
117 property STRING s (link);
119 public void test(self)
121 printf("%s\n", self->s);
125 AT_CHECK([gob2 test.gob])
126 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
128 TEST_TYPE_MODULE([:Test])
131 [[#include <stdlib.h>
133 #include "test-mod.h"
135 void devnull(const char *a, GLogLevelFlags b, const char *c, gpointer d) { }
142 /* should fail, suppress internal glib logging... */
143 handler = g_log_set_handler("GLib-GObject", G_LOG_LEVEL_MASK, devnull, 0);
144 t = g_object_new(test_get_type(), NULL);
147 g_log_remove_handler("GLib-GObject", handler);
149 /* Register dynamic type */
150 g_type_module_use(g_object_new(test_mod_get_type(), NULL));
152 /* should work now */
153 t = g_object_new(test_get_type(), "s", "Hello, World", (char *)NULL);
161 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
163 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
164 test.o test-mod.o main.o])
165 AT_CHECK([./main], [0], [Hello, World
170 AT_SETUP([GOB2_CHECK min-version test])
172 AT_DATA([configure.ac],
177 AT_CHECK([$AUTOCONF && test -f configure || exit 77], [0], [ignore], [ignore])
180 m4_bpatsubst(m4_dquote(m4_defn([AT_PACKAGE_VERSION])), [[^][0-9.]]))
182 m4_define([MYVER_P1], m4_dquote(m4_reverse(m4_unquote(
183 m4_split(m4_defn([MYVER]), [[.]])))))
184 m4_define([MYVER_P1], m4_join([.], m4_reverse(
185 m4_eval(m4_car(MYVER_P1)+1), m4_shift(MYVER_P1))))
187 AT_DATA([test.in], [[@GOB2@
190 cat >configure.ac <<EOF
191 [m4@&t@_include([$builddir/gob2.m4])]
192 [m4@&t@_pattern_forbid([^GOB2_])]
193 [m4@&t@_pattern_forbid([^DX_])]
194 [AC_INIT([gob2_check], [0])]
195 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER]))[)]
196 GOB2=\`command -v \$GOB2\`
197 [AC_CONFIG_FILES([test])]
200 AT_CHECK([$AUTOCONF --force])
201 AT_CHECK([./configure], [0], [ignore])
203 command -v gob2 >expout
204 AT_CHECK([cat test], [0], [expout], [ignore])
207 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER_P1]))[)]' configure.ac >configure.new
208 mv -f configure.new configure.ac
209 AT_CHECK([$AUTOCONF --force])
210 AT_CHECK([./configure], [1], [ignore], [ignore])
214 AT_SETUP([private data members])
216 AT_DATA([test.gob], [[%ctop{
219 class :Test from G:Object
223 public int get_x(G:Object *go) { return TEST(go)->_priv->x; }
224 public void set_x(G:Object *go, int val) { TEST(go)->_priv->x = val; }
227 AT_CHECK([gob2 test.gob])
228 AT_CHECK([$HAVE_GOBJECT_PRIVATES || exit 77])
229 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
231 AT_DATA([main.c], [[#include <config.h>
237 GObject *go = g_object_new(test_get_type(), NULL);
239 printf("%d\n", test_get_x(go));
240 printf("%d\n", (test_set_x(go, 123), test_get_x(go)));
245 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
247 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
249 AT_CHECK([./main], [0], [42
255 AT_SETUP([private data members (dynamic)])
257 AT_DATA([test.gob], [[%ctop{
260 class :Test from G:Object (dynamic)
264 public int get_x(G:Object *go) { return TEST(go)->_priv->x; }
265 public void set_x(G:Object *go, int val) { TEST(go)->_priv->x = val; }
268 AT_CHECK([gob2 test.gob])
269 AT_CHECK([$HAVE_GOBJECT_PRIVATES || exit 77])
270 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
272 TEST_TYPE_MODULE([:Test])
274 AT_DATA([main.c], [[#include <config.h>
277 #include "test-mod.h"
283 g_type_module_use(g_object_new(test_mod_get_type(), NULL));
284 go = g_object_new(test_get_type(), NULL);
286 printf("%d\n", test_get_x(go));
287 printf("%d\n", (test_set_x(go, 123), test_get_x(go)));
292 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
294 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
295 test.o test-mod.o main.o])
296 AT_CHECK([./main], [0], [54