Use ASCII as much as possible in LC_MESSAGES of all locales to improve readability...
[glibc.git] / iconv / tst-iconv6.c
blobace7dc68b2946a94f2b9f0c4967a42ceb8f4f110
1 /* Testing ucs4le_internal_loop() in gconv_simple.c.
2 Copyright (C) 2016-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <stdio.h>
20 #include <errno.h>
21 #include <string.h>
22 #include <inttypes.h>
23 #include <iconv.h>
24 #include <byteswap.h>
25 #include <endian.h>
27 static int
28 do_test (void)
30 iconv_t cd;
31 char *inptr;
32 size_t inlen;
33 char *outptr;
34 size_t outlen;
35 size_t n;
36 int e;
37 int result = 0;
39 #if __BYTE_ORDER == __BIG_ENDIAN
40 /* On big-endian machines, ucs4le_internal_loop() swaps the bytes before
41 error checking. Thus the input values has to be swapped. */
42 # define VALUE(val) bswap_32 (val)
43 #else
44 # define VALUE(val) val
45 #endif
46 uint32_t inbuf[3] = { VALUE (0x41), VALUE (0x80000000), VALUE (0x42) };
47 uint32_t outbuf[3] = { 0, 0, 0 };
49 cd = iconv_open ("WCHAR_T", "UCS-4LE");
50 if (cd == (iconv_t) -1)
52 printf ("cannot convert from UCS4LE to wchar_t: %m\n");
53 return 1;
56 inptr = (char *) inbuf;
57 inlen = sizeof (inbuf);
58 outptr = (char *) outbuf;
59 outlen = sizeof (outbuf);
61 n = iconv (cd, &inptr, &inlen, &outptr, &outlen);
62 e = errno;
64 if (n != (size_t) -1)
66 printf ("incorrect iconv() return value: %zd, expected -1\n", n);
67 result = 1;
70 if (e != EILSEQ)
72 printf ("incorrect error value: %s, expected %s\n",
73 strerror (e), strerror (EILSEQ));
74 result = 1;
77 if (inptr != (char *) &inbuf[1])
79 printf ("inptr=0x%p does not point to invalid character! Expected=0x%p\n"
80 , inptr, &inbuf[1]);
81 result = 1;
84 if (inlen != sizeof (inbuf) - sizeof (uint32_t))
86 printf ("inlen=%zd != %zd\n"
87 , inlen, sizeof (inbuf) - sizeof (uint32_t));
88 result = 1;
91 if (outptr != (char *) &outbuf[1])
93 printf ("outptr=0x%p does not point to invalid character in inbuf! "
94 "Expected=0x%p\n"
95 , outptr, &outbuf[1]);
96 result = 1;
99 if (outlen != sizeof (inbuf) - sizeof (uint32_t))
101 printf ("outlen=%zd != %zd\n"
102 , outlen, sizeof (outbuf) - sizeof (uint32_t));
103 result = 1;
106 if (outbuf[0] != 0x41 || outbuf[1] != 0 || outbuf[2] != 0)
108 puts ("Characters conversion is incorrect!");
109 result = 1;
112 iconv_close (cd);
114 return result;
117 #define TEST_FUNCTION do_test ()
118 #include "../test-skeleton.c"