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