1/* Test some mathematical operator transliterations (BZ #23132)
2
3 Copyright (C) 2019-2022 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
19
20#include <iconv.h>
21#include <locale.h>
22#include <stdio.h>
23#include <string.h>
24#include <support/check.h>
25
26static int
27do_test (void)
28{
29 iconv_t cd;
30
31 /* str[] = "⟦ ⟧ ⟨ ⟩"
32 " ⟬ ⟭ ⦀"
33 " ⦃ ⦄ ⦅ ⦆"
34 " ⦇ ⦈ ⦉ ⦊"
35 " ⧣ ⧥ ⧵ ⧸ ⧹"
36 " ⧼ ⧽ ⧾ ⧿"; */
37
38 const char str[] = "\u27E6 \u27E7 \u27E8 \u27E9"
39 " \u27EC \u27ED \u2980"
40 " \u2983 \u2984 \u2985 \u2986"
41 " \u2987 \u2988 \u2989 \u298A"
42 " \u29E3 \u29E5 \u29F5 \u29F8 \u29F9"
43 " \u29FC \u29FD \u29FE \u29FF";
44
45 const char expected[] = "[| |] < >"
46 " (( )) |||"
47 " {| |} (( ))"
48 " (| |) <| |>"
49 " # # \\ / \\"
50 " < > + -";
51
52 char *inptr = (char *) str;
53 size_t inlen = strlen (str) + 1;
54 char outbuf[500];
55 char *outptr = outbuf;
56 size_t outlen = sizeof (outbuf);
57 int result = 0;
58 size_t n;
59
60 if (setlocale (LC_ALL, "en_US.UTF-8") == NULL)
61 FAIL_EXIT1 ("setlocale failed");
62
63 cd = iconv_open (tocode: "ASCII//TRANSLIT", fromcode: "UTF-8");
64 if (cd == (iconv_t) -1)
65 FAIL_EXIT1 ("iconv_open failed");
66
67 n = iconv (cd: cd, inbuf: &inptr, inbytesleft: &inlen, outbuf: &outptr, outbytesleft: &outlen);
68 if (n != 24)
69 {
70 if (n == (size_t) -1)
71 printf (format: "iconv() returned error: %m\n");
72 else
73 printf (format: "iconv() returned %Zd, expected 24\n", n);
74 result = 1;
75 }
76 if (inlen != 0)
77 {
78 puts (s: "not all input consumed");
79 result = 1;
80 }
81 else if (inptr - str != strlen (str) + 1)
82 {
83 printf (format: "inptr wrong, advanced by %td\n", inptr - str);
84 result = 1;
85 }
86 if (memcmp (outbuf, expected, sizeof (expected)) != 0)
87 {
88 printf (format: "result wrong: \"%.*s\", expected: \"%s\"\n",
89 (int) (sizeof (outbuf) - outlen), outbuf, expected);
90 result = 1;
91 }
92 else if (outlen != sizeof (outbuf) - sizeof (expected))
93 {
94 printf (format: "outlen wrong: %Zd, expected %Zd\n", outlen,
95 sizeof (outbuf) - 15);
96 result = 1;
97 }
98 else
99 printf (format: "output is \"%s\" which is OK\n", outbuf);
100
101 return result;
102}
103
104#include <support/test-driver.c>
105

source code of glibc/localedata/tst-iconv-math-trans.c