Mercurial > hg > octave-nkf > gnulib-hg
annotate tests/unistr/test-u16-uctomb.c @ 14079:97fc9a21a8fb
maint: update almost all copyright ranges to include 2011
Run the new "make update-copyright" rule.
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Sat, 01 Jan 2011 20:17:23 +0100 |
parents | 0dccf75b8c55 |
children | 8250f2777afc |
rev | line source |
---|---|
12649
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Test of u16_uctomb() function. |
14079
97fc9a21a8fb
maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents:
12649
diff
changeset
|
2 Copyright (C) 2010-2011 Free Software Foundation, Inc. |
12649
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 (at your option) any later version. |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */ |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 #include <config.h> |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 #include "unistr.h" |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 #include "macros.h" |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 #define MAGIC 0xBADE |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 int |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 main () |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 { |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 /* Test ISO 646 character, in particular the NUL character. */ |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 { |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 ucs4_t uc; |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 for (uc = 0; uc < 0x80; uc++) |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 { |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 uint16_t buf[3] = { MAGIC, MAGIC, MAGIC }; |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 int ret; |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 ret = u16_uctomb (buf, uc, 0); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 ASSERT (ret == -2); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 ASSERT (buf[0] == MAGIC); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 ret = u16_uctomb (buf, uc, 1); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 ASSERT (ret == 1); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 ASSERT (buf[0] == uc); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 ASSERT (buf[1] == MAGIC); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 } |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 } |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 /* Test BMP character. */ |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 { |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 ucs4_t uc = 0x20AC; |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 uint16_t buf[3] = { MAGIC, MAGIC, MAGIC }; |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 int ret; |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 ret = u16_uctomb (buf, uc, 0); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 ASSERT (ret == -2); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 ASSERT (buf[0] == MAGIC); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 ret = u16_uctomb (buf, uc, 1); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 ASSERT (ret == 1); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 ASSERT (buf[0] == uc); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 ASSERT (buf[1] == MAGIC); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 } |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 /* Test non-BMP character. */ |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 { |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
68 ucs4_t uc = 0x10FFFD; |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
69 uint16_t buf[3] = { MAGIC, MAGIC, MAGIC }; |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
70 int ret; |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
71 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
72 ret = u16_uctomb (buf, uc, 0); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
73 ASSERT (ret == -2); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
74 ASSERT (buf[0] == MAGIC); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
75 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
76 ret = u16_uctomb (buf, uc, 1); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
77 ASSERT (ret == -2); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
78 ASSERT (buf[0] == MAGIC); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
79 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
80 ret = u16_uctomb (buf, uc, 2); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
81 ASSERT (ret == 2); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
82 ASSERT (buf[0] == 0xDBFF); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
83 ASSERT (buf[1] == 0xDFFD); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
84 ASSERT (buf[2] == MAGIC); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
85 } |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
86 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
87 /* Test invalid characters. */ |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
88 { |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
89 ucs4_t invalid[] = { 0x110000, 0xD800, 0xDBFF, 0xDC00, 0xDFFF }; |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
90 uint16_t buf[3] = { MAGIC, MAGIC, MAGIC }; |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
91 size_t i; |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
92 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
93 for (i = 0; i < SIZEOF (invalid); i++) |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
94 { |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
95 ucs4_t uc = invalid[i]; |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
96 int n; |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
97 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
98 for (n = 0; n <= 2; n++) |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
99 { |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
100 int ret = u16_uctomb (buf, uc, n); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
101 ASSERT (ret == -1); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
102 ASSERT (buf[0] == MAGIC); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
103 ASSERT (buf[1] == MAGIC); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
104 ASSERT (buf[2] == MAGIC); |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
105 } |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
106 } |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
107 } |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
108 |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
109 return 0; |
0dccf75b8c55
Tests for module 'unistr/u16-uctomb'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
110 } |