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"
75 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
82 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
84 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
85 test-a.o test-fooable.o main.o])
86 AT_CHECK([./main], [0], [42
91 dnl Test that a dynamic type can implement an interface.
92 AT_SETUP([interface implementation (dynamic)])
93 AT_KEYWORDS([runtime])dnl
96 TEST_FOOABLE_IMPL_DYN([Test:A], [G:Object], [return 54;])
102 #include "test-fooable.h"
104 #include "test-a-mod.h"
111 g_type_module_use(g_object_new(TEST_TYPE_A_MOD, NULL));
113 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
120 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
122 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
123 test-a.o test-a-mod.o test-fooable.o main.o])
124 AT_CHECK([./main], [0], [54
129 dnl Test that a static type can override the interface implementation
130 dnl in the parent type.
131 AT_SETUP([interface method override])
132 AT_KEYWORDS([runtime])dnl
135 TEST_FOOABLE_IMPL([Test:A], [G:Object],
136 [puts("Test:A foo called"); return 42;])
137 TEST_FOOABLE_IMPL([Test:B], [Test:A],
138 [puts("Test:B foo called"); return 54;])
141 [[#include <config.h>
144 #include "test-fooable.h"
153 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
158 rc = test_foo(g_object_new(TEST_TYPE_B, NULL));
166 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
168 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
169 test-a.o test-b.o test-fooable.o main.o])
170 AT_CHECK([./main], [0], [Test:A foo called
178 dnl Test that a dynamic type can override the interface implementation of
179 dnl a static parent type.
180 AT_SETUP([interface method override (dynamic)])
181 AT_KEYWORDS([runtime])dnl
184 TEST_FOOABLE_IMPL([Test:A], [G:Object],
185 [puts("Test:A foo called"); return 42;])
186 TEST_FOOABLE_IMPL_DYN([Test:B], [Test:A],
187 [puts("Test:B foo called"); return 54;])
190 [[#include <config.h>
193 #include "test-fooable.h"
196 #include "test-b-mod.h"
203 g_type_module_use(g_object_new(TEST_TYPE_B_MOD, NULL));
205 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
210 rc = test_foo(g_object_new(TEST_TYPE_B, NULL));
218 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
220 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
221 test-a.o test-b.o test-b-mod.o test-fooable.o main.o])
223 AT_CHECK([./main], [0], [Test:A foo called
231 dnl Test that a dynamic type can override the interface implementation of a
232 dnl dynamic parent type.
233 AT_SETUP([interface method override (dynamic) #2])
234 AT_KEYWORDS([runtime])dnl
237 TEST_FOOABLE_IMPL_DYN([Test:A], [G:Object],
238 [puts("Test:A foo called"); return 42;])
239 TEST_FOOABLE_IMPL_DYN([Test:B], [Test:A],
240 [puts("Test:B foo called"); return 54;])
243 [[#include <config.h>
246 #include "test-fooable.h"
248 #include "test-a-mod.h"
250 #include "test-b-mod.h"
257 g_type_module_use(g_object_new(TEST_TYPE_A_MOD, NULL));
258 g_type_module_use(g_object_new(TEST_TYPE_B_MOD, NULL));
260 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
265 rc = test_foo(g_object_new(TEST_TYPE_B, NULL));
273 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
275 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
276 test-a.o test-a-mod.o test-b.o test-b-mod.o test-fooable.o main.o])
278 AT_CHECK([./main], [0], [Test:A foo called
286 AT_SETUP([interface method chaining])
287 AT_KEYWORDS([runtime])dnl
290 TEST_FOOABLE_IMPL([Test:A], [G:Object],
291 [puts("Test:A foo called"); return PARENT_HANDLER(go);])
292 TEST_FOOABLE_IMPL([Test:B], [Test:A],
293 [puts("Test:B foo called"); return PARENT_HANDLER(go);])
294 TEST_FOOABLE_IMPL([Test:C], [Test:B],
295 [puts("Test:C foo called"); return PARENT_HANDLER(go);])
298 [[#include <config.h>
301 #include "test-fooable.h"
311 rc = test_foo(g_object_new(TEST_TYPE_C, NULL));
320 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
322 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
323 test-a.o test-b.o test-c.o test-fooable.o main.o])
324 AT_CHECK([./main], [0], [Test:C foo called
332 AT_SETUP([interface method chaining (dynamic)])
333 AT_KEYWORDS([runtime])dnl
336 TEST_FOOABLE_IMPL_DYN([Test:A], [G:Object],
337 [puts("Test:A foo called"); return PARENT_HANDLER(go);])
338 TEST_FOOABLE_IMPL_DYN([Test:B], [Test:A],
339 [puts("Test:B foo called"); return PARENT_HANDLER(go);])
340 TEST_FOOABLE_IMPL_DYN([Test:C], [Test:B],
341 [puts("Test:C foo called"); return PARENT_HANDLER(go);])
344 [[#include <config.h>
347 #include "test-fooable.h"
349 #include "test-a-mod.h"
351 #include "test-b-mod.h"
353 #include "test-c-mod.h"
360 g_type_module_use(g_object_new(TEST_TYPE_A_MOD, NULL));
361 g_type_module_use(g_object_new(TEST_TYPE_B_MOD, NULL));
362 g_type_module_use(g_object_new(TEST_TYPE_C_MOD, NULL));
364 rc = test_foo(g_object_new(TEST_TYPE_C, NULL));
373 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
375 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
376 test-a.o test-a-mod.o test-b.o test-b-mod.o test-c.o test-c-mod.o \
377 test-fooable.o main.o])
378 AT_CHECK([./main], [0], [Test:C foo called