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])
32 char *stupid_pointer = "ug";
34 /* This works fine. */
35 Str *test_good = (Str *) (str_new ("%d", the_answer));
36 test_good = test_good;
38 /* This gets a warning thanks to our function attribute. */
39 Str *test_bad = (Str *) (str_new ("%d", stupid_pointer));
46 str_gob=$abs_top_srcdir/t/str.gob
47 AT_CHECK([gob2 "$str_gob"])
48 TEST_COMPILE_GOBJECT([str.c], [0], [], [stderr])
51 # Check for correct diagnostic messages on the target lines...
52 AT_CHECK([awk '/want a string/ { print NR }' "$str_gob" >str_lines])
56 AS_VAR_ARITH([total], [1 + $total])
57 AT_CHECK([awk -v line="$l" -v file="$str_gob" -NF : \
58 '$1 == file && $2 == line { exit 42 }' str_stderr], [42])
61 AT_CHECK([test x"$total" = x"2"])
63 TEST_COMPILE_GOBJECT([main.c], [0], [], [stderr])
64 AT_CHECK([awk -NF : '$1 == "main.c" && $2 == "15" { exit 42 }' stderr], [42])
66 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main str.o main.o])
70 dnl Check that dynamic types are accepted and compile OK...
71 AT_SETUP([dynamic types])
72 AT_KEYWORDS([dynamic])
75 [[class :Test from G:Object (dynamic)
77 public void test(void)
82 AT_CHECK([gob2 test.gob])
88 test_register_type(NULL);
92 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
93 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
94 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main test.o main.o])
98 dnl Dynamic types: simple test case which checks that we can instantiate a
99 dnl dynamic type after registration.
100 AT_SETUP([dynamic type registration])
101 AT_KEYWORDS([dynamic runtime])
107 class :Test from G:Object (dynamic)
109 public gchar *s = { g_strdup("(nil)") };
110 property STRING s (link);
112 public void test(self)
114 printf("%s\n", self->s);
123 class :Mod from G:Type:Module
125 override (G:Type:Module) gboolean load(G:Type:Module *m)
127 test_register_type(m);
138 void devnull(const char *a, GLogLevelFlags b, const char *c, gpointer d) { }
142 GTypeModule *m = g_object_new(mod_get_type(), NULL);
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 g_type_module_use(m);
154 /* should work now */
155 t = g_object_new(test_get_type(), "s", "Hello, World", (char *)NULL);
164 AT_CHECK([gob2 mod.gob])
165 AT_CHECK([gob2 test.gob])
166 TEST_COMPILE_GOBJECT([mod.c], [0], [], [ignore])
167 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
168 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
169 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main mod.o test.o main.o])
170 AT_CHECK([./main], [0], [Hello, World
175 dnl Dynamic types: check that we can call interface methods of dynamic types.
176 AT_SETUP([dynamic interface implementation])
177 AT_KEYWORDS([dynamic runtime interface])
180 [[#define IF_TYPE_TEST if_test_get_type()
182 typedef struct IFTestIface {
183 GTypeInterface parent;
185 void (*test)(GObject *obj);
188 GType if_test_get_type(void);
197 class :Test from G:Object (dynamic)
200 private const char *s = { "Hello, World!" };
201 interface IF:Test private void test(G:Object *o)
203 Self *self = SELF(o);
204 printf("%s\n", self->_priv->s);
213 class :Mod from G:Type:Module
215 override (G:Type:Module) gboolean load(G:Type:Module *m)
217 test_register_type(m);
228 GType if_test_get_type(void)
230 static GType type = 0;
232 static const GTypeInfo info = {
233 sizeof (IFTestIface),
238 type = g_type_register_static(G_TYPE_INTERFACE, "IFTest", &info, 0);
245 GTypeModule *m = g_object_new(TYPE_MOD, NULL);
248 g_type_module_use(m);
249 t = g_object_new(TYPE_TEST, NULL);
251 g_return_val_if_fail(G_TYPE_CHECK_INSTANCE_TYPE(t, IF_TYPE_TEST),
253 G_TYPE_INSTANCE_GET_INTERFACE(t, IF_TYPE_TEST, IFTestIface)->test(t);
259 AT_CHECK([gob2 mod.gob])
260 AT_CHECK([gob2 test.gob])
261 TEST_COMPILE_GOBJECT([mod.c], [0], [], [ignore])
262 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
263 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
264 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main mod.o test.o main.o])
265 AT_CHECK([./main], [0], [Hello, World!
270 AT_SETUP([GOB2_CHECK min-version test])
272 AT_DATA([configure.ac],
277 AT_CHECK([$AUTOCONF && test -f configure || exit 77], [0], [ignore], [ignore])
280 m4_bpatsubst(m4_dquote(m4_defn([AT_PACKAGE_VERSION])), [[^][0-9.]]))
282 m4_define([MYVER_P1], m4_dquote(m4_reverse(m4_unquote(
283 m4_split(m4_defn([MYVER]), [[.]])))))
284 m4_define([MYVER_P1], m4_join([.], m4_reverse(
285 m4_eval(m4_car(MYVER_P1)+1), m4_shift(MYVER_P1))))
287 AT_DATA([test.in], [[@GOB2@
290 cat >configure.ac <<EOF
291 [m4@&t@_include([$builddir/gob2.m4])]
292 [m4@&t@_pattern_forbid([^GOB2_])]
293 [AC_INIT([gob2_check], [0])]
294 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER]))[)]
295 GOB2=\`command -v \$GOB2\`
296 [AC_CONFIG_FILES([test])]
299 AT_CHECK([$AUTOCONF --force])
300 AT_CHECK([./configure], [0], [ignore])
302 command -v gob2 >expout
303 AT_CHECK([cat test], [0], [expout], [ignore])
306 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER_P1]))[)]' configure.ac >configure.new
307 mv -f configure.new configure.ac
308 AT_CHECK([$AUTOCONF --force])
309 AT_CHECK([./configure], [1], [ignore], [ignore])