1 dnl Copyright © 2019-2023 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])
24 # check if compiler supports format warnings
29 void foo(const char *, ...) G_GNUC_PRINTF(1, 2);
36 [[BEGIN { pass=0; FS=":"; }
37 /%s/ && $1 == "VERIFY" && $2 == 99 { pass=1; }
42 set x $CPPFLAGS $CFLAGS $LIBGOBJECT_CFLAGS; shift
43 AS_IF([$CC "$@" -c fmt.c 1>/dev/null 2>out && $AWK -f fmt.awk out],
45 [AS_IF([$CC "$@" -Wformat -c fmt.c 1>/dev/null 2>out && $AWK -f fmt.awk out],
46 [CFLAGS="$CFLAGS -Wformat" fmt_warnings=:])])
54 Str *test_good, *test_bad;
55 char *stupid_pointer = "ug";
60 /* This works fine. */
61 test_good = (Str *) (str_new ("%d", the_answer));
62 test_good = test_good;
64 /* This gets a warning thanks to our function attribute. */
65 test_bad = (Str *) (str_new ("%d", stupid_pointer));
72 str_gob=$abs_top_srcdir/t/str.gob
73 AT_CHECK([gob2 "$str_gob"])
74 AT_CHECK([$HAVE_GOBJECT_PRIVATES || exit 77])
76 TEST_COMPILE_GOBJECT([str.c], [0], [], [stderr])
78 TEST_COMPILE_GOBJECT([main.c], [0], [], [stderr])
80 TEST_LINK_GOBJECT([main], [str.o main.o])
83 [[/want a string/ { lines[NR] = 1; }
86 while ((rc = getline < "str_stderr") > 0) {
87 sub(/.*[\/]/, "", $1);
88 if (/%s/ && $1 == "str.gob" && $2 in lines)
106 # Check for correct diagnostic messages on the target lines...
107 AT_CHECK([$fmt_warnings || exit 77
108 $AWK -f str.awk "$str_gob" || exit 1
109 $AWK -f - main_stderr <<'EOF'
110 BEGIN { pass=0; FS=":"; }
111 /%d/ && $1 == "main.c" && $2 == 17 { pass=1; }
117 dnl Check that dynamic types are accepted and compile OK...
118 AT_SETUP([dynamic types])
119 AT_KEYWORDS([dynamic])
121 AT_DATA([test.gob], [[%ctop{
124 class :Test from G:Object (dynamic)
126 public void test(void)
131 AT_CHECK([gob2 test.gob])
132 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
135 [[#include <config.h>
140 test_register_type(NULL);
143 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
144 TEST_LINK_GOBJECT([main], [test.o main.o])
148 dnl Dynamic types: simple test case which checks that we can instantiate a
149 dnl dynamic type after registration.
150 AT_SETUP([dynamic type registration])
151 AT_KEYWORDS([dynamic runtime])
153 AT_DATA([test.gob], [[%ctop{
159 class :Test from G:Object (dynamic)
161 public gchar *s = { g_strdup("(nil)") };
162 property STRING s (link);
164 public void test(self)
166 printf("%s\n", self->s);
170 AT_CHECK([gob2 test.gob])
171 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
173 TEST_TYPE_MODULE([:Test])
176 [[#include <stdlib.h>
178 #include "test-mod.h"
180 void devnull(const char *a, GLogLevelFlags b, const char *c, gpointer d) { }
189 /* should fail, suppress internal glib logging... */
190 handler = g_log_set_handler("GLib-GObject", G_LOG_LEVEL_MASK, devnull, 0);
191 t = g_object_new(test_get_type(), NULL);
194 g_log_remove_handler("GLib-GObject", handler);
196 /* Register dynamic type */
197 g_type_module_use(g_object_new(test_mod_get_type(), NULL));
199 /* should work now */
200 t = g_object_new(test_get_type(), "s", "Hello, World", (char *)NULL);
208 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
209 TEST_LINK_GOBJECT([main], [test.o test-mod.o main.o])
210 AT_CHECK([./main], [0], [Hello, World
215 AT_SETUP([GOB2_CHECK min-version test])
217 AT_DATA([configure.ac],
222 AT_CHECK([$AUTOCONF && test -f configure || exit 77], [0], [ignore], [ignore])
225 m4_bpatsubst(m4_dquote(m4_defn([AT_PACKAGE_VERSION])), [[^][0-9.]]))
227 m4_define([MYVER_P1], m4_dquote(m4_reverse(m4_unquote(
228 m4_split(m4_defn([MYVER]), [[.]])))))
229 m4_define([MYVER_P1], m4_join([.], m4_reverse(
230 m4_eval(m4_car(MYVER_P1)+1), m4_shift(MYVER_P1))))
232 AT_DATA([test.in], [[@GOB2@
235 cat >configure.ac <<EOF
236 [m4@&t@_include([$builddir/gob2.m4])]
237 [m4@&t@_pattern_forbid([^GOB2_])]
238 [m4@&t@_pattern_forbid([^DX_])]
239 [AC_INIT([gob2_check], [0])]
240 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER]))[)]
241 GOB2=\`command -v \$GOB2\`
242 [AC_CONFIG_FILES([test])]
245 AT_CHECK([$AUTOCONF --force])
246 AT_CHECK([./configure], [0], [ignore])
248 command -v gob2 >expout
249 AT_CHECK([cat test], [0], [expout], [ignore])
252 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER_P1]))[)]' configure.ac >configure.new
253 mv -f configure.new configure.ac
254 AT_CHECK([$AUTOCONF --force])
255 AT_CHECK([./configure], [1], [ignore], [ignore])
259 AT_SETUP([private data members])
261 AT_DATA([test.gob], [[%ctop{
264 class :Test from G:Object
268 public int get_x(G:Object *go) { return TEST(go)->_priv->x; }
269 public void set_x(G:Object *go, int val) { TEST(go)->_priv->x = val; }
272 AT_CHECK([gob2 test.gob])
273 AT_CHECK([$HAVE_GOBJECT_PRIVATES || exit 77])
274 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
276 AT_DATA([main.c], [[#include <config.h>
285 go = g_object_new(test_get_type(), NULL);
287 printf("%d\n", test_get_x(go));
288 printf("%d\n", (test_set_x(go, 123), test_get_x(go)));
293 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
294 TEST_LINK_GOBJECT([main], [test.o main.o])
295 AT_CHECK([./main], [0], [42
301 AT_SETUP([private data members (dynamic)])
303 AT_DATA([test.gob], [[%ctop{
306 class :Test from G:Object (dynamic)
310 public int get_x(G:Object *go) { return TEST(go)->_priv->x; }
311 public void set_x(G:Object *go, int val) { TEST(go)->_priv->x = val; }
314 AT_CHECK([gob2 test.gob])
315 AT_CHECK([$HAVE_GOBJECT_PRIVATES || exit 77])
316 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
318 TEST_TYPE_MODULE([:Test])
320 AT_DATA([main.c], [[#include <config.h>
323 #include "test-mod.h"
330 g_type_module_use(g_object_new(test_mod_get_type(), NULL));
331 go = g_object_new(test_get_type(), NULL);
333 printf("%d\n", test_get_x(go));
334 printf("%d\n", (test_set_x(go, 123), test_get_x(go)));
339 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
340 TEST_LINK_GOBJECT([main], [test.o test-mod.o main.o])
341 AT_CHECK([./main], [0], [54