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