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.c72
1 files changed, 70 insertions, 2 deletions
diff --git a/src/util/test_disk.c b/src/util/test_disk.c
index 055e155e9..7b9a6d45c 100644
--- a/src/util/test_disk.c
+++ b/src/util/test_disk.c
@@ -28,6 +28,7 @@
28 28
29#define TESTSTRING "Hello World\0" 29#define TESTSTRING "Hello World\0"
30 30
31
31static int 32static int
32testReadWrite () 33testReadWrite ()
33{ 34{
@@ -79,6 +80,7 @@ testReadWrite ()
79 return 0; 80 return 0;
80} 81}
81 82
83
82static int 84static int
83testOpenClose () 85testOpenClose ()
84{ 86{
@@ -104,6 +106,7 @@ testOpenClose ()
104 106
105static int ok; 107static int ok;
106 108
109
107static int 110static int
108scan_callback (void *want, const char *filename) 111scan_callback (void *want, const char *filename)
109{ 112{
@@ -112,41 +115,83 @@ scan_callback (void *want, const char *filename)
112 return GNUNET_OK; 115 return GNUNET_OK;
113} 116}
114 117
118
115static int 119static int
116testDirScan () 120testDirScan ()
117{ 121{
118 if (GNUNET_OK != 122 if (GNUNET_OK !=
119 GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry")) 123 GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry"))
124 {
125 GNUNET_break (0);
120 return 1; 126 return 1;
127 }
121 if (GNUNET_OK != 128 if (GNUNET_OK !=
122 GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more")) 129 GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more"))
130 {
131 GNUNET_break (0);
123 return 1; 132 return 1;
133 }
124 GNUNET_DISK_directory_scan ("test", &scan_callback, 134 GNUNET_DISK_directory_scan ("test", &scan_callback,
125 "test" DIR_SEPARATOR_STR "entry"); 135 "test" DIR_SEPARATOR_STR "entry");
126 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) 136 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
137 {
138 GNUNET_break (0);
127 return 1; 139 return 1;
140 }
128 if (ok < 2) 141 if (ok < 2)
142 {
143 GNUNET_break (0);
129 return 1; 144 return 1;
145 }
130 return 0; 146 return 0;
131} 147}
132 148
133 149
134static int 150static int
151iter_callback (void *cls,
152 const char *filename)
153{
154 int *i = cls;
155
156 (*i)++;
157 return GNUNET_OK;
158}
159
160
161static int
135testDirIter () 162testDirIter ()
136{ 163{
137 int i; 164 int i;
138 165
139 i = 0; 166 i = 0;
140 if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry")) 167 if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry"))
168 {
169 GNUNET_break (0);
141 return 1; 170 return 1;
171 }
142 if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_many")) 172 if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_many"))
173 {
174 GNUNET_break (0);
143 return 1; 175 return 1;
176 }
144 if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_more")) 177 if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_more"))
178 {
179 GNUNET_break (0);
145 return 1; 180 return 1;
181 }
182 GNUNET_DISK_directory_scan ("test",
183 &iter_callback,
184 &i);
146 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) 185 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
186 {
187 GNUNET_break (0);
147 return 1; 188 return 1;
189 }
148 if (i < 3) 190 if (i < 3)
191 {
192 GNUNET_break (0);
149 return 1; 193 return 1;
194 }
150 return 0; 195 return 0;
151} 196}
152 197
@@ -183,19 +228,40 @@ static int
183testDirMani () 228testDirMani ()
184{ 229{
185 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file ("test/ing")) 230 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file ("test/ing"))
231 {
232 GNUNET_break (0);
186 return 1; 233 return 1;
234 }
187 if (GNUNET_NO != GNUNET_DISK_file_test ("test")) 235 if (GNUNET_NO != GNUNET_DISK_file_test ("test"))
236 {
237 GNUNET_break (0);
188 return 1; 238 return 1;
239 }
189 if (GNUNET_NO != GNUNET_DISK_file_test ("test/ing")) 240 if (GNUNET_NO != GNUNET_DISK_file_test ("test/ing"))
241 {
242 GNUNET_break (0);
190 return 1; 243 return 1;
244 }
191 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) 245 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
246 {
247 GNUNET_break (0);
192 return 1; 248 return 1;
249 }
193 if (GNUNET_OK != GNUNET_DISK_directory_create ("test")) 250 if (GNUNET_OK != GNUNET_DISK_directory_create ("test"))
251 {
252 GNUNET_break (0);
194 return 1; 253 return 1;
254 }
195 if (GNUNET_YES != GNUNET_DISK_directory_test ("test", GNUNET_YES)) 255 if (GNUNET_YES != GNUNET_DISK_directory_test ("test", GNUNET_YES))
256 {
257 GNUNET_break (0);
196 return 1; 258 return 1;
259 }
197 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) 260 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
261 {
262 GNUNET_break (0);
198 return 1; 263 return 1;
264 }
199 return 0; 265 return 0;
200} 266}
201 267
@@ -213,9 +279,11 @@ main (int argc, char *argv[])
213 failureCount += testCanonicalize (); 279 failureCount += testCanonicalize ();
214 failureCount += testChangeOwner (); 280 failureCount += testChangeOwner ();
215 failureCount += testDirMani (); 281 failureCount += testDirMani ();
216 if (failureCount != 0) 282 if (0 != failureCount)
217 { 283 {
218 FPRINTF (stderr, "\n%u TESTS FAILED!\n", failureCount); 284 FPRINTF (stderr,
285 "\n%u TESTS FAILED!\n",
286 failureCount);
219 return -1; 287 return -1;
220 } 288 }
221 return 0; 289 return 0;