Replace MUTEX_INITIALIZER with _LIBC_LOCK_INITIALIZER in generic code
[glibc.git] / iconv / tst-iconv2.c
blob31ceee02d73eaa7453a63ea1e62bd7ffce0425a2
1 /* Copyright (C) 2001-2015 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 2001.
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 <errno.h>
20 #include <iconv.h>
21 #include <mcheck.h>
22 #include <stddef.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
28 static int
29 do_test (void)
31 char buf[3];
32 const wchar_t wc[1] = L"a";
33 iconv_t cd;
34 char *inptr;
35 size_t inlen;
36 char *outptr;
37 size_t outlen;
38 size_t n;
39 int e;
40 int result = 0;
42 mtrace ();
44 cd = iconv_open ("UCS4", "WCHAR_T");
45 if (cd == (iconv_t) -1)
47 printf ("cannot convert from wchar_t to UCS4: %m\n");
48 exit (1);
51 inptr = (char *) wc;
52 inlen = sizeof (wchar_t);
53 outptr = buf;
54 outlen = 3;
56 n = iconv (cd, &inptr, &inlen, &outptr, &outlen);
57 e = errno;
59 if (n != (size_t) -1)
61 printf ("incorrect iconv() return value: %zd, expected -1\n", n);
62 result = 1;
65 if (e != E2BIG)
67 printf ("incorrect error value: %s, expected %s\n",
68 strerror (e), strerror (E2BIG));
69 result = 1;
72 if (inptr != (char *) wc)
74 puts ("inptr changed");
75 result = 1;
78 if (inlen != sizeof (wchar_t))
80 puts ("inlen changed");
81 result = 1;
84 if (outptr != buf)
86 puts ("outptr changed");
87 result = 1;
90 if (outlen != 3)
92 puts ("outlen changed");
93 result = 1;
96 iconv_close (cd);
98 return result;
101 #define TEST_FUNCTION do_test ()
102 #include "../test-skeleton.c"