| 1 |
/** |
| 2 |
* This file is part of the Detox package. |
| 3 |
* |
| 4 |
* Copyright (c) Doug Harple <[email protected]> |
| 5 |
* |
| 6 |
* For the full copyright and license information, please view the LICENSE |
| 7 |
* file that was distributed with this source code. |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <stdlib.h> |
| 11 |
#include <stdio.h> |
| 12 |
#include <string.h> |
| 13 |
|
| 14 |
#include "builtin_table.h" |
| 15 |
#include "clean_string.h" |
| 16 |
#include "detox_struct.h" |
| 17 |
#include "table.h" |
| 18 |
|
| 19 |
#include "unit_struct.h" |
| 20 |
|
| 21 |
#define DATA_COUNT 6 |
| 22 |
static struct test_filename data[DATA_COUNT] = { |
| 23 |
|
| 24 |
// legacy tests |
| 25 |
|
| 26 |
{ |
| 27 |
.filename = "safe string", |
| 28 |
.expected_a = "safe string", |
| 29 |
.expected_b = "safe string", |
| 30 |
}, |
| 31 |
{ |
| 32 |
.filename = "\xAE reg", |
| 33 |
.expected_a = "\u00AE reg", |
| 34 |
.expected_b = "\u00AE reg", |
| 35 |
}, |
| 36 |
{ |
| 37 |
.filename = "\xA9 copy", |
| 38 |
.expected_a = "\u00A9 copy", |
| 39 |
.expected_b = "\u00A9 copy", |
| 40 |
}, |
| 41 |
{ |
| 42 |
.filename = "\xC6 capital AE", |
| 43 |
.expected_a = "\u00C6 capital AE", |
| 44 |
.expected_b = "\u00C6 capital AE", |
| 45 |
}, |
| 46 |
{ |
| 47 |
.filename = "\xDE capital thorn", |
| 48 |
.expected_a = "\u00DE capital thorn", |
| 49 |
.expected_b = "\u00DE capital thorn", |
| 50 |
}, |
| 51 |
|
| 52 |
// full coverage - test default translation rules |
| 53 |
|
| 54 |
{ |
| 55 |
.filename = "\x80 not in table", |
| 56 |
.expected_a = "_ not in table", |
| 57 |
.expected_b = "\x80 not in table", |
| 58 |
}, |
| 59 |
}; |
| 60 |
|
| 61 |
#test test_clean_iso8859_1 |
| 62 |
table_t *table_a; |
| 63 |
table_t *table_b; |
| 64 |
char *output; |
| 65 |
int i; |
| 66 |
|
| 67 |
table_a = load_builtin_iso8859_1_table(); |
| 68 |
table_b = load_builtin_iso8859_1_table(); |
| 69 |
|
| 70 |
table_a->default_translation = strdup("_"); |
| 71 |
table_b->default_translation = NULL; |
| 72 |
|
| 73 |
// confirm that our a/b test is still valid |
| 74 |
ck_assert(table_get(table_b, 0x80) == NULL); |
| 75 |
|
| 76 |
for (i = 0; i < DATA_COUNT; i++) { |
| 77 |
output = clean_iso8859_1(data[i].filename, table_a); |
| 78 |
ck_assert_str_eq(output, data[i].expected_a); |
| 79 |
|
| 80 |
output = clean_iso8859_1(data[i].filename, table_b); |
| 81 |
ck_assert_str_eq(output, data[i].expected_b); |
| 82 |
} |
| 83 |
|
| 84 |
#test test_clean_iso8859_1_null |
| 85 |
char *output; |
| 86 |
|
| 87 |
// confirm NULL works |
| 88 |
output = clean_iso8859_1(NULL, NULL); |
| 89 |
ck_assert(output == NULL); |
| 90 |
|
| 91 |
#test-exit(1) test_clean_iso8859_1_missing_table |
| 92 |
clean_iso8859_1("what", NULL); |