annotate tests/unistr/test-u16-next.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12682
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of u16_next() 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.
12682
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
12682
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "unistr.h"
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include "macros.h"
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 int
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 main ()
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 {
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 ucs4_t uc;
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 const uint16_t *ret;
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 /* Test NUL unit input. */
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 {
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 static const uint16_t input[] = { 0 };
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 uc = 0xBADFACE;
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 ret = u16_next (&uc, input);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 ASSERT (ret == NULL);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 ASSERT (uc == 0);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 }
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 /* Test ISO 646 unit input. */
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 {
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 ucs4_t c;
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 uint16_t buf[2];
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 for (c = 1; c < 0x80; c++)
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 {
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 buf[0] = c;
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 buf[1] = 0;
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 uc = 0xBADFACE;
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 ret = u16_next (&uc, buf);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 ASSERT (ret == buf + 1);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 ASSERT (uc == c);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 }
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 }
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 /* Test BMP unit input. */
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 {
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 static const uint16_t input[] = { 0x20AC, 0 };
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 uc = 0xBADFACE;
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 ret = u16_next (&uc, input);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 ASSERT (ret == input + 1);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 ASSERT (uc == 0x20AC);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 }
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 /* Test 2-units character input. */
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 {
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 static const uint16_t input[] = { 0xD835, 0xDD1F, 0 };
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 uc = 0xBADFACE;
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 ret = u16_next (&uc, input);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 ASSERT (ret == input + 2);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 ASSERT (uc == 0x1D51F);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 }
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 /* Test incomplete/invalid 1-unit input. */
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 {
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 static const uint16_t input[] = { 0xD835, 0 };
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 uc = 0xBADFACE;
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 ret = u16_next (&uc, input);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 ASSERT (ret == NULL);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 ASSERT (uc == 0xFFFD);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 }
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 {
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 static const uint16_t input[] = { 0xDD1F, 0 };
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 uc = 0xBADFACE;
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 ret = u16_next (&uc, input);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 ASSERT (ret == NULL);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 ASSERT (uc == 0xFFFD);
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 }
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 return 0;
a040345566ab Tests for module 'unistr/u16-next'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 }