elf: Remove /etc/suid-debug support
[glibc.git] / localedata / tst-iconv-emojis-trans.c
blobde4c20a2797aded8ea0a3c5360b143efb62915ab
1 /* Test some emoji transliterations
3 Copyright (C) 2019-2023 Free Software Foundation, Inc.
4 Copyright The GNU Toolchain Authors.
6 This file is part of the GNU C Library.
8 The GNU C Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 The GNU C Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with the GNU C Library; if not, see
20 <https://www.gnu.org/licenses/>. */
22 #include <iconv.h>
23 #include <locale.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <support/check.h>
28 static int
29 do_test (void)
31 iconv_t cd;
33 const int num_emojis = 70;
35 const char str[] = "โ™ก โ™ฅ โค ๐Ÿ’™ ๐Ÿ’“ "
36 "๐Ÿ’” ๐Ÿ’– ๐Ÿ’— ๐Ÿ’š ๐Ÿ’› "
37 "๐Ÿ’œ ๐Ÿ–ค ๐Ÿงก ๐Ÿค ๐ŸคŽ "
38 "๐Ÿ˜€ ๐Ÿ˜ ๐Ÿ˜‚ ๐Ÿ˜ƒ ๐Ÿ˜„ "
39 "๐Ÿ˜… ๐Ÿ˜† ๐Ÿ˜‡ ๐Ÿ˜ˆ ๐Ÿ˜‰ "
40 "๐Ÿ˜Š ๐Ÿ˜‹ ๐Ÿ˜Œ ๐Ÿ˜ ๐Ÿ˜Ž "
41 "๐Ÿ˜ ๐Ÿ˜ ๐Ÿ˜‘ ๐Ÿ˜’ ๐Ÿ˜“ "
42 "๐Ÿ˜” ๐Ÿ˜• ๐Ÿ˜– ๐Ÿ˜— ๐Ÿ˜˜ "
43 "๐Ÿ˜™ ๐Ÿ˜š ๐Ÿ˜› ๐Ÿ˜œ ๐Ÿ˜ "
44 "๐Ÿ˜ž ๐Ÿ˜Ÿ ๐Ÿ˜  ๐Ÿ˜ก ๐Ÿ˜ข "
45 "๐Ÿ˜ฃ ๐Ÿ˜ฆ ๐Ÿ˜ง ๐Ÿ˜จ ๐Ÿ˜ฉ "
46 "๐Ÿ˜ญ ๐Ÿ˜ฎ ๐Ÿ˜ฏ ๐Ÿ˜ฐ ๐Ÿ˜ฑ "
47 "๐Ÿ˜ฒ ๐Ÿ˜ธ ๐Ÿ˜น ๐Ÿ˜บ ๐Ÿ˜ป "
48 "๐Ÿ˜ผ ๐Ÿ˜ฝ ๐Ÿ™ ๐Ÿ™‚ ๐Ÿ™ƒ";
50 const char expected[] = "<3 <3 <3 <3 <3 "
51 "</3 <3 <3 <3 <3 "
52 "<3 <3 <3 <3 <3 "
53 ":-D :-D :'D :-D :-D "
54 ":-D :-D O:-) >:) ;-) "
55 ":-) :-P :-) :-* B-) "
56 ";-) :-| :-| :-| :'-| "
57 ":-| :-/ :-S :-* :-* "
58 ":-* :-* :-P ;-P X-P "
59 ":-( :-( >:-( :-( :'-( "
60 "X-( :-O :-O :-O :-O "
61 ":\"-( :-O :-O :'-O :-O "
62 ":-O :-3 :'-3 :-3 :-3 "
63 ";-3 :-3 :-( :-) (-:";
65 char *inptr = (char *) str;
66 size_t inlen = strlen (str) + 1;
67 char outbuf[500];
68 char *outptr = outbuf;
69 size_t outlen = sizeof (outbuf);
70 int result = 0;
71 size_t n;
73 if (setlocale (LC_ALL, "en_US.UTF-8") == NULL)
74 FAIL_EXIT1 ("setlocale failed");
76 cd = iconv_open ("ASCII//TRANSLIT", "UTF-8");
77 if (cd == (iconv_t) -1)
78 FAIL_EXIT1 ("iconv_open failed");
80 n = iconv (cd, &inptr, &inlen, &outptr, &outlen);
81 if (n != num_emojis)
83 if (n == (size_t) -1)
84 printf ("iconv() returned error: %m\n");
85 else
86 printf ("iconv() returned %zd, expected %d\n", n, num_emojis);
87 result = 1;
89 if (inlen != 0)
91 puts ("not all input consumed");
92 result = 1;
94 else if (inptr - str != strlen (str) + 1)
96 printf ("inptr wrong, advanced by %td\n", inptr - str);
97 result = 1;
99 if (memcmp (outbuf, expected, sizeof (expected)) != 0)
101 printf ("result wrong: \"%.*s\", expected: \"%s\"\n",
102 (int) (sizeof (outbuf) - outlen), outbuf, expected);
103 result = 1;
105 else if (outlen != sizeof (outbuf) - sizeof (expected))
107 printf ("outlen wrong: %zd, expected %zd\n", outlen,
108 sizeof (outbuf) - sizeof (expected));
109 result = 1;
111 else
112 printf ("output is \"%s\" which is OK\n", outbuf);
114 return result;
117 #include <support/test-driver.c>