root/maint/gnulib/tests/test-mbrtoc32-w32.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. test_one_locale
  2. main
  3. main

   1 /* Test of conversion of multibyte character to 32-bit wide character.
   2    Copyright (C) 2008-2021 Free Software Foundation, Inc.
   3 
   4    This program is free software: you can redistribute it and/or modify
   5    it under the terms of the GNU General Public License as published by
   6    the Free Software Foundation; either version 3 of the License, or
   7    (at your option) any later version.
   8 
   9    This program is distributed in the hope that it will be useful,
  10    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12    GNU General Public License for more details.
  13 
  14    You should have received a copy of the GNU General Public License
  15    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
  16 
  17 #include <config.h>
  18 
  19 #include <uchar.h>
  20 
  21 #include <errno.h>
  22 #include <locale.h>
  23 #include <stdio.h>
  24 #include <stdlib.h>
  25 #include <string.h>
  26 
  27 #include "localcharset.h"
  28 #include "macros.h"
  29 
  30 #if defined _WIN32 && !defined __CYGWIN__
  31 
  32 static int
  33 test_one_locale (const char *name, int codepage)
     /* [previous][next][first][last][top][bottom][index][help] */
  34 {
  35   mbstate_t state;
  36   char32_t wc;
  37   size_t ret;
  38 
  39 # if 1
  40   /* Portable code to set the locale.  */
  41   {
  42     char name_with_codepage[1024];
  43 
  44     sprintf (name_with_codepage, "%s.%d", name, codepage);
  45 
  46     /* Set the locale.  */
  47     if (setlocale (LC_ALL, name_with_codepage) == NULL)
  48       return 77;
  49   }
  50 # else
  51   /* Hacky way to set a locale.codepage combination that setlocale() refuses
  52      to set.  */
  53   {
  54     /* Codepage of the current locale, set with setlocale().
  55        Not necessarily the same as GetACP().  */
  56     extern __declspec(dllimport) unsigned int __lc_codepage;
  57 
  58     /* Set the locale.  */
  59     if (setlocale (LC_ALL, name) == NULL)
  60       return 77;
  61 
  62     /* Clobber the codepage and MB_CUR_MAX, both set by setlocale().  */
  63     __lc_codepage = codepage;
  64     switch (codepage)
  65       {
  66       case 1252:
  67       case 1256:
  68         MB_CUR_MAX = 1;
  69         break;
  70       case 932:
  71       case 950:
  72       case 936:
  73         MB_CUR_MAX = 2;
  74         break;
  75       case 54936:
  76       case 65001:
  77         MB_CUR_MAX = 4;
  78         break;
  79       }
  80 
  81     /* Test whether the codepage is really available.  */
  82     memset (&state, '\0', sizeof (mbstate_t));
  83     if (mbrtoc32 (&wc, " ", 1, &state) == (size_t)(-1))
  84       return 77;
  85   }
  86 # endif
  87 
  88   /* Test zero-length input.  */
  89   {
  90     memset (&state, '\0', sizeof (mbstate_t));
  91     wc = (char32_t) 0xBADFACE;
  92     ret = mbrtoc32 (&wc, "x", 0, &state);
  93     /* gnulib's implementation returns (size_t)(-2).
  94        The AIX 5.1 implementation returns (size_t)(-1).
  95        glibc's implementation returns 0.  */
  96     ASSERT (ret == (size_t)(-2) || ret == (size_t)(-1) || ret == 0);
  97     ASSERT (mbsinit (&state));
  98   }
  99 
 100   /* Test NUL byte input.  */
 101   {
 102     memset (&state, '\0', sizeof (mbstate_t));
 103     wc = (char32_t) 0xBADFACE;
 104     ret = mbrtoc32 (&wc, "", 1, &state);
 105     ASSERT (ret == 0);
 106     ASSERT (wc == 0);
 107     ASSERT (mbsinit (&state));
 108     ret = mbrtoc32 (NULL, "", 1, &state);
 109     ASSERT (ret == 0);
 110     ASSERT (mbsinit (&state));
 111   }
 112 
 113   /* Test single-byte input.  */
 114   {
 115     int c;
 116     char buf[1];
 117 
 118     memset (&state, '\0', sizeof (mbstate_t));
 119     for (c = 0; c < 0x100; c++)
 120       switch (c)
 121         {
 122         case '\t': case '\v': case '\f':
 123         case ' ': case '!': case '"': case '#': case '%':
 124         case '&': case '\'': case '(': case ')': case '*':
 125         case '+': case ',': case '-': case '.': case '/':
 126         case '0': case '1': case '2': case '3': case '4':
 127         case '5': case '6': case '7': case '8': case '9':
 128         case ':': case ';': case '<': case '=': case '>':
 129         case '?':
 130         case 'A': case 'B': case 'C': case 'D': case 'E':
 131         case 'F': case 'G': case 'H': case 'I': case 'J':
 132         case 'K': case 'L': case 'M': case 'N': case 'O':
 133         case 'P': case 'Q': case 'R': case 'S': case 'T':
 134         case 'U': case 'V': case 'W': case 'X': case 'Y':
 135         case 'Z':
 136         case '[': case '\\': case ']': case '^': case '_':
 137         case 'a': case 'b': case 'c': case 'd': case 'e':
 138         case 'f': case 'g': case 'h': case 'i': case 'j':
 139         case 'k': case 'l': case 'm': case 'n': case 'o':
 140         case 'p': case 'q': case 'r': case 's': case 't':
 141         case 'u': case 'v': case 'w': case 'x': case 'y':
 142         case 'z': case '{': case '|': case '}': case '~':
 143           /* c is in the ISO C "basic character set".  */
 144           buf[0] = c;
 145           wc = (char32_t) 0xBADFACE;
 146           ret = mbrtoc32 (&wc, buf, 1, &state);
 147           ASSERT (ret == 1);
 148           ASSERT (wc == c);
 149           ASSERT (mbsinit (&state));
 150           ret = mbrtoc32 (NULL, buf, 1, &state);
 151           ASSERT (ret == 1);
 152           ASSERT (mbsinit (&state));
 153           break;
 154         }
 155   }
 156 
 157   /* Test special calling convention, passing a NULL pointer.  */
 158   {
 159     memset (&state, '\0', sizeof (mbstate_t));
 160     wc = (char32_t) 0xBADFACE;
 161     ret = mbrtoc32 (&wc, NULL, 5, &state);
 162     ASSERT (ret == 0);
 163     ASSERT (wc == (char32_t) 0xBADFACE);
 164     ASSERT (mbsinit (&state));
 165   }
 166 
 167   switch (codepage)
 168     {
 169     case 1252:
 170       /* Locale encoding is CP1252, an extension of ISO-8859-1.  */
 171       {
 172         char input[] = "B\374\337er"; /* "Büßer" */
 173         memset (&state, '\0', sizeof (mbstate_t));
 174 
 175         wc = (char32_t) 0xBADFACE;
 176         ret = mbrtoc32 (&wc, input, 1, &state);
 177         ASSERT (ret == 1);
 178         ASSERT (wc == 'B');
 179         ASSERT (mbsinit (&state));
 180         input[0] = '\0';
 181 
 182         wc = (char32_t) 0xBADFACE;
 183         ret = mbrtoc32 (&wc, input + 1, 1, &state);
 184         ASSERT (ret == 1);
 185         ASSERT (c32tob (wc) == (unsigned char) '\374');
 186         ASSERT (wc == 0x00FC);
 187         ASSERT (mbsinit (&state));
 188         input[1] = '\0';
 189 
 190         /* Test support of NULL first argument.  */
 191         ret = mbrtoc32 (NULL, input + 2, 3, &state);
 192         ASSERT (ret == 1);
 193         ASSERT (mbsinit (&state));
 194 
 195         wc = (char32_t) 0xBADFACE;
 196         ret = mbrtoc32 (&wc, input + 2, 3, &state);
 197         ASSERT (ret == 1);
 198         ASSERT (c32tob (wc) == (unsigned char) '\337');
 199         ASSERT (wc == 0x00DF);
 200         ASSERT (mbsinit (&state));
 201         input[2] = '\0';
 202 
 203         wc = (char32_t) 0xBADFACE;
 204         ret = mbrtoc32 (&wc, input + 3, 2, &state);
 205         ASSERT (ret == 1);
 206         ASSERT (wc == 'e');
 207         ASSERT (mbsinit (&state));
 208         input[3] = '\0';
 209 
 210         wc = (char32_t) 0xBADFACE;
 211         ret = mbrtoc32 (&wc, input + 4, 1, &state);
 212         ASSERT (ret == 1);
 213         ASSERT (wc == 'r');
 214         ASSERT (mbsinit (&state));
 215       }
 216       return 0;
 217 
 218     case 1256:
 219       /* Locale encoding is CP1256, not the same as ISO-8859-6.  */
 220       {
 221         char input[] = "x\302\341\346y"; /* "xآلوy" */
 222         memset (&state, '\0', sizeof (mbstate_t));
 223 
 224         wc = (char32_t) 0xBADFACE;
 225         ret = mbrtoc32 (&wc, input, 1, &state);
 226         ASSERT (ret == 1);
 227         ASSERT (wc == 'x');
 228         ASSERT (mbsinit (&state));
 229         input[0] = '\0';
 230 
 231         wc = (char32_t) 0xBADFACE;
 232         ret = mbrtoc32 (&wc, input + 1, 1, &state);
 233         ASSERT (ret == 1);
 234         ASSERT (c32tob (wc) == (unsigned char) '\302');
 235         ASSERT (wc == 0x0622);
 236         ASSERT (mbsinit (&state));
 237         input[1] = '\0';
 238 
 239         /* Test support of NULL first argument.  */
 240         ret = mbrtoc32 (NULL, input + 2, 3, &state);
 241         ASSERT (ret == 1);
 242         ASSERT (mbsinit (&state));
 243 
 244         wc = (char32_t) 0xBADFACE;
 245         ret = mbrtoc32 (&wc, input + 2, 3, &state);
 246         ASSERT (ret == 1);
 247         ASSERT (c32tob (wc) == (unsigned char) '\341');
 248         ASSERT (wc == 0x0644);
 249         ASSERT (mbsinit (&state));
 250         input[2] = '\0';
 251 
 252         wc = (char32_t) 0xBADFACE;
 253         ret = mbrtoc32 (&wc, input + 3, 2, &state);
 254         ASSERT (ret == 1);
 255         ASSERT (c32tob (wc) == (unsigned char) '\346');
 256         ASSERT (wc == 0x0648);
 257         ASSERT (mbsinit (&state));
 258         input[3] = '\0';
 259 
 260         wc = (char32_t) 0xBADFACE;
 261         ret = mbrtoc32 (&wc, input + 4, 1, &state);
 262         ASSERT (ret == 1);
 263         ASSERT (wc == 'y');
 264         ASSERT (mbsinit (&state));
 265       }
 266       return 0;
 267 
 268     case 932:
 269       /* Locale encoding is CP932, similar to Shift_JIS.  */
 270       {
 271         char input[] = "<\223\372\226\173\214\352>"; /* "<日本語>" */
 272         memset (&state, '\0', sizeof (mbstate_t));
 273 
 274         wc = (char32_t) 0xBADFACE;
 275         ret = mbrtoc32 (&wc, input, 1, &state);
 276         ASSERT (ret == 1);
 277         ASSERT (wc == '<');
 278         ASSERT (mbsinit (&state));
 279         input[0] = '\0';
 280 
 281         wc = (char32_t) 0xBADFACE;
 282         ret = mbrtoc32 (&wc, input + 1, 2, &state);
 283         ASSERT (ret == 2);
 284         ASSERT (c32tob (wc) == EOF);
 285         ASSERT (wc == 0x65E5);
 286         ASSERT (mbsinit (&state));
 287         input[1] = '\0';
 288         input[2] = '\0';
 289 
 290         wc = (char32_t) 0xBADFACE;
 291         ret = mbrtoc32 (&wc, input + 3, 1, &state);
 292         ASSERT (ret == (size_t)(-2));
 293         ASSERT (wc == (char32_t) 0xBADFACE);
 294         ASSERT (!mbsinit (&state));
 295         input[3] = '\0';
 296 
 297         wc = (char32_t) 0xBADFACE;
 298         ret = mbrtoc32 (&wc, input + 4, 4, &state);
 299         ASSERT (ret == 1);
 300         ASSERT (c32tob (wc) == EOF);
 301         ASSERT (wc == 0x672C);
 302         ASSERT (mbsinit (&state));
 303         input[4] = '\0';
 304 
 305         /* Test support of NULL first argument.  */
 306         ret = mbrtoc32 (NULL, input + 5, 3, &state);
 307         ASSERT (ret == 2);
 308         ASSERT (mbsinit (&state));
 309 
 310         wc = (char32_t) 0xBADFACE;
 311         ret = mbrtoc32 (&wc, input + 5, 3, &state);
 312         ASSERT (ret == 2);
 313         ASSERT (c32tob (wc) == EOF);
 314         ASSERT (wc == 0x8A9E);
 315         ASSERT (mbsinit (&state));
 316         input[5] = '\0';
 317         input[6] = '\0';
 318 
 319         wc = (char32_t) 0xBADFACE;
 320         ret = mbrtoc32 (&wc, input + 7, 1, &state);
 321         ASSERT (ret == 1);
 322         ASSERT (wc == '>');
 323         ASSERT (mbsinit (&state));
 324 
 325         /* Test some invalid input.  */
 326         memset (&state, '\0', sizeof (mbstate_t));
 327         wc = (char32_t) 0xBADFACE;
 328         ret = mbrtoc32 (&wc, "\377", 1, &state); /* 0xFF */
 329         ASSERT ((ret == (size_t)-1 && errno == EILSEQ) || ret == (size_t)-2);
 330 
 331         memset (&state, '\0', sizeof (mbstate_t));
 332         wc = (char32_t) 0xBADFACE;
 333         ret = mbrtoc32 (&wc, "\225\377", 2, &state); /* 0x95 0xFF */
 334         ASSERT ((ret == (size_t)-1 && errno == EILSEQ) || (ret == 2 && wc == 0x30FB));
 335       }
 336       return 0;
 337 
 338     case 950:
 339       /* Locale encoding is CP950, similar to Big5.  */
 340       {
 341         char input[] = "<\244\351\245\273\273\171>"; /* "<日本語>" */
 342         memset (&state, '\0', sizeof (mbstate_t));
 343 
 344         wc = (char32_t) 0xBADFACE;
 345         ret = mbrtoc32 (&wc, input, 1, &state);
 346         ASSERT (ret == 1);
 347         ASSERT (wc == '<');
 348         ASSERT (mbsinit (&state));
 349         input[0] = '\0';
 350 
 351         wc = (char32_t) 0xBADFACE;
 352         ret = mbrtoc32 (&wc, input + 1, 2, &state);
 353         ASSERT (ret == 2);
 354         ASSERT (c32tob (wc) == EOF);
 355         ASSERT (wc == 0x65E5);
 356         ASSERT (mbsinit (&state));
 357         input[1] = '\0';
 358         input[2] = '\0';
 359 
 360         wc = (char32_t) 0xBADFACE;
 361         ret = mbrtoc32 (&wc, input + 3, 1, &state);
 362         ASSERT (ret == (size_t)(-2));
 363         ASSERT (wc == (char32_t) 0xBADFACE);
 364         ASSERT (!mbsinit (&state));
 365         input[3] = '\0';
 366 
 367         wc = (char32_t) 0xBADFACE;
 368         ret = mbrtoc32 (&wc, input + 4, 4, &state);
 369         ASSERT (ret == 1);
 370         ASSERT (c32tob (wc) == EOF);
 371         ASSERT (wc == 0x672C);
 372         ASSERT (mbsinit (&state));
 373         input[4] = '\0';
 374 
 375         /* Test support of NULL first argument.  */
 376         ret = mbrtoc32 (NULL, input + 5, 3, &state);
 377         ASSERT (ret == 2);
 378         ASSERT (mbsinit (&state));
 379 
 380         wc = (char32_t) 0xBADFACE;
 381         ret = mbrtoc32 (&wc, input + 5, 3, &state);
 382         ASSERT (ret == 2);
 383         ASSERT (c32tob (wc) == EOF);
 384         ASSERT (wc == 0x8A9E);
 385         ASSERT (mbsinit (&state));
 386         input[5] = '\0';
 387         input[6] = '\0';
 388 
 389         wc = (char32_t) 0xBADFACE;
 390         ret = mbrtoc32 (&wc, input + 7, 1, &state);
 391         ASSERT (ret == 1);
 392         ASSERT (wc == '>');
 393         ASSERT (mbsinit (&state));
 394 
 395         /* Test some invalid input.  */
 396         memset (&state, '\0', sizeof (mbstate_t));
 397         wc = (char32_t) 0xBADFACE;
 398         ret = mbrtoc32 (&wc, "\377", 1, &state); /* 0xFF */
 399         ASSERT ((ret == (size_t)-1 && errno == EILSEQ) || ret == (size_t)-2);
 400 
 401         memset (&state, '\0', sizeof (mbstate_t));
 402         wc = (char32_t) 0xBADFACE;
 403         ret = mbrtoc32 (&wc, "\225\377", 2, &state); /* 0x95 0xFF */
 404         ASSERT ((ret == (size_t)-1 && errno == EILSEQ) || (ret == 2 && wc == '?'));
 405       }
 406       return 0;
 407 
 408     case 936:
 409       /* Locale encoding is CP936 = GBK, an extension of GB2312.  */
 410       {
 411         char input[] = "<\310\325\261\276\325\132>"; /* "<日本語>" */
 412         memset (&state, '\0', sizeof (mbstate_t));
 413 
 414         wc = (char32_t) 0xBADFACE;
 415         ret = mbrtoc32 (&wc, input, 1, &state);
 416         ASSERT (ret == 1);
 417         ASSERT (wc == '<');
 418         ASSERT (mbsinit (&state));
 419         input[0] = '\0';
 420 
 421         wc = (char32_t) 0xBADFACE;
 422         ret = mbrtoc32 (&wc, input + 1, 2, &state);
 423         ASSERT (ret == 2);
 424         ASSERT (c32tob (wc) == EOF);
 425         ASSERT (wc == 0x65E5);
 426         ASSERT (mbsinit (&state));
 427         input[1] = '\0';
 428         input[2] = '\0';
 429 
 430         wc = (char32_t) 0xBADFACE;
 431         ret = mbrtoc32 (&wc, input + 3, 1, &state);
 432         ASSERT (ret == (size_t)(-2));
 433         ASSERT (wc == (char32_t) 0xBADFACE);
 434         ASSERT (!mbsinit (&state));
 435         input[3] = '\0';
 436 
 437         wc = (char32_t) 0xBADFACE;
 438         ret = mbrtoc32 (&wc, input + 4, 4, &state);
 439         ASSERT (ret == 1);
 440         ASSERT (c32tob (wc) == EOF);
 441         ASSERT (wc == 0x672C);
 442         ASSERT (mbsinit (&state));
 443         input[4] = '\0';
 444 
 445         /* Test support of NULL first argument.  */
 446         ret = mbrtoc32 (NULL, input + 5, 3, &state);
 447         ASSERT (ret == 2);
 448         ASSERT (mbsinit (&state));
 449 
 450         wc = (char32_t) 0xBADFACE;
 451         ret = mbrtoc32 (&wc, input + 5, 3, &state);
 452         ASSERT (ret == 2);
 453         ASSERT (c32tob (wc) == EOF);
 454         ASSERT (wc == 0x8A9E);
 455         ASSERT (mbsinit (&state));
 456         input[5] = '\0';
 457         input[6] = '\0';
 458 
 459         wc = (char32_t) 0xBADFACE;
 460         ret = mbrtoc32 (&wc, input + 7, 1, &state);
 461         ASSERT (ret == 1);
 462         ASSERT (wc == '>');
 463         ASSERT (mbsinit (&state));
 464 
 465         /* Test some invalid input.  */
 466         memset (&state, '\0', sizeof (mbstate_t));
 467         wc = (char32_t) 0xBADFACE;
 468         ret = mbrtoc32 (&wc, "\377", 1, &state); /* 0xFF */
 469         ASSERT ((ret == (size_t)-1 && errno == EILSEQ) || ret == (size_t)-2);
 470 
 471         memset (&state, '\0', sizeof (mbstate_t));
 472         wc = (char32_t) 0xBADFACE;
 473         ret = mbrtoc32 (&wc, "\225\377", 2, &state); /* 0x95 0xFF */
 474         ASSERT ((ret == (size_t)-1 && errno == EILSEQ) || (ret == 2 && wc == '?'));
 475       }
 476       return 0;
 477 
 478     case 54936:
 479       /* Locale encoding is CP54936 = GB18030.  */
 480       if (strcmp (locale_charset (), "GB18030") != 0)
 481         return 77;
 482       {
 483         char input[] = "s\250\271\201\060\211\070\224\071\375\067!"; /* "süß😋!" */
 484         memset (&state, '\0', sizeof (mbstate_t));
 485 
 486         wc = (char32_t) 0xBADFACE;
 487         ret = mbrtoc32 (&wc, input, 1, &state);
 488         ASSERT (ret == 1);
 489         ASSERT (wc == 's');
 490         ASSERT (mbsinit (&state));
 491         input[0] = '\0';
 492 
 493         wc = (char32_t) 0xBADFACE;
 494         ret = mbrtoc32 (&wc, input + 1, 1, &state);
 495         ASSERT (ret == (size_t)(-2));
 496         ASSERT (wc == (char32_t) 0xBADFACE);
 497         ASSERT (!mbsinit (&state));
 498         input[1] = '\0';
 499 
 500         wc = (char32_t) 0xBADFACE;
 501         ret = mbrtoc32 (&wc, input + 2, 9, &state);
 502         ASSERT (ret == 1);
 503         ASSERT (c32tob (wc) == EOF);
 504         ASSERT (wc == 0x00FC);
 505         ASSERT (mbsinit (&state));
 506         input[2] = '\0';
 507 
 508         /* Test support of NULL first argument.  */
 509         ret = mbrtoc32 (NULL, input + 3, 8, &state);
 510         ASSERT (ret == 4);
 511         ASSERT (mbsinit (&state));
 512 
 513         wc = (char32_t) 0xBADFACE;
 514         ret = mbrtoc32 (&wc, input + 3, 8, &state);
 515         ASSERT (ret == 4);
 516         ASSERT (c32tob (wc) == EOF);
 517         ASSERT (wc == 0x00DF);
 518         ASSERT (mbsinit (&state));
 519         input[3] = '\0';
 520         input[4] = '\0';
 521         input[5] = '\0';
 522         input[6] = '\0';
 523 
 524         /* Test support of NULL first argument.  */
 525         ret = mbrtoc32 (NULL, input + 7, 4, &state);
 526         ASSERT (ret == 4);
 527         ASSERT (mbsinit (&state));
 528 
 529         wc = (char32_t) 0xBADFACE;
 530         ret = mbrtoc32 (&wc, input + 7, 4, &state);
 531         ASSERT (ret == 4);
 532         ASSERT (c32tob (wc) == EOF);
 533         ASSERT (wc == 0x1F60B);
 534         ASSERT (mbsinit (&state));
 535         input[7] = '\0';
 536         input[8] = '\0';
 537         input[9] = '\0';
 538         input[10] = '\0';
 539 
 540         wc = (char32_t) 0xBADFACE;
 541         ret = mbrtoc32 (&wc, input + 11, 1, &state);
 542         ASSERT (ret == 1);
 543         ASSERT (wc == '!');
 544         ASSERT (mbsinit (&state));
 545 
 546         /* Test some invalid input.  */
 547         memset (&state, '\0', sizeof (mbstate_t));
 548         wc = (char32_t) 0xBADFACE;
 549         ret = mbrtoc32 (&wc, "\377", 1, &state); /* 0xFF */
 550         ASSERT (ret == (size_t)-1);
 551         ASSERT (errno == EILSEQ);
 552 
 553         memset (&state, '\0', sizeof (mbstate_t));
 554         wc = (char32_t) 0xBADFACE;
 555         ret = mbrtoc32 (&wc, "\225\377", 2, &state); /* 0x95 0xFF */
 556         ASSERT (ret == (size_t)-1);
 557         ASSERT (errno == EILSEQ);
 558 
 559         memset (&state, '\0', sizeof (mbstate_t));
 560         wc = (char32_t) 0xBADFACE;
 561         ret = mbrtoc32 (&wc, "\201\045", 2, &state); /* 0x81 0x25 */
 562         ASSERT (ret == (size_t)-1);
 563         ASSERT (errno == EILSEQ);
 564 
 565         memset (&state, '\0', sizeof (mbstate_t));
 566         wc = (char32_t) 0xBADFACE;
 567         ret = mbrtoc32 (&wc, "\201\060\377", 3, &state); /* 0x81 0x30 0xFF */
 568         ASSERT (ret == (size_t)-1);
 569         ASSERT (errno == EILSEQ);
 570 
 571         memset (&state, '\0', sizeof (mbstate_t));
 572         wc = (char32_t) 0xBADFACE;
 573         ret = mbrtoc32 (&wc, "\201\060\377\064", 4, &state); /* 0x81 0x30 0xFF 0x34 */
 574         ASSERT (ret == (size_t)-1);
 575         ASSERT (errno == EILSEQ);
 576 
 577         memset (&state, '\0', sizeof (mbstate_t));
 578         wc = (char32_t) 0xBADFACE;
 579         ret = mbrtoc32 (&wc, "\201\060\211\072", 4, &state); /* 0x81 0x30 0x89 0x3A */
 580         ASSERT (ret == (size_t)-1);
 581         ASSERT (errno == EILSEQ);
 582       }
 583       return 0;
 584 
 585     case 65001:
 586       /* Locale encoding is CP65001 = UTF-8.  */
 587       if (strcmp (locale_charset (), "UTF-8") != 0)
 588         return 77;
 589       {
 590         char input[] = "s\303\274\303\237\360\237\230\213!"; /* "süß😋!" */
 591         memset (&state, '\0', sizeof (mbstate_t));
 592 
 593         wc = (char32_t) 0xBADFACE;
 594         ret = mbrtoc32 (&wc, input, 1, &state);
 595         ASSERT (ret == 1);
 596         ASSERT (wc == 's');
 597         ASSERT (mbsinit (&state));
 598         input[0] = '\0';
 599 
 600         wc = (char32_t) 0xBADFACE;
 601         ret = mbrtoc32 (&wc, input + 1, 1, &state);
 602         ASSERT (ret == (size_t)(-2));
 603         ASSERT (wc == (char32_t) 0xBADFACE);
 604         ASSERT (!mbsinit (&state));
 605         input[1] = '\0';
 606 
 607         wc = (char32_t) 0xBADFACE;
 608         ret = mbrtoc32 (&wc, input + 2, 7, &state);
 609         ASSERT (ret == 1);
 610         ASSERT (c32tob (wc) == EOF);
 611         ASSERT (wc == 0x00FC);
 612         ASSERT (mbsinit (&state));
 613         input[2] = '\0';
 614 
 615         /* Test support of NULL first argument.  */
 616         ret = mbrtoc32 (NULL, input + 3, 6, &state);
 617         ASSERT (ret == 2);
 618         ASSERT (mbsinit (&state));
 619 
 620         wc = (char32_t) 0xBADFACE;
 621         ret = mbrtoc32 (&wc, input + 3, 6, &state);
 622         ASSERT (ret == 2);
 623         ASSERT (c32tob (wc) == EOF);
 624         ASSERT (wc == 0x00DF);
 625         ASSERT (mbsinit (&state));
 626         input[3] = '\0';
 627         input[4] = '\0';
 628 
 629         /* Test support of NULL first argument.  */
 630         ret = mbrtoc32 (NULL, input + 5, 4, &state);
 631         ASSERT (ret == 4);
 632         ASSERT (mbsinit (&state));
 633 
 634         wc = (char32_t) 0xBADFACE;
 635         ret = mbrtoc32 (&wc, input + 5, 4, &state);
 636         ASSERT (ret == 4);
 637         ASSERT (c32tob (wc) == EOF);
 638         ASSERT (wc == 0x1F60B);
 639         ASSERT (mbsinit (&state));
 640         input[5] = '\0';
 641         input[6] = '\0';
 642         input[7] = '\0';
 643         input[8] = '\0';
 644 
 645         wc = (char32_t) 0xBADFACE;
 646         ret = mbrtoc32 (&wc, input + 9, 1, &state);
 647         ASSERT (ret == 1);
 648         ASSERT (wc == '!');
 649         ASSERT (mbsinit (&state));
 650 
 651         /* Test some invalid input.  */
 652         memset (&state, '\0', sizeof (mbstate_t));
 653         wc = (char32_t) 0xBADFACE;
 654         ret = mbrtoc32 (&wc, "\377", 1, &state); /* 0xFF */
 655         ASSERT (ret == (size_t)-1);
 656         ASSERT (errno == EILSEQ);
 657 
 658         memset (&state, '\0', sizeof (mbstate_t));
 659         wc = (char32_t) 0xBADFACE;
 660         ret = mbrtoc32 (&wc, "\303\300", 2, &state); /* 0xC3 0xC0 */
 661         ASSERT (ret == (size_t)-1);
 662         ASSERT (errno == EILSEQ);
 663 
 664         memset (&state, '\0', sizeof (mbstate_t));
 665         wc = (char32_t) 0xBADFACE;
 666         ret = mbrtoc32 (&wc, "\343\300", 2, &state); /* 0xE3 0xC0 */
 667         ASSERT (ret == (size_t)-1);
 668         ASSERT (errno == EILSEQ);
 669 
 670         memset (&state, '\0', sizeof (mbstate_t));
 671         wc = (char32_t) 0xBADFACE;
 672         ret = mbrtoc32 (&wc, "\343\300\200", 3, &state); /* 0xE3 0xC0 0x80 */
 673         ASSERT (ret == (size_t)-1);
 674         ASSERT (errno == EILSEQ);
 675 
 676         memset (&state, '\0', sizeof (mbstate_t));
 677         wc = (char32_t) 0xBADFACE;
 678         ret = mbrtoc32 (&wc, "\343\200\300", 3, &state); /* 0xE3 0x80 0xC0 */
 679         ASSERT (ret == (size_t)-1);
 680         ASSERT (errno == EILSEQ);
 681 
 682         memset (&state, '\0', sizeof (mbstate_t));
 683         wc = (char32_t) 0xBADFACE;
 684         ret = mbrtoc32 (&wc, "\363\300", 2, &state); /* 0xF3 0xC0 */
 685         ASSERT (ret == (size_t)-1);
 686         ASSERT (errno == EILSEQ);
 687 
 688         memset (&state, '\0', sizeof (mbstate_t));
 689         wc = (char32_t) 0xBADFACE;
 690         ret = mbrtoc32 (&wc, "\363\300\200\200", 4, &state); /* 0xF3 0xC0 0x80 0x80 */
 691         ASSERT (ret == (size_t)-1);
 692         ASSERT (errno == EILSEQ);
 693 
 694         memset (&state, '\0', sizeof (mbstate_t));
 695         wc = (char32_t) 0xBADFACE;
 696         ret = mbrtoc32 (&wc, "\363\200\300", 3, &state); /* 0xF3 0x80 0xC0 */
 697         ASSERT (ret == (size_t)-1);
 698         ASSERT (errno == EILSEQ);
 699 
 700         memset (&state, '\0', sizeof (mbstate_t));
 701         wc = (char32_t) 0xBADFACE;
 702         ret = mbrtoc32 (&wc, "\363\200\300\200", 4, &state); /* 0xF3 0x80 0xC0 0x80 */
 703         ASSERT (ret == (size_t)-1);
 704         ASSERT (errno == EILSEQ);
 705 
 706         memset (&state, '\0', sizeof (mbstate_t));
 707         wc = (char32_t) 0xBADFACE;
 708         ret = mbrtoc32 (&wc, "\363\200\200\300", 4, &state); /* 0xF3 0x80 0x80 0xC0 */
 709         ASSERT (ret == (size_t)-1);
 710         ASSERT (errno == EILSEQ);
 711       }
 712       return 0;
 713 
 714     default:
 715       return 1;
 716     }
 717 }
 718 
 719 int
 720 main (int argc, char *argv[])
     /* [previous][next][first][last][top][bottom][index][help] */
 721 {
 722   int codepage = atoi (argv[argc - 1]);
 723   int result;
 724   int i;
 725 
 726   result = 77;
 727   for (i = 1; i < argc - 1; i++)
 728     {
 729       int ret = test_one_locale (argv[i], codepage);
 730 
 731       if (ret != 77)
 732         result = ret;
 733     }
 734 
 735   if (result == 77)
 736     {
 737       fprintf (stderr, "Skipping test: found no locale with codepage %d\n",
 738                codepage);
 739     }
 740   return result;
 741 }
 742 
 743 #else
 744 
 745 int
 746 main (int argc, char *argv[])
     /* [previous][next][first][last][top][bottom][index][help] */
 747 {
 748   fputs ("Skipping test: not a native Windows system\n", stderr);
 749   return 77;
 750 }
 751 
 752 #endif

/* [previous][next][first][last][top][bottom][index][help] */