1 dnl Copyright © 2020, 2022-2023 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])
83 TEST_LINK_GOBJECT([main], [test-a.o test-fooable.o main.o])
84 AT_CHECK([./main], [0], [42
89 dnl Test that a dynamic type can implement an interface.
90 AT_SETUP([interface implementation (dynamic)])
91 AT_KEYWORDS([runtime])dnl
94 TEST_FOOABLE_IMPL_DYN([Test:A], [G:Object], [return 54;])
100 #include "test-fooable.h"
102 #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])
119 TEST_LINK_GOBJECT([main], [test-a.o test-a-mod.o test-fooable.o main.o])
120 AT_CHECK([./main], [0], [54
125 dnl Test that a static type can override the interface implementation
126 dnl in the parent type.
127 AT_SETUP([interface method override])
128 AT_KEYWORDS([runtime])dnl
131 TEST_FOOABLE_IMPL([Test:A], [G:Object],
132 [puts("Test:A foo called"); return 42;])
133 TEST_FOOABLE_IMPL([Test:B], [Test:A],
134 [puts("Test:B foo called"); return 54;])
137 [[#include <config.h>
140 #include "test-fooable.h"
149 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
154 rc = test_foo(g_object_new(TEST_TYPE_B, NULL));
162 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
163 TEST_LINK_GOBJECT([main], [test-a.o test-b.o test-fooable.o main.o])
164 AT_CHECK([./main], [0], [Test:A foo called
172 dnl Test that a dynamic type can override the interface implementation of
173 dnl a static parent type.
174 AT_SETUP([interface method override (dynamic)])
175 AT_KEYWORDS([runtime])dnl
178 TEST_FOOABLE_IMPL([Test:A], [G:Object],
179 [puts("Test:A foo called"); return 42;])
180 TEST_FOOABLE_IMPL_DYN([Test:B], [Test:A],
181 [puts("Test:B foo called"); return 54;])
184 [[#include <config.h>
187 #include "test-fooable.h"
190 #include "test-b-mod.h"
197 g_type_module_use(g_object_new(TEST_TYPE_B_MOD, NULL));
199 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
204 rc = test_foo(g_object_new(TEST_TYPE_B, NULL));
212 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
213 TEST_LINK_GOBJECT([main],
214 [test-a.o test-b.o test-b-mod.o test-fooable.o main.o])
215 AT_CHECK([./main], [0], [Test:A foo called
223 dnl Test that a dynamic type can override the interface implementation of a
224 dnl dynamic parent type.
225 AT_SETUP([interface method override (dynamic) #2])
226 AT_KEYWORDS([runtime])dnl
229 TEST_FOOABLE_IMPL_DYN([Test:A], [G:Object],
230 [puts("Test:A foo called"); return 42;])
231 TEST_FOOABLE_IMPL_DYN([Test:B], [Test:A],
232 [puts("Test:B foo called"); return 54;])
235 [[#include <config.h>
238 #include "test-fooable.h"
240 #include "test-a-mod.h"
242 #include "test-b-mod.h"
249 g_type_module_use(g_object_new(TEST_TYPE_A_MOD, NULL));
250 g_type_module_use(g_object_new(TEST_TYPE_B_MOD, NULL));
252 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
257 rc = test_foo(g_object_new(TEST_TYPE_B, NULL));
265 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
266 TEST_LINK_GOBJECT([main],
267 [test-a.o test-a-mod.o test-b.o test-b-mod.o test-fooable.o main.o])
268 AT_CHECK([./main], [0], [Test:A foo called
276 AT_SETUP([interface method chaining])
277 AT_KEYWORDS([runtime])dnl
280 TEST_FOOABLE_IMPL([Test:A], [G:Object],
281 [puts("Test:A foo called"); return PARENT_HANDLER(go);])
282 TEST_FOOABLE_IMPL([Test:B], [Test:A],
283 [puts("Test:B foo called"); return PARENT_HANDLER(go);])
284 TEST_FOOABLE_IMPL([Test:C], [Test:B],
285 [puts("Test:C foo called"); return PARENT_HANDLER(go);])
288 [[#include <config.h>
291 #include "test-fooable.h"
301 rc = test_foo(g_object_new(TEST_TYPE_C, NULL));
310 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
311 TEST_LINK_GOBJECT([main], [test-a.o test-b.o test-c.o test-fooable.o main.o])
312 AT_CHECK([./main], [0], [Test:C foo called
320 AT_SETUP([interface method chaining (dynamic)])
321 AT_KEYWORDS([runtime])dnl
324 TEST_FOOABLE_IMPL_DYN([Test:A], [G:Object],
325 [puts("Test:A foo called"); return PARENT_HANDLER(go);])
326 TEST_FOOABLE_IMPL_DYN([Test:B], [Test:A],
327 [puts("Test:B foo called"); return PARENT_HANDLER(go);])
328 TEST_FOOABLE_IMPL_DYN([Test:C], [Test:B],
329 [puts("Test:C foo called"); return PARENT_HANDLER(go);])
332 [[#include <config.h>
335 #include "test-fooable.h"
337 #include "test-a-mod.h"
339 #include "test-b-mod.h"
341 #include "test-c-mod.h"
348 g_type_module_use(g_object_new(TEST_TYPE_A_MOD, NULL));
349 g_type_module_use(g_object_new(TEST_TYPE_B_MOD, NULL));
350 g_type_module_use(g_object_new(TEST_TYPE_C_MOD, NULL));
352 rc = test_foo(g_object_new(TEST_TYPE_C, NULL));
361 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
362 TEST_LINK_GOBJECT([main], m4_join([ ],
363 [test-a.o test-a-mod.o test-b.o test-b-mod.o test-c.o test-c-mod.o],
364 [test-fooable.o main.o]))
365 AT_CHECK([./main], [0], [Test:C foo called