Commit | Line | Data |
---|---|---|
b90f122b RK |
1 | /* |
2 | * This file is part of DisOrder. | |
3 | * Copyright (C) 2005, 2007, 2008 Richard Kettlewell | |
4 | * | |
e7eb3a27 | 5 | * This program is free software: you can redistribute it and/or modify |
b90f122b | 6 | * it under the terms of the GNU General Public License as published by |
e7eb3a27 | 7 | * the Free Software Foundation, either version 3 of the License, or |
b90f122b | 8 | * (at your option) any later version. |
e7eb3a27 RK |
9 | * |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
b90f122b | 15 | * You should have received a copy of the GNU General Public License |
e7eb3a27 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
b90f122b RK |
17 | */ |
18 | #include "test.h" | |
19 | ||
c68d8eba | 20 | static void test_casefold(void) { |
b90f122b RK |
21 | uint32_t c, l; |
22 | const char *input, *canon_folded, *compat_folded, *canon_expected, *compat_expected; | |
23 | ||
b90f122b RK |
24 | /* This isn't a very exhaustive test. Unlike for normalization, there don't |
25 | * seem to be any public test vectors for these algorithms. */ | |
26 | ||
27 | for(c = 1; c < 256; ++c) { | |
28 | input = utf32_to_utf8(&c, 1, 0); | |
29 | canon_folded = utf8_casefold_canon(input, strlen(input), 0); | |
30 | compat_folded = utf8_casefold_compat(input, strlen(input), 0); | |
31 | switch(c) { | |
32 | default: | |
33 | if((c >= 'A' && c <= 'Z') | |
34 | || (c >= 0xC0 && c <= 0xDE && c != 0xD7)) | |
35 | l = c ^ 0x20; | |
36 | else | |
37 | l = c; | |
38 | break; | |
39 | case 0xB5: /* MICRO SIGN */ | |
40 | l = 0x3BC; /* GREEK SMALL LETTER MU */ | |
41 | break; | |
42 | case 0xDF: /* LATIN SMALL LETTER SHARP S */ | |
43 | check_string(canon_folded, "ss"); | |
44 | check_string(compat_folded, "ss"); | |
45 | l = 0; | |
46 | break; | |
47 | } | |
48 | if(l) { | |
49 | uint32_t *d; | |
50 | /* Case-folded data is now normalized */ | |
51 | d = utf32_decompose_canon(&l, 1, 0); | |
52 | canon_expected = utf32_to_utf8(d, utf32_len(d), 0); | |
53 | if(strcmp(canon_folded, canon_expected)) { | |
54 | fprintf(stderr, "%s:%d: canon-casefolding %#lx got '%s', expected '%s'\n", | |
55 | __FILE__, __LINE__, (unsigned long)c, | |
56 | format(canon_folded), format(canon_expected)); | |
57 | count_error(); | |
58 | } | |
59 | ++tests; | |
60 | d = utf32_decompose_compat(&l, 1, 0); | |
61 | compat_expected = utf32_to_utf8(d, utf32_len(d), 0); | |
62 | if(strcmp(compat_folded, compat_expected)) { | |
63 | fprintf(stderr, "%s:%d: compat-casefolding %#lx got '%s', expected '%s'\n", | |
64 | __FILE__, __LINE__, (unsigned long)c, | |
65 | format(compat_folded), format(compat_expected)); | |
66 | count_error(); | |
67 | } | |
68 | ++tests; | |
69 | } | |
70 | } | |
71 | check_string(utf8_casefold_canon("", 0, 0), ""); | |
72 | } | |
73 | ||
c68d8eba RK |
74 | TEST(casefold); |
75 | ||
b90f122b RK |
76 | /* |
77 | Local Variables: | |
78 | c-basic-offset:2 | |
79 | comment-column:40 | |
80 | fill-column:79 | |
81 | indent-tabs-mode:nil | |
82 | End: | |
83 | */ |