1 dnl Copyright © 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 dnl Create the Test:Fooable interface with the following interface method:
8 dnl int foo(G:Object *obj);
10 dnl Link in test-fooable.o
11 m4_define([TEST_FOOABLE_IFACE],
12 [AT_KEYWORDS([interface])dnl
13 AT_CHECK([cp $srcdir/t/test-fooable.c $srcdir/t/test-fooable.h .])
14 TEST_COMPILE_GOBJECT([test-fooable.c], [0], [], [ignore])])
16 dnl TEST_FOOABLE_IMPL(Class:Name, Parent:Class, foo_body)
17 dnl TEST_FOOABLE_IMPL_DYN(Class:Name, Parent:Class, foo_body)
18 m4_define([TEST_FOOABLE_IMPL],
19 [TEST_FOOABLE_IMPL_([$1], TEST_CLASSNAME_REPLACE_SEP([$1], [-]),
20 [$2], TEST_CLASSNAME_REPLACE_SEP([$2], [-]),
23 m4_define([TEST_FOOABLE_IMPL_DYN],
24 [TEST_FOOABLE_IMPL([$1], [$2], [$3], [(dynamic)])
25 TEST_TYPE_MODULE([$1])])
27 m4_define([TEST_FOOABLE_IMPL_],
28 [AT_DATA([$2.gob], [[%ctop{
34 #include "test-fooable.h"
36 ]m4_if([$4], [g-object], [], [[
41 class $1 from $3]m4_default_nblank([
43 (interface Test:Fooable)
45 interface Test:Fooable private int foo(G:Object *go)
53 AT_CHECK([gob2 $2.gob])
54 TEST_COMPILE_GOBJECT([$2.c], [0], [], [ignore])])
56 dnl Test that a static type can implement an interface.
57 AT_SETUP([interface implementation])
58 AT_KEYWORDS([runtime])dnl
61 TEST_FOOABLE_IMPL([Test:A], [G:Object], [return 42;])
67 #include "test-fooable.h"
74 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
81 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
83 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
84 test-a.o test-fooable.o main.o])
85 AT_CHECK([./main], [0], [42
90 dnl Test that a dynamic type can implement an interface.
91 AT_SETUP([interface implementation (dynamic)])
92 AT_KEYWORDS([runtime])dnl
95 TEST_FOOABLE_IMPL_DYN([Test:A], [G:Object], [return 54;])
101 #include "test-fooable.h"
103 #include "test-a-mod.h"
109 g_type_module_use(g_object_new(TEST_TYPE_A_MOD, NULL));
111 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
118 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
120 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
121 test-a.o test-a-mod.o test-fooable.o main.o])
122 AT_CHECK([./main], [0], [54
127 dnl Test that a static type can override the interface implementation
128 dnl in the parent type.
129 AT_SETUP([interface method override])
130 AT_KEYWORDS([runtime])dnl
133 TEST_FOOABLE_IMPL([Test:A], [G:Object],
134 [puts("Test:A foo called"); return 42;])
135 TEST_FOOABLE_IMPL([Test:B], [Test:A],
136 [puts("Test:B foo called"); return 54;])
139 [[#include <config.h>
142 #include "test-fooable.h"
150 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
155 rc = test_foo(g_object_new(TEST_TYPE_B, NULL));
163 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
165 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
166 test-a.o test-b.o test-fooable.o main.o])
167 AT_CHECK([./main], [0], [Test:A foo called
175 dnl Test that a dynamic type can override the interface implementation of
176 dnl a static parent type.
177 AT_SETUP([interface method override (dynamic)])
178 AT_KEYWORDS([runtime])dnl
181 TEST_FOOABLE_IMPL([Test:A], [G:Object],
182 [puts("Test:A foo called"); return 42;])
183 TEST_FOOABLE_IMPL_DYN([Test:B], [Test:A],
184 [puts("Test:B foo called"); return 54;])
187 [[#include <config.h>
190 #include "test-fooable.h"
193 #include "test-b-mod.h"
199 g_type_module_use(g_object_new(TEST_TYPE_B_MOD, NULL));
201 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
206 rc = test_foo(g_object_new(TEST_TYPE_B, NULL));
214 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
216 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
217 test-a.o test-b.o test-b-mod.o test-fooable.o main.o])
219 AT_CHECK([./main], [0], [Test:A foo called
227 dnl Test that a dynamic type can override the interface implementation of a
228 dnl dynamic parent type.
229 AT_SETUP([interface method override (dynamic) #2])
230 AT_KEYWORDS([runtime])dnl
233 TEST_FOOABLE_IMPL_DYN([Test:A], [G:Object],
234 [puts("Test:A foo called"); return 42;])
235 TEST_FOOABLE_IMPL_DYN([Test:B], [Test:A],
236 [puts("Test:B foo called"); return 54;])
239 [[#include <config.h>
242 #include "test-fooable.h"
244 #include "test-a-mod.h"
246 #include "test-b-mod.h"
252 g_type_module_use(g_object_new(TEST_TYPE_A_MOD, NULL));
253 g_type_module_use(g_object_new(TEST_TYPE_B_MOD, NULL));
255 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
260 rc = test_foo(g_object_new(TEST_TYPE_B, NULL));
268 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
270 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
271 test-a.o test-a-mod.o test-b.o test-b-mod.o test-fooable.o main.o])
273 AT_CHECK([./main], [0], [Test:A foo called
281 AT_SETUP([interface method chaining])
282 AT_KEYWORDS([runtime])dnl
285 TEST_FOOABLE_IMPL([Test:A], [G:Object],
286 [puts("Test:A foo called"); return PARENT_HANDLER(go);])
287 TEST_FOOABLE_IMPL([Test:B], [Test:A],
288 [puts("Test:B foo called"); return PARENT_HANDLER(go);])
289 TEST_FOOABLE_IMPL([Test:C], [Test:B],
290 [puts("Test:C foo called"); return PARENT_HANDLER(go);])
293 [[#include <config.h>
296 #include "test-fooable.h"
305 rc = test_foo(g_object_new(TEST_TYPE_C, NULL));
314 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
316 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
317 test-a.o test-b.o test-c.o test-fooable.o main.o])
318 AT_CHECK([./main], [0], [Test:C foo called
326 AT_SETUP([interface method chaining (dynamic)])
327 AT_KEYWORDS([runtime])dnl
330 TEST_FOOABLE_IMPL_DYN([Test:A], [G:Object],
331 [puts("Test:A foo called"); return PARENT_HANDLER(go);])
332 TEST_FOOABLE_IMPL_DYN([Test:B], [Test:A],
333 [puts("Test:B foo called"); return PARENT_HANDLER(go);])
334 TEST_FOOABLE_IMPL_DYN([Test:C], [Test:B],
335 [puts("Test:C foo called"); return PARENT_HANDLER(go);])
338 [[#include <config.h>
341 #include "test-fooable.h"
343 #include "test-a-mod.h"
345 #include "test-b-mod.h"
347 #include "test-c-mod.h"
353 g_type_module_use(g_object_new(TEST_TYPE_A_MOD, NULL));
354 g_type_module_use(g_object_new(TEST_TYPE_B_MOD, NULL));
355 g_type_module_use(g_object_new(TEST_TYPE_C_MOD, NULL));
357 rc = test_foo(g_object_new(TEST_TYPE_C, NULL));
366 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
368 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
369 test-a.o test-a-mod.o test-b.o test-b-mod.o test-c.o test-c-mod.o \
370 test-fooable.o main.o])
371 AT_CHECK([./main], [0], [Test:C foo called