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 TEST_TYPE_MODULE(Class:Name)
7 dnl Create a GTypeModule (Class:Name:Mod) which registers the dynamic
8 dnl type indiciated by Class:Name.
9 m4_define([TEST_TYPE_MODULE],
10 [TEST_TYPE_MODULE_([$1], m4_translit([[$1]], [:A-Z], [_a-z]),
11 m4_translit([[$1]], [:A-Z], [-a-z]))])
13 m4_define([TEST_TYPE_MODULE_],
14 [AT_KEYWORDS([dynamic])dnl
16 AT_DATA([$3-mod.gob], [[%{
19 class $1:Mod from G:Type:Module
21 override (G:Type:Module) gboolean load(G:Type:Module *m)
28 AT_CHECK([gob2 $3-mod.gob])
29 TEST_COMPILE_GOBJECT([$3-mod.c], [0], [], [ignore])])
31 dnl Create the Test:Fooable interface with the following interface method:
33 dnl int foo(G:Object *obj);
35 dnl Link in test-fooable.o
36 m4_define([TEST_FOOABLE_IFACE],
37 [AT_KEYWORDS([interface])dnl
38 AT_CHECK([cp $srcdir/t/test-fooable.c $srcdir/t/test-fooable.h .])
39 TEST_COMPILE_GOBJECT([test-fooable.c], [0], [], [ignore])])
41 dnl TEST_FOOABLE_IMPL(Class:Name, Parent:Class, foo_body)
42 dnl TEST_FOOABLE_IMPL_DYN(Class:Name, Parent:Class, foo_body)
43 m4_define([TEST_FOOABLE_IMPL],
44 [TEST_FOOABLE_IMPL_([$1], m4_translit([[$1]], [:A-Z], [-a-z]),
45 [$2], m4_translit([[$2]], [:A-Z], [-a-z]),
48 m4_define([TEST_FOOABLE_IMPL_DYN],
49 [TEST_FOOABLE_IMPL([$1], [$2], [$3], [(dynamic)])
50 TEST_TYPE_MODULE([$1])])
52 m4_define([TEST_FOOABLE_IMPL_],
53 [AT_DATA([$2.gob], [[%{
56 #include "test-fooable.h"
58 ]m4_if([$4], [g-object], [], [[
63 class $1 from $3]m4_default_nblank([
65 (interface Test:Fooable)
67 interface Test:Fooable private int foo(G:Object *go)
74 AT_CHECK([gob2 $2.gob])
75 TEST_COMPILE_GOBJECT([$2.c], [0], [], [ignore])])
77 dnl Test that a static type can implement an interface.
78 AT_SETUP([interface implementation])
79 AT_KEYWORDS([runtime])dnl
82 TEST_FOOABLE_IMPL([Test:A], [G:Object], [return 42;])
87 #include "test-fooable.h"
94 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
101 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
103 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
104 test-a.o test-fooable.o main.o])
105 AT_CHECK([./main], [0], [42
110 dnl Test that a dynamic type can implement an interface.
111 AT_SETUP([interface implementation (dynamic)])
112 AT_KEYWORDS([runtime])dnl
115 TEST_FOOABLE_IMPL_DYN([Test:A], [G:Object], [return 54;])
120 #include "test-fooable.h"
122 #include "test-a-mod.h"
128 g_type_module_use(g_object_new(TEST_TYPE_A_MOD, NULL));
130 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
137 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
139 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
140 test-a.o test-a-mod.o test-fooable.o main.o])
141 AT_CHECK([./main], [0], [54
146 dnl Test that a static type can override the interface implementation
147 dnl in the parent type.
148 AT_SETUP([interface method override])
149 AT_KEYWORDS([runtime])dnl
152 TEST_FOOABLE_IMPL([Test:A], [G:Object],
153 [puts("Test:A foo called"); return 42;])
154 TEST_FOOABLE_IMPL([Test:B], [Test:A],
155 [puts("Test:B foo called"); return 54;])
160 #include "test-fooable.h"
168 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
173 rc = test_foo(g_object_new(TEST_TYPE_B, NULL));
181 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
183 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
184 test-a.o test-b.o test-fooable.o main.o])
185 AT_CHECK([./main], [0], [Test:A foo called
193 dnl Test that a dynamic type can override the interface implementation of
194 dnl a static parent type.
195 AT_SETUP([interface method override (dynamic)])
196 AT_KEYWORDS([runtime])dnl
199 TEST_FOOABLE_IMPL([Test:A], [G:Object],
200 [puts("Test:A foo called"); return 42;])
201 TEST_FOOABLE_IMPL_DYN([Test:B], [Test:A],
202 [puts("Test:B foo called"); return 54;])
206 #include "test-fooable.h"
209 #include "test-b-mod.h"
215 g_type_module_use(g_object_new(TEST_TYPE_B_MOD, NULL));
217 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
222 rc = test_foo(g_object_new(TEST_TYPE_B, NULL));
230 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
232 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
233 test-a.o test-b.o test-b-mod.o test-fooable.o main.o])
237 AT_CHECK([./main], [0], [Test:A foo called
245 dnl Test that a dynamic type can override the interface implementation of a
246 dnl dynamic parent type.
247 AT_SETUP([interface method override (dynamic) #2])
248 AT_KEYWORDS([runtime])dnl
251 TEST_FOOABLE_IMPL_DYN([Test:A], [G:Object],
252 [puts("Test:A foo called"); return 42;])
253 TEST_FOOABLE_IMPL_DYN([Test:B], [Test:A],
254 [puts("Test:B foo called"); return 54;])
258 #include "test-fooable.h"
260 #include "test-a-mod.h"
262 #include "test-b-mod.h"
268 g_type_module_use(g_object_new(TEST_TYPE_A_MOD, NULL));
269 g_type_module_use(g_object_new(TEST_TYPE_B_MOD, NULL));
271 rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
276 rc = test_foo(g_object_new(TEST_TYPE_B, NULL));
284 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
286 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
287 test-a.o test-a-mod.o test-b.o test-b-mod.o test-fooable.o main.o])
291 AT_CHECK([./main], [0], [Test:A foo called