]> 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 89ecf67eb2f563a8f83eb1a3c24a2479350dafbc..8a7be8d59b0a7cd5a45484d7265a21b62ba983fe 100644 (file)
@@ -1,17 +1,17 @@
-dnl Copyright © 2019-2020, 2022 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
@@ -141,6 +141,140 @@ 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])
@@ -221,3 +355,90 @@ AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
 ])
 
 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