]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
libtextstyle: Implement 'installcheck' target.
authorBruno Haible <bruno@clisp.org>
Thu, 19 Jun 2025 09:42:59 +0000 (11:42 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 19 Jun 2025 09:45:26 +0000 (11:45 +0200)
* libtextstyle/install-tests/test-version.c: New file.
* libtextstyle/install-tests/test-api.c: New file.
* libtextstyle/install-tests/Makefile.am: New file.
* libtextstyle/configure.ac (AUGMENT_SHLIBPATH): New variable.
(AC_CONFIG_FILES): Add install-tests/Makefile.
* libtextstyle/Makefile.am (SUBDIRS): Add install-tests.

libtextstyle/Makefile.am
libtextstyle/configure.ac
libtextstyle/install-tests/Makefile.am [new file with mode: 0644]
libtextstyle/install-tests/test-api.c [new file with mode: 0644]
libtextstyle/install-tests/test-version.c [new file with mode: 0644]

index 4a363cde107906dbe43113ef519e9442f1ba69e9..e06ec61ec68b52d54e1faac1b59d807697459f23 100644 (file)
@@ -1,5 +1,5 @@
 ## Makefile for the toplevel directory of GNU libtextstyle
-## Copyright (C) 1995-2024 Free Software Foundation, Inc.
+## Copyright (C) 1995-2025 Free Software Foundation, Inc.
 ##
 ## This program is free software: you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -20,7 +20,7 @@ AUTOMAKE_OPTIONS = 1.13 gnu
 ACLOCAL_AMFLAGS = -I m4 -I gnulib-m4
 
 # The list of subdirectories containing Makefiles.
-SUBDIRS = lib tests adhoc-tests doc
+SUBDIRS = lib tests adhoc-tests install-tests doc
 
 EXTRA_DIST = \
   version.sh \
index dce1439e40f34d737f16e2e95e442b2c6a72edfb..12317ce1c17178ea1d6fdd39ad8aab5cc5d1c7da 100644 (file)
@@ -170,6 +170,19 @@ AC_PATH_PROG([TEXI2DVI], [texi2dvi], [$ac_aux_dir_abs/missing texi2dvi])
 AC_PATH_PROG([DVIPS], [dvips], [$ac_aux_dir_abs/missing dvips])
 AC_PATH_PROG([PERL], [perl], [$ac_aux_dir_abs/missing perl])
 
+dnl Test for features used in install-tests.
+dnl shlibpath_var and PATH_SEPARATOR are set by LT_INIT.
+if test -n "${shlibpath_var}"; then
+  if test "${shlibpath_var}" = PATH; then
+    AUGMENT_SHLIBPATH="PATH='\$(bindir)'${PATH_SEPARATOR}\"\$\$PATH\";"
+  else
+    AUGMENT_SHLIBPATH="${shlibpath_var}='\$(libdir)':\"\$\$${shlibpath_var}\"; export ${shlibpath_var};"
+  fi
+else
+  AUGMENT_SHLIBPATH=
+fi
+AC_SUBST([AUGMENT_SHLIBPATH])
+
 AC_CONFIG_FILES([Makefile])
 AC_CONFIG_FILES([doc/Makefile])
 AC_CONFIG_FILES([lib/Makefile])
@@ -178,4 +191,5 @@ AC_CONFIG_FILES([lib/textstyle/version.h:lib/textstyle/version.in.h])
 AC_CONFIG_FILES([lib/textstyle/woe32dll.h:lib/textstyle/woe32dll.in.h])
 AC_CONFIG_FILES([tests/Makefile])
 AC_CONFIG_FILES([adhoc-tests/Makefile])
+AC_CONFIG_FILES([install-tests/Makefile])
 AC_OUTPUT
diff --git a/libtextstyle/install-tests/Makefile.am b/libtextstyle/install-tests/Makefile.am
new file mode 100644 (file)
index 0000000..7f833b1
--- /dev/null
@@ -0,0 +1,35 @@
+## Makefile for libtextstyle/install-tests.
+## Copyright (C) 2025 Free Software Foundation, Inc.
+##
+## This program is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+## Process this file with automake to produce Makefile.in.
+
+installcheck-local:
+       $(CC) -I$(includedir) -L$(libdir) \
+             $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+             $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
+             -o test-version $(srcdir)/test-version.c -ltextstyle
+       @AUGMENT_SHLIBPATH@ ./test-version
+       rm -rf test-version test-version$(EXEEXT)
+       $(CC) -I$(includedir) -L$(libdir) \
+             $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+             -DTOP_SRCDIR=\"$(top_srcdir)/\" \
+             $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
+             -o test-api $(srcdir)/test-api.c -ltextstyle
+       @AUGMENT_SHLIBPATH@ ./test-api
+       rm -rf test-api test-api$(EXEEXT)
+
+EXTRA_DIST = test-version.c test-api.c
+CLEANFILES = test-version test-version$(EXEEXT) test-api test-api$(EXEEXT)
diff --git a/libtextstyle/install-tests/test-api.c b/libtextstyle/install-tests/test-api.c
new file mode 100644 (file)
index 0000000..dc5fc15
--- /dev/null
@@ -0,0 +1,90 @@
+/* Test parts of the API.
+   Copyright (C) 2018-2025 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2025.  */
+
+#include <textstyle.h>
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int
+main ()
+{
+  /* Test based on libtextstyle/adhoc-tests/hello.c.  */
+
+  memory_ostream_t mstream = memory_ostream_create ();
+
+  style_file_name = TOP_SRCDIR "adhoc-tests/hello-default.css";
+  styled_ostream_t stream =
+    html_styled_ostream_create (mstream, style_file_name);
+
+  ostream_write_str (stream, "Hello ");
+
+  /* Associate the entire full name in CSS class 'name'.  */
+  styled_ostream_begin_use_class (stream, "name");
+
+  ostream_write_str (stream, "Dr. ");
+  styled_ostream_begin_use_class (stream, "boy-name");
+  /* Start a hyperlink.  */
+  styled_ostream_set_hyperlink (stream, "https://en.wikipedia.org/wiki/Linus_Pauling", NULL);
+  ostream_write_str (stream, "Linus");
+  styled_ostream_end_use_class (stream, "boy-name");
+  ostream_write_str (stream, " Pauling");
+  /* End the current hyperlink.  */
+  styled_ostream_set_hyperlink (stream, NULL, NULL);
+
+  /* Terminate the name.  */
+  styled_ostream_end_use_class (stream, "name");
+
+  ostream_write_str (stream, "!\n");
+
+  /* Flush and close the stream.  */
+  styled_ostream_free (stream);
+
+  const void *buf;
+  size_t buflen;
+  memory_ostream_contents (mstream, &buf, &buflen);
+
+  const char *expected =
+    "<?xml version=\"1.0\"?>\n"
+    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n"
+    "<html>\n"
+    "<head>\n"
+    "<style type=\"text/css\">\n"
+    "<!--\n"
+    "/* This file is in the public domain.\n"
+    "\n"
+    "   Styling rules for the color-hello example.  */\n"
+    "\n"
+    ".name      { text-decoration : underline; }\n"
+    ".boy-name  { background-color : rgb(123,201,249); }\n"
+    ".girl-name { background-color : rgb(250,149,158); }\n"
+    "-->\n"
+    "</style>\n"
+    "</head>\n"
+    "<body>\n"
+    "Hello&nbsp;<span class=\"name\">Dr.&nbsp;</span><a href=\"https://en.wikipedia.org/wiki/Linus_Pauling\"><span class=\"name\"><span class=\"boy-name\">Linus</span>&nbsp;Pauling</span></a>!<br/></body>\n"
+    "</html>\n";
+  assert (buflen == strlen (expected));
+  assert (memcmp ((const char *) buf, expected, buflen) == 0);
+
+  ostream_free (mstream);
+
+  return 0;
+}
diff --git a/libtextstyle/install-tests/test-version.c b/libtextstyle/install-tests/test-version.c
new file mode 100644 (file)
index 0000000..0b2afe4
--- /dev/null
@@ -0,0 +1,33 @@
+/* Test the version information.
+   Copyright (C) 2025 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2025.  */
+
+#include <textstyle.h>
+
+#include <stdio.h>
+
+int
+main ()
+{
+  if (!(_libtextstyle_version == _LIBTEXTSTYLE_VERSION))
+    {
+      fprintf (stderr, "Installation problem: include file says version 0x%x, whereas library says version 0x%x\n",
+               _LIBTEXTSTYLE_VERSION, _libtextstyle_version);
+      return 1;
+    }
+  return 0;
+}