Tests for module 'mbscasecmp'.
authorBruno Haible <bruno@clisp.org>
Sun, 11 Feb 2007 21:44:25 +0000 (21:44 +0000)
committerBruno Haible <bruno@clisp.org>
Sun, 11 Feb 2007 21:44:25 +0000 (21:44 +0000)
ChangeLog
modules/mbscasecmp-tests [new file with mode: 0644]
tests/test-mbscasecmp.c [new file with mode: 0644]
tests/test-mbscasecmp.sh [new file with mode: 0755]

index a02adbb..18c231d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 (file)
index 0000000..d715cc7
--- /dev/null
@@ -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 (file)
index 0000000..5fd1127
--- /dev/null
@@ -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 (executable)
index 0000000..1ec7d5e
--- /dev/null
@@ -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}