Mercurial > gnulib
annotate tests/unistr/test-u16-mblen.c @ 40057:b06060465f09
maint: Run 'make update-copyright'
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 01 Jan 2019 00:25:11 +0100 |
parents | 10eb9086bea0 |
children |
rev | line source |
---|---|
12637
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Test of u16_mblen() function. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 2010-2019 Free Software Foundation, Inc. |
12637
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 (at your option) any later version. |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
19190 | 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
12637
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */ |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 #include <config.h> |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 #include "unistr.h" |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 #include "macros.h" |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 int |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 main () |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 { |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 int ret; |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 /* Test zero-length input. */ |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 { |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 static const uint16_t input[] = { 0 }; |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 ret = u16_mblen (input, 0); |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 ASSERT (ret == -1); |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 } |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 /* Test NUL unit input. */ |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 { |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 static const uint16_t input[] = { 0 }; |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 ret = u16_mblen (input, 1); |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 ASSERT (ret == 0); |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 } |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 /* Test ISO 646 unit input. */ |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 { |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 ucs4_t c; |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 uint16_t buf[1]; |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 for (c = 1; c < 0x80; c++) |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 { |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 buf[0] = c; |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 ret = u16_mblen (buf, 1); |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 ASSERT (ret == 1); |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 } |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 } |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 /* Test BMP unit input. */ |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 { |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 static const uint16_t input[] = { 0x20AC }; |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 ret = u16_mblen (input, 1); |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 ASSERT (ret == 1); |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 } |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 /* Test 2-units character input. */ |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 { |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 static const uint16_t input[] = { 0xD835, 0xDD1F }; |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 ret = u16_mblen (input, 2); |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
68 ASSERT (ret == 2); |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
69 } |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
70 |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
71 /* Test incomplete/invalid 1-unit input. */ |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
72 { |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
73 static const uint16_t input[] = { 0xD835 }; |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
74 ret = u16_mblen (input, 1); |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
75 ASSERT (ret == -1); |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
76 } |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
77 { |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
78 static const uint16_t input[] = { 0xDD1F }; |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
79 ret = u16_mblen (input, 1); |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
80 ASSERT (ret == -1); |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
81 } |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
82 |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
83 return 0; |
d10a6bd72a86
Tests for module 'unistr/u16-mblen'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
84 } |