]> git.draconx.ca Git - gob-dx.git/blob - tests/general.at
Fix testsuite on ancient GLib.
[gob-dx.git] / tests / general.at
1 dnl Copyright © 2019-2021 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.
5
6 AT_SETUP([test.gob compilation])
7
8 AT_CHECK([gob2 "$abs_top_srcdir/t/test.gob"])
9 AT_CHECK([$HAVE_GTK2 || exit 77])
10 TEST_COMPILE_GOBJECT([$GTK_CFLAGS test-object.c], [0], [], [ignore])
11
12 AT_CLEANUP
13
14 AT_SETUP([test.gob C++ compilation])
15
16 AT_CHECK([gob2 --for-cpp "$abs_top_srcdir/t/test.gob"])
17 AT_CHECK([$HAVE_GTK2 || exit 77])
18 TEST_COMPILEXX_GOBJECT([$GTK_CFLAGS test-object.cc], [0], [], [ignore])
19
20 AT_CLEANUP
21
22 AT_SETUP([str.gob])
23
24 AT_DATA([main.c],
25 [[#include <config.h>
26 #include "str.h"
27
28 int main(void)
29 {
30   g_type_init ();
31
32   int the_answer = 42;
33   char *stupid_pointer = "ug";
34
35   /* This works fine. */
36   Str *test_good = (Str *) (str_new ("%d", the_answer));
37   test_good = test_good;
38
39   /* This gets a warning thanks to our function attribute. */
40   Str *test_bad = (Str *) (str_new ("%d", stupid_pointer));
41   test_bad = test_bad;
42
43   return 0;
44 }
45 ]])
46
47 str_gob=$abs_top_srcdir/t/str.gob
48 AT_CHECK([gob2 "$str_gob"])
49 AT_CHECK([$HAVE_GOBJECT_PRIVATES || exit 77])
50 TEST_COMPILE_GOBJECT([str.c], [0], [], [stderr])
51 mv stderr str_stderr
52
53 # Check for correct diagnostic messages on the target lines...
54 AT_CHECK([awk '/want a string/ { print NR }' "$str_gob" >str_lines])
55 total=0
56 exec 3<str_lines
57 while read l <&3; do
58   AS_VAR_ARITH([total], [1 + $total])
59   AT_CHECK([awk -v line="$l" -v file="$str_gob" -NF : \
60     '$1 == file && $2 == line { exit 42 }' str_stderr], [42])
61 done
62 exec 3<&-
63 AT_CHECK([test x"$total" = x"2"])
64
65 TEST_COMPILE_GOBJECT([main.c], [0], [], [stderr])
66 AT_CHECK([awk -NF : '$1 == "main.c" && $2 == "16" { exit 42 }' stderr], [42])
67
68 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main str.o main.o])
69
70 AT_CLEANUP
71
72 dnl Check that dynamic types are accepted and compile OK...
73 AT_SETUP([dynamic types])
74 AT_KEYWORDS([dynamic])
75
76 AT_DATA([test.gob], [[%ctop{
77 #include <config.h>
78 %}
79 class :Test from G:Object (dynamic)
80 {
81   public void test(void)
82   {
83   }
84 }
85 ]])
86 AT_CHECK([gob2 test.gob])
87 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
88
89 AT_DATA([main.c],
90 [[#include <config.h>
91 #include "test.h"
92 int main(void)
93 {
94   test_register_type(NULL);
95 }
96 ]])
97 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
98
99 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main test.o main.o])
100
101 AT_CLEANUP
102
103 dnl Dynamic types: simple test case which checks that we can instantiate a
104 dnl dynamic type after registration.
105 AT_SETUP([dynamic type registration])
106 AT_KEYWORDS([dynamic runtime])
107
108 AT_DATA([test.gob], [[%ctop{
109 #include <config.h>
110 %}
111 %{
112 #include <stdio.h>
113 %}
114 class :Test from G:Object (dynamic)
115 {
116   public gchar *s = { g_strdup("(nil)") };
117   property STRING s (link);
118
119   public void test(self)
120   {
121     printf("%s\n", self->s);
122   }
123 }
124 ]])
125 AT_CHECK([gob2 test.gob])
126 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
127
128 TEST_TYPE_MODULE([:Test])
129
130 AT_DATA([main.c],
131 [[#include <stdlib.h>
132 #include "test.h"
133 #include "test-mod.h"
134
135 void devnull(const char *a, GLogLevelFlags b, const char *c, gpointer d) { }
136
137 int main(void)
138 {
139   guint handler;
140   Test *t;
141
142   /* should fail, suppress internal glib logging...  */
143   handler = g_log_set_handler("GLib-GObject", G_LOG_LEVEL_MASK, devnull, 0);
144   t = g_object_new(test_get_type(), NULL);
145   if (t != NULL)
146     return EXIT_FAILURE;
147   g_log_remove_handler("GLib-GObject", handler);
148
149   /* Register dynamic type */
150   g_type_module_use(g_object_new(test_mod_get_type(), NULL));
151
152   /* should work now */
153   t = g_object_new(test_get_type(), "s", "Hello, World", (char *)NULL);
154   if (!t)
155     return EXIT_FAILURE;
156
157   test_test(t);
158   return EXIT_SUCCESS;
159 }
160 ]])
161 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
162
163 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
164   test.o test-mod.o main.o])
165 AT_CHECK([./main], [0], [Hello, World
166 ])
167
168 AT_CLEANUP
169
170 AT_SETUP([GOB2_CHECK min-version test])
171
172 AT_DATA([configure.ac],
173 [[AC_PREREQ([2.62])
174 AC_INIT([test], [0])
175 AC_OUTPUT
176 ]])
177 AT_CHECK([$AUTOCONF && test -f configure || exit 77], [0], [ignore], [ignore])
178
179 m4_define([MYVER],
180   m4_bpatsubst(m4_dquote(m4_defn([AT_PACKAGE_VERSION])), [[^][0-9.]]))
181
182 m4_define([MYVER_P1], m4_dquote(m4_reverse(m4_unquote(
183   m4_split(m4_defn([MYVER]), [[.]])))))
184 m4_define([MYVER_P1], m4_join([.], m4_reverse(
185   m4_eval(m4_car(MYVER_P1)+1), m4_shift(MYVER_P1))))
186
187 AT_DATA([test.in], [[@GOB2@
188 ]])
189
190 cat >configure.ac <<EOF
191 [m4@&t@_include([$builddir/gob2.m4])]
192 [m4@&t@_pattern_forbid([^GOB2_])]
193 [AC_INIT([gob2_check], [0])]
194 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER]))[)]
195 GOB2=\`command -v \$GOB2\`
196 [AC_CONFIG_FILES([test])]
197 [AC_OUTPUT]
198 EOF
199 AT_CHECK([$AUTOCONF --force])
200 AT_CHECK([./configure], [0], [ignore])
201
202 command -v gob2 >expout
203 AT_CHECK([cat test], [0], [expout], [ignore])
204
205 sed '/GOB2_CHECK/c\
206 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER_P1]))[)]' configure.ac >configure.new
207 mv -f configure.new configure.ac
208 AT_CHECK([$AUTOCONF --force])
209 AT_CHECK([./configure], [1], [ignore], [ignore])
210
211 AT_CLEANUP
212
213 AT_SETUP([private data members])
214
215 AT_DATA([test.gob], [[%ctop{
216 #include <config.h>
217 %}
218 class :Test from G:Object
219 {
220   private int x = 42;
221
222   public int get_x(G:Object *go) { return TEST(go)->_priv->x; }
223   public void set_x(G:Object *go, int val) { TEST(go)->_priv->x = val; }
224 }
225 ]])
226 AT_CHECK([gob2 test.gob])
227 AT_CHECK([$HAVE_GOBJECT_PRIVATES || exit 77])
228 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
229
230 AT_DATA([main.c], [[#include <config.h>
231 #include <stdio.h>
232 #include "test.h"
233
234 int main(void)
235 {
236   GObject *go = g_object_new(test_get_type(), NULL);
237
238   printf("%d\n", test_get_x(go));
239   printf("%d\n", (test_set_x(go, 123), test_get_x(go)));
240
241   return 0;
242 }
243 ]])
244 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
245
246 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
247   test.o main.o])
248 AT_CHECK([./main], [0], [42
249 123
250 ])
251
252 AT_CLEANUP
253
254 AT_SETUP([private data members (dynamic)])
255
256 AT_DATA([test.gob], [[%ctop{
257 #include <config.h>
258 %}
259 class :Test from G:Object (dynamic)
260 {
261   private int x = 54;
262
263   public int get_x(G:Object *go) { return TEST(go)->_priv->x; }
264   public void set_x(G:Object *go, int val) { TEST(go)->_priv->x = val; }
265 }
266 ]])
267 AT_CHECK([gob2 test.gob])
268 AT_CHECK([$HAVE_GOBJECT_PRIVATES || exit 77])
269 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
270
271 TEST_TYPE_MODULE([:Test])
272
273 AT_DATA([main.c], [[#include <config.h>
274 #include <stdio.h>
275 #include "test.h"
276 #include "test-mod.h"
277
278 int main(void)
279 {
280   GObject *go;
281
282   g_type_module_use(g_object_new(test_mod_get_type(), NULL));
283   go = g_object_new(test_get_type(), NULL);
284
285   printf("%d\n", test_get_x(go));
286   printf("%d\n", (test_set_x(go, 123), test_get_x(go)));
287
288   return 0;
289 }
290 ]])
291 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
292
293 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
294   test.o test-mod.o main.o])
295 AT_CHECK([./main], [0], [54
296 123
297 ])
298
299 AT_CLEANUP