]> git.draconx.ca Git - gob-dx.git/blob - tests/general.at
Minor testsuite cleanup.
[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 AT_CHECK([gob2 test.gob])
119 TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
120
121 TEST_TYPE_MODULE([:Test])
122
123 AT_DATA([main.c],
124 [[#include <stdlib.h>
125 #include "test.h"
126 #include "test-mod.h"
127
128 void devnull(const char *a, GLogLevelFlags b, const char *c, gpointer d) { }
129
130 int main(void)
131 {
132   guint handler;
133   Test *t;
134
135   /* should fail, suppress internal glib logging...  */
136   handler = g_log_set_handler("GLib-GObject", G_LOG_LEVEL_MASK, devnull, 0);
137   t = g_object_new(test_get_type(), NULL);
138   if (t != NULL)
139     return EXIT_FAILURE;
140   g_log_remove_handler("GLib-GObject", handler);
141
142   /* Register dynamic type */
143   g_type_module_use(g_object_new(test_mod_get_type(), NULL));
144
145   /* should work now */
146   t = g_object_new(test_get_type(), "s", "Hello, World", (char *)NULL);
147   if (!t)
148     return EXIT_FAILURE;
149
150   test_test(t);
151   return EXIT_SUCCESS;
152 }
153 ]])
154 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
155
156 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
157   test.o test-mod.o main.o])
158 AT_CHECK([./main], [0], [Hello, World
159 ])
160
161 AT_CLEANUP
162
163 AT_SETUP([GOB2_CHECK min-version test])
164
165 AT_DATA([configure.ac],
166 [[AC_PREREQ([2.62])
167 AC_INIT([test], [0])
168 AC_OUTPUT
169 ]])
170 AT_CHECK([$AUTOCONF && test -f configure || exit 77], [0], [ignore], [ignore])
171
172 m4_define([MYVER],
173   m4_bpatsubst(m4_dquote(m4_defn([AT_PACKAGE_VERSION])), [[^][0-9.]]))
174
175 m4_define([MYVER_P1], m4_dquote(m4_reverse(m4_unquote(
176   m4_split(m4_defn([MYVER]), [[.]])))))
177 m4_define([MYVER_P1], m4_join([.], m4_reverse(
178   m4_eval(m4_car(MYVER_P1)+1), m4_shift(MYVER_P1))))
179
180 AT_DATA([test.in], [[@GOB2@
181 ]])
182
183 cat >configure.ac <<EOF
184 [m4@&t@_include([$builddir/gob2.m4])]
185 [m4@&t@_pattern_forbid([^GOB2_])]
186 [AC_INIT([gob2_check], [0])]
187 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER]))[)]
188 GOB2=\`command -v \$GOB2\`
189 [AC_CONFIG_FILES([test])]
190 [AC_OUTPUT]
191 EOF
192 AT_CHECK([$AUTOCONF --force])
193 AT_CHECK([./configure], [0], [ignore])
194
195 command -v gob2 >expout
196 AT_CHECK([cat test], [0], [expout], [ignore])
197
198 sed '/GOB2_CHECK/c\
199 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER_P1]))[)]' configure.ac >configure.new
200 mv -f configure.new configure.ac
201 AT_CHECK([$AUTOCONF --force])
202 AT_CHECK([./configure], [1], [ignore], [ignore])
203
204 AT_CLEANUP