Debian Codegraph @

tests/unit/test_spoof_config_file.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 #include <unistd.h>
14
15 #include "config_file_spoof.h"
16 #include "config_file.h"
17 #include "detox_struct.h"
18 #include "parse_options.h"
19
20 static char *detoxrc =
21 "sequence default{safe{builtin \"safe\";};wipeup{remove_trailing;};};"
22 "sequence \"iso8859_1\"{iso8859_1{builtin \"iso8859_1\";};safe{"
23 "builtin \"safe\";};wipeup{remove_trailing;};};"
24 "sequence \"iso8859_1-legacy\"{iso8859_1{builtin \"cp1252\";};iso8859_1{"
25 "builtin \"iso8859_1\";};safe{builtin \"safe\";};wipeup{remove_trailing;"
26 "};};sequence \"utf_8\"{utf_8{builtin \"unicode\";};safe{"
27 "builtin \"safe\";};wipeup{remove_trailing;};};sequence \"uncgi\"{uncgi;"
28 "safe{builtin \"safe\";};wipeup{remove_trailing;};};sequence \"lower\"{"
29 "safe{builtin \"safe\";};lower;wipeup{remove_trailing;};};"
30 "sequence \"iso8859_1-only\"{iso8859_1{builtin \"iso8859_1\";};};"
31 "sequence \"cp1252-only\"{iso8859_1{builtin \"cp1252\";};};"
32 "sequence \"utf_8-only\"{utf_8{builtin \"unicode\";};};"
33 "sequence \"uncgi-only\"{uncgi;};sequence \"lower-only\"{lower;};ignore{"
34 "filename \"{arch}\";};"
35 ;
36
37 static char *tempfile;
38
39 void setup(void)
40 {
41 int fd;
42
43 tempfile = malloc(1024);
44 sprintf(tempfile, "/tmp/detoxrc-test-XXXXXX");
45 fd = mkstemp(tempfile);
46 fprintf(stderr, "writing to %s\n", tempfile);
47 dprintf(fd, "%s", detoxrc);
48 }
49
50 void teardown(void)
51 {
52 fprintf(stderr, "deleting %s\n", tempfile);
53 unlink(tempfile);
54 }
55
56 #test test_spoof_config_file
57 options_t *main_options;
58 config_file_t *parsed;
59 config_file_t *spoofed;
60 sequence_t *parsed_sequence;
61 sequence_t *spoofed_sequence;
62 filter_t *parsed_filter;
63 filter_t *spoofed_filter;
64
65 main_options = options_init();
66 parsed = parse_config_file(tempfile, NULL, main_options);
67 spoofed = spoof_config_file();
68
69 // check names
70
71 parsed_sequence = parsed->sequences;
72 spoofed_sequence = spoofed->sequences;
73
74 do {
75 if (parsed_sequence == NULL || spoofed_sequence == NULL) {
76 break;
77 }
78
79 ck_assert_str_eq(parsed_sequence->name, spoofed_sequence->name);
80
81 //
82 //
83 //
84
85 parsed_filter = parsed_sequence->filters;
86 spoofed_filter = spoofed_sequence->filters;
87
88 do {
89 if (parsed_filter == NULL || spoofed_filter == NULL) {
90 break;
91 }
92
93 ck_assert_msg(parsed_filter->cleaner == spoofed_filter->cleaner, "unit test cleaner doesn't match spoofed cleaner");
94
95 ck_assert_str_eq(
96 parsed_filter->filename ? parsed_filter->filename : "...NULL...",
97 spoofed_filter->filename ? spoofed_filter->filename : "...NULL..."
98 );
99 ck_assert_str_eq(
100 parsed_filter->builtin ? parsed_filter->builtin : "...NULL...",
101 spoofed_filter->builtin ? spoofed_filter->builtin : "...NULL..."
102 );
103 ck_assert_int_eq(parsed_filter->remove_trailing, spoofed_filter->remove_trailing);
104 ck_assert_int_eq(parsed_filter->max_length, spoofed_filter->max_length);
105
106 parsed_filter = parsed_filter->next;
107 spoofed_filter = spoofed_filter->next;
108 } while (1);
109
110 //
111 //
112 //
113
114 parsed_sequence = parsed_sequence->next;
115 spoofed_sequence = spoofed_sequence->next;
116 } while (1);
117
118 ck_assert_msg(parsed_sequence == NULL, "unit test config file is too long");
119 ck_assert_msg(spoofed_sequence == NULL, "spoofed config file is too long");
120
121 #main-pre
122 tcase_add_checked_fixture(tc1_1, setup, teardown);