diff options
Diffstat (limited to 'src/util/test_bio.c')
-rw-r--r-- | src/util/test_bio.c | 601 |
1 files changed, 322 insertions, 279 deletions
diff --git a/src/util/test_bio.c b/src/util/test_bio.c index 53b45c23a..0c8453121 100644 --- a/src/util/test_bio.c +++ b/src/util/test_bio.c | |||
@@ -30,363 +30,406 @@ | |||
30 | #define TESTSTRING "testString" | 30 | #define TESTSTRING "testString" |
31 | #define TESTNUMBER64 ((int64_t) 100000L) | 31 | #define TESTNUMBER64 ((int64_t) 100000L) |
32 | 32 | ||
33 | |||
33 | static int | 34 | static int |
34 | test_normal_rw () | 35 | test_normal_rw (void) |
35 | { | 36 | { |
36 | char *msg; | 37 | struct GNUNET_BIO_WriteHandle *wh; |
37 | int64_t testNum; | 38 | struct GNUNET_BIO_ReadHandle *rh; |
38 | char *readResultString; | 39 | void *buffer; |
39 | char *fileName = GNUNET_DISK_mktemp ("gnunet_bio"); | 40 | size_t buffer_size = 0; |
40 | struct GNUNET_BIO_WriteHandle *fileW; | 41 | char *filename = GNUNET_DISK_mktemp ("gnunet-bio"); |
41 | struct GNUNET_BIO_ReadHandle *fileR; | 42 | struct GNUNET_CONTAINER_MetaData *mdW; |
42 | struct GNUNET_CONTAINER_MetaData *metaDataW; | 43 | struct GNUNET_CONTAINER_MetaData *mdR = NULL; |
43 | struct GNUNET_CONTAINER_MetaData *metaDataR; | 44 | char *rString = NULL; |
44 | 45 | int64_t wNum = TESTNUMBER64; | |
45 | metaDataW = GNUNET_CONTAINER_meta_data_create (); | 46 | int64_t rNum = 0; |
46 | metaDataR = NULL; | 47 | |
47 | GNUNET_CONTAINER_meta_data_add_publication_date (metaDataW); | 48 | mdW = GNUNET_CONTAINER_meta_data_create (); |
48 | 49 | GNUNET_CONTAINER_meta_data_add_publication_date (mdW); | |
49 | fileW = GNUNET_BIO_write_open (fileName); | 50 | |
50 | GNUNET_assert (NULL != fileW); | 51 | struct GNUNET_BIO_WriteSpec ws[] = { |
51 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW, TESTSTRING)); | 52 | GNUNET_BIO_write_spec_string ("test-normal-rw-string", TESTSTRING), |
52 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_meta_data (fileW, metaDataW)); | 53 | GNUNET_BIO_write_spec_meta_data ("test-normal-rw-metadata", mdW), |
53 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int64 (fileW, TESTNUMBER64)); | 54 | GNUNET_BIO_write_spec_int64 ("test-normal-rw-int64", &wNum), |
54 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); | 55 | GNUNET_BIO_write_spec_end(), |
55 | 56 | }; | |
56 | fileR = GNUNET_BIO_read_open (fileName); | 57 | |
57 | GNUNET_assert (NULL != fileR); | 58 | struct GNUNET_BIO_ReadSpec rs[] = { |
58 | readResultString = NULL; | 59 | GNUNET_BIO_read_spec_string ("test-normal-rw-string", &rString, 200), |
59 | GNUNET_assert (GNUNET_OK == | 60 | GNUNET_BIO_read_spec_meta_data ("test-normal-rw-metadata", &mdR), |
60 | GNUNET_BIO_read_string (fileR, "Read string error", | 61 | GNUNET_BIO_read_spec_int64 ("test-normal-rw-int64", &rNum), |
61 | &readResultString, 200)); | 62 | GNUNET_BIO_read_spec_end(), |
62 | GNUNET_assert (NULL != readResultString); | 63 | }; |
63 | GNUNET_assert (0 == strcmp (TESTSTRING, readResultString)); | 64 | |
64 | GNUNET_free (readResultString); | 65 | /* I/O on file */ |
66 | wh = GNUNET_BIO_write_open_file (filename); | ||
67 | GNUNET_assert (NULL != wh); | ||
68 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_spec_commit (wh, ws)); | ||
69 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | ||
70 | |||
71 | rh = GNUNET_BIO_read_open_file (filename); | ||
72 | GNUNET_assert (NULL != rh); | ||
73 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs)); | ||
74 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); | ||
75 | GNUNET_assert (0 == strcmp (TESTSTRING, rString)); | ||
76 | GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_meta_data_test_equal (mdR, mdW)); | ||
77 | GNUNET_assert (wNum == rNum); | ||
78 | |||
79 | GNUNET_CONTAINER_meta_data_destroy (mdR); | ||
80 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); | ||
81 | GNUNET_free(filename); | ||
82 | |||
83 | /* I/O on buffer */ | ||
84 | wh = GNUNET_BIO_write_open_buffer (); | ||
85 | GNUNET_assert (NULL != wh); | ||
86 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_spec_commit (wh, ws)); | ||
65 | GNUNET_assert (GNUNET_OK == | 87 | GNUNET_assert (GNUNET_OK == |
66 | GNUNET_BIO_read_meta_data (fileR, "Read meta error", | 88 | GNUNET_BIO_get_buffer_contents (wh, |
67 | &metaDataR)); | 89 | NULL, |
68 | GNUNET_assert (GNUNET_YES == | 90 | &buffer, |
69 | GNUNET_CONTAINER_meta_data_test_equal (metaDataR, metaDataW)); | 91 | &buffer_size)); |
70 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_int64 (fileR, &testNum)); | 92 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); |
71 | GNUNET_BIO_read_close (fileR, &msg); | 93 | |
72 | GNUNET_CONTAINER_meta_data_destroy (metaDataW); | 94 | rh = GNUNET_BIO_read_open_buffer (buffer, buffer_size); |
73 | GNUNET_CONTAINER_meta_data_destroy (metaDataR); | 95 | GNUNET_assert (NULL != rh); |
74 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); | 96 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs)); |
75 | GNUNET_free (fileName); | 97 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); |
98 | GNUNET_assert (0 == strcmp (TESTSTRING, rString)); | ||
99 | GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_meta_data_test_equal (mdR, mdW)); | ||
100 | GNUNET_assert (wNum == rNum); | ||
101 | |||
102 | GNUNET_free (buffer); | ||
103 | |||
104 | GNUNET_CONTAINER_meta_data_destroy (mdW); | ||
105 | GNUNET_CONTAINER_meta_data_destroy (mdR); | ||
76 | return 0; | 106 | return 0; |
77 | } | 107 | } |
78 | 108 | ||
79 | 109 | ||
80 | static int | 110 | static int |
81 | test_nullstring_rw () | 111 | test_nullstring_rw (void) |
82 | { | 112 | { |
83 | char *msg; | 113 | struct GNUNET_BIO_WriteHandle *wh; |
84 | char *readResultString = (char *) "not null"; | 114 | struct GNUNET_BIO_ReadHandle *rh; |
85 | struct GNUNET_BIO_WriteHandle *fileW; | 115 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); |
86 | struct GNUNET_BIO_ReadHandle *fileR; | 116 | char *rString = "not null"; |
87 | char *fileName = GNUNET_DISK_mktemp ("gnunet_bio"); | 117 | |
88 | 118 | wh = GNUNET_BIO_write_open_file (filename); | |
89 | fileW = GNUNET_BIO_write_open (fileName); | 119 | GNUNET_assert (NULL != wh); |
90 | GNUNET_assert (NULL != fileW); | 120 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh, |
91 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW, NULL)); | 121 | "test-nullstring-rw", |
92 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); | 122 | NULL)); |
93 | 123 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | |
94 | fileR = GNUNET_BIO_read_open (fileName); | 124 | |
95 | GNUNET_assert (NULL != fileR); | 125 | rh = GNUNET_BIO_read_open_file (filename); |
96 | GNUNET_assert (GNUNET_OK == | 126 | GNUNET_assert (NULL != rh); |
97 | GNUNET_BIO_read_string (fileR, "Read string error", | 127 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_string (rh, |
98 | &readResultString, 200)); | 128 | "test-nullstring-rw", |
99 | GNUNET_assert (NULL == readResultString); | 129 | &rString, 200)); |
100 | GNUNET_BIO_read_close (fileR, &msg); | 130 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); |
101 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); | 131 | |
102 | GNUNET_free (fileName); | 132 | GNUNET_assert (NULL == rString); |
103 | 133 | ||
134 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); | ||
135 | GNUNET_free (filename); | ||
104 | return 0; | 136 | return 0; |
105 | } | 137 | } |
106 | 138 | ||
107 | 139 | ||
108 | static int | 140 | static int |
109 | test_emptystring_rw () | 141 | test_emptystring_rw (void) |
110 | { | 142 | { |
111 | char *msg; | 143 | struct GNUNET_BIO_WriteHandle *wh; |
112 | char *readResultString; | 144 | struct GNUNET_BIO_ReadHandle *rh; |
113 | struct GNUNET_BIO_WriteHandle *fileW; | 145 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); |
114 | struct GNUNET_BIO_ReadHandle *fileR; | 146 | char *rString = NULL; |
115 | char *fileName = GNUNET_DISK_mktemp ("gnunet_bio"); | 147 | |
116 | 148 | wh = GNUNET_BIO_write_open_file (filename); | |
117 | fileW = GNUNET_BIO_write_open (fileName); | 149 | GNUNET_assert (NULL != wh); |
118 | GNUNET_assert (NULL != fileW); | 150 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh, |
119 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW, "")); | 151 | "test-emptystring-rw", |
120 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); | 152 | "")); |
121 | 153 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | |
122 | fileR = GNUNET_BIO_read_open (fileName); | 154 | |
123 | GNUNET_assert (NULL != fileR); | 155 | rh = GNUNET_BIO_read_open_file (filename); |
124 | readResultString = NULL; | 156 | GNUNET_assert (NULL != rh); |
125 | GNUNET_assert (GNUNET_OK == | 157 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_string (rh, |
126 | GNUNET_BIO_read_string (fileR, "Read string error", | 158 | "test-emptystring-rw", |
127 | &readResultString, 200)); | 159 | &rString, 200)); |
128 | GNUNET_free (readResultString); | 160 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); |
129 | GNUNET_BIO_read_close (fileR, &msg); | 161 | |
130 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); | 162 | GNUNET_free (rString); |
131 | GNUNET_free (fileName); | 163 | |
164 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); | ||
165 | GNUNET_free (filename); | ||
132 | return 0; | 166 | return 0; |
133 | } | 167 | } |
134 | 168 | ||
135 | 169 | ||
136 | static int | 170 | static int |
137 | test_bigstring_rw () | 171 | test_bigstring_rw (void) |
138 | { | 172 | { |
139 | char *msg; | 173 | struct GNUNET_BIO_WriteHandle *wh; |
140 | char *readResultString; | 174 | struct GNUNET_BIO_ReadHandle *rh; |
141 | struct GNUNET_BIO_WriteHandle *fileW; | 175 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); |
142 | struct GNUNET_BIO_ReadHandle *fileR; | 176 | char *rString = NULL; |
143 | char *fileName = GNUNET_DISK_mktemp ("gnunet_bio"); | 177 | |
144 | 178 | wh = GNUNET_BIO_write_open_file (filename); | |
145 | fileW = GNUNET_BIO_write_open (fileName); | 179 | GNUNET_assert (NULL != wh); |
146 | GNUNET_assert (NULL != fileW); | 180 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh, |
147 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW, TESTSTRING)); | 181 | "test-bigstring-rw", |
148 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); | 182 | TESTSTRING)); |
149 | 183 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | |
150 | fileR = GNUNET_BIO_read_open (fileName); | 184 | |
151 | GNUNET_assert (NULL != fileR); | 185 | rh = GNUNET_BIO_read_open_file (filename); |
152 | readResultString = NULL; | 186 | GNUNET_assert (NULL != rh); |
153 | GNUNET_assert (GNUNET_SYSERR == | 187 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_string (rh, |
154 | GNUNET_BIO_read_string (fileR, "Read string error", | 188 | "test-bigstring-rw", |
155 | &readResultString, 1)); | 189 | &rString, 1)); |
156 | GNUNET_assert (NULL == readResultString); | 190 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); |
157 | msg = NULL; | 191 | |
158 | GNUNET_BIO_read_close (fileR, &msg); | 192 | GNUNET_assert (NULL == rString); |
159 | GNUNET_free (msg); | 193 | |
160 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); | 194 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); |
161 | GNUNET_free (fileName); | 195 | GNUNET_free (filename); |
162 | return 0; | 196 | return 0; |
163 | } | 197 | } |
164 | 198 | ||
165 | 199 | ||
166 | static int | 200 | static int |
167 | test_bigmeta_rw () | 201 | test_bigmeta_rw (void) |
168 | { | 202 | { |
169 | char *msg; | ||
170 | static char meta[1024 * 1024 * 10]; | 203 | static char meta[1024 * 1024 * 10]; |
171 | struct GNUNET_BIO_WriteHandle *fileW; | 204 | struct GNUNET_BIO_WriteHandle *wh; |
172 | struct GNUNET_BIO_ReadHandle *fileR; | 205 | struct GNUNET_BIO_ReadHandle *rh; |
173 | char *fileName = GNUNET_DISK_mktemp ("gnunet_bio"); | 206 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); |
174 | struct GNUNET_CONTAINER_MetaData *metaDataR; | 207 | struct GNUNET_CONTAINER_MetaData *mdR = NULL; |
175 | 208 | ||
176 | memset (meta, 'b', sizeof(meta)); | 209 | memset (meta, 'b', sizeof (meta)); |
177 | meta[sizeof(meta) - 1] = '\0'; | 210 | meta[sizeof (meta) - 1] = '\0'; |
178 | fileW = GNUNET_BIO_write_open (fileName); | 211 | |
179 | GNUNET_assert (NULL != fileW); | 212 | wh = GNUNET_BIO_write_open_file (filename); |
180 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (fileW, sizeof(meta))); | 213 | GNUNET_assert (NULL != wh); |
181 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write (fileW, meta, sizeof(meta))); | 214 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh, |
182 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); | 215 | "test-bigmeta-rw-int32", |
183 | 216 | sizeof (meta))); | |
184 | fileR = GNUNET_BIO_read_open (fileName); | 217 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write (wh, |
185 | GNUNET_assert (NULL != fileR); | 218 | "test-bigmeta-rw-bytes", |
186 | metaDataR = NULL; | 219 | meta, |
220 | sizeof (meta))); | ||
221 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | ||
222 | |||
223 | rh = GNUNET_BIO_read_open_file (filename); | ||
224 | GNUNET_assert (NULL != rh); | ||
187 | GNUNET_assert (GNUNET_SYSERR == | 225 | GNUNET_assert (GNUNET_SYSERR == |
188 | GNUNET_BIO_read_meta_data (fileR, "Read meta error", | 226 | GNUNET_BIO_read_meta_data (rh, |
189 | &metaDataR)); | 227 | "test-bigmeta-rw-metadata", |
190 | msg = NULL; | 228 | &mdR)); |
191 | GNUNET_BIO_read_close (fileR, &msg); | 229 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); |
192 | GNUNET_free (msg); | 230 | |
193 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); | 231 | GNUNET_assert (NULL == mdR); |
194 | GNUNET_assert (NULL == metaDataR); | 232 | |
195 | GNUNET_free (fileName); | 233 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); |
234 | GNUNET_free (filename); | ||
196 | return 0; | 235 | return 0; |
197 | } | 236 | } |
198 | 237 | ||
199 | 238 | ||
200 | static int | 239 | static int |
201 | test_directory_r () | 240 | test_directory_r (void) |
202 | { | 241 | { |
203 | #ifdef __linux__ | 242 | #ifdef LINUX |
204 | char *msg; | 243 | struct GNUNET_BIO_ReadHandle *rh; |
205 | char readResult[200]; | 244 | char rString[200]; |
206 | struct GNUNET_BIO_ReadHandle *fileR; | 245 | |
207 | 246 | rh = GNUNET_BIO_read_open_file ("/dev"); | |
208 | fileR = GNUNET_BIO_read_open ("/dev"); | 247 | GNUNET_assert (NULL != rh); |
209 | GNUNET_assert (NULL != fileR); | 248 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read (rh, |
210 | GNUNET_assert (GNUNET_SYSERR == | 249 | "test-directory-r", |
211 | GNUNET_BIO_read (fileR, "Read error", readResult, | 250 | rString, |
212 | sizeof(readResult))); | 251 | sizeof (rString))); |
213 | msg = NULL; | 252 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); |
214 | GNUNET_BIO_read_close (fileR, &msg); | ||
215 | GNUNET_free (msg); | ||
216 | #endif | 253 | #endif |
217 | return 0; | 254 | return 0; |
218 | } | 255 | } |
219 | 256 | ||
220 | 257 | ||
221 | static int | 258 | static int |
222 | test_nullfile_rw () | 259 | test_nullfile_rw (void) |
223 | { | 260 | { |
224 | static char fileNameNO[102401]; | 261 | static char filename[102401]; |
225 | struct GNUNET_BIO_WriteHandle *fileWNO; | 262 | struct GNUNET_BIO_WriteHandle *wh; |
226 | struct GNUNET_BIO_ReadHandle *fileRNO; | 263 | struct GNUNET_BIO_ReadHandle *rh; |
227 | 264 | ||
228 | memset (fileNameNO, 'a', sizeof(fileNameNO)); | 265 | memset (filename, 'a', sizeof (filename)); |
229 | fileNameNO[sizeof(fileNameNO) - 1] = '\0'; | 266 | filename[sizeof (filename) - 1] = '\0'; |
230 | 267 | ||
231 | GNUNET_log_skip (1, GNUNET_NO); | 268 | GNUNET_log_skip (2, GNUNET_NO); |
232 | fileWNO = GNUNET_BIO_write_open (fileNameNO); | 269 | wh = GNUNET_BIO_write_open_file (filename); |
233 | GNUNET_log_skip (0, GNUNET_YES); | 270 | GNUNET_log_skip (0, GNUNET_YES); |
234 | GNUNET_assert (NULL == fileWNO); | 271 | GNUNET_assert (NULL == wh); |
235 | 272 | ||
236 | GNUNET_log_skip (1, GNUNET_NO); | 273 | GNUNET_log_skip (2, GNUNET_NO); |
237 | fileRNO = GNUNET_BIO_read_open (fileNameNO); | 274 | rh = GNUNET_BIO_read_open_file (filename); |
238 | GNUNET_log_skip (0, GNUNET_YES); | 275 | GNUNET_log_skip (0, GNUNET_YES); |
239 | GNUNET_assert (NULL == fileRNO); | 276 | GNUNET_assert (NULL == rh); |
277 | |||
240 | return 0; | 278 | return 0; |
241 | } | 279 | } |
242 | 280 | ||
243 | 281 | ||
244 | static int | 282 | static int |
245 | test_fullfile_rw () | 283 | test_fullfile_rw (void) |
246 | { | 284 | { |
247 | #ifdef __linux__ | 285 | #ifdef LINUX |
248 | /* /dev/full only seems to exist on Linux */ | 286 | /* /dev/full doesn't exist on every platform */ |
249 | char *msg; | 287 | struct GNUNET_BIO_WriteHandle *wh; |
250 | int64_t testNum; | 288 | struct GNUNET_BIO_ReadHandle *rh; |
251 | char *readResultString; | 289 | char *rString = NULL; |
252 | char readResult[200]; | 290 | char rResult[200]; |
253 | struct GNUNET_BIO_WriteHandle *fileW; | 291 | struct GNUNET_CONTAINER_MetaData *mdW; |
254 | struct GNUNET_BIO_ReadHandle *fileR; | 292 | struct GNUNET_CONTAINER_MetaData *mdR = NULL; |
255 | struct GNUNET_CONTAINER_MetaData *metaDataW; | 293 | |
256 | struct GNUNET_CONTAINER_MetaData *metaDataR; | 294 | mdW = GNUNET_CONTAINER_meta_data_create (); |
257 | 295 | GNUNET_CONTAINER_meta_data_add_publication_date (mdW); | |
258 | metaDataW = GNUNET_CONTAINER_meta_data_create (); | 296 | |
259 | GNUNET_CONTAINER_meta_data_add_publication_date (metaDataW); | 297 | struct GNUNET_BIO_WriteSpec ws[] = { |
260 | 298 | GNUNET_BIO_write_spec_object ("test-fullfile-rw-bytes", | |
261 | fileW = GNUNET_BIO_write_open ("/dev/full"); | 299 | TESTSTRING, |
262 | GNUNET_assert (NULL != fileW); | 300 | strlen (TESTSTRING)), |
263 | (void) GNUNET_BIO_write (fileW, TESTSTRING, strlen (TESTSTRING)); | 301 | GNUNET_BIO_write_spec_string ("test-fullfile-rw-string", |
264 | (void) GNUNET_BIO_write_string (fileW, TESTSTRING); | 302 | TESTSTRING), |
265 | (void) GNUNET_BIO_write_meta_data (fileW, metaDataW); | 303 | GNUNET_BIO_write_spec_meta_data ("test-fullfile-rw-metadata", |
266 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_close (fileW)); | 304 | mdW), |
267 | GNUNET_CONTAINER_meta_data_destroy (metaDataW); | 305 | GNUNET_BIO_write_spec_end (), |
268 | 306 | }; | |
269 | fileW = GNUNET_BIO_write_open ("/dev/full"); | 307 | |
270 | GNUNET_assert (NULL != fileW); | 308 | struct GNUNET_BIO_ReadSpec rs[] = { |
271 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_close (fileW)); | 309 | GNUNET_BIO_read_spec_object ("test-fullfile-rw-bytes", |
272 | 310 | rResult, | |
273 | fileR = GNUNET_BIO_read_open ("/dev/null"); | 311 | sizeof (rResult)), |
274 | GNUNET_assert (NULL != fileR); | 312 | GNUNET_BIO_read_spec_string ("test-fullfile-rw-string", |
275 | GNUNET_assert (GNUNET_SYSERR == | 313 | &rString, |
276 | GNUNET_BIO_read (fileR, "Read error", readResult, | 314 | 200), |
277 | sizeof(readResult))); | 315 | GNUNET_BIO_read_spec_meta_data ("test-fullfile-rw-metadata", |
278 | readResultString = NULL; | 316 | &mdR), |
279 | GNUNET_assert (GNUNET_SYSERR == | 317 | GNUNET_BIO_read_spec_end(), |
280 | GNUNET_BIO_read_string (fileR, "Read string error", | 318 | }; |
281 | &readResultString, 200)); | 319 | |
282 | GNUNET_assert (NULL == readResultString); | 320 | wh = GNUNET_BIO_write_open_file ("/dev/full"); |
283 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_int64 (fileR, &testNum)); | 321 | GNUNET_assert (NULL != wh); |
284 | metaDataR = NULL; | 322 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_spec_commit (wh, ws)); |
285 | GNUNET_assert (GNUNET_SYSERR == | 323 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_close (wh, NULL)); |
286 | GNUNET_BIO_read_meta_data (fileR, "Read meta error", | 324 | |
287 | &metaDataR)); | 325 | rh = GNUNET_BIO_read_open_file ("/dev/null"); |
288 | msg = NULL; | 326 | GNUNET_assert (NULL != rh); |
289 | GNUNET_BIO_read_close (fileR, &msg); | 327 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_spec_commit (rh, rs)); |
290 | GNUNET_free (msg); | 328 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); |
291 | GNUNET_assert (NULL == metaDataR); | 329 | |
330 | GNUNET_assert (NULL == rString); | ||
331 | GNUNET_assert (NULL == mdR); | ||
292 | #endif | 332 | #endif |
293 | return 0; | 333 | return 0; |
294 | } | 334 | } |
295 | 335 | ||
296 | 336 | ||
297 | static int | 337 | static int |
298 | test_fakestring_rw () | 338 | test_fakestring_rw (void) |
299 | { | 339 | { |
300 | char *msg; | 340 | struct GNUNET_BIO_WriteHandle *wh; |
301 | int32_t tmpInt = 2; | 341 | struct GNUNET_BIO_ReadHandle *rh; |
302 | char *readResult; | 342 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); |
303 | struct GNUNET_BIO_WriteHandle *fileW; | 343 | char *rString = NULL; |
304 | struct GNUNET_BIO_ReadHandle *fileR; | 344 | |
305 | char *fileName = GNUNET_DISK_mktemp ("gnunet_bio"); | 345 | wh = GNUNET_BIO_write_open_file (filename); |
306 | 346 | GNUNET_assert (NULL != wh); | |
307 | fileW = GNUNET_BIO_write_open (fileName); | 347 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh, |
308 | GNUNET_assert (NULL != fileW); | 348 | "test-fakestring-rw-int32", |
309 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (fileW, tmpInt)); | 349 | 2)); |
310 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); | 350 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); |
311 | 351 | ||
312 | fileR = GNUNET_BIO_read_open (fileName); | 352 | rh = GNUNET_BIO_read_open_file (filename); |
313 | GNUNET_assert (NULL != fileR); | 353 | GNUNET_assert (NULL != rh); |
314 | GNUNET_assert (GNUNET_SYSERR == | 354 | GNUNET_assert (GNUNET_SYSERR == |
315 | GNUNET_BIO_read_string (fileR, "Read string error", | 355 | GNUNET_BIO_read_string (rh, |
316 | &readResult, 200)); | 356 | "test-fakestring-rw-string", |
317 | msg = NULL; | 357 | &rString, 200)); |
318 | GNUNET_BIO_read_close (fileR, &msg); | 358 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); |
319 | GNUNET_free (msg); | 359 | |
320 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); | 360 | GNUNET_assert (NULL == rString); |
321 | GNUNET_free (fileName); | 361 | |
362 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); | ||
363 | GNUNET_free (filename); | ||
322 | return 0; | 364 | return 0; |
323 | } | 365 | } |
324 | 366 | ||
325 | 367 | ||
326 | static int | 368 | static int |
327 | test_fakemeta_rw () | 369 | test_fakemeta_rw (void) |
328 | { | 370 | { |
329 | char *msg; | 371 | struct GNUNET_BIO_WriteHandle *wh; |
330 | int32_t tmpInt = 2; | 372 | struct GNUNET_BIO_ReadHandle *rh; |
331 | struct GNUNET_BIO_WriteHandle *fileW; | 373 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); |
332 | struct GNUNET_BIO_ReadHandle *fileR; | 374 | struct GNUNET_CONTAINER_MetaData *mdR = NULL; |
333 | char *fileName = GNUNET_DISK_mktemp ("gnunet_bio"); | 375 | |
334 | struct GNUNET_CONTAINER_MetaData *metaDataR; | 376 | wh = GNUNET_BIO_write_open_file (filename); |
335 | 377 | GNUNET_assert (NULL != wh); | |
336 | fileW = GNUNET_BIO_write_open (fileName); | 378 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh, |
337 | GNUNET_assert (NULL != fileW); | 379 | "test-fakestring-rw-int32", |
338 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (fileW, tmpInt)); | 380 | 2)); |
339 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); | 381 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); |
340 | 382 | ||
341 | fileR = GNUNET_BIO_read_open (fileName); | 383 | rh = GNUNET_BIO_read_open_file (filename); |
342 | GNUNET_assert (NULL != fileR); | 384 | GNUNET_assert (NULL != rh); |
343 | metaDataR = NULL; | ||
344 | GNUNET_assert (GNUNET_SYSERR == | 385 | GNUNET_assert (GNUNET_SYSERR == |
345 | GNUNET_BIO_read_meta_data (fileR, "Read meta error", | 386 | GNUNET_BIO_read_meta_data (rh, |
346 | &metaDataR)); | 387 | "test-fakestring-rw-metadata", |
347 | GNUNET_assert (NULL == metaDataR); | 388 | &mdR)); |
348 | msg = NULL; | 389 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); |
349 | GNUNET_BIO_read_close (fileR, &msg); | 390 | |
350 | GNUNET_free (msg); | 391 | GNUNET_assert (NULL == mdR); |
351 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); | 392 | |
352 | GNUNET_free (fileName); | 393 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); |
394 | GNUNET_free (filename); | ||
353 | return 0; | 395 | return 0; |
354 | } | 396 | } |
355 | 397 | ||
356 | 398 | ||
357 | static int | 399 | static int |
358 | test_fakebigmeta_rw () | 400 | test_fakebigmeta_rw (void) |
359 | { | 401 | { |
360 | char *msg; | 402 | struct GNUNET_BIO_WriteHandle *wh; |
361 | int32_t tmpInt = 1024 * 1024 * 10; | 403 | struct GNUNET_BIO_ReadHandle *rh; |
362 | struct GNUNET_BIO_WriteHandle *fileW; | 404 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); |
363 | struct GNUNET_BIO_ReadHandle *fileR; | 405 | struct GNUNET_CONTAINER_MetaData *mdR = NULL; |
364 | char *fileName = GNUNET_DISK_mktemp ("gnunet_bio"); | 406 | int32_t wNum = 1024 * 1024 * 10; |
365 | struct GNUNET_CONTAINER_MetaData *metaDataR; | 407 | |
366 | 408 | wh = GNUNET_BIO_write_open_file (filename); | |
367 | fileW = GNUNET_BIO_write_open (fileName); | 409 | GNUNET_assert (NULL != wh); |
368 | GNUNET_assert (NULL != fileW); | 410 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh, |
369 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (fileW, tmpInt)); | 411 | "test-fakebigmeta-rw-int32", |
370 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); | 412 | wNum)); |
371 | 413 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | |
372 | fileR = GNUNET_BIO_read_open (fileName); | 414 | |
373 | GNUNET_assert (NULL != fileR); | 415 | rh = GNUNET_BIO_read_open_file (filename); |
374 | metaDataR = NULL; | 416 | GNUNET_assert (NULL != rh); |
375 | GNUNET_assert (GNUNET_SYSERR == | 417 | GNUNET_assert (GNUNET_SYSERR == |
376 | GNUNET_BIO_read_meta_data (fileR, "Read meta error", | 418 | GNUNET_BIO_read_meta_data (rh, |
377 | &metaDataR)); | 419 | "test-fakebigmeta-rw-metadata", |
378 | msg = NULL; | 420 | &mdR)); |
379 | GNUNET_BIO_read_close (fileR, &msg); | 421 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); |
380 | GNUNET_free (msg); | 422 | |
381 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); | 423 | GNUNET_assert (NULL == mdR); |
382 | GNUNET_assert (NULL == metaDataR); | 424 | |
383 | GNUNET_free (fileName); | 425 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); |
426 | GNUNET_free (filename); | ||
384 | return 0; | 427 | return 0; |
385 | } | 428 | } |
386 | 429 | ||
387 | 430 | ||
388 | static int | 431 | static int |
389 | check_string_rw () | 432 | check_string_rw (void) |
390 | { | 433 | { |
391 | GNUNET_assert (0 == test_nullstring_rw ()); | 434 | GNUNET_assert (0 == test_nullstring_rw ()); |
392 | GNUNET_assert (0 == test_emptystring_rw ()); | 435 | GNUNET_assert (0 == test_emptystring_rw ()); |
@@ -397,7 +440,7 @@ check_string_rw () | |||
397 | 440 | ||
398 | 441 | ||
399 | static int | 442 | static int |
400 | check_metadata_rw () | 443 | check_metadata_rw (void) |
401 | { | 444 | { |
402 | GNUNET_assert (0 == test_fakebigmeta_rw ()); | 445 | GNUNET_assert (0 == test_fakebigmeta_rw ()); |
403 | GNUNET_assert (0 == test_fakemeta_rw ()); | 446 | GNUNET_assert (0 == test_fakemeta_rw ()); |
@@ -407,7 +450,7 @@ check_metadata_rw () | |||
407 | 450 | ||
408 | 451 | ||
409 | static int | 452 | static int |
410 | check_file_rw () | 453 | check_file_rw (void) |
411 | { | 454 | { |
412 | GNUNET_assert (0 == test_normal_rw ()); | 455 | GNUNET_assert (0 == test_normal_rw ()); |
413 | GNUNET_assert (0 == test_nullfile_rw ()); | 456 | GNUNET_assert (0 == test_nullfile_rw ()); |