summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2008-12-19 03:34:16 +0100
committerBruno Haible <bruno@clisp.org>2008-12-19 03:34:16 +0100
commitbc7cb38da9d3ee6dcbf20f0dbbcf9cc6e29a04b6 (patch)
tree2d13a88660646dcc63af2707fa5c489845453810
parentbbac77e3c8118a4e0c689cbcf34100f9b0bff426 (diff)
downloadgnulib-bc7cb38da9d3ee6dcbf20f0dbbcf9cc6e29a04b6.tar.gz
Tests for module 'mbsinit'.
-rw-r--r--ChangeLog6
-rw-r--r--modules/mbsinit-tests17
-rw-r--r--tests/test-mbsinit.c62
-rwxr-xr-xtests/test-mbsinit.sh15
4 files changed, 100 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 3e920fe621..a7a3c31f24 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2008-12-18 Bruno Haible <bruno@clisp.org>
+ * modules/mbsinit-tests: New file.
+ * tests/test-mbsinit.sh: New file.
+ * tests/test-mbsinit.c: New file.
+
+2008-12-18 Bruno Haible <bruno@clisp.org>
+
* modules/mbrtowc-tests: New file.
* tests/test-mbrtowc1.sh: New file.
* tests/test-mbrtowc2.sh: New file.
diff --git a/modules/mbsinit-tests b/modules/mbsinit-tests
new file mode 100644
index 0000000000..9dead7d9b0
--- /dev/null
+++ b/modules/mbsinit-tests
@@ -0,0 +1,17 @@
+Files:
+tests/test-mbsinit.sh
+tests/test-mbsinit.c
+m4/locale-fr.m4
+m4/codeset.m4
+
+Depends-on:
+mbrtowc
+
+configure.ac:
+gt_LOCALE_FR_UTF8
+
+Makefile.am:
+TESTS += test-mbsinit.sh
+TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' LOCALE_FR_UTF8='@LOCALE_FR_UTF8@'
+check_PROGRAMS += test-mbsinit
+
diff --git a/tests/test-mbsinit.c b/tests/test-mbsinit.c
new file mode 100644
index 0000000000..5d4c9c3aed
--- /dev/null
+++ b/tests/test-mbsinit.c
@@ -0,0 +1,62 @@
+/* Test of test for initial conversion state.
+ Copyright (C) 2008 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 <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2008. */
+
+#include <config.h>
+
+#include <wchar.h>
+
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define ASSERT(expr) \
+ do \
+ { \
+ if (!(expr)) \
+ { \
+ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+ fflush (stderr); \
+ abort (); \
+ } \
+ } \
+ while (0)
+
+int
+main (int argc, char *argv[])
+{
+ static mbstate_t state;
+
+ ASSERT (mbsinit (&state));
+
+ if (argc > 1)
+ {
+ static const char input[1] = "\303";
+ wchar_t wc;
+ size_t ret;
+
+ /* configure should already have checked that the locale is supported. */
+ if (setlocale (LC_ALL, "") == NULL)
+ return 1;
+
+ ret = mbrtowc (&wc, input, 1, &state);
+ ASSERT (ret == (size_t)(-2));
+ ASSERT (!mbsinit (&state));
+ }
+
+ return 0;
+}
diff --git a/tests/test-mbsinit.sh b/tests/test-mbsinit.sh
new file mode 100755
index 0000000000..bbda48d2c2
--- /dev/null
+++ b/tests/test-mbsinit.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Test whether a specific UTF-8 locale is installed.
+: ${LOCALE_FR_UTF8=fr_FR.UTF-8}
+if test $LOCALE_FR_UTF8 = none; then
+ if test -f /usr/bin/localedef; then
+ echo "Skipping test: no french Unicode locale is installed"
+ else
+ echo "Skipping test: no french Unicode locale is supported"
+ fi
+ exit 77
+fi
+
+LC_ALL=$LOCALE_FR_UTF8 \
+./test-mbsinit${EXEEXT}