]> git.draconx.ca Git - dxcommon.git/blob - tests/libs.at
ab348ded7bbb3d95650c8ebc6852c10d68b3c6ee
[dxcommon.git] / tests / libs.at
1 dnl Copyright © 2019 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   esac
25 done
26 printf '%s %s\n' "\$cflags" "\$libs"
27 EOF
28 chmod +x pkg-config
29 ]])
30
31 AT_SETUP([libdiscid probes])
32 AT_KEYWORDS([libdiscid])
33
34 mkdir discid
35 AT_DATA([discid/discid.h],
36 [[typedef void DiscId;
37 DiscId *discid_new(void);
38 void discid_free(DiscId *);
39 #ifndef DISCID_VERSION_MAJOR
40 #  define DISCID_VERSION_MAJOR 2
41 #endif
42 ]])
43
44 AT_DATA([test.in],
45 [[@HAVE_LIBDISCID@
46 @LIBDISCID_CFLAGS@
47 @LIBDISCID_LIBS@
48 ]])
49
50 TEST_CONFIGURE_AC([[DX_LIB_LIBDISCID([1.2.3], [HAVE_LIBDISCID=yes],
51                                               [HAVE_LIBDISCID=no])
52 AC_SUBST([HAVE_LIBDISCID])
53 AC_CONFIG_FILES([test])
54 ]])
55 TEST_AUTORECONF
56
57 # Check the search via explicit flags
58 TEST_CONFIGURE([LIBDISCID_CFLAGS=-I. LIBDISCID_LIBS="$builddir/t/libdummy.a"])
59 AT_CHECK_UNQUOTED([cat test], [0], [yes
60 -I.
61 $builddir/t/libdummy.a
62 ])
63
64 # Check the search via pkg-config
65 TEST_DUMMY_PKGCONFIG([-I.], [$builddir/t/libdummy.a])
66 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
67 AT_CHECK_UNQUOTED([cat test], [0], [yes
68 -I.
69 $builddir/t/libdummy.a
70 ])
71
72 # Check the default -ldiscid search
73 cp "$builddir/t/libdummy.a" libdiscid.a
74 TEST_CONFIGURE([PKG_CONFIG=false CFLAGS=-I. LDFLAGS=-L.])
75 AT_CHECK_UNQUOTED([cat test], [0], [yes
76
77 -ldiscid
78 ])
79
80 # Check the failure case
81 TEST_CONFIGURE([PKG_CONFIG=false CFLAGS='-I. -DDISCID_VERSION_MAJOR=0'])
82 AT_CHECK_UNQUOTED([cat test], [0], [no
83
84
85 ])
86
87 AT_CLEANUP