about summary refs log tree commit diff
path: root/localedata/tst-iconv-emojis-trans.c
diff options
context:
space:
mode:
Diffstat (limited to 'localedata/tst-iconv-emojis-trans.c')
-rw-r--r--localedata/tst-iconv-emojis-trans.c117
1 files changed, 117 insertions, 0 deletions
diff --git a/localedata/tst-iconv-emojis-trans.c b/localedata/tst-iconv-emojis-trans.c
new file mode 100644
index 0000000000..de4c20a279
--- /dev/null
+++ b/localedata/tst-iconv-emojis-trans.c
@@ -0,0 +1,117 @@
+/* Test some emoji transliterations
+
+   Copyright (C) 2019-2023 Free Software Foundation, Inc.
+   Copyright The GNU Toolchain Authors.
+
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <iconv.h>
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+#include <support/check.h>
+
+static int
+do_test (void)
+{
+  iconv_t cd;
+
+  const int num_emojis = 70;
+
+  const char str[] = "โ™ก โ™ฅ โค ๐Ÿ’™ ๐Ÿ’“ "
+                     "๐Ÿ’” ๐Ÿ’– ๐Ÿ’— ๐Ÿ’š ๐Ÿ’› "
+                     "๐Ÿ’œ ๐Ÿ–ค ๐Ÿงก ๐Ÿค ๐ŸคŽ "
+                     "๐Ÿ˜€ ๐Ÿ˜ ๐Ÿ˜‚ ๐Ÿ˜ƒ ๐Ÿ˜„ "
+                     "๐Ÿ˜… ๐Ÿ˜† ๐Ÿ˜‡ ๐Ÿ˜ˆ ๐Ÿ˜‰ "
+                     "๐Ÿ˜Š ๐Ÿ˜‹ ๐Ÿ˜Œ ๐Ÿ˜ ๐Ÿ˜Ž "
+                     "๐Ÿ˜ ๐Ÿ˜ ๐Ÿ˜‘ ๐Ÿ˜’ ๐Ÿ˜“ "
+                     "๐Ÿ˜” ๐Ÿ˜• ๐Ÿ˜– ๐Ÿ˜— ๐Ÿ˜˜ "
+                     "๐Ÿ˜™ ๐Ÿ˜š ๐Ÿ˜› ๐Ÿ˜œ ๐Ÿ˜ "
+                     "๐Ÿ˜ž ๐Ÿ˜Ÿ ๐Ÿ˜  ๐Ÿ˜ก ๐Ÿ˜ข "
+                     "๐Ÿ˜ฃ ๐Ÿ˜ฆ ๐Ÿ˜ง ๐Ÿ˜จ ๐Ÿ˜ฉ "
+                     "๐Ÿ˜ญ ๐Ÿ˜ฎ ๐Ÿ˜ฏ ๐Ÿ˜ฐ ๐Ÿ˜ฑ "
+                     "๐Ÿ˜ฒ ๐Ÿ˜ธ ๐Ÿ˜น ๐Ÿ˜บ ๐Ÿ˜ป "
+                     "๐Ÿ˜ผ ๐Ÿ˜ฝ ๐Ÿ™ ๐Ÿ™‚ ๐Ÿ™ƒ";
+
+  const char expected[] = "<3 <3 <3 <3 <3 "
+                          "</3 <3 <3 <3 <3 "
+                          "<3 <3 <3 <3 <3 "
+                          ":-D :-D :'D :-D :-D "
+                          ":-D :-D O:-) >:) ;-) "
+                          ":-) :-P :-) :-* B-) "
+                          ";-) :-| :-| :-| :'-| "
+                          ":-| :-/ :-S :-* :-* "
+                          ":-* :-* :-P ;-P X-P "
+                          ":-( :-( >:-( :-( :'-( "
+                          "X-( :-O :-O :-O :-O "
+                          ":\"-( :-O :-O :'-O :-O "
+                          ":-O :-3 :'-3 :-3 :-3 "
+                          ";-3 :-3 :-( :-) (-:";
+
+  char *inptr = (char *) str;
+  size_t inlen = strlen (str) + 1;
+  char outbuf[500];
+  char *outptr = outbuf;
+  size_t outlen = sizeof (outbuf);
+  int result = 0;
+  size_t n;
+
+  if (setlocale (LC_ALL, "en_US.UTF-8") == NULL)
+    FAIL_EXIT1 ("setlocale failed");
+
+  cd = iconv_open ("ASCII//TRANSLIT", "UTF-8");
+  if (cd == (iconv_t) -1)
+    FAIL_EXIT1 ("iconv_open failed");
+
+  n = iconv (cd, &inptr, &inlen, &outptr, &outlen);
+  if (n != num_emojis)
+    {
+      if (n == (size_t) -1)
+        printf ("iconv() returned error: %m\n");
+      else
+        printf ("iconv() returned %zd, expected %d\n", n, num_emojis);
+      result = 1;
+    }
+  if (inlen != 0)
+    {
+      puts ("not all input consumed");
+      result = 1;
+    }
+  else if (inptr - str != strlen (str) + 1)
+    {
+      printf ("inptr wrong, advanced by %td\n", inptr - str);
+      result = 1;
+    }
+  if (memcmp (outbuf, expected, sizeof (expected)) != 0)
+    {
+      printf ("result wrong: \"%.*s\", expected: \"%s\"\n",
+              (int) (sizeof (outbuf) - outlen), outbuf, expected);
+      result = 1;
+    }
+  else if (outlen != sizeof (outbuf) - sizeof (expected))
+    {
+      printf ("outlen wrong: %zd, expected %zd\n", outlen,
+              sizeof (outbuf) - sizeof (expected));
+      result = 1;
+    }
+  else
+    printf ("output is \"%s\" which is OK\n", outbuf);
+
+  return result;
+}
+
+#include <support/test-driver.c>