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], [[%{
31 #include "test-fooable.h"
33 ]m4_if([$4], [g-object], [], [[
38 class $1 from $3]m4_default_nblank([
40 (interface Test:Fooable)
42 interface Test:Fooable private int foo(G:Object *go)
50 AT_CHECK([gob2 $2.gob])
51 TEST_COMPILE_GOBJECT([$2.c], [0], [], [ignore])])
53 dnl Test that a static type can implement an interface.
54 AT_SETUP([interface implementation])
55 AT_KEYWORDS([runtime])dnl
58 TEST_FOOABLE_IMPL([Test:A], [G:Object], [return 42;])
63 #include "test-fooable.h"
70 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
77 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
79 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
80 test-a.o test-fooable.o main.o])
81 AT_CHECK([./main], [0], [42
86 dnl Test that a dynamic type can implement an interface.
87 AT_SETUP([interface implementation (dynamic)])
88 AT_KEYWORDS([runtime])dnl
91 TEST_FOOABLE_IMPL_DYN([Test:A], [G:Object], [return 54;])
96 #include "test-fooable.h"
98 #include "test-a-mod.h"
104 g_type_module_use(g_object_new(TEST_TYPE_A_MOD, NULL));
106 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
113 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
115 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
116 test-a.o test-a-mod.o test-fooable.o main.o])
117 AT_CHECK([./main], [0], [54
122 dnl Test that a static type can override the interface implementation
123 dnl in the parent type.
124 AT_SETUP([interface method override])
125 AT_KEYWORDS([runtime])dnl
128 TEST_FOOABLE_IMPL([Test:A], [G:Object],
129 [puts("Test:A foo called"); return 42;])
130 TEST_FOOABLE_IMPL([Test:B], [Test:A],
131 [puts("Test:B foo called"); return 54;])
136 #include "test-fooable.h"
144 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
149 rc = test_foo(g_object_new(TEST_TYPE_B, NULL));
157 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
159 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
160 test-a.o test-b.o test-fooable.o main.o])
161 AT_CHECK([./main], [0], [Test:A foo called
169 dnl Test that a dynamic type can override the interface implementation of
170 dnl a static parent type.
171 AT_SETUP([interface method override (dynamic)])
172 AT_KEYWORDS([runtime])dnl
175 TEST_FOOABLE_IMPL([Test:A], [G:Object],
176 [puts("Test:A foo called"); return 42;])
177 TEST_FOOABLE_IMPL_DYN([Test:B], [Test:A],
178 [puts("Test:B foo called"); return 54;])
183 #include "test-fooable.h"
186 #include "test-b-mod.h"
192 g_type_module_use(g_object_new(TEST_TYPE_B_MOD, NULL));
194 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
199 rc = test_foo(g_object_new(TEST_TYPE_B, NULL));
207 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
209 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
210 test-a.o test-b.o test-b-mod.o test-fooable.o main.o])
212 AT_CHECK([./main], [0], [Test:A foo called
220 dnl Test that a dynamic type can override the interface implementation of a
221 dnl dynamic parent type.
222 AT_SETUP([interface method override (dynamic) #2])
223 AT_KEYWORDS([runtime])dnl
226 TEST_FOOABLE_IMPL_DYN([Test:A], [G:Object],
227 [puts("Test:A foo called"); return 42;])
228 TEST_FOOABLE_IMPL_DYN([Test:B], [Test:A],
229 [puts("Test:B foo called"); return 54;])
234 #include "test-fooable.h"
236 #include "test-a-mod.h"
238 #include "test-b-mod.h"
244 g_type_module_use(g_object_new(TEST_TYPE_A_MOD, NULL));
245 g_type_module_use(g_object_new(TEST_TYPE_B_MOD, NULL));
247 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
252 rc = test_foo(g_object_new(TEST_TYPE_B, NULL));
260 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
262 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
263 test-a.o test-a-mod.o test-b.o test-b-mod.o test-fooable.o main.o])
265 AT_CHECK([./main], [0], [Test:A foo called
273 AT_SETUP([interface method chaining])
274 AT_KEYWORDS([runtime])dnl
277 TEST_FOOABLE_IMPL([Test:A], [G:Object],
278 [puts("Test:A foo called"); return PARENT_HANDLER(go);])
279 TEST_FOOABLE_IMPL([Test:B], [Test:A],
280 [puts("Test:B foo called"); return PARENT_HANDLER(go);])
281 TEST_FOOABLE_IMPL([Test:C], [Test:B],
282 [puts("Test:C foo called"); return PARENT_HANDLER(go);])
287 #include "test-fooable.h"
296 rc = test_foo(g_object_new(TEST_TYPE_C, NULL));
305 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
307 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
308 test-a.o test-b.o test-c.o test-fooable.o main.o])
309 AT_CHECK([./main], [0], [Test:C foo called
317 AT_SETUP([interface method chaining (dynamic)])
318 AT_KEYWORDS([runtime])dnl
321 TEST_FOOABLE_IMPL_DYN([Test:A], [G:Object],
322 [puts("Test:A foo called"); return PARENT_HANDLER(go);])
323 TEST_FOOABLE_IMPL_DYN([Test:B], [Test:A],
324 [puts("Test:B foo called"); return PARENT_HANDLER(go);])
325 TEST_FOOABLE_IMPL_DYN([Test:C], [Test:B],
326 [puts("Test:C foo called"); return PARENT_HANDLER(go);])
331 #include "test-fooable.h"
333 #include "test-a-mod.h"
335 #include "test-b-mod.h"
337 #include "test-c-mod.h"
343 g_type_module_use(g_object_new(TEST_TYPE_A_MOD, NULL));
344 g_type_module_use(g_object_new(TEST_TYPE_B_MOD, NULL));
345 g_type_module_use(g_object_new(TEST_TYPE_C_MOD, NULL));
347 rc = test_foo(g_object_new(TEST_TYPE_C, NULL));
356 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
358 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
359 test-a.o test-a-mod.o test-b.o test-b-mod.o test-c.o test-c-mod.o \
360 test-fooable.o main.o])
361 AT_CHECK([./main], [0], [Test:C foo called