nptl: Add more coverage in tst-cancel4
[glibc.git] / iconv / tst-iconv6.c
blob57d7f389e9e72dbee624061954958b8c760a6415
1 /* Testing ucs4le_internal_loop() in gconv_simple.c.
2 Copyright (C) 2016 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>
26 static int
27 do_test (void)
29 iconv_t cd;
30 char *inptr;
31 size_t inlen;
32 char *outptr;
33 size_t outlen;
34 size_t n;
35 int e;
36 int result = 0;
38 #if __BYTE_ORDER == __BIG_ENDIAN
39 /* On big-endian machines, ucs4le_internal_loop() swaps the bytes before
40 error checking. Thus the input values has to be swapped. */
41 # define VALUE(val) bswap_32 (val)
42 #else
43 # define VALUE(val) val
44 #endif
45 uint32_t inbuf[3] = { VALUE (0x41), VALUE (0x80000000), VALUE (0x42) };
46 uint32_t outbuf[3] = { 0, 0, 0 };
48 cd = iconv_open ("WCHAR_T", "UCS-4LE");
49 if (cd == (iconv_t) -1)
51 printf ("cannot convert from UCS4LE to wchar_t: %m\n");
52 return 1;
55 inptr = (char *) inbuf;
56 inlen = sizeof (inbuf);
57 outptr = (char *) outbuf;
58 outlen = sizeof (outbuf);
60 n = iconv (cd, &inptr, &inlen, &outptr, &outlen);
61 e = errno;
63 if (n != (size_t) -1)
65 printf ("incorrect iconv() return value: %zd, expected -1\n", n);
66 result = 1;
69 if (e != EILSEQ)
71 printf ("incorrect error value: %s, expected %s\n",
72 strerror (e), strerror (EILSEQ));
73 result = 1;
76 if (inptr != (char *) &inbuf[1])
78 printf ("inptr=0x%p does not point to invalid character! Expected=0x%p\n"
79 , inptr, &inbuf[1]);
80 result = 1;
83 if (inlen != sizeof (inbuf) - sizeof (uint32_t))
85 printf ("inlen=%zd != %zd\n"
86 , inlen, sizeof (inbuf) - sizeof (uint32_t));
87 result = 1;
90 if (outptr != (char *) &outbuf[1])
92 printf ("outptr=0x%p does not point to invalid character in inbuf! "
93 "Expected=0x%p\n"
94 , outptr, &outbuf[1]);
95 result = 1;
98 if (outlen != sizeof (inbuf) - sizeof (uint32_t))
100 printf ("outlen=%zd != %zd\n"
101 , outlen, sizeof (outbuf) - sizeof (uint32_t));
102 result = 1;
105 if (outbuf[0] != 0x41 || outbuf[1] != 0 || outbuf[2] != 0)
107 puts ("Characters conversion is incorrect!");
108 result = 1;
111 iconv_close (cd);
113 return result;
116 #define TEST_FUNCTION do_test ()
117 #include "../test-skeleton.c"