Mercurial > hg > octave-lyh > gnulib-hg
changeset 10908:bcd9ca0eda6e
Tests for module 'mbsinit'.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 19 Dec 2008 03:34:16 +0100 |
parents | 9ad8bcddd5f9 |
children | 796f25c7bd1a |
files | ChangeLog modules/mbsinit-tests tests/test-mbsinit.c tests/test-mbsinit.sh |
diffstat | 4 files changed, 100 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +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.
new file mode 100644 --- /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 +
new file mode 100644 --- /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; +}
new file mode 100755 --- /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}