]> Savannah Git Hosting - gnulib.git/commitdiff
mbrtowc, mbrtoc32 tests: Refactor.
authorBruno Haible <bruno@clisp.org>
Mon, 16 Jan 2023 13:30:06 +0000 (14:30 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 16 Jan 2023 13:30:06 +0000 (14:30 +0100)
* tests/test-mbrtowc.c (main): Straighten convoluted code.
* tests/test-mbrtoc32.c (main): Likewise.

ChangeLog
tests/test-mbrtoc32.c
tests/test-mbrtowc.c

index 9bc953423f17c3ebd5cfcd24c46462718a8f90b2..045e1c62471ab7f097f92f85f61ac6aea297b95b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-01-16  Bruno Haible  <bruno@clisp.org>
+
+       mbrtowc, mbrtoc32 tests: Refactor.
+       * tests/test-mbrtowc.c (main): Straighten convoluted code.
+       * tests/test-mbrtoc32.c (main): Likewise.
+
 2023-01-16  Paul Eggert  <eggert@cs.ucla.edu>
 
        sigpipe tests: Modernize use of 'head'.
index c8f735d520b67271c238ff05ab04982049b31d1d..36b520f7b8547c7cc4f21ee84640cecae88ad561 100644 (file)
@@ -72,10 +72,6 @@ main (int argc, char *argv[])
     for (c = 0; c < 0x100; c++)
       switch (c)
         {
-        default:
-          if (! (c && 1 < argc && argv[1][0] == '5'))
-            break;
-          FALLTHROUGH;
         case '\t': case '\v': case '\f':
         case ' ': case '!': case '"': case '#': case '%':
         case '&': case '\'': case '(': case ')': case '*':
@@ -97,25 +93,23 @@ main (int argc, char *argv[])
         case 'p': case 'q': case 'r': case 's': case 't':
         case 'u': case 'v': case 'w': case 'x': case 'y':
         case 'z': case '{': case '|': case '}': case '~':
-          /* c is in the ISO C "basic character set", or argv[1] starts
-             with '5' so we are testing all nonnull bytes.  */
+          /* c is in the ISO C "basic character set".  */
+          ASSERT (c < 0x80);
+          /* c is an ASCII character.  */
           buf[0] = c;
+
           wc = (char32_t) 0xBADFACE;
           ret = mbrtoc32 (&wc, buf, 1, &state);
           ASSERT (ret == 1);
-          if (c < 0x80)
-            /* c is an ASCII character.  */
-            ASSERT (wc == c);
-          else
-            /* argv[1] starts with '5', that is, we are testing the C or POSIX
-               locale.
-               On most platforms, the bytes 0x80..0xFF map to U+0080..U+00FF.
-               But on musl libc, the bytes 0x80..0xFF map to U+DF80..U+DFFF.  */
-            ASSERT (wc == (btowc (c) == 0xDF00 + c ? btowc (c) : c));
+          ASSERT (wc == c);
           ASSERT (mbsinit (&state));
+
           ret = mbrtoc32 (NULL, buf, 1, &state);
           ASSERT (ret == 1);
           ASSERT (mbsinit (&state));
+
+          break;
+        default:
           break;
         }
   }
@@ -368,7 +362,35 @@ main (int argc, char *argv[])
         return 0;
 
       case '5':
-        /* C locale; tested above.  */
+        /* C or POSIX locale.  */
+        {
+          int c;
+          char buf[1];
+
+          memset (&state, '\0', sizeof (mbstate_t));
+          for (c = 0; c < 0x100; c++)
+            if (c != 0)
+              {
+                /* We are testing all nonnull bytes.  */
+                buf[0] = c;
+
+                wc = (char32_t) 0xBADFACE;
+                ret = mbrtoc32 (&wc, buf, 1, &state);
+                ASSERT (ret == 1);
+                if (c < 0x80)
+                  /* c is an ASCII character.  */
+                  ASSERT (wc == c);
+                else
+                  /* On most platforms, the bytes 0x80..0xFF map to U+0080..U+00FF.
+                     But on musl libc, the bytes 0x80..0xFF map to U+DF80..U+DFFF.  */
+                  ASSERT (wc == (btowc (c) == 0xDF00 + c ? btowc (c) : c));
+                ASSERT (mbsinit (&state));
+
+                ret = mbrtoc32 (NULL, buf, 1, &state);
+                ASSERT (ret == 1);
+                ASSERT (mbsinit (&state));
+              }
+        }
         return 0;
       }
 
index 9019ea0e71a1272a022a4dcdf21c8f8fb3426386..b358d8d583bc02337091fcfb64f9f81c4c8c0c51 100644 (file)
@@ -72,10 +72,6 @@ main (int argc, char *argv[])
     for (c = 0; c < 0x100; c++)
       switch (c)
         {
-        default:
-          if (! (c && 1 < argc && argv[1][0] == '5'))
-            break;
-          FALLTHROUGH;
         case '\t': case '\v': case '\f':
         case ' ': case '!': case '"': case '#': case '%':
         case '&': case '\'': case '(': case ')': case '*':
@@ -97,25 +93,23 @@ main (int argc, char *argv[])
         case 'p': case 'q': case 'r': case 's': case 't':
         case 'u': case 'v': case 'w': case 'x': case 'y':
         case 'z': case '{': case '|': case '}': case '~':
-          /* c is in the ISO C "basic character set", or argv[1] starts
-             with '5' so we are testing all nonnull bytes.  */
+          /* c is in the ISO C "basic character set".  */
+          ASSERT (c < 0x80);
+          /* c is an ASCII character.  */
           buf[0] = c;
+
           wc = (wchar_t) 0xBADFACE;
           ret = mbrtowc (&wc, buf, 1, &state);
           ASSERT (ret == 1);
-          if (c < 0x80)
-            /* c is an ASCII character.  */
-            ASSERT (wc == c);
-          else
-            /* argv[1] starts with '5', that is, we are testing the C or POSIX
-               locale.
-               On most platforms, the bytes 0x80..0xFF map to U+0080..U+00FF.
-               But on musl libc, the bytes 0x80..0xFF map to U+DF80..U+DFFF.  */
-            ASSERT (wc == (btowc (c) == 0xDF00 + c ? btowc (c) : c));
+          ASSERT (wc == c);
           ASSERT (mbsinit (&state));
+
           ret = mbrtowc (NULL, buf, 1, &state);
           ASSERT (ret == 1);
           ASSERT (mbsinit (&state));
+
+          break;
+        default:
           break;
         }
   }
@@ -349,7 +343,35 @@ main (int argc, char *argv[])
         return 0;
 
       case '5':
-        /* C locale; tested above.  */
+        /* C or POSIX locale.  */
+        {
+          int c;
+          char buf[1];
+
+          memset (&state, '\0', sizeof (mbstate_t));
+          for (c = 0; c < 0x100; c++)
+            if (c != 0)
+              {
+                /* We are testing all nonnull bytes.  */
+                buf[0] = c;
+
+                wc = (wchar_t) 0xBADFACE;
+                ret = mbrtowc (&wc, buf, 1, &state);
+                ASSERT (ret == 1);
+                if (c < 0x80)
+                  /* c is an ASCII character.  */
+                  ASSERT (wc == c);
+                else
+                  /* On most platforms, the bytes 0x80..0xFF map to U+0080..U+00FF.
+                     But on musl libc, the bytes 0x80..0xFF map to U+DF80..U+DFFF.  */
+                  ASSERT (wc == (btowc (c) == 0xDF00 + c ? btowc (c) : c));
+                ASSERT (mbsinit (&state));
+
+                ret = mbrtowc (NULL, buf, 1, &state);
+                ASSERT (ret == 1);
+                ASSERT (mbsinit (&state));
+              }
+        }
         return 0;
       }