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/>. */
26 #include <support/check.h>
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 "
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;
68 char *outptr
= outbuf
;
69 size_t outlen
= sizeof (outbuf
);
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
);
84 printf ("iconv() returned error: %m\n");
86 printf ("iconv() returned %zd, expected %d\n", n
, num_emojis
);
91 puts ("not all input consumed");
94 else if (inptr
- str
!= strlen (str
) + 1)
96 printf ("inptr wrong, advanced by %td\n", inptr
- str
);
99 if (memcmp (outbuf
, expected
, sizeof (expected
)) != 0)
101 printf ("result wrong: \"%.*s\", expected: \"%s\"\n",
102 (int) (sizeof (outbuf
) - outlen
), outbuf
, expected
);
105 else if (outlen
!= sizeof (outbuf
) - sizeof (expected
))
107 printf ("outlen wrong: %zd, expected %zd\n", outlen
,
108 sizeof (outbuf
) - sizeof (expected
));
112 printf ("output is \"%s\" which is OK\n", outbuf
);
117 #include <support/test-driver.c>