1 dnl Copyright © 2019-2022 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 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o 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])
145 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main test.o main.o])
149 dnl Dynamic types: simple test case which checks that we can instantiate a
150 dnl dynamic type after registration.
151 AT_SETUP([dynamic type registration])
152 AT_KEYWORDS([dynamic runtime])
154 AT_DATA([test.gob], [[%ctop{
160 class :Test from G:Object (dynamic)
162 public gchar *s = { g_strdup("(nil)") };
163 property STRING s (link);
165 public void test(self)
167 printf("%s\n", self->s);
171 AT_CHECK([gob2 test.gob])
172 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
174 TEST_TYPE_MODULE([:Test])
177 [[#include <stdlib.h>
179 #include "test-mod.h"
181 void devnull(const char *a, GLogLevelFlags b, const char *c, gpointer d) { }
190 /* should fail, suppress internal glib logging... */
191 handler = g_log_set_handler("GLib-GObject", G_LOG_LEVEL_MASK, devnull, 0);
192 t = g_object_new(test_get_type(), NULL);
195 g_log_remove_handler("GLib-GObject", handler);
197 /* Register dynamic type */
198 g_type_module_use(g_object_new(test_mod_get_type(), NULL));
200 /* should work now */
201 t = g_object_new(test_get_type(), "s", "Hello, World", (char *)NULL);
209 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
211 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
212 test.o test-mod.o main.o])
213 AT_CHECK([./main], [0], [Hello, World
218 AT_SETUP([GOB2_CHECK min-version test])
220 AT_DATA([configure.ac],
225 AT_CHECK([$AUTOCONF && test -f configure || exit 77], [0], [ignore], [ignore])
228 m4_bpatsubst(m4_dquote(m4_defn([AT_PACKAGE_VERSION])), [[^][0-9.]]))
230 m4_define([MYVER_P1], m4_dquote(m4_reverse(m4_unquote(
231 m4_split(m4_defn([MYVER]), [[.]])))))
232 m4_define([MYVER_P1], m4_join([.], m4_reverse(
233 m4_eval(m4_car(MYVER_P1)+1), m4_shift(MYVER_P1))))
235 AT_DATA([test.in], [[@GOB2@
238 cat >configure.ac <<EOF
239 [m4@&t@_include([$builddir/gob2.m4])]
240 [m4@&t@_pattern_forbid([^GOB2_])]
241 [m4@&t@_pattern_forbid([^DX_])]
242 [AC_INIT([gob2_check], [0])]
243 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER]))[)]
244 GOB2=\`command -v \$GOB2\`
245 [AC_CONFIG_FILES([test])]
248 AT_CHECK([$AUTOCONF --force])
249 AT_CHECK([./configure], [0], [ignore])
251 command -v gob2 >expout
252 AT_CHECK([cat test], [0], [expout], [ignore])
255 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER_P1]))[)]' configure.ac >configure.new
256 mv -f configure.new configure.ac
257 AT_CHECK([$AUTOCONF --force])
258 AT_CHECK([./configure], [1], [ignore], [ignore])
262 AT_SETUP([private data members])
264 AT_DATA([test.gob], [[%ctop{
267 class :Test from G:Object
271 public int get_x(G:Object *go) { return TEST(go)->_priv->x; }
272 public void set_x(G:Object *go, int val) { TEST(go)->_priv->x = val; }
275 AT_CHECK([gob2 test.gob])
276 AT_CHECK([$HAVE_GOBJECT_PRIVATES || exit 77])
277 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
279 AT_DATA([main.c], [[#include <config.h>
288 go = g_object_new(test_get_type(), NULL);
290 printf("%d\n", test_get_x(go));
291 printf("%d\n", (test_set_x(go, 123), test_get_x(go)));
296 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
298 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
300 AT_CHECK([./main], [0], [42
306 AT_SETUP([private data members (dynamic)])
308 AT_DATA([test.gob], [[%ctop{
311 class :Test from G:Object (dynamic)
315 public int get_x(G:Object *go) { return TEST(go)->_priv->x; }
316 public void set_x(G:Object *go, int val) { TEST(go)->_priv->x = val; }
319 AT_CHECK([gob2 test.gob])
320 AT_CHECK([$HAVE_GOBJECT_PRIVATES || exit 77])
321 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
323 TEST_TYPE_MODULE([:Test])
325 AT_DATA([main.c], [[#include <config.h>
328 #include "test-mod.h"
335 g_type_module_use(g_object_new(test_mod_get_type(), NULL));
336 go = g_object_new(test_get_type(), NULL);
338 printf("%d\n", test_get_x(go));
339 printf("%d\n", (test_set_x(go, 123), test_get_x(go)));
344 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
346 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
347 test.o test-mod.o main.o])
348 AT_CHECK([./main], [0], [54