From: Bruno Haible Date: Sun, 11 Feb 2007 21:44:25 +0000 (+0000) Subject: Tests for module 'mbscasecmp'. X-Git-Tag: cvs-readonly~1082 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=aa2bb6c8cf19cf27f6c790f146b66fe443a156fe;p=gnulib.git Tests for module 'mbscasecmp'. --- diff --git a/ChangeLog b/ChangeLog index a02adbbf8..18c231d00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2007-02-11 Bruno Haible + * modules/mbscasecmp-tests: New file. + * tests/test-mbscasecmp.sh: New file. + * tests/test-mbscasecmp.c: New file. + +2007-02-11 Bruno Haible + Ensure O(n) worst-case complexity of mbscasestr. * lib/mbscasestr.c: Include stdbool.h. (knuth_morris_pratt_unibyte, knuth_morris_pratt_multibyte): New diff --git a/modules/mbscasecmp-tests b/modules/mbscasecmp-tests new file mode 100644 index 000000000..d715cc721 --- /dev/null +++ b/modules/mbscasecmp-tests @@ -0,0 +1,17 @@ +Files: +tests/test-mbscasecmp.sh +tests/test-mbscasecmp.c +m4/locale-tr.m4 +m4/codeset.m4 + +Depends-on: + +configure.ac: +gt_LOCALE_TR_UTF8 + +Makefile.am: +TESTS += test-mbscasecmp.sh +TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' LOCALE_TR_UTF8='@LOCALE_TR_UTF8@' +EXTRA_DIST += test-mbscasecmp.sh +check_PROGRAMS += test-mbscasecmp + diff --git a/tests/test-mbscasecmp.c b/tests/test-mbscasecmp.c new file mode 100644 index 000000000..5fd112714 --- /dev/null +++ b/tests/test-mbscasecmp.c @@ -0,0 +1,59 @@ +/* Test of case-insensitive string comparison function. + Copyright (C) 2007 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 2, 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include +#include + +#define ASSERT(expr) if (!(expr)) abort (); + +int +main () +{ + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + ASSERT (mbscasecmp ("paragraph", "Paragraph") == 0); + + ASSERT (mbscasecmp ("paragrapH", "parAgRaph") == 0); + + ASSERT (mbscasecmp ("paragraph", "paraLyzed") < 0); + ASSERT (mbscasecmp ("paraLyzed", "paragraph") > 0); + + ASSERT (mbscasecmp ("para", "paragraph") < 0); + ASSERT (mbscasecmp ("paragraph", "para") > 0); + + /* The following tests shows how mbscasecmp() is different from + strcasecmp(). */ + + ASSERT (mbscasecmp ("\303\266zg\303\274r", "\303\226ZG\303\234R") == 0); /* özgür */ + ASSERT (mbscasecmp ("\303\226ZG\303\234R", "\303\266zg\303\274r") == 0); /* özgür */ + + /* This test shows how strings of different size can compare equal. */ + ASSERT (mbscasecmp ("turkish", "TURK\304\260SH") == 0); + ASSERT (mbscasecmp ("TURK\304\260SH", "turkish") == 0); + + return 0; +} diff --git a/tests/test-mbscasecmp.sh b/tests/test-mbscasecmp.sh new file mode 100755 index 000000000..1ec7d5e80 --- /dev/null +++ b/tests/test-mbscasecmp.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Test whether a specific Turkish locale is installed. +: ${LOCALE_TR_UTF8=tr_TR.UTF-8} +if test $LOCALE_TR_UTF8 = none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no turkish Unicode locale is installed" + else + echo "Skipping test: no turkish Unicode locale is supported" + fi + exit 77 +fi + +LC_ALL=$LOCALE_TR_UTF8 \ +./test-mbscasecmp${EXEEXT}