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

index 423e463..19f7d09 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2007-03-10  Bruno Haible  <bruno@clisp.org>
 
+       * modules/c-strcase-tests: New file.
+       * tests/test-c-strcase.sh: New file.
+       * tests/test-c-strcasecmp.c: New file.
+       * tests/test-c-strncasecmp.c: New file.
+
        * modules/atexit-tests: New file.
        * tests/test-atexit.sh: New file.
        * tests/test-atexit.c: New file.
diff --git a/modules/c-strcase-tests b/modules/c-strcase-tests
new file mode 100644 (file)
index 0000000..84173ad
--- /dev/null
@@ -0,0 +1,18 @@
+Files:
+tests/test-c-strcase.sh
+tests/test-c-strcasecmp.c
+tests/test-c-strncasecmp.c
+m4/locale-fr.m4
+m4/locale-tr.m4
+
+Depends-on:
+
+configure.ac:
+gt_LOCALE_FR
+gt_LOCALE_TR_UTF8
+
+Makefile.am:
+TESTS += test-c-strcase.sh
+TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' LOCALE_FR='@LOCALE_FR@' LOCALE_TR_UTF8='@LOCALE_TR_UTF8@'
+check_PROGRAMS += test-c-strcasecmp test-c-strncasecmp
+EXTRA_DIST += test-c-strcase.sh
diff --git a/tests/test-c-strcase.sh b/tests/test-c-strcase.sh
new file mode 100755 (executable)
index 0000000..5fcf906
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+# Test in the C locale.
+./test-c-strcasecmp${EXEEXT} || exit 1
+./test-c-strncasecmp${EXEEXT} || exit 1
+
+# Test in an ISO-8859-1 or ISO-8859-15 locale.
+: ${LOCALE_FR=fr_FR}
+if test $LOCALE_FR != none; then
+  LC_ALL=$LOCALE_FR ./test-c-strcasecmp${EXEEXT} locale || exit 1
+  LC_ALL=$LOCALE_FR ./test-c-strncasecmp${EXEEXT} locale || exit 1
+fi
+
+# Test in a Turkish UTF-8 locale.
+: ${LOCALE_TR_UTF8=tr_TR.UTF-8}
+if test $LOCALE_TR_UTF8 != none; then
+  LC_ALL=$LOCALE_TR_UTF8 ./test-c-strcasecmp${EXEEXT} locale || exit 1
+  LC_ALL=$LOCALE_TR_UTF8 ./test-c-strncasecmp${EXEEXT} locale || exit 1
+fi
+
+exit 0
diff --git a/tests/test-c-strcasecmp.c b/tests/test-c-strcasecmp.c
new file mode 100644 (file)
index 0000000..a7f65ec
--- /dev/null
@@ -0,0 +1,68 @@
+/* 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 (int argc, char *argv[])
+{
+  if (argc > 1)
+    {
+      /* configure should already have checked that the locale is supported.  */
+      if (setlocale (LC_ALL, "") == NULL)
+       return 1;
+    }
+
+  ASSERT (c_strcasecmp ("paragraph", "Paragraph") == 0);
+
+  ASSERT (c_strcasecmp ("paragrapH", "parAgRaph") == 0);
+
+  ASSERT (c_strcasecmp ("paragraph", "paraLyzed") < 0);
+  ASSERT (c_strcasecmp ("paraLyzed", "paragraph") > 0);
+
+  ASSERT (c_strcasecmp ("para", "paragraph") < 0);
+  ASSERT (c_strcasecmp ("paragraph", "para") > 0);
+
+  /* The following tests shows how c_strcasecmp() is different from
+     strcasecmp().  */
+
+  ASSERT (c_strcasecmp ("\311mile", "\351mile") < 0);
+  ASSERT (c_strcasecmp ("\351mile", "\311mile") > 0);
+
+  /* The following tests shows how c_strcasecmp() is different from
+     mbscasecmp().  */
+
+  ASSERT (c_strcasecmp ("\303\266zg\303\274r", "\303\226ZG\303\234R") > 0); /* özgür */
+  ASSERT (c_strcasecmp ("\303\226ZG\303\234R", "\303\266zg\303\274r") < 0); /* özgür */
+
+  /* This test shows how strings of different size cannot compare equal.  */
+  ASSERT (c_strcasecmp ("turkish", "TURK\304\260SH") < 0);
+  ASSERT (c_strcasecmp ("TURK\304\260SH", "turkish") > 0);
+
+  return 0;
+}
diff --git a/tests/test-c-strncasecmp.c b/tests/test-c-strncasecmp.c
new file mode 100644 (file)
index 0000000..4f1214c
--- /dev/null
@@ -0,0 +1,82 @@
+/* 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 (int argc, char *argv[])
+{
+  if (argc > 1)
+    {
+      /* configure should already have checked that the locale is supported.  */
+      if (setlocale (LC_ALL, "") == NULL)
+       return 1;
+    }
+
+  ASSERT (c_strncasecmp ("paragraph", "Paragraph", 1000000) == 0);
+  ASSERT (c_strncasecmp ("paragraph", "Paragraph", 9) == 0);
+
+  ASSERT (c_strncasecmp ("paragrapH", "parAgRaph", 1000000) == 0);
+  ASSERT (c_strncasecmp ("paragrapH", "parAgRaph", 9) == 0);
+
+  ASSERT (c_strncasecmp ("paragraph", "paraLyzed", 10) < 0);
+  ASSERT (c_strncasecmp ("paragraph", "paraLyzed", 9) < 0);
+  ASSERT (c_strncasecmp ("paragraph", "paraLyzed", 5) < 0);
+  ASSERT (c_strncasecmp ("paragraph", "paraLyzed", 4) == 0);
+  ASSERT (c_strncasecmp ("paraLyzed", "paragraph", 10) > 0);
+  ASSERT (c_strncasecmp ("paraLyzed", "paragraph", 9) > 0);
+  ASSERT (c_strncasecmp ("paraLyzed", "paragraph", 5) > 0);
+  ASSERT (c_strncasecmp ("paraLyzed", "paragraph", 4) == 0);
+
+  ASSERT (c_strncasecmp ("para", "paragraph", 10) < 0);
+  ASSERT (c_strncasecmp ("para", "paragraph", 9) < 0);
+  ASSERT (c_strncasecmp ("para", "paragraph", 5) < 0);
+  ASSERT (c_strncasecmp ("para", "paragraph", 4) == 0);
+  ASSERT (c_strncasecmp ("paragraph", "para", 10) > 0);
+  ASSERT (c_strncasecmp ("paragraph", "para", 9) > 0);
+  ASSERT (c_strncasecmp ("paragraph", "para", 5) > 0);
+  ASSERT (c_strncasecmp ("paragraph", "para", 4) == 0);
+
+  /* The following tests shows how c_strncasecmp() is different from
+     strncasecmp().  */
+
+  ASSERT (c_strncasecmp ("\311mily", "\351mile", 4) < 0);
+  ASSERT (c_strncasecmp ("\351mile", "\311mily", 4) > 0);
+
+  /* The following tests shows how c_strncasecmp() is different from
+     mbsncasecmp().  */
+
+  ASSERT (c_strncasecmp ("\303\266zg\303\274r", "\303\226ZG\303\234R", 99) > 0); /* özgür */
+  ASSERT (c_strncasecmp ("\303\226ZG\303\234R", "\303\266zg\303\274r", 99) < 0); /* özgür */
+
+  /* This test shows how strings of different size cannot compare equal.  */
+  ASSERT (c_strncasecmp ("turkish", "TURK\304\260SH", 7) < 0);
+  ASSERT (c_strncasecmp ("TURK\304\260SH", "turkish", 7) > 0);
+
+  return 0;
+}