annotate tests/unistr/test-u32-mbtoucr.c @ 18052:20a313c1ef00

unistr/uN-strtok-tests: avoid a trivial leak * tests/unistr/test-u-strtok.h (test_u_strtok): Untabify. Free input and delim after the multibyte delimiter tests.
author Daiki Ueno <ueno@gnu.org>
date Tue, 07 Jul 2015 15:12:52 +0900
parents ab58d4870664
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12647
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of u32_mbtoucr() function.
17848
ab58d4870664 version-etc: new year
Paul Eggert <eggert@cs.ucla.edu>
parents: 17587
diff changeset
2 Copyright (C) 2010-2015 Free Software Foundation, Inc.
12647
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "unistr.h"
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include "macros.h"
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 int
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 main ()
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 {
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 ucs4_t uc;
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 int ret;
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 /* Test NUL unit input. */
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 {
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 static const uint32_t input[] = { 0 };
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 uc = 0xBADFACE;
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 ret = u32_mbtoucr (&uc, input, 1);
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 ASSERT (ret == 1);
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 ASSERT (uc == 0);
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 }
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 /* Test ISO 646 unit input. */
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 {
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 ucs4_t c;
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 uint32_t buf[1];
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 for (c = 0; c < 0x80; c++)
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 {
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 buf[0] = c;
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 uc = 0xBADFACE;
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 ret = u32_mbtoucr (&uc, buf, 1);
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 ASSERT (ret == 1);
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 ASSERT (uc == c);
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 }
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 }
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 /* Test BMP unit input. */
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 {
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 static const uint32_t input[] = { 0x20AC };
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 uc = 0xBADFACE;
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 ret = u32_mbtoucr (&uc, input, 1);
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 ASSERT (ret == 1);
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 ASSERT (uc == 0x20AC);
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 }
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 /* Test non-BMP unit input. */
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 {
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 static const uint32_t input[] = { 0x1D51F };
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 uc = 0xBADFACE;
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 ret = u32_mbtoucr (&uc, input, 1);
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 ASSERT (ret == 1);
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 ASSERT (uc == 0x1D51F);
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 }
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 /* Test incomplete/invalid 1-unit input. */
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 {
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 static const uint32_t input[] = { 0x340000 };
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 uc = 0xBADFACE;
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 ret = u32_mbtoucr (&uc, input, 1);
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 ASSERT (ret == -1);
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 ASSERT (uc == 0xFFFD);
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 }
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 return 0;
072b60aea2a1 Tests for module 'unistr/u32-mbtoucr'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 }