]> git.draconx.ca Git - gob-dx.git/blob - tests/general.at
Expand the interface implementation test cases.
[gob-dx.git] / tests / general.at
1 dnl Copyright © 2019-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.
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 "str.h"
26
27 int main(void)
28 {
29   g_type_init ();
30
31   int the_answer = 42;
32   char *stupid_pointer = "ug";
33
34   /* This works fine. */
35   Str *test_good = (Str *) (str_new ("%d", the_answer));
36   test_good = test_good;
37
38   /* This gets a warning thanks to our function attribute. */
39   Str *test_bad = (Str *) (str_new ("%d", stupid_pointer));
40   test_bad = test_bad;
41
42   return 0;
43 }
44 ]])
45
46 str_gob=$abs_top_srcdir/t/str.gob
47 AT_CHECK([gob2 "$str_gob"])
48 TEST_COMPILE_GOBJECT([str.c], [0], [], [stderr])
49 mv stderr str_stderr
50
51 # Check for correct diagnostic messages on the target lines...
52 AT_CHECK([awk '/want a string/ { print NR }' "$str_gob" >str_lines])
53 total=0
54 exec 3<str_lines
55 while read l <&3; do
56   AS_VAR_ARITH([total], [1 + $total])
57   AT_CHECK([awk -v line="$l" -v file="$str_gob" -NF : \
58     '$1 == file && $2 == line { exit 42 }' str_stderr], [42])
59 done
60 exec 3<&-
61 AT_CHECK([test x"$total" = x"2"])
62
63 TEST_COMPILE_GOBJECT([main.c], [0], [], [stderr])
64 AT_CHECK([awk -NF : '$1 == "main.c" && $2 == "15" { exit 42 }' stderr], [42])
65
66 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main str.o main.o])
67
68 AT_CLEANUP
69
70 dnl Check that dynamic types are accepted and compile OK...
71 AT_SETUP([dynamic types])
72 AT_KEYWORDS([dynamic])
73
74 AT_DATA([test.gob],
75 [[class :Test from G:Object (dynamic)
76 {
77   public void test(void)
78   {
79   }
80 }
81 ]])
82 AT_CHECK([gob2 test.gob])
83
84 AT_DATA([main.c],
85 [[#include "test.h"
86 int main(void)
87 {
88   test_register_type(NULL);
89 }
90 ]])
91
92 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
93 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
94 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main test.o main.o])
95
96 AT_CLEANUP
97
98 dnl Dynamic types: simple test case which checks that we can instantiate a
99 dnl dynamic type after registration.
100 AT_SETUP([dynamic type registration])
101 AT_KEYWORDS([dynamic runtime])
102
103 AT_DATA([test.gob],
104 [[%{
105 #include <stdio.h>
106 %}
107 class :Test from G:Object (dynamic)
108 {
109   public gchar *s = { g_strdup("(nil)") };
110   property STRING s (link);
111
112   public void test(self)
113   {
114     printf("%s\n", self->s);
115   }
116 }
117 ]])
118
119 AT_DATA([mod.gob],
120 [[%{
121 #include "test.h"
122 %}
123 class :Mod from G:Type:Module
124 {
125   override (G:Type:Module) gboolean load(G:Type:Module *m)
126   {
127     test_register_type(m);
128     return TRUE;
129   }
130 }
131 ]])
132
133 AT_DATA([main.c],
134 [[#include <stdio.h>
135 #include "mod.h"
136 #include "test.h"
137
138 void devnull(const char *a, GLogLevelFlags b, const char *c, gpointer d) { }
139
140 int main(void)
141 {
142   GTypeModule *m = g_object_new(mod_get_type(), NULL);
143   guint handler;
144   Test *t;
145
146   /* should fail, suppress internal glib logging...  */
147   handler = g_log_set_handler("GLib-GObject", G_LOG_LEVEL_MASK, devnull, 0);
148   t = g_object_new(test_get_type(), NULL);
149   if (t != NULL)
150     return EXIT_FAILURE;
151   g_log_remove_handler("GLib-GObject", handler);
152
153   g_type_module_use(m);
154   /* should work now */
155   t = g_object_new(test_get_type(), "s", "Hello, World", (char *)NULL);
156   if (!t)
157     return EXIT_FAILURE;
158
159   test_test(t);
160   return EXIT_SUCCESS;
161 }
162 ]])
163
164 AT_CHECK([gob2 mod.gob])
165 AT_CHECK([gob2 test.gob])
166 TEST_COMPILE_GOBJECT([mod.c], [0], [], [ignore])
167 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
168 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
169 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main mod.o test.o main.o])
170 AT_CHECK([./main], [0], [Hello, World
171 ])
172
173 AT_CLEANUP
174
175 AT_SETUP([GOB2_CHECK min-version test])
176
177 AT_DATA([configure.ac],
178 [[AC_PREREQ([2.62])
179 AC_INIT([test], [0])
180 AC_OUTPUT
181 ]])
182 AT_CHECK([$AUTOCONF && test -f configure || exit 77], [0], [ignore], [ignore])
183
184 m4_define([MYVER],
185   m4_bpatsubst(m4_dquote(m4_defn([AT_PACKAGE_VERSION])), [[^][0-9.]]))
186
187 m4_define([MYVER_P1], m4_dquote(m4_reverse(m4_unquote(
188   m4_split(m4_defn([MYVER]), [[.]])))))
189 m4_define([MYVER_P1], m4_join([.], m4_reverse(
190   m4_eval(m4_car(MYVER_P1)+1), m4_shift(MYVER_P1))))
191
192 AT_DATA([test.in], [[@GOB2@
193 ]])
194
195 cat >configure.ac <<EOF
196 [m4@&t@_include([$builddir/gob2.m4])]
197 [m4@&t@_pattern_forbid([^GOB2_])]
198 [AC_INIT([gob2_check], [0])]
199 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER]))[)]
200 GOB2=\`command -v \$GOB2\`
201 [AC_CONFIG_FILES([test])]
202 [AC_OUTPUT]
203 EOF
204 AT_CHECK([$AUTOCONF --force])
205 AT_CHECK([./configure], [0], [ignore])
206
207 command -v gob2 >expout
208 AT_CHECK([cat test], [0], [expout], [ignore])
209
210 sed '/GOB2_CHECK/c\
211 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER_P1]))[)]' configure.ac >configure.new
212 mv -f configure.new configure.ac
213 AT_CHECK([$AUTOCONF --force])
214 AT_CHECK([./configure], [1], [ignore], [ignore])
215
216 AT_CLEANUP