diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | modules/mbscasecmp-tests | 17 | ||||
-rw-r--r-- | tests/test-mbscasecmp.c | 59 | ||||
-rwxr-xr-x | tests/test-mbscasecmp.sh | 15 |
4 files changed, 97 insertions, 0 deletions
@@ -1,5 +1,11 @@ 2007-02-11 Bruno Haible <bruno@clisp.org> + * modules/mbscasecmp-tests: New file. + * tests/test-mbscasecmp.sh: New file. + * tests/test-mbscasecmp.c: New file. + +2007-02-11 Bruno Haible <bruno@clisp.org> + 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 0000000000..d715cc7212 --- /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 0000000000..5fd1127147 --- /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 <bruno@clisp.org>, 2007. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <string.h> + +#include <locale.h> +#include <stdlib.h> + +#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 0000000000..1ec7d5e807 --- /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} |