summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2007-02-11 21:44:25 +0000
committerBruno Haible <bruno@clisp.org>2007-02-11 21:44:25 +0000
commitaa2bb6c8cf19cf27f6c790f146b66fe443a156fe (patch)
treed923913163e56a9bff8d3ec3ed62703a62a73cd8 /tests
parent35aa104af1bc1bd8263bde7c4202406845403f83 (diff)
downloadgnulib-aa2bb6c8cf19cf27f6c790f146b66fe443a156fe.tar.gz
Tests for module 'mbscasecmp'.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-mbscasecmp.c59
-rwxr-xr-xtests/test-mbscasecmp.sh15
2 files changed, 74 insertions, 0 deletions
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}