aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_disk.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/test_disk.c')
-rw-r--r--src/util/test_disk.c336
1 files changed, 168 insertions, 168 deletions
diff --git a/src/util/test_disk.c b/src/util/test_disk.c
index 5746aa96e..13fb18e88 100644
--- a/src/util/test_disk.c
+++ b/src/util/test_disk.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file util/test_disk.c 22 * @file util/test_disk.c
@@ -30,51 +30,51 @@
30 30
31 31
32static int 32static int
33testReadWrite () 33testReadWrite()
34{ 34{
35 char tmp[100 + 1]; 35 char tmp[100 + 1];
36 int ret; 36 int ret;
37 37
38 if (strlen (TESTSTRING) != 38 if (strlen(TESTSTRING) !=
39 GNUNET_DISK_fn_write (".testfile", TESTSTRING, strlen (TESTSTRING), 39 GNUNET_DISK_fn_write(".testfile", TESTSTRING, strlen(TESTSTRING),
40 GNUNET_DISK_PERM_USER_READ | 40 GNUNET_DISK_PERM_USER_READ |
41 GNUNET_DISK_PERM_USER_WRITE)) 41 GNUNET_DISK_PERM_USER_WRITE))
42 return 1; 42 return 1;
43 if (GNUNET_OK != GNUNET_DISK_file_test (".testfile")) 43 if (GNUNET_OK != GNUNET_DISK_file_test(".testfile"))
44 return 1; 44 return 1;
45 ret = GNUNET_DISK_fn_read (".testfile", tmp, sizeof (tmp) - 1); 45 ret = GNUNET_DISK_fn_read(".testfile", tmp, sizeof(tmp) - 1);
46 if (ret < 0) 46 if (ret < 0)
47 { 47 {
48 fprintf (stderr, "Error reading file `%s' in testReadWrite\n", ".testfile"); 48 fprintf(stderr, "Error reading file `%s' in testReadWrite\n", ".testfile");
49 return 1; 49 return 1;
50 } 50 }
51 tmp[ret] = '\0'; 51 tmp[ret] = '\0';
52 if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1)) 52 if (0 != memcmp(tmp, TESTSTRING, strlen(TESTSTRING) + 1))
53 { 53 {
54 fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp, 54 fprintf(stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
55 TESTSTRING, ".testfile"); 55 TESTSTRING, ".testfile");
56 return 1; 56 return 1;
57 } 57 }
58 GNUNET_DISK_file_copy (".testfile", ".testfile2"); 58 GNUNET_DISK_file_copy(".testfile", ".testfile2");
59 memset (tmp, 0, sizeof (tmp)); 59 memset(tmp, 0, sizeof(tmp));
60 ret = GNUNET_DISK_fn_read (".testfile2", tmp, sizeof (tmp) - 1); 60 ret = GNUNET_DISK_fn_read(".testfile2", tmp, sizeof(tmp) - 1);
61 if (ret < 0) 61 if (ret < 0)
62 { 62 {
63 fprintf (stderr, "Error reading file `%s' in testReadWrite\n", 63 fprintf(stderr, "Error reading file `%s' in testReadWrite\n",
64 ".testfile2"); 64 ".testfile2");
65 return 1; 65 return 1;
66 } 66 }
67 tmp[ret] = '\0'; 67 tmp[ret] = '\0';
68 if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1)) 68 if (0 != memcmp(tmp, TESTSTRING, strlen(TESTSTRING) + 1))
69 { 69 {
70 fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp, 70 fprintf(stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
71 TESTSTRING, ".testfile2"); 71 TESTSTRING, ".testfile2");
72 return 1; 72 return 1;
73 } 73 }
74 74
75 GNUNET_break (0 == unlink (".testfile")); 75 GNUNET_break(0 == unlink(".testfile"));
76 GNUNET_break (0 == unlink (".testfile2")); 76 GNUNET_break(0 == unlink(".testfile2"));
77 if (GNUNET_NO != GNUNET_DISK_file_test (".testfile")) 77 if (GNUNET_NO != GNUNET_DISK_file_test(".testfile"))
78 return 1; 78 return 1;
79 79
80 return 0; 80 return 0;
@@ -82,24 +82,24 @@ testReadWrite ()
82 82
83 83
84static int 84static int
85testOpenClose () 85testOpenClose()
86{ 86{
87 struct GNUNET_DISK_FileHandle *fh; 87 struct GNUNET_DISK_FileHandle *fh;
88 uint64_t size; 88 uint64_t size;
89 89
90 fh = GNUNET_DISK_file_open (".testfile", 90 fh = GNUNET_DISK_file_open(".testfile",
91 GNUNET_DISK_OPEN_READWRITE | 91 GNUNET_DISK_OPEN_READWRITE |
92 GNUNET_DISK_OPEN_CREATE, 92 GNUNET_DISK_OPEN_CREATE,
93 GNUNET_DISK_PERM_USER_READ | 93 GNUNET_DISK_PERM_USER_READ |
94 GNUNET_DISK_PERM_USER_WRITE); 94 GNUNET_DISK_PERM_USER_WRITE);
95 GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh)); 95 GNUNET_assert(GNUNET_NO == GNUNET_DISK_handle_invalid(fh));
96 GNUNET_break (5 == GNUNET_DISK_file_write (fh, "Hello", 5)); 96 GNUNET_break(5 == GNUNET_DISK_file_write(fh, "Hello", 5));
97 GNUNET_DISK_file_close (fh); 97 GNUNET_DISK_file_close(fh);
98 GNUNET_break (GNUNET_OK == 98 GNUNET_break(GNUNET_OK ==
99 GNUNET_DISK_file_size (".testfile", &size, GNUNET_NO, GNUNET_YES)); 99 GNUNET_DISK_file_size(".testfile", &size, GNUNET_NO, GNUNET_YES));
100 if (size != 5) 100 if (size != 5)
101 return 1; 101 return 1;
102 GNUNET_break (0 == unlink (".testfile")); 102 GNUNET_break(0 == unlink(".testfile"));
103 103
104 return 0; 104 return 0;
105} 105}
@@ -108,116 +108,116 @@ static int ok;
108 108
109 109
110static int 110static int
111scan_callback (void *want, const char *filename) 111scan_callback(void *want, const char *filename)
112{ 112{
113 if (NULL != strstr (filename, want)) 113 if (NULL != strstr(filename, want))
114 ok++; 114 ok++;
115 return GNUNET_OK; 115 return GNUNET_OK;
116} 116}
117 117
118 118
119static int 119static int
120testDirScan () 120testDirScan()
121{ 121{
122 if (GNUNET_OK != 122 if (GNUNET_OK !=
123 GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry")) 123 GNUNET_DISK_directory_create("test" DIR_SEPARATOR_STR "entry"))
124 { 124 {
125 GNUNET_break (0); 125 GNUNET_break(0);
126 return 1; 126 return 1;
127 } 127 }
128 if (GNUNET_OK != 128 if (GNUNET_OK !=
129 GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more")) 129 GNUNET_DISK_directory_create("test" DIR_SEPARATOR_STR "entry_more"))
130 { 130 {
131 GNUNET_break (0); 131 GNUNET_break(0);
132 return 1; 132 return 1;
133 } 133 }
134 GNUNET_DISK_directory_scan ("test", &scan_callback, 134 GNUNET_DISK_directory_scan("test", &scan_callback,
135 "test" DIR_SEPARATOR_STR "entry"); 135 "test" DIR_SEPARATOR_STR "entry");
136 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) 136 if (GNUNET_OK != GNUNET_DISK_directory_remove("test"))
137 { 137 {
138 GNUNET_break (0); 138 GNUNET_break(0);
139 return 1; 139 return 1;
140 } 140 }
141 if (ok < 2) 141 if (ok < 2)
142 { 142 {
143 GNUNET_break (0); 143 GNUNET_break(0);
144 return 1; 144 return 1;
145 } 145 }
146 return 0; 146 return 0;
147} 147}
148 148
149 149
150static int 150static int
151iter_callback (void *cls, 151iter_callback(void *cls,
152 const char *filename) 152 const char *filename)
153{ 153{
154 int *i = cls; 154 int *i = cls;
155 155
156 (*i)++; 156 (*i)++;
157 return GNUNET_OK; 157 return GNUNET_OK;
158} 158}
159 159
160 160
161static int 161static int
162testDirIter () 162testDirIter()
163{ 163{
164 int i; 164 int i;
165 165
166 i = 0; 166 i = 0;
167 if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry")) 167 if (GNUNET_OK != GNUNET_DISK_directory_create("test/entry"))
168 { 168 {
169 GNUNET_break (0); 169 GNUNET_break(0);
170 return 1; 170 return 1;
171 } 171 }
172 if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_many")) 172 if (GNUNET_OK != GNUNET_DISK_directory_create("test/entry_many"))
173 { 173 {
174 GNUNET_break (0); 174 GNUNET_break(0);
175 return 1; 175 return 1;
176 } 176 }
177 if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_more")) 177 if (GNUNET_OK != GNUNET_DISK_directory_create("test/entry_more"))
178 { 178 {
179 GNUNET_break (0); 179 GNUNET_break(0);
180 return 1; 180 return 1;
181 } 181 }
182 GNUNET_DISK_directory_scan ("test", 182 GNUNET_DISK_directory_scan("test",
183 &iter_callback, 183 &iter_callback,
184 &i); 184 &i);
185 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) 185 if (GNUNET_OK != GNUNET_DISK_directory_remove("test"))
186 { 186 {
187 GNUNET_break (0); 187 GNUNET_break(0);
188 return 1; 188 return 1;
189 } 189 }
190 if (i < 3) 190 if (i < 3)
191 { 191 {
192 GNUNET_break (0); 192 GNUNET_break(0);
193 return 1; 193 return 1;
194 } 194 }
195 return 0; 195 return 0;
196} 196}
197 197
198 198
199static int 199static int
200testCanonicalize () 200testCanonicalize()
201{ 201{
202 char *fn = GNUNET_strdup ("ab?><|cd*ef:/g\""); 202 char *fn = GNUNET_strdup("ab?><|cd*ef:/g\"");
203 203
204 GNUNET_DISK_filename_canonicalize (fn); 204 GNUNET_DISK_filename_canonicalize(fn);
205 if (0 != strcmp (fn, "ab____cd_ef__g_")) 205 if (0 != strcmp(fn, "ab____cd_ef__g_"))
206 { 206 {
207 GNUNET_free (fn); 207 GNUNET_free(fn);
208 return 1; 208 return 1;
209 } 209 }
210 GNUNET_free (fn); 210 GNUNET_free(fn);
211 return 0; 211 return 0;
212} 212}
213 213
214 214
215static int 215static int
216testChangeOwner () 216testChangeOwner()
217{ 217{
218#ifndef WINDOWS 218#ifndef WINDOWS
219 GNUNET_log_skip (1, GNUNET_NO); 219 GNUNET_log_skip(1, GNUNET_NO);
220 if (GNUNET_OK == GNUNET_DISK_file_change_owner ("/dev/null", "unknownuser")) 220 if (GNUNET_OK == GNUNET_DISK_file_change_owner("/dev/null", "unknownuser"))
221 return 1; 221 return 1;
222#endif 222#endif
223 return 0; 223 return 0;
@@ -225,66 +225,66 @@ testChangeOwner ()
225 225
226 226
227static int 227static int
228testDirMani () 228testDirMani()
229{ 229{
230 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file ("test/ing")) 230 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file("test/ing"))
231 { 231 {
232 GNUNET_break (0); 232 GNUNET_break(0);
233 return 1; 233 return 1;
234 } 234 }
235 if (GNUNET_NO != GNUNET_DISK_file_test ("test")) 235 if (GNUNET_NO != GNUNET_DISK_file_test("test"))
236 { 236 {
237 GNUNET_break (0); 237 GNUNET_break(0);
238 return 1; 238 return 1;
239 } 239 }
240 if (GNUNET_NO != GNUNET_DISK_file_test ("test/ing")) 240 if (GNUNET_NO != GNUNET_DISK_file_test("test/ing"))
241 { 241 {
242 GNUNET_break (0); 242 GNUNET_break(0);
243 return 1; 243 return 1;
244 } 244 }
245 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) 245 if (GNUNET_OK != GNUNET_DISK_directory_remove("test"))
246 { 246 {
247 GNUNET_break (0); 247 GNUNET_break(0);
248 return 1; 248 return 1;
249 } 249 }
250 if (GNUNET_OK != GNUNET_DISK_directory_create ("test")) 250 if (GNUNET_OK != GNUNET_DISK_directory_create("test"))
251 { 251 {
252 GNUNET_break (0); 252 GNUNET_break(0);
253 return 1; 253 return 1;
254 } 254 }
255 if (GNUNET_YES != GNUNET_DISK_directory_test ("test", GNUNET_YES)) 255 if (GNUNET_YES != GNUNET_DISK_directory_test("test", GNUNET_YES))
256 { 256 {
257 GNUNET_break (0); 257 GNUNET_break(0);
258 return 1; 258 return 1;
259 } 259 }
260 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) 260 if (GNUNET_OK != GNUNET_DISK_directory_remove("test"))
261 { 261 {
262 GNUNET_break (0); 262 GNUNET_break(0);
263 return 1; 263 return 1;
264 } 264 }
265 return 0; 265 return 0;
266} 266}
267 267
268 268
269int 269int
270main (int argc, char *argv[]) 270main(int argc, char *argv[])
271{ 271{
272 unsigned int failureCount = 0; 272 unsigned int failureCount = 0;
273 273
274 GNUNET_log_setup ("test-disk", "WARNING", NULL); 274 GNUNET_log_setup("test-disk", "WARNING", NULL);
275 failureCount += testReadWrite (); 275 failureCount += testReadWrite();
276 failureCount += testOpenClose (); 276 failureCount += testOpenClose();
277 failureCount += testDirScan (); 277 failureCount += testDirScan();
278 failureCount += testDirIter (); 278 failureCount += testDirIter();
279 failureCount += testCanonicalize (); 279 failureCount += testCanonicalize();
280 failureCount += testChangeOwner (); 280 failureCount += testChangeOwner();
281 failureCount += testDirMani (); 281 failureCount += testDirMani();
282 if (0 != failureCount) 282 if (0 != failureCount)
283 { 283 {
284 fprintf (stderr, 284 fprintf(stderr,
285 "\n%u TESTS FAILED!\n", 285 "\n%u TESTS FAILED!\n",
286 failureCount); 286 failureCount);
287 return -1; 287 return -1;
288 } 288 }
289 return 0; 289 return 0;
290} /* end of main */ 290} /* end of main */