1 /* Test of u16_uctomb() function.
2 Copyright (C) 2010-2014 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */
30 /* Test ISO 646 character, in particular the NUL character. */
34 for (uc = 0; uc < 0x80; uc++)
36 uint16_t buf[3] = { MAGIC, MAGIC, MAGIC };
39 ret = u16_uctomb (buf, uc, 0);
41 ASSERT (buf[0] == MAGIC);
43 ret = u16_uctomb (buf, uc, 1);
45 ASSERT (buf[0] == uc);
46 ASSERT (buf[1] == MAGIC);
50 /* Test BMP character. */
53 uint16_t buf[3] = { MAGIC, MAGIC, MAGIC };
56 ret = u16_uctomb (buf, uc, 0);
58 ASSERT (buf[0] == MAGIC);
60 ret = u16_uctomb (buf, uc, 1);
62 ASSERT (buf[0] == uc);
63 ASSERT (buf[1] == MAGIC);
66 /* Test non-BMP character. */
69 uint16_t buf[3] = { MAGIC, MAGIC, MAGIC };
72 ret = u16_uctomb (buf, uc, 0);
74 ASSERT (buf[0] == MAGIC);
76 ret = u16_uctomb (buf, uc, 1);
78 ASSERT (buf[0] == MAGIC);
80 ret = u16_uctomb (buf, uc, 2);
82 ASSERT (buf[0] == 0xDBFF);
83 ASSERT (buf[1] == 0xDFFD);
84 ASSERT (buf[2] == MAGIC);
87 /* Test invalid characters. */
89 ucs4_t invalid[] = { 0x110000, 0xD800, 0xDBFF, 0xDC00, 0xDFFF };
90 uint16_t buf[3] = { MAGIC, MAGIC, MAGIC };
93 for (i = 0; i < SIZEOF (invalid); i++)
95 ucs4_t uc = invalid[i];
98 for (n = 0; n <= 2; n++)
100 int ret = u16_uctomb (buf, uc, n);
102 ASSERT (buf[0] == MAGIC);
103 ASSERT (buf[1] == MAGIC);
104 ASSERT (buf[2] == MAGIC);