]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - wcsmbs/tst-mbrtowc.c
[powerpc] No need to enter "Ignore Exceptions Mode"
[thirdparty/glibc.git] / wcsmbs / tst-mbrtowc.c
index e83ac6521a04580f3ee88e03277a5c919f74974f..6534d856dea28b4b00bf59333cb2d62918f15fe3 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 2000-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
 
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
 
+/* We always want assert to be fully defined.  */
+#undef NDEBUG
 #include <assert.h>
 #include <locale.h>
 #include <stdio.h>
@@ -45,6 +46,20 @@ utf8_test_1 (void)
   assert (mbrtowc (&wc, "", 1, &s) == 0);      /* test final byte processing */
   assert (wc == 0);            /* test final byte decoding */
 
+  /* The following test is by Al Viro <aviro@redhat.com>.  */
+  const char str[] = "\xe0\xa0\x80";
+
+  wc = 42;                     /* arbitrary number */
+  memset (&s, 0, sizeof (s));  /* get s into initial state */
+  assert (mbrtowc (&wc, str, 1, &s) == -2);
+  assert (mbrtowc (&wc, str + 1, 2, &s) == 2);
+  assert (wc == 0x800);
+
+  wc = 42;                     /* arbitrary number */
+  memset (&s, 0, sizeof (s));  /* get s into initial state */
+  assert (mbrtowc (&wc, str, 3, &s) == 3);
+  assert (wc == 0x800);
+
   return 0;
 }
 
@@ -136,8 +151,8 @@ utf8_test (void)
 }
 
 
-int
-main (void)
+static int
+do_test (void)
 {
   int result = 0;
 
@@ -171,8 +186,7 @@ check_ascii (const char *locname)
       char buf[MB_CUR_MAX];
       wchar_t wc = 0xffffffff;
       mbstate_t s;
-      size_t n;
-      int i;
+      size_t n, i;
 
       for (i = 0; i < MB_CUR_MAX; ++i)
        buf[i] = c + i;
@@ -216,3 +230,6 @@ check_ascii (const char *locname)
 
   return res != 0;
 }
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"