]> git.draconx.ca Git - dxcommon.git/blobdiff - tests/libs.at
dx_getline: Fix EOF handling in standard C fallback.
[dxcommon.git] / tests / libs.at
index cc09cead3a26e280d9d9ee97e09ac5cdbe08127d..8a7be8d59b0a7cd5a45484d7265a21b62ba983fe 100644 (file)
@@ -1,17 +1,17 @@
-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.
+# Copyright © 2019-2020, 2022-2024 Nick Bowler
+#
+# License GPLv3+: GNU General Public License version 3 or any later version.
+# This is free software: you are free to change and redistribute it.
+# 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.
+# TEST_DUMMY_PKGCONFIG([cflags], [libs])
+#
+# Create a hack pkg-config script in the current working directory which
+# responds to --cflags and --libs with the provided values.  The macro
+# arguments should each be a single shell word, suitable for the right
+# hand side of a shell assignment.
 m4_define([TEST_DUMMY_PKGCONFIG],
 [[cat >pkg-config <<EOF
 #!/bin/sh
@@ -21,6 +21,7 @@ do
   case \$arg in
   --cflags) cflags=]$1[;;
   --libs) libs=]$2[;;
+  --atleast-pkgconfig-version) exit;;
   esac
 done
 printf '%s %s\n' "\$cflags" "\$libs"
@@ -29,7 +30,7 @@ chmod +x pkg-config
 ]])
 
 AT_SETUP([libdiscid probes])
-AT_KEYWORDS([libdiscid])
+AT_KEYWORDS([lib libdiscid])
 
 mkdir discid
 AT_DATA([discid/discid.h],
@@ -86,6 +87,194 @@ AT_CHECK_UNQUOTED([cat test], [0], [no
 
 AT_CLEANUP
 
+AT_SETUP([curses probes])
+AT_KEYWORDS([lib curses ncurses])
+
+AT_DATA([curses.h],
+[[void initscr(void) { }
+void endwin(void) { }
+void curs_set(int);
+]])
+
+AT_DATA([test.in],
+[[@HAVE_CURSES@
+@CURSES_CFLAGS@
+@CURSES_LIBS@
+]])
+
+TEST_CONFIGURE_AC([[DX_LIB_CURSES([HAVE_CURSES=yes], [HAVE_CURSES=no])
+AC_SUBST([HAVE_CURSES])
+AC_CONFIG_FILES([test])
+]])
+TEST_AUTORECONF
+
+# Check the search via explicit flags
+TEST_CONFIGURE([CURSES_CFLAGS=-I. CURSES_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 -lcurses search
+cp "$builddir/t/libdummy.a" libcurses.a
+TEST_CONFIGURE([PKG_CONFIG=false CFLAGS=-I. LDFLAGS=-L.])
+AT_CHECK_UNQUOTED([cat test], [0], [yes
+
+-lcurses
+])
+
+# Check the failure case
+cp "$builddir/t/libempty.a" libcurses.a
+TEST_CONFIGURE([PKG_CONFIG=false CFLAGS=-I. LDFLAGS=-L.])
+AT_CHECK_UNQUOTED([cat test], [0], [no
+
+
+])
+
+AT_CLEANUP
+
+AT_SETUP([DX_CHECK_CURSES_GETMOUSE_NCURSES])
+AT_KEYWORDS([lib curses ncurses])
+
+mkdir ncurses sysv bogus
+AT_DATA([ncurses/curses.h],
+[[typedef struct MEVENT { int x; } MEVENT;
+int getmouse_nc_(MEVENT *);
+#define getmouse getmouse_nc_
+]])
+
+AT_DATA([sysv/curses.h],
+[[unsigned getmouse(void);
+]])
+
+AT_DATA([bogus/curses.h],
+[[typedef int MEVENT;
+int getmouse_bogus_(void *);
+#define getmouse getmouse_bogus_
+]])
+
+AT_DATA([test.in],
+[[@dx_cv_curses_have_getmouse_ncurses@
+]])
+
+TEST_CONFIGURE_AC([[AC_CONFIG_HEADERS([config.h])
+DX_CHECK_CURSES_GETMOUSE_NCURSES
+AC_SUBST([dx_cv_curses_have_getmouse_ncurses])
+AC_CONFIG_FILES([test])
+]])
+TEST_AUTORECONF
+
+TEST_CONFIGURE([CURSES_CFLAGS=-Incurses CURSES_LIBS="$builddir/t/libdummy.a"])
+AT_CHECK([cat test && grep HAVE_CURSES config.h], [0], [yes
+#define HAVE_CURSES_GETMOUSE_NCURSES 1
+])
+
+TEST_CONFIGURE([CURSES_CFLAGS=-Isysv CURSES_LIBS="$builddir/t/libdummy.a"])
+AT_CHECK([cat test && grep HAVE_CURSES config.h], [0], [no
+/* #undef HAVE_CURSES_GETMOUSE_NCURSES */
+])
+
+TEST_CONFIGURE([CURSES_CFLAGS=-Ibogus CURSES_LIBS="$builddir/t/libdummy.a"])
+AT_CHECK([cat test && grep HAVE_CURSES config.h], [0], [no
+/* #undef HAVE_CURSES_GETMOUSE_NCURSES */
+])
+
+AT_CLEANUP
+
+AT_SETUP([DX_CHECK_CURSES_MOUSE_SUPPORT])
+AT_KEYWORDS([lib curses ncurses])
+
+mkdir hp ncurses sysv
+
+# HP-UX 11 curses contains definitions of mouse functions in the library but
+# is missing declarations and associated macros in <curses.h>, although they
+# are present in the alternate "cur_colr" implementation.
+#
+# Regardless, neither implementation seems to have working mouse support with
+# any X terminal emulator so for now no workarounds are provided and the checks
+# are expected to return "no".
+AT_DATA([hp/curses.h],
+[[int mouse_set(unsigned long);
+int request_mouse_pos(void);
+]])
+
+# Ncurses-like mouse functions.
+AT_DATA([ncurses/curses.h],
+[[unsigned long mousemask(unsigned long, unsigned long *);
+typedef int MEVENT;
+int getmouse_nc_(MEVENT *);
+#define getmouse getmouse_nc_
+#define BUTTON1_RELEASED 1L
+#define BUTTON1_PRESSED 2L
+
+/* rename this to avoid false positives in the test */
+#define mouse_set mouse_set_bogus_
+]])
+
+# SysV-like mouse funcitons.
+AT_DATA([sysv/curses.h],
+[[int mouse_set(unsigned long);
+int request_mouse_pos(void);
+
+#define BUTTON_STATUS(x) 0
+#define BUTTON_RELEASED 0
+#define BUTTON_PRESSED 1
+
+#define BUTTON1_RELEASED 1L
+#define BUTTON1_PRESSED 2L
+]])
+
+AT_DATA([test.in],
+[[@dx_cv_curses_have_mouse_set@
+@dx_cv_curses_have_mousemask@
+@dx_cv_curses_have_getmouse_ncurses@
+@dx_cv_curses_have_request_mouse_pos@
+]])
+
+TEST_CONFIGURE_AC([[AC_CONFIG_HEADERS([config.h])
+DX_CHECK_CURSES_MOUSE_SUPPORT
+AC_SUBST([dx_cv_curses_have_mouse_set])
+AC_SUBST([dx_cv_curses_have_mousemask])
+AC_SUBST([dx_cv_curses_have_request_mouse_pos])
+AC_SUBST([dx_cv_curses_have_getmouse_ncurses])
+AC_CONFIG_FILES([test])
+]])
+TEST_AUTORECONF
+
+TEST_CONFIGURE([CURSES_CFLAGS=-Ihp CURSES_LIBS="$builddir/t/libdummy.a"])
+AT_CHECK([cat test && grep CURSES_MOUSE_SUPPORT config.h], [0], [no
+no
+
+
+/* #undef HAVE_CURSES_MOUSE_SUPPORT */
+])
+
+TEST_CONFIGURE([CURSES_CFLAGS=-Incurses CURSES_LIBS="$builddir/t/libdummy.a"])
+AT_CHECK([cat test && grep CURSES_MOUSE_SUPPORT config.h], [0], [no
+yes
+yes
+
+#define HAVE_CURSES_MOUSE_SUPPORT 1
+])
+
+TEST_CONFIGURE([CURSES_CFLAGS=-Isysv CURSES_LIBS="$builddir/t/libdummy.a"])
+AT_CHECK([cat test && grep CURSES_MOUSE_SUPPORT config.h], [0], [yes
+
+no
+yes
+#define HAVE_CURSES_MOUSE_SUPPORT 1
+])
+
+AT_CLEANUP
+
 AT_SETUP([GLib GNU inline workaround])
 
 TEST_DUMMY_PKGCONFIG([-I.], [$builddir/t/libdummy.a])
@@ -125,11 +314,15 @@ TEST_AUTORECONF
 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
 AT_CHECK([./test.sh], [0], [ignore], [ignore])
 
-AT_CHECK([grep G_INLINE_FUNC config.h], [0],
+AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
 [/* #undef G_INLINE_FUNC */
 ])
+AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
+[/* #undef G_IMPLEMENT_INLINES */
+])
 
-cat >>glib.h <<'EOF'
+cp glib.h glib-orig.h
+cat glib-orig.h - >glib.h <<'EOF'
 #ifndef G_INLINE_FUNC
 #  define G_INLINE_FUNC extern inline
 #endif
@@ -137,8 +330,115 @@ G_INLINE_FUNC void break_things(void) { }
 EOF
 
 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
-AT_CHECK([grep G_INLINE_FUNC config.h], [0],
+AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
 [#define G_INLINE_FUNC static inline
+])
+AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
+[/* #undef G_IMPLEMENT_INLINES */
+])
+
+cat glib-orig.h - >glib.h <<'EOF'
+#define G_INLINE_FUNC extern inline
+#ifdef G_IMPLEMENT_INLINES
+extern void break_things(void);
+#else
+G_INLINE_FUNC void break_things(void) { }
+#endif
+EOF
+
+TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
+AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
+[/* #undef G_INLINE_FUNC */
+])
+AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
+[#define G_IMPLEMENT_INLINES 1
+])
+
+AT_CLEANUP
+
+AT_SETUP([DX_CHECK_SYSLOG])
+
+AT_DATA([syslog.h],
+[[/* since syslog is normally in the standard C library, to make negative
+link tests possible we use a dummy external name */
+extern void dx_link_stub(void);
+
+static void openlog(const char *, int, int) { dx_link_stub(); }
+static void syslog(int, const char *, ...) { dx_link_stub(); }
+static void closelog(void) { dx_link_stub(); }
+
+#define LOG_PID  1
+#define LOG_USER 2
+#define LOG_ERR  0
+]])
+
+AT_DATA([test.in],
+[[@ac_cv_header_syslog_h@
+@dx_cv_have_syslog@
+]])
+
+TEST_CONFIGURE_AC([[DX_CHECK_SYSLOG
+AC_SUBST([ac_cv_header_syslog_h])
+AC_SUBST([dx_cv_have_syslog])
+AC_CONFIG_FILES([test])
+]])
+TEST_AUTORECONF
+
+TEST_CONFIGURE([CFLAGS=-I.])
+AT_CHECK([cat test], [0], [yes
+no
+])
+
+TEST_CONFIGURE([CFLAGS=-I. LIBS="$builddir/t/libdummy.a"])
+AT_CHECK([cat test], [0], [yes
+yes
+])
+
+AT_CLEANUP
+
+AT_SETUP([DX_CHECK_GETLINE])
+
+AT_DATA([stdio.h],
+[[/* since getline is normally in the standard C library, to make negative link
+tests possible we use a dummy external name */
+extern void dx_link_stub(void);
+typedef unsigned long size_t;
+typedef long ssize_t;
+typedef int FILE;
+
+static FILE stdin[1];
+
+#if !NO_GETLINE_DECL
+static size_t getline(char **line, size_t *n, FILE *f) { dx_link_stub(); }
+#endif
+]])
+
+AT_DATA([test.in],
+[[@dx_cv_have_getline@
+@DEFS@
+]])
+
+TEST_CONFIGURE_AC([[AC_PROG_CC
+CPPFLAGS="-I$srcdir $CPPFLAGS"
+DX_CHECK_GETLINE
+AC_SUBST([dx_cv_have_getline])
+AC_CONFIG_FILES([test])
+]])
+TEST_AUTORECONF
+
+TEST_CONFIGURE
+AT_CHECK([sed '[s/-DPACKAGE\([^\\ ]*\\.\)*[^ ]* *//g]' test], [0], [no
+
+])
+
+TEST_CONFIGURE([LIBS="$builddir/t/libdummy.a"])
+AT_CHECK([sed '[s/-DPACKAGE\([^\\ ]*\\.\)*[^ ]* *//g]' test], [0], [yes
+-DHAVE_GETLINE=1
+])
+
+TEST_CONFIGURE([CPPFLAGS="-DNO_GETLINE_DECL" LIBS="$builddir/t/libdummy.a"])
+AT_CHECK([sed '[s/-DPACKAGE\([^\\ ]*\\.\)*[^ ]* *//g]' test], [0], [no
+
 ])
 
 AT_CLEANUP