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.c331
1 files changed, 166 insertions, 165 deletions
diff --git a/src/util/test_disk.c b/src/util/test_disk.c
index cacbe8be0..7ed61c332 100644
--- a/src/util/test_disk.c
+++ b/src/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,25 @@ 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,
100 GNUNET_YES));
100 if (size != 5) 101 if (size != 5)
101 return 1; 102 return 1;
102 GNUNET_break(0 == unlink(".testfile")); 103 GNUNET_break (0 == unlink (".testfile"));
103 104
104 return 0; 105 return 0;
105} 106}
@@ -108,48 +109,48 @@ static int ok;
108 109
109 110
110static int 111static int
111scan_callback(void *want, const char *filename) 112scan_callback (void *want, const char *filename)
112{ 113{
113 if (NULL != strstr(filename, want)) 114 if (NULL != strstr (filename, want))
114 ok++; 115 ok++;
115 return GNUNET_OK; 116 return GNUNET_OK;
116} 117}
117 118
118 119
119static int 120static int
120testDirScan() 121testDirScan ()
121{ 122{
122 if (GNUNET_OK != 123 if (GNUNET_OK !=
123 GNUNET_DISK_directory_create("test" DIR_SEPARATOR_STR "entry")) 124 GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry"))
124 { 125 {
125 GNUNET_break(0); 126 GNUNET_break (0);
126 return 1; 127 return 1;
127 } 128 }
128 if (GNUNET_OK != 129 if (GNUNET_OK !=
129 GNUNET_DISK_directory_create("test" DIR_SEPARATOR_STR "entry_more")) 130 GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more"))
130 { 131 {
131 GNUNET_break(0); 132 GNUNET_break (0);
132 return 1; 133 return 1;
133 } 134 }
134 GNUNET_DISK_directory_scan("test", &scan_callback, 135 GNUNET_DISK_directory_scan ("test", &scan_callback,
135 "test" DIR_SEPARATOR_STR "entry"); 136 "test" DIR_SEPARATOR_STR "entry");
136 if (GNUNET_OK != GNUNET_DISK_directory_remove("test")) 137 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
137 { 138 {
138 GNUNET_break(0); 139 GNUNET_break (0);
139 return 1; 140 return 1;
140 } 141 }
141 if (ok < 2) 142 if (ok < 2)
142 { 143 {
143 GNUNET_break(0); 144 GNUNET_break (0);
144 return 1; 145 return 1;
145 } 146 }
146 return 0; 147 return 0;
147} 148}
148 149
149 150
150static int 151static int
151iter_callback(void *cls, 152iter_callback (void *cls,
152 const char *filename) 153 const char *filename)
153{ 154{
154 int *i = cls; 155 int *i = cls;
155 156
@@ -159,130 +160,130 @@ iter_callback(void *cls,
159 160
160 161
161static int 162static int
162testDirIter() 163testDirIter ()
163{ 164{
164 int i; 165 int i;
165 166
166 i = 0; 167 i = 0;
167 if (GNUNET_OK != GNUNET_DISK_directory_create("test/entry")) 168 if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry"))
168 { 169 {
169 GNUNET_break(0); 170 GNUNET_break (0);
170 return 1; 171 return 1;
171 } 172 }
172 if (GNUNET_OK != GNUNET_DISK_directory_create("test/entry_many")) 173 if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_many"))
173 { 174 {
174 GNUNET_break(0); 175 GNUNET_break (0);
175 return 1; 176 return 1;
176 } 177 }
177 if (GNUNET_OK != GNUNET_DISK_directory_create("test/entry_more")) 178 if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_more"))
178 { 179 {
179 GNUNET_break(0); 180 GNUNET_break (0);
180 return 1; 181 return 1;
181 } 182 }
182 GNUNET_DISK_directory_scan("test", 183 GNUNET_DISK_directory_scan ("test",
183 &iter_callback, 184 &iter_callback,
184 &i); 185 &i);
185 if (GNUNET_OK != GNUNET_DISK_directory_remove("test")) 186 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
186 { 187 {
187 GNUNET_break(0); 188 GNUNET_break (0);
188 return 1; 189 return 1;
189 } 190 }
190 if (i < 3) 191 if (i < 3)
191 { 192 {
192 GNUNET_break(0); 193 GNUNET_break (0);
193 return 1; 194 return 1;
194 } 195 }
195 return 0; 196 return 0;
196} 197}
197 198
198 199
199static int 200static int
200testCanonicalize() 201testCanonicalize ()
201{ 202{
202 char *fn = GNUNET_strdup("ab?><|cd*ef:/g\""); 203 char *fn = GNUNET_strdup ("ab?><|cd*ef:/g\"");
203 204
204 GNUNET_DISK_filename_canonicalize(fn); 205 GNUNET_DISK_filename_canonicalize (fn);
205 if (0 != strcmp(fn, "ab____cd_ef__g_")) 206 if (0 != strcmp (fn, "ab____cd_ef__g_"))
206 { 207 {
207 GNUNET_free(fn); 208 GNUNET_free (fn);
208 return 1; 209 return 1;
209 } 210 }
210 GNUNET_free(fn); 211 GNUNET_free (fn);
211 return 0; 212 return 0;
212} 213}
213 214
214 215
215static int 216static int
216testChangeOwner() 217testChangeOwner ()
217{ 218{
218 GNUNET_log_skip(1, GNUNET_NO); 219 GNUNET_log_skip (1, GNUNET_NO);
219 if (GNUNET_OK == GNUNET_DISK_file_change_owner("/dev/null", "unknownuser")) 220 if (GNUNET_OK == GNUNET_DISK_file_change_owner ("/dev/null", "unknownuser"))
220 return 1; 221 return 1;
221 return 0; 222 return 0;
222} 223}
223 224
224 225
225static int 226static int
226testDirMani() 227testDirMani ()
227{ 228{
228 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file("test/ing")) 229 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file ("test/ing"))
229 { 230 {
230 GNUNET_break(0); 231 GNUNET_break (0);
231 return 1; 232 return 1;
232 } 233 }
233 if (GNUNET_NO != GNUNET_DISK_file_test("test")) 234 if (GNUNET_NO != GNUNET_DISK_file_test ("test"))
234 { 235 {
235 GNUNET_break(0); 236 GNUNET_break (0);
236 return 1; 237 return 1;
237 } 238 }
238 if (GNUNET_NO != GNUNET_DISK_file_test("test/ing")) 239 if (GNUNET_NO != GNUNET_DISK_file_test ("test/ing"))
239 { 240 {
240 GNUNET_break(0); 241 GNUNET_break (0);
241 return 1; 242 return 1;
242 } 243 }
243 if (GNUNET_OK != GNUNET_DISK_directory_remove("test")) 244 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
244 { 245 {
245 GNUNET_break(0); 246 GNUNET_break (0);
246 return 1; 247 return 1;
247 } 248 }
248 if (GNUNET_OK != GNUNET_DISK_directory_create("test")) 249 if (GNUNET_OK != GNUNET_DISK_directory_create ("test"))
249 { 250 {
250 GNUNET_break(0); 251 GNUNET_break (0);
251 return 1; 252 return 1;
252 } 253 }
253 if (GNUNET_YES != GNUNET_DISK_directory_test("test", GNUNET_YES)) 254 if (GNUNET_YES != GNUNET_DISK_directory_test ("test", GNUNET_YES))
254 { 255 {
255 GNUNET_break(0); 256 GNUNET_break (0);
256 return 1; 257 return 1;
257 } 258 }
258 if (GNUNET_OK != GNUNET_DISK_directory_remove("test")) 259 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
259 { 260 {
260 GNUNET_break(0); 261 GNUNET_break (0);
261 return 1; 262 return 1;
262 } 263 }
263 return 0; 264 return 0;
264} 265}
265 266
266 267
267int 268int
268main(int argc, char *argv[]) 269main (int argc, char *argv[])
269{ 270{
270 unsigned int failureCount = 0; 271 unsigned int failureCount = 0;
271 272
272 GNUNET_log_setup("test-disk", "WARNING", NULL); 273 GNUNET_log_setup ("test-disk", "WARNING", NULL);
273 failureCount += testReadWrite(); 274 failureCount += testReadWrite ();
274 failureCount += testOpenClose(); 275 failureCount += testOpenClose ();
275 failureCount += testDirScan(); 276 failureCount += testDirScan ();
276 failureCount += testDirIter(); 277 failureCount += testDirIter ();
277 failureCount += testCanonicalize(); 278 failureCount += testCanonicalize ();
278 failureCount += testChangeOwner(); 279 failureCount += testChangeOwner ();
279 failureCount += testDirMani(); 280 failureCount += testDirMani ();
280 if (0 != failureCount) 281 if (0 != failureCount)
281 { 282 {
282 fprintf(stderr, 283 fprintf (stderr,
283 "\n%u TESTS FAILED!\n", 284 "\n%u TESTS FAILED!\n",
284 failureCount); 285 failureCount);
285 return -1; 286 return -1;
286 } 287 }
287 return 0; 288 return 0;
288} /* end of main */ 289} /* end of main */