]> git.draconx.ca Git - dxcommon.git/blob - tests/libs.at
Add library test for curses.
[dxcommon.git] / tests / libs.at
1 dnl Copyright © 2019-2020, 2022 Nick Bowler
2 dnl
3 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
4 dnl This is free software: you are free to do what the fuck you want to.
5 dnl There is NO WARRANTY, to the extent permitted by law.
6
7 AT_BANNER([Library tests])
8
9 dnl TEST_DUMMY_PKGCONFIG([cflags], [libs])
10 dnl
11 dnl Create a hack pkg-config script in the current working directory which
12 dnl responds to --cflags and --libs with the provided values.  The macro
13 dnl arguments should each be a single shell word, suitable for the right
14 dnl hand side of a shell assignment.
15 m4_define([TEST_DUMMY_PKGCONFIG],
16 [[cat >pkg-config <<EOF
17 #!/bin/sh
18 cflags= libs=
19 for arg
20 do
21   case \$arg in
22   --cflags) cflags=]$1[;;
23   --libs) libs=]$2[;;
24   --atleast-pkgconfig-version) exit;;
25   esac
26 done
27 printf '%s %s\n' "\$cflags" "\$libs"
28 EOF
29 chmod +x pkg-config
30 ]])
31
32 AT_SETUP([libdiscid probes])
33 AT_KEYWORDS([lib libdiscid])
34
35 mkdir discid
36 AT_DATA([discid/discid.h],
37 [[typedef void DiscId;
38 DiscId *discid_new(void);
39 void discid_free(DiscId *);
40 #ifndef DISCID_VERSION_MAJOR
41 #  define DISCID_VERSION_MAJOR 2
42 #endif
43 ]])
44
45 AT_DATA([test.in],
46 [[@HAVE_LIBDISCID@
47 @LIBDISCID_CFLAGS@
48 @LIBDISCID_LIBS@
49 ]])
50
51 TEST_CONFIGURE_AC([[DX_LIB_LIBDISCID([1.2.3], [HAVE_LIBDISCID=yes],
52                                               [HAVE_LIBDISCID=no])
53 AC_SUBST([HAVE_LIBDISCID])
54 AC_CONFIG_FILES([test])
55 ]])
56 TEST_AUTORECONF
57
58 # Check the search via explicit flags
59 TEST_CONFIGURE([LIBDISCID_CFLAGS=-I. LIBDISCID_LIBS="$builddir/t/libdummy.a"])
60 AT_CHECK_UNQUOTED([cat test], [0], [yes
61 -I.
62 $builddir/t/libdummy.a
63 ])
64
65 # Check the search via pkg-config
66 TEST_DUMMY_PKGCONFIG([-I.], [$builddir/t/libdummy.a])
67 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
68 AT_CHECK_UNQUOTED([cat test], [0], [yes
69 -I.
70 $builddir/t/libdummy.a
71 ])
72
73 # Check the default -ldiscid search
74 cp "$builddir/t/libdummy.a" libdiscid.a
75 TEST_CONFIGURE([PKG_CONFIG=false CFLAGS=-I. LDFLAGS=-L.])
76 AT_CHECK_UNQUOTED([cat test], [0], [yes
77
78 -ldiscid
79 ])
80
81 # Check the failure case
82 TEST_CONFIGURE([PKG_CONFIG=false CFLAGS='-I. -DDISCID_VERSION_MAJOR=0'])
83 AT_CHECK_UNQUOTED([cat test], [0], [no
84
85
86 ])
87
88 AT_CLEANUP
89
90 AT_SETUP([curses probes])
91 AT_KEYWORDS([lib curses ncurses])
92
93 AT_DATA([curses.h],
94 [[void initscr(void) { }
95 void endwin(void) { }
96 void curs_set(int);
97 ]])
98
99 AT_DATA([test.in],
100 [[@HAVE_CURSES@
101 @CURSES_CFLAGS@
102 @CURSES_LIBS@
103 ]])
104
105 TEST_CONFIGURE_AC([[DX_LIB_CURSES([HAVE_CURSES=yes], [HAVE_CURSES=no])
106 AC_SUBST([HAVE_CURSES])
107 AC_CONFIG_FILES([test])
108 ]])
109 TEST_AUTORECONF
110
111 # Check the search via explicit flags
112 TEST_CONFIGURE([CURSES_CFLAGS=-I. CURSES_LIBS="$builddir/t/libdummy.a"])
113 AT_CHECK_UNQUOTED([cat test], [0], [yes
114 -I.
115 $builddir/t/libdummy.a
116 ])
117
118 # Check the search via pkg-config
119 TEST_DUMMY_PKGCONFIG([-I.], [$builddir/t/libdummy.a])
120 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
121 AT_CHECK_UNQUOTED([cat test], [0], [yes
122 -I.
123 $builddir/t/libdummy.a
124 ])
125
126 # Check the default -lcurses search
127 cp "$builddir/t/libdummy.a" libcurses.a
128 TEST_CONFIGURE([PKG_CONFIG=false CFLAGS=-I. LDFLAGS=-L.])
129 AT_CHECK_UNQUOTED([cat test], [0], [yes
130
131 -lcurses
132 ])
133
134 # Check the failure case
135 cp "$builddir/t/libempty.a" libcurses.a
136 TEST_CONFIGURE([PKG_CONFIG=false CFLAGS=-I. LDFLAGS=-L.])
137 AT_CHECK_UNQUOTED([cat test], [0], [no
138
139
140 ])
141
142 AT_CLEANUP
143
144 AT_SETUP([GLib GNU inline workaround])
145
146 TEST_DUMMY_PKGCONFIG([-I.], [$builddir/t/libdummy.a])
147
148 # This test will only work if we have a version of GCC that implements
149 # C99 inline semantics by default.
150 AT_DATA([a.c],
151 [[#if __GNUC__
152 extern inline void my_dup_fn(void) { }
153 #endif
154 int main(void) { return 0; }
155 ]])
156 AT_DATA([b.c],
157 [[#if __GNUC__
158 extern inline void my_dup_fn(void) { }
159 #endif
160 ]])
161
162 AT_DATA([test.sh.in],
163 [[#!/bin/sh
164 @CC@ @CPPFLAGS@ @CFLAGS@ -c a.c || exit 77
165 @CC@ @CPPFLAGS@ @CFLAGS@ -c b.c || exit 77
166 @CC@ @CFLAGS@ @LDFLAGS@ a.o b.o || exit 0
167 exit 77
168 ]])
169
170 AT_DATA([glib.h],
171 [[#define GLIB_CHECK_VERSION(x, y, z) 1
172 const char *g_get_prgname(void);
173 ]])
174
175 TEST_CONFIGURE_AC([[AC_CONFIG_HEADERS([config.h])
176 DX_LIB_GLIB2
177 AC_CONFIG_FILES([test.sh], [chmod +x test.sh])
178 ]])
179 TEST_AUTORECONF
180 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
181 AT_CHECK([./test.sh], [0], [ignore], [ignore])
182
183 AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
184 [/* #undef G_INLINE_FUNC */
185 ])
186 AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
187 [/* #undef G_IMPLEMENT_INLINES */
188 ])
189
190 cp glib.h glib-orig.h
191 cat glib-orig.h - >glib.h <<'EOF'
192 #ifndef G_INLINE_FUNC
193 #  define G_INLINE_FUNC extern inline
194 #endif
195 G_INLINE_FUNC void break_things(void) { }
196 EOF
197
198 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
199 AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
200 [#define G_INLINE_FUNC static inline
201 ])
202 AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
203 [/* #undef G_IMPLEMENT_INLINES */
204 ])
205
206 cat glib-orig.h - >glib.h <<'EOF'
207 #define G_INLINE_FUNC extern inline
208 #ifdef G_IMPLEMENT_INLINES
209 extern void break_things(void);
210 #else
211 G_INLINE_FUNC void break_things(void) { }
212 #endif
213 EOF
214
215 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
216 AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
217 [/* #undef G_INLINE_FUNC */
218 ])
219 AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
220 [#define G_IMPLEMENT_INLINES 1
221 ])
222
223 AT_CLEANUP