Debian Codegraph @

tests/common/test_oscap_util.c

raw symbols SCIP
1 /*
2 * Copyright 2023 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * Authors:
20 * Evgenii Kolesnikov <[email protected]>
21 */
22
23 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:411:9`!
24 #include <config.h>cxx . . $ `<file>/build/config.h`/
25 #endif
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/
31 #include "common/public/oscap_helpers.h"cxx . . $ `<file>/src/common/public/oscap_helpers.h`/
32
33 int test_oscap_path_startswithcxx . . $ test_oscap_path_startswith(b126dc7c1de90089).(void);
34 int test_oscap_strrmcxx . . $ test_oscap_strrm(b126dc7c1de90089).(void);
35 int test_oscap_indentcxx . . $ test_oscap_indent(b126dc7c1de90089).(void);
36 int test_oscap_remove_excess_whitespacecxx . . $ test_oscap_remove_excess_whitespace(b126dc7c1de90089).(void);
37
38 int test_oscap_path_startswithcxx . . $ test_oscap_path_startswith(b126dc7c1de90089).()
39 {
40 if (!oscap_path_startswithcxx . . $ oscap_path_startswith(b7a7aa4a824b7595).("/", "/"))
41 return 1;
42 if (!oscap_path_startswithcxx . . $ oscap_path_startswith(b7a7aa4a824b7595).("/aaa", "/"))
43 return 2;
44 if (!oscap_path_startswithcxx . . $ oscap_path_startswith(b7a7aa4a824b7595).("/aaa", "/aaa"))
45 return 3;
46 if (!oscap_path_startswithcxx . . $ oscap_path_startswith(b7a7aa4a824b7595).("/aaa/bbb", "/aaa"))
47 return 4;
48 if (!oscap_path_startswithcxx . . $ oscap_path_startswith(b7a7aa4a824b7595).("/aaa/bbb/ccc", "/aaa"))
49 return 5;
50 if (!oscap_path_startswithcxx . . $ oscap_path_startswith(b7a7aa4a824b7595).("/aaa/bbb/ccc/", "/aaa/"))
51 return 6;
52 if (!oscap_path_startswithcxx . . $ oscap_path_startswith(b7a7aa4a824b7595).("/aaa/bbb/ccc", "/aaa/bbb/ccc"))
53 return 7;
54 if (!oscap_path_startswithcxx . . $ oscap_path_startswith(b7a7aa4a824b7595).("/aaa/bbb/ccc", ""))
55 return 8;
56 if (!oscap_path_startswithcxx . . $ oscap_path_startswith(b7a7aa4a824b7595).("", ""))
57 return 9;
58 if (!oscap_path_startswithcxx . . $ oscap_path_startswith(b7a7aa4a824b7595).("", "/"))
59 return 10;
60
61 if (oscap_path_startswithcxx . . $ oscap_path_startswith(b7a7aa4a824b7595).("/bbb", "/aaa"))
62 return 101;
63 if (oscap_path_startswithcxx . . $ oscap_path_startswith(b7a7aa4a824b7595).("/bbb/aaa", "/aaa"))
64 return 102;
65 if (oscap_path_startswithcxx . . $ oscap_path_startswith(b7a7aa4a824b7595).("/bbb/aaa/", "/aaa"))
66 return 103;
67 if (oscap_path_startswithcxx . . $ oscap_path_startswith(b7a7aa4a824b7595).("/bbb/aaa/", "/aaa/"))
68 return 104;
69
70 return 0;
71 }
72
73 int test_oscap_strrmcxx . . $ test_oscap_strrm(b126dc7c1de90089).()
74 {
75 char str[] = "abcdef12345678def90";
76 size_t len = strlencxx . . $ strlen(751346f8406fd082).(str);
77
78 oscap_strrmcxx . . $ oscap_strrm(72c91e5e80d20bae).(str, "0");
79 if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(str, "abcdef12345678def9", len) != 0)
80 return 1;
81
82 oscap_strrmcxx . . $ oscap_strrm(72c91e5e80d20bae).(str, "abc");
83 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(str, "def12345678def9") != 0)
84 return 2;
85
86 oscap_strrmcxx . . $ oscap_strrm(72c91e5e80d20bae).(str, "def");
87 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(str, "123456789") != 0)
88 return 3;
89
90 oscap_strrmcxx . . $ oscap_strrm(72c91e5e80d20bae).(str, "5");
91 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(str, "12346789") != 0)
92 return 4;
93
94 return 0;
95 }
96
97 int test_oscap_indentcxx . . $ test_oscap_indent(b126dc7c1de90089).()
98 {
99 char *indented;
100
101 char *str1 = "hello";
102 indented = oscap_indentcxx . . $ oscap_indent(2050848944e00d54).(str1, 2);
103 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(indented, " hello") != 0)
104 return 1;
105 freecxx . . $ free(5d22bdacc48458e8).(indented);
106
107 char *str2 = "hello";
108 indented = oscap_indentcxx . . $ oscap_indent(2050848944e00d54).(str2, 0);
109 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(indented, "hello") != 0)
110 return 2;
111 freecxx . . $ free(5d22bdacc48458e8).(indented);
112
113 char *str3 = "hello\nworld\nsee you tomorrow";
114 indented = oscap_indentcxx . . $ oscap_indent(2050848944e00d54).(str3, 4);
115 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(indented, " hello\n world\n see you tomorrow") != 0)
116 return 3;
117 freecxx . . $ free(5d22bdacc48458e8).(indented);
118
119 char *str4 = "";
120 indented = oscap_indentcxx . . $ oscap_indent(2050848944e00d54).(str4, 2);
121 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(indented, " ") != 0)
122 return 4;
123 freecxx . . $ free(5d22bdacc48458e8).(indented);
124
125 char *str5 = "hello\n\n\n\nbye\n";
126 indented = oscap_indentcxx . . $ oscap_indent(2050848944e00d54).(str5, 2);
127 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(indented, " hello\n\n\n\n bye\n") != 0)
128 return 5;
129 freecxx . . $ free(5d22bdacc48458e8).(indented);
130
131 char *str6 = "\n\n\n\n\n\n\n\n";
132 indented = oscap_indentcxx . . $ oscap_indent(2050848944e00d54).(str6, 2);
133 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(indented, "\n\n\n\n\n\n\n\n") != 0)
134 return 6;
135 freecxx . . $ free(5d22bdacc48458e8).(indented);
136
137 return 0;
138 }
139
140 int test_oscap_remove_excess_whitespacecxx . . $ test_oscap_remove_excess_whitespace(b126dc7c1de90089).()
141 {
142 char *result;
143
144 char *str1 = " hello \n world \n";
145 result = oscap_remove_excess_whitespacecxx . . $ oscap_remove_excess_whitespace(a8b8e32347182212).(str1);
146 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(result, "hello\nworld\n") != 0)
147 return 1;
148 freecxx . . $ free(5d22bdacc48458e8).(result);
149
150 char *str2 = " hello world ";
151 result = oscap_remove_excess_whitespacecxx . . $ oscap_remove_excess_whitespace(a8b8e32347182212).(str2);
152 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(result, "hello world") != 0)
153 return 2;
154 freecxx . . $ free(5d22bdacc48458e8).(result);
155
156 char *str3 = " \n \n \n";
157 result = oscap_remove_excess_whitespacecxx . . $ oscap_remove_excess_whitespace(a8b8e32347182212).(str3);
158 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(result, "") != 0)
159 return 3;
160 freecxx . . $ free(5d22bdacc48458e8).(result);
161
162 char *str4 = "";
163 result = oscap_remove_excess_whitespacecxx . . $ oscap_remove_excess_whitespace(a8b8e32347182212).(str4);
164 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(result, "") != 0)
165 return 4;
166 freecxx . . $ free(5d22bdacc48458e8).(result);
167
168 return 0;
169 }
170
171 int maincxx . . $ main(afcd3168fc1188a4). (int argc, char *argv[])
172 {
173 int retval = 0;
174
175 if ((retval = test_oscap_path_startswithcxx . . $ test_oscap_path_startswith(b126dc7c1de90089).()) != 0)
176 return retval;
177 if ((retval = test_oscap_strrmcxx . . $ test_oscap_strrm(b126dc7c1de90089).()) != 0)
178 return retval;
179 if ((retval = test_oscap_indentcxx . . $ test_oscap_indent(b126dc7c1de90089).()) != 0)
180 return retval;
181 if ((retval = test_oscap_remove_excess_whitespacecxx . . $ test_oscap_remove_excess_whitespace(b126dc7c1de90089).()) != 0)
182 return retval;
183
184 return retval;
185 }