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])
30 Str *test_good, *test_bad;
31 char *stupid_pointer = "ug";
36 /* This works fine. */
37 test_good = (Str *) (str_new ("%d", the_answer));
38 test_good = test_good;
40 /* This gets a warning thanks to our function attribute. */
41 test_bad = (Str *) (str_new ("%d", stupid_pointer));
48 str_gob=$abs_top_srcdir/t/str.gob
49 AT_CHECK([gob2 "$str_gob"])
50 AT_CHECK([$HAVE_GOBJECT_PRIVATES || exit 77])
51 TEST_COMPILE_GOBJECT([str.c], [0], [], [stderr])
54 # Check for correct diagnostic messages on the target lines...
55 AT_CHECK([$AWK '/want a string/ { print NR }' "$str_gob" >str_lines])
59 AS_VAR_ARITH([total], [1 + $total])
60 AT_CHECK([$AWK -v line="$l" -v file="$str_gob" -F : \
61 '$1 == file && $2 == line { exit 42 }' str_stderr], [42])
64 AT_CHECK([test x"$total" = x"2"])
66 TEST_COMPILE_GOBJECT([main.c], [0], [], [stderr])
67 AT_CHECK([$AWK -F : '$1 == "main.c" && $2 == "17" { exit 42 }' stderr], [42])
69 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main str.o main.o])
73 dnl Check that dynamic types are accepted and compile OK...
74 AT_SETUP([dynamic types])
75 AT_KEYWORDS([dynamic])
77 AT_DATA([test.gob], [[%ctop{
80 class :Test from G:Object (dynamic)
82 public void test(void)
87 AT_CHECK([gob2 test.gob])
88 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
96 test_register_type(NULL);
99 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
101 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main test.o main.o])
105 dnl Dynamic types: simple test case which checks that we can instantiate a
106 dnl dynamic type after registration.
107 AT_SETUP([dynamic type registration])
108 AT_KEYWORDS([dynamic runtime])
110 AT_DATA([test.gob], [[%ctop{
116 class :Test from G:Object (dynamic)
118 public gchar *s = { g_strdup("(nil)") };
119 property STRING s (link);
121 public void test(self)
123 printf("%s\n", self->s);
127 AT_CHECK([gob2 test.gob])
128 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
130 TEST_TYPE_MODULE([:Test])
133 [[#include <stdlib.h>
135 #include "test-mod.h"
137 void devnull(const char *a, GLogLevelFlags b, const char *c, gpointer d) { }
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 /* Register dynamic type */
154 g_type_module_use(g_object_new(test_mod_get_type(), NULL));
156 /* should work now */
157 t = g_object_new(test_get_type(), "s", "Hello, World", (char *)NULL);
165 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
167 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
168 test.o test-mod.o main.o])
169 AT_CHECK([./main], [0], [Hello, World
174 AT_SETUP([GOB2_CHECK min-version test])
176 AT_DATA([configure.ac],
181 AT_CHECK([$AUTOCONF && test -f configure || exit 77], [0], [ignore], [ignore])
184 m4_bpatsubst(m4_dquote(m4_defn([AT_PACKAGE_VERSION])), [[^][0-9.]]))
186 m4_define([MYVER_P1], m4_dquote(m4_reverse(m4_unquote(
187 m4_split(m4_defn([MYVER]), [[.]])))))
188 m4_define([MYVER_P1], m4_join([.], m4_reverse(
189 m4_eval(m4_car(MYVER_P1)+1), m4_shift(MYVER_P1))))
191 AT_DATA([test.in], [[@GOB2@
194 cat >configure.ac <<EOF
195 [m4@&t@_include([$builddir/gob2.m4])]
196 [m4@&t@_pattern_forbid([^GOB2_])]
197 [m4@&t@_pattern_forbid([^DX_])]
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])
218 AT_SETUP([private data members])
220 AT_DATA([test.gob], [[%ctop{
223 class :Test from G:Object
227 public int get_x(G:Object *go) { return TEST(go)->_priv->x; }
228 public void set_x(G:Object *go, int val) { TEST(go)->_priv->x = val; }
231 AT_CHECK([gob2 test.gob])
232 AT_CHECK([$HAVE_GOBJECT_PRIVATES || exit 77])
233 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
235 AT_DATA([main.c], [[#include <config.h>
244 go = g_object_new(test_get_type(), NULL);
246 printf("%d\n", test_get_x(go));
247 printf("%d\n", (test_set_x(go, 123), test_get_x(go)));
252 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
254 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
256 AT_CHECK([./main], [0], [42
262 AT_SETUP([private data members (dynamic)])
264 AT_DATA([test.gob], [[%ctop{
267 class :Test from G:Object (dynamic)
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 TEST_TYPE_MODULE([:Test])
281 AT_DATA([main.c], [[#include <config.h>
284 #include "test-mod.h"
291 g_type_module_use(g_object_new(test_mod_get_type(), NULL));
292 go = g_object_new(test_get_type(), NULL);
294 printf("%d\n", test_get_x(go));
295 printf("%d\n", (test_set_x(go, 123), test_get_x(go)));
300 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
302 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
303 test.o test-mod.o main.o])
304 AT_CHECK([./main], [0], [54