]> git.draconx.ca Git - dxcommon.git/blobdiff - tests/libs.at
Add library test for libdiscid
[dxcommon.git] / tests / libs.at
diff --git a/tests/libs.at b/tests/libs.at
new file mode 100644 (file)
index 0000000..ab348de
--- /dev/null
@@ -0,0 +1,87 @@
+dnl Copyright © 2019 Nick Bowler
+dnl
+dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
+dnl This is free software: you are free to do what the fuck you want to.
+dnl There is NO WARRANTY, to the extent permitted by law.
+
+AT_BANNER([Library tests])
+
+dnl TEST_DUMMY_PKGCONFIG([cflags], [libs])
+dnl
+dnl Create a hack pkg-config script in the current working directory which
+dnl responds to --cflags and --libs with the provided values.  The macro
+dnl arguments should each be a single shell word, suitable for the right
+dnl hand side of a shell assignment.
+m4_define([TEST_DUMMY_PKGCONFIG],
+[[cat >pkg-config <<EOF
+#!/bin/sh
+cflags= libs=
+for arg
+do
+  case \$arg in
+  --cflags) cflags=]$1[;;
+  --libs) libs=]$2[;;
+  esac
+done
+printf '%s %s\n' "\$cflags" "\$libs"
+EOF
+chmod +x pkg-config
+]])
+
+AT_SETUP([libdiscid probes])
+AT_KEYWORDS([libdiscid])
+
+mkdir discid
+AT_DATA([discid/discid.h],
+[[typedef void DiscId;
+DiscId *discid_new(void);
+void discid_free(DiscId *);
+#ifndef DISCID_VERSION_MAJOR
+#  define DISCID_VERSION_MAJOR 2
+#endif
+]])
+
+AT_DATA([test.in],
+[[@HAVE_LIBDISCID@
+@LIBDISCID_CFLAGS@
+@LIBDISCID_LIBS@
+]])
+
+TEST_CONFIGURE_AC([[DX_LIB_LIBDISCID([1.2.3], [HAVE_LIBDISCID=yes],
+                                              [HAVE_LIBDISCID=no])
+AC_SUBST([HAVE_LIBDISCID])
+AC_CONFIG_FILES([test])
+]])
+TEST_AUTORECONF
+
+# Check the search via explicit flags
+TEST_CONFIGURE([LIBDISCID_CFLAGS=-I. LIBDISCID_LIBS="$builddir/t/libdummy.a"])
+AT_CHECK_UNQUOTED([cat test], [0], [yes
+-I.
+$builddir/t/libdummy.a
+])
+
+# Check the search via pkg-config
+TEST_DUMMY_PKGCONFIG([-I.], [$builddir/t/libdummy.a])
+TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
+AT_CHECK_UNQUOTED([cat test], [0], [yes
+-I.
+$builddir/t/libdummy.a
+])
+
+# Check the default -ldiscid search
+cp "$builddir/t/libdummy.a" libdiscid.a
+TEST_CONFIGURE([PKG_CONFIG=false CFLAGS=-I. LDFLAGS=-L.])
+AT_CHECK_UNQUOTED([cat test], [0], [yes
+
+-ldiscid
+])
+
+# Check the failure case
+TEST_CONFIGURE([PKG_CONFIG=false CFLAGS='-I. -DDISCID_VERSION_MAJOR=0'])
+AT_CHECK_UNQUOTED([cat test], [0], [no
+
+
+])
+
+AT_CLEANUP