Debian Codegraph @

tests/unit/test_clean_iso8859_1_cp1252.template

raw
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 5
22 static struct test_filename data[DATA_COUNT] = {
23
24 {
25 .filename = "safe string",
26 .expected_a = "safe string",
27 .expected_b = "safe string",
28 },
29 {
30 .filename = "\x80 euro",
31 .expected_a = "\u20AC euro",
32 .expected_b = "\u20AC euro",
33 },
34 {
35 .filename = "\x97 em dash",
36 .expected_a = "\u2014 em dash",
37 .expected_b = "\u2014 em dash",
38 },
39
40 {
41 .filename = "\x81 undefined",
42 .expected_a = "- undefined",
43 .expected_b = "- undefined",
44 },
45
46 {
47 .filename = "\xA1 outside scope",
48 .expected_a = "_ outside scope",
49 .expected_b = "\xA1 outside scope",
50 },
51 };
52
53 #test test_clean_iso8859_1_cp1252
54 table_t *table_a;
55 table_t *table_b;
56 char *output;
57 int i;
58
59 table_a = load_builtin_cp1252_table();
60 table_b = load_builtin_cp1252_table();
61
62 table_a->default_translation = strdup("_");
63 table_b->default_translation = NULL;
64
65 // confirm that our a/b test is still valid
66 ck_assert(table_get(table_a, 0xA1) == NULL);
67 ck_assert(table_get(table_b, 0xA1) == NULL);
68
69 for (i = 0; i < DATA_COUNT; i++) {
70 output = clean_iso8859_1(data[i].filename, table_a);
71 ck_assert_str_eq(output, data[i].expected_a);
72
73 output = clean_iso8859_1(data[i].filename, table_b);
74 ck_assert_str_eq(output, data[i].expected_b);
75 }