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.c101
1 files changed, 51 insertions, 50 deletions
diff --git a/src/util/test_disk.c b/src/util/test_disk.c
index 91154a6f5..e8ec88c9f 100644
--- a/src/util/test_disk.c
+++ b/src/util/test_disk.c
@@ -38,40 +38,41 @@ testReadWrite ()
38 38
39 if (strlen (TESTSTRING) != 39 if (strlen (TESTSTRING) !=
40 GNUNET_DISK_fn_write (".testfile", TESTSTRING, strlen (TESTSTRING), 40 GNUNET_DISK_fn_write (".testfile", TESTSTRING, strlen (TESTSTRING),
41 GNUNET_DISK_PERM_USER_READ | 41 GNUNET_DISK_PERM_USER_READ |
42 GNUNET_DISK_PERM_USER_WRITE)) 42 GNUNET_DISK_PERM_USER_WRITE))
43 return 1; 43 return 1;
44 if (GNUNET_OK != GNUNET_DISK_file_test (".testfile")) 44 if (GNUNET_OK != GNUNET_DISK_file_test (".testfile"))
45 return 1; 45 return 1;
46 ret = GNUNET_DISK_fn_read (".testfile", tmp, sizeof (tmp) - 1); 46 ret = GNUNET_DISK_fn_read (".testfile", tmp, sizeof (tmp) - 1);
47 if (ret < 0) 47 if (ret < 0)
48 { 48 {
49 fprintf (stderr, "Error reading file `%s' in testReadWrite\n", ".testfile"); 49 fprintf (stderr, "Error reading file `%s' in testReadWrite\n",
50 return 1; 50 ".testfile");
51 } 51 return 1;
52 }
52 tmp[ret] = '\0'; 53 tmp[ret] = '\0';
53 if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1)) 54 if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1))
54 { 55 {
55 fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp, 56 fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n",
56 TESTSTRING, ".testfile"); 57 tmp, TESTSTRING, ".testfile");
57 return 1; 58 return 1;
58 } 59 }
59 GNUNET_DISK_file_copy (".testfile", ".testfile2"); 60 GNUNET_DISK_file_copy (".testfile", ".testfile2");
60 memset (tmp, 0, sizeof (tmp)); 61 memset (tmp, 0, sizeof (tmp));
61 ret = GNUNET_DISK_fn_read (".testfile2", tmp, sizeof (tmp) - 1); 62 ret = GNUNET_DISK_fn_read (".testfile2", tmp, sizeof (tmp) - 1);
62 if (ret < 0) 63 if (ret < 0)
63 { 64 {
64 fprintf (stderr, "Error reading file `%s' in testReadWrite\n", 65 fprintf (stderr, "Error reading file `%s' in testReadWrite\n",
65 ".testfile2"); 66 ".testfile2");
66 return 1; 67 return 1;
67 } 68 }
68 tmp[ret] = '\0'; 69 tmp[ret] = '\0';
69 if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1)) 70 if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1))
70 { 71 {
71 fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp, 72 fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n",
72 TESTSTRING, ".testfile2"); 73 tmp, TESTSTRING, ".testfile2");
73 return 1; 74 return 1;
74 } 75 }
75 76
76 GNUNET_break (0 == UNLINK (".testfile")); 77 GNUNET_break (0 == UNLINK (".testfile"));
77 GNUNET_break (0 == UNLINK (".testfile2")); 78 GNUNET_break (0 == UNLINK (".testfile2"));
@@ -89,15 +90,15 @@ testOpenClose ()
89 long avail; 90 long avail;
90 91
91 fh = GNUNET_DISK_file_open (".testfile", 92 fh = GNUNET_DISK_file_open (".testfile",
92 GNUNET_DISK_OPEN_READWRITE | 93 GNUNET_DISK_OPEN_READWRITE |
93 GNUNET_DISK_OPEN_CREATE, 94 GNUNET_DISK_OPEN_CREATE,
94 GNUNET_DISK_PERM_USER_READ | 95 GNUNET_DISK_PERM_USER_READ |
95 GNUNET_DISK_PERM_USER_WRITE); 96 GNUNET_DISK_PERM_USER_WRITE);
96 GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh)); 97 GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh));
97 GNUNET_break (5 == GNUNET_DISK_file_write (fh, "Hello", 5)); 98 GNUNET_break (5 == GNUNET_DISK_file_write (fh, "Hello", 5));
98 GNUNET_DISK_file_close (fh); 99 GNUNET_DISK_file_close (fh);
99 GNUNET_break (GNUNET_OK == 100 GNUNET_break (GNUNET_OK ==
100 GNUNET_DISK_file_size (".testfile", &size, GNUNET_NO)); 101 GNUNET_DISK_file_size (".testfile", &size, GNUNET_NO));
101 if (size != 5) 102 if (size != 5)
102 return 1; 103 return 1;
103 GNUNET_break (0 == UNLINK (".testfile")); 104 GNUNET_break (0 == UNLINK (".testfile"));
@@ -107,19 +108,19 @@ testOpenClose ()
107 avail = GNUNET_DISK_get_blocks_available (".testfile"); 108 avail = GNUNET_DISK_get_blocks_available (".testfile");
108 GNUNET_log_skip (0, GNUNET_NO); 109 GNUNET_log_skip (0, GNUNET_NO);
109 fh = GNUNET_DISK_file_open (".testfile", 110 fh = GNUNET_DISK_file_open (".testfile",
110 GNUNET_DISK_OPEN_READWRITE | 111 GNUNET_DISK_OPEN_READWRITE |
111 GNUNET_DISK_OPEN_CREATE, 112 GNUNET_DISK_OPEN_CREATE,
112 GNUNET_DISK_PERM_USER_WRITE | 113 GNUNET_DISK_PERM_USER_WRITE |
113 GNUNET_DISK_PERM_USER_READ); 114 GNUNET_DISK_PERM_USER_READ);
114 GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh)); 115 GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh));
115 while ((avail == GNUNET_DISK_get_blocks_available (".testfile")) && 116 while ((avail == GNUNET_DISK_get_blocks_available (".testfile")) &&
116 (avail != -1)) 117 (avail != -1))
117 if (16 != GNUNET_DISK_file_write (fh, "HelloWorld123456", 16)) 118 if (16 != GNUNET_DISK_file_write (fh, "HelloWorld123456", 16))
118 { 119 {
119 GNUNET_DISK_file_close (fh); 120 GNUNET_DISK_file_close (fh);
120 GNUNET_break (0 == UNLINK (".testfile")); 121 GNUNET_break (0 == UNLINK (".testfile"));
121 return 1; 122 return 1;
122 } 123 }
123 GNUNET_DISK_file_close (fh); 124 GNUNET_DISK_file_close (fh);
124 GNUNET_break (0 == UNLINK (".testfile")); 125 GNUNET_break (0 == UNLINK (".testfile"));
125 126
@@ -146,7 +147,7 @@ testDirScan ()
146 GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more")) 147 GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more"))
147 return 1; 148 return 1;
148 GNUNET_DISK_directory_scan ("test", &scan_callback, 149 GNUNET_DISK_directory_scan ("test", &scan_callback,
149 "test" DIR_SEPARATOR_STR "entry"); 150 "test" DIR_SEPARATOR_STR "entry");
150 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) 151 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
151 return 1; 152 return 1;
152 if (ok < 2) 153 if (ok < 2)
@@ -156,7 +157,7 @@ testDirScan ()
156 157
157static void 158static void
158iter_callback (void *cls, struct GNUNET_DISK_DirectoryIterator *di, 159iter_callback (void *cls, struct GNUNET_DISK_DirectoryIterator *di,
159 const char *filename, const char *dirname) 160 const char *filename, const char *dirname)
160{ 161{
161 int *i = cls; 162 int *i = cls;
162 163
@@ -168,7 +169,7 @@ static void
168iter_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 169iter_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
169{ 170{
170 GNUNET_DISK_directory_iterator_start (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 171 GNUNET_DISK_directory_iterator_start (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
171 "test", &iter_callback, cls); 172 "test", &iter_callback, cls);
172} 173}
173 174
174static int 175static int
@@ -202,14 +203,14 @@ testGetHome ()
202 cfg = GNUNET_CONFIGURATION_create (); 203 cfg = GNUNET_CONFIGURATION_create ();
203 GNUNET_assert (cfg != NULL); 204 GNUNET_assert (cfg != NULL);
204 GNUNET_CONFIGURATION_set_value_string (cfg, "service", "HOME", 205 GNUNET_CONFIGURATION_set_value_string (cfg, "service", "HOME",
205 "/tmp/test-gnunet-disk-a/b/c"); 206 "/tmp/test-gnunet-disk-a/b/c");
206 fn = GNUNET_DISK_get_home_filename (cfg, "service", "d", "e", NULL); 207 fn = GNUNET_DISK_get_home_filename (cfg, "service", "d", "e", NULL);
207 GNUNET_assert (fn != NULL); 208 GNUNET_assert (fn != NULL);
208 GNUNET_CONFIGURATION_destroy (cfg); 209 GNUNET_CONFIGURATION_destroy (cfg);
209 ret = strcmp ("/tmp/test-gnunet-disk-a/b/c/d/e", fn); 210 ret = strcmp ("/tmp/test-gnunet-disk-a/b/c/d/e", fn);
210 GNUNET_free (fn); 211 GNUNET_free (fn);
211 GNUNET_break (GNUNET_OK == 212 GNUNET_break (GNUNET_OK ==
212 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-disk-a")); 213 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-disk-a"));
213 return ret; 214 return ret;
214} 215}
215 216
@@ -220,10 +221,10 @@ testCanonicalize ()
220 221
221 GNUNET_DISK_filename_canonicalize (fn); 222 GNUNET_DISK_filename_canonicalize (fn);
222 if (0 != strcmp (fn, "ab____cd_ef__g_")) 223 if (0 != strcmp (fn, "ab____cd_ef__g_"))
223 { 224 {
224 GNUNET_free (fn); 225 GNUNET_free (fn);
225 return 1; 226 return 1;
226 } 227 }
227 GNUNET_free (fn); 228 GNUNET_free (fn);
228 return 0; 229 return 0;
229} 230}
@@ -275,9 +276,9 @@ main (int argc, char *argv[])
275 failureCount += testChangeOwner (); 276 failureCount += testChangeOwner ();
276 failureCount += testDirMani (); 277 failureCount += testDirMani ();
277 if (failureCount != 0) 278 if (failureCount != 0)
278 { 279 {
279 fprintf (stderr, "\n%u TESTS FAILED!\n", failureCount); 280 fprintf (stderr, "\n%u TESTS FAILED!\n", failureCount);
280 return -1; 281 return -1;
281 } 282 }
282 return 0; 283 return 0;
283} /* end of main */ 284} /* end of main */