From: Bruno Haible Date: Fri, 19 Dec 2008 02:34:16 +0000 (+0100) Subject: Tests for module 'mbsinit'. X-Git-Tag: v0.1~6577 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=bc7cb38da9d3ee6dcbf20f0dbbcf9cc6e29a04b6;p=gnulib.git Tests for module 'mbsinit'. --- diff --git a/ChangeLog b/ChangeLog index 3e920fe62..a7a3c31f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2008-12-18 Bruno Haible + * modules/mbsinit-tests: New file. + * tests/test-mbsinit.sh: New file. + * tests/test-mbsinit.c: New file. + +2008-12-18 Bruno Haible + * 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 000000000..9dead7d9b --- /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 000000000..5d4c9c3ae --- /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 . */ + +/* Written by Bruno Haible , 2008. */ + +#include + +#include + +#include +#include +#include + +#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 000000000..bbda48d2c --- /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}