aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-12-25 22:58:03 +0100
committerChristian Grothoff <christian@grothoff.org>2019-12-25 22:58:03 +0100
commit0f4460e545f19ec74bf53438b246d64f0127884e (patch)
tree54a7951d46a4f2102933b3e77fe3ee01295ef7fd /src/microhttpd
parentf5d59eb3a7c54cd13550ed906a67f1bff630b2c6 (diff)
downloadlibmicrohttpd-0f4460e545f19ec74bf53438b246d64f0127884e.tar.gz
libmicrohttpd-0f4460e545f19ec74bf53438b246d64f0127884e.zip
more logging in testcase
Diffstat (limited to 'src/microhttpd')
-rw-r--r--src/microhttpd/test_postprocessor.c70
1 files changed, 63 insertions, 7 deletions
diff --git a/src/microhttpd/test_postprocessor.c b/src/microhttpd/test_postprocessor.c
index 6f8ce6f5..4b0c9e07 100644
--- a/src/microhttpd/test_postprocessor.c
+++ b/src/microhttpd/test_postprocessor.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 Copyright (C) 2007,2013 Christian Grothoff 3 Copyright (C) 2007,2013,2019 Christian Grothoff
4 4
5 libmicrohttpd is free software; you can redistribute it and/or modify 5 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -104,7 +104,6 @@ value_checker (void *cls,
104 int idx = *want_off; 104 int idx = *want_off;
105 (void) kind; /* Unused. Silent compiler warning. */ 105 (void) kind; /* Unused. Silent compiler warning. */
106 106
107
108#if 0 107#if 0
109 fprintf (stderr, 108 fprintf (stderr,
110 "VC: `%s' `%s' `%s' `%s' `%.*s'\n", 109 "VC: `%s' `%s' `%s' `%s' `%.*s'\n",
@@ -123,12 +122,26 @@ value_checker (void *cls,
123 (0 != memcmp (data, &want[idx + 4][off], size))) 122 (0 != memcmp (data, &want[idx + 4][off], size)))
124 { 123 {
125 *want_off = -1; 124 *want_off = -1;
125 fprintf (stderr,
126 "Failed with: `%s' `%s' `%s' `%s' `%.*s'\n",
127 key, filename, content_type, transfer_encoding,
128 (int) size,
129 data);
130 fprintf (stderr,
131 "Unexpected result: %d/%d/%d/%d/%d/%d/%d\n",
132 (idx < 0),
133 (want[idx] == NULL),
134 (0 != strcmp (key, want[idx])),
135 (mismatch (filename, want[idx + 1])),
136 (mismatch (content_type, want[idx + 2])),
137 (mismatch (transfer_encoding, want[idx + 3])),
138 (0 != memcmp (data, &want[idx + 4][off], size)));
139
126 return MHD_NO; 140 return MHD_NO;
127 } 141 }
128 if (off + size == strlen (want[idx + 4])) 142 if (off + size == strlen (want[idx + 4]))
129 *want_off = idx + 5; 143 *want_off = idx + 5;
130 return MHD_YES; 144 return MHD_YES;
131
132} 145}
133 146
134 147
@@ -155,18 +168,27 @@ test_urlencoding_case (unsigned int want_start,
155 MHD_HTTP_POST_ENCODING_FORM_URLENCODED); 168 MHD_HTTP_POST_ENCODING_FORM_URLENCODED);
156 header.kind = MHD_HEADER_KIND; 169 header.kind = MHD_HEADER_KIND;
157 pp = MHD_create_post_processor (&connection, 170 pp = MHD_create_post_processor (&connection,
158 1024, &value_checker, &want_off); 171 1024,
172 &value_checker,
173 &want_off);
159 i = 0; 174 i = 0;
160 size = strlen (url_data); 175 size = strlen (url_data);
161 while (i < size) 176 while (i < size)
162 { 177 {
163 delta = 1 + MHD_random_ () % (size - i); 178 delta = 1 + MHD_random_ () % (size - i);
164 MHD_post_process (pp, &url_data[i], delta); 179 MHD_post_process (pp,
180 &url_data[i],
181 delta);
165 i += delta; 182 i += delta;
166 } 183 }
167 MHD_destroy_post_processor (pp); 184 MHD_destroy_post_processor (pp);
168 if (want_off != want_end) 185 if (want_off != want_end)
186 {
187 fprintf (stderr,
188 "Test failed in line %u\n",
189 (unsigned int) __LINE__);
169 return 1; 190 return 1;
191 }
170 return 0; 192 return 0;
171} 193}
172 194
@@ -175,11 +197,18 @@ static int
175test_urlencoding (void) 197test_urlencoding (void)
176{ 198{
177 unsigned int errorCount = 0; 199 unsigned int errorCount = 0;
200
178 errorCount += test_urlencoding_case (URL_START, URL_END, URL_DATA); 201 errorCount += test_urlencoding_case (URL_START, URL_END, URL_DATA);
179 errorCount += test_urlencoding_case (URL_NOVALUE1_START, URL_NOVALUE1_END, 202 errorCount += test_urlencoding_case (URL_NOVALUE1_START,
203 URL_NOVALUE1_END,
180 URL_NOVALUE1_DATA); 204 URL_NOVALUE1_DATA);
181 errorCount += test_urlencoding_case (URL_NOVALUE2_START, URL_NOVALUE2_END, 205 errorCount += test_urlencoding_case (URL_NOVALUE2_START,
206 URL_NOVALUE2_END,
182 URL_NOVALUE2_DATA); 207 URL_NOVALUE2_DATA);
208 fprintf (stderr,
209 "Test failed in line %u with %u errors\n",
210 (unsigned int) __LINE__,
211 errorCount);
183 return errorCount; 212 return errorCount;
184} 213}
185 214
@@ -220,7 +249,13 @@ test_multipart_garbage (void)
220 MHD_post_process (pp, &xdata[splitpoint], size - splitpoint); 249 MHD_post_process (pp, &xdata[splitpoint], size - splitpoint);
221 MHD_destroy_post_processor (pp); 250 MHD_destroy_post_processor (pp);
222 if (want_off != FORM_END) 251 if (want_off != FORM_END)
252 {
253 fprintf (stderr,
254 "Test failed in line %u at point %d\n",
255 (unsigned int) __LINE__,
256 (int) splitpoint);
223 return (int) splitpoint; 257 return (int) splitpoint;
258 }
224 } 259 }
225 return 0; 260 return 0;
226} 261}
@@ -255,7 +290,13 @@ test_multipart_splits (void)
255 MHD_post_process (pp, &FORM_DATA[splitpoint], size - splitpoint); 290 MHD_post_process (pp, &FORM_DATA[splitpoint], size - splitpoint);
256 MHD_destroy_post_processor (pp); 291 MHD_destroy_post_processor (pp);
257 if (want_off != FORM_END) 292 if (want_off != FORM_END)
293 {
294 fprintf (stderr,
295 "Test failed in line %u at point %d\n",
296 (unsigned int) __LINE__,
297 (int) splitpoint);
258 return (int) splitpoint; 298 return (int) splitpoint;
299 }
259 } 300 }
260 return 0; 301 return 0;
261} 302}
@@ -293,7 +334,12 @@ test_multipart (void)
293 } 334 }
294 MHD_destroy_post_processor (pp); 335 MHD_destroy_post_processor (pp);
295 if (want_off != FORM_END) 336 if (want_off != FORM_END)
337 {
338 fprintf (stderr,
339 "Test failed in line %u\n",
340 (unsigned int) __LINE__);
296 return 2; 341 return 2;
342 }
297 return 0; 343 return 0;
298} 344}
299 345
@@ -330,7 +376,12 @@ test_nested_multipart (void)
330 } 376 }
331 MHD_destroy_post_processor (pp); 377 MHD_destroy_post_processor (pp);
332 if (want_off != FORM_NESTED_END) 378 if (want_off != FORM_NESTED_END)
379 {
380 fprintf (stderr,
381 "Test failed in line %u\n",
382 (unsigned int) __LINE__);
333 return 4; 383 return 4;
384 }
334 return 0; 385 return 0;
335} 386}
336 387
@@ -366,7 +417,12 @@ test_empty_value (void)
366 } 417 }
367 MHD_destroy_post_processor (pp); 418 MHD_destroy_post_processor (pp);
368 if (want_off != URL_EMPTY_VALUE_END) 419 if (want_off != URL_EMPTY_VALUE_END)
420 {
421 fprintf (stderr,
422 "Test failed in line %u\n",
423 (unsigned int) __LINE__);
369 return 8; 424 return 8;
425 }
370 return 0; 426 return 0;
371} 427}
372 428