Debian Codegraph @

tests/unit/test_clean_max_length.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 "clean_string.h"
15 #include "detox_struct.h"
16
17 #include "unit_struct.h"
18
19 #define DATA_COUNT 18
20 static struct test_filename data[DATA_COUNT] = {
21
22 // legacy tests
23
24 {
25 .filename = "___________underscore_______________________.x",
26 .expected = "___________underscore_________.x",
27 .max_length = 32,
28 },
29 {
30 .filename = "..........how.....does.....this....translate......",
31 .expected = "..........how.....does.....this.",
32 .max_length = 32,
33 },
34 {
35 .filename = "_-_-_-_-_-dotted-_-_-_-_line.....part......two.......",
36 .expected = "_-_-_-_-_-dotted-_-_-_-_line....",
37 .max_length = 32,
38 },
39 {
40 .filename = "blah-.-de_._da",
41 .expected = "blah-.-de_._da",
42 .max_length = 32,
43 },
44
45 // from the detoxrc.5 manpage
46
47 {
48 .filename = "this_is_my_file.txt",
49 .expected = "this_is_.txt",
50 .max_length = 12,
51 },
52
53 // github issue 46
54
55 {
56 .filename = "safe.txt",
57 .expected = "safe.txt",
58 .max_length = 32,
59 },
60
61 {
62 .filename = "safe.and.stu.ff.txt",
63 .expected = "safe.an.ff.txt",
64 .max_length = 14,
65 },
66
67 {
68 .filename = "safe and stuff.txt",
69 .expected = "safe and.txt",
70 .max_length = 12,
71 },
72
73 {
74 .filename = "safe and stuff.txt",
75 .expected = "safe.txt",
76 .max_length = 8,
77 },
78
79 {
80 .filename = "safe.tar.gz",
81 .expected = "safe.tar.gz",
82 .max_length = 32,
83 },
84
85 {
86 .filename = "safe and stuff.tar.gz",
87 .expected = "safe and stuff.tar.gz",
88 .max_length = 22,
89 },
90
91 {
92 .filename = "safe and stuff.tar.gz",
93 .expected = "safe and stuff.tar.gz",
94 .max_length = 21,
95 },
96
97 {
98 .filename = "safe and stuff.tar.gz",
99 .expected = "safe and stuf.tar.gz",
100 .max_length = 20,
101 },
102
103 {
104 .filename = "safe and stuff.tar.gz",
105 .expected = "safe .tar.gz",
106 .max_length = 12,
107 },
108
109 {
110 .filename = "safe and stuff.tar.gz",
111 .expected = "sa.tar.gz",
112 .max_length = 9,
113 },
114
115 {
116 .filename = "safe and stuff.tar.gz",
117 .expected = "s.tar.gz",
118 .max_length = 8,
119 },
120
121 {
122 .filename = "safe and stuff.tar.gz",
123 .expected = "safe and stuff.tar.gz",
124 .max_length = 7,
125 },
126
127 {
128 .filename = "safe and stuff.tar.gz",
129 .expected = "safe and stuff.tar.gz",
130 .max_length = 0,
131 },
132 };
133
134 #test test_clean_max_length
135 char *output;
136 int i;
137
138 for (i = 0; i < DATA_COUNT; i++) {
139 output = clean_max_length(data[i].filename, data[i].max_length);
140 ck_assert_str_eq(output, data[i].expected);
141 }
142
143 #test test_clean_max_length_null
144 char *output;
145
146 // confirm NULL works
147 output = clean_max_length(NULL, 0);
148 ck_assert(output == NULL);