Tests for module 'mbsinit'.
authorBruno Haible <bruno@clisp.org>
Fri, 19 Dec 2008 02:34:16 +0000 (03:34 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 19 Dec 2008 02:34:16 +0000 (03:34 +0100)
ChangeLog
modules/mbsinit-tests [new file with mode: 0644]
tests/test-mbsinit.c [new file with mode: 0644]
tests/test-mbsinit.sh [new file with mode: 0755]

index 3e920fe..a7a3c31 100644 (file)
--- 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 (file)
index 0000000..9dead7d
--- /dev/null
@@ -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 (file)
index 0000000..5d4c9c3
--- /dev/null
@@ -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 (executable)
index 0000000..bbda48d
--- /dev/null
@@ -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}