libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 292b565629f620d9656891186651dd2daf01242c
parent bbc57f9386bbd30e21320c59c6b76f91448fab0f
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Wed, 15 Sep 2021 13:57:21 +0300

test_postprocessor: test urlencoding more thoroughly

Diffstat:
Msrc/microhttpd/test_postprocessor.c | 99++++++++++++++++++++++++++++++++++++++++---------------------------------------
1 file changed, 50 insertions(+), 49 deletions(-)

diff --git a/src/microhttpd/test_postprocessor.c b/src/microhttpd/test_postprocessor.c @@ -197,59 +197,60 @@ test_urlencoding_case (unsigned int want_start, unsigned int want_end, const char *url_data) { - struct MHD_Connection connection; - struct MHD_HTTP_Header header; - struct MHD_PostProcessor *pp; - unsigned int want_off = want_start; - size_t i; - size_t delta; - size_t size; + size_t step; + const size_t size = strlen (url_data); - memset (&connection, 0, sizeof (struct MHD_Connection)); - memset (&header, 0, sizeof (struct MHD_HTTP_Header)); - connection.headers_received = &header; - header.header = MHD_HTTP_HEADER_CONTENT_TYPE; - header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED; - header.header_size = MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_CONTENT_TYPE); - header.value_size = MHD_STATICSTR_LEN_ ( - MHD_HTTP_POST_ENCODING_FORM_URLENCODED); - header.kind = MHD_HEADER_KIND; - pp = MHD_create_post_processor (&connection, - 1024, - &value_checker, - &want_off); - if (NULL == pp) - { - fprintf (stderr, "Failed to create post processor.\n" - "Line: %u\n", (unsigned int) __LINE__); - exit (50); - } - i = 0; - size = strlen (url_data); - while (i < size) + for (step = 1; size >= step; ++step) { - delta = 1 + MHD_random_ () % (size - i); - if (MHD_YES != MHD_post_process (pp, - &url_data[i], - delta)) + struct MHD_Connection connection; + struct MHD_HTTP_Header header; + struct MHD_PostProcessor *pp; + unsigned int want_off = want_start; + size_t i; + + memset (&connection, 0, sizeof (struct MHD_Connection)); + memset (&header, 0, sizeof (struct MHD_HTTP_Header)); + connection.headers_received = &header; + header.header = MHD_HTTP_HEADER_CONTENT_TYPE; + header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED; + header.header_size = MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_CONTENT_TYPE); + header.value_size = + MHD_STATICSTR_LEN_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED); + header.kind = MHD_HEADER_KIND; + pp = MHD_create_post_processor (&connection, + 1024, + &value_checker, + &want_off); + if (NULL == pp) { - fprintf (stderr, "Failed to process the data.\n" - "i: %u. delta: %u.\n" - "Line: %u\n", (unsigned) i, (unsigned) delta, - (unsigned int) __LINE__); - exit (49); + fprintf (stderr, "Failed to create post processor.\n" + "Line: %u\n", (unsigned int) __LINE__); + exit (50); + } + for (i = 0; size > i; i += step) + { + size_t left = size - i; + if (MHD_YES != MHD_post_process (pp, + &url_data[i], + (left > step) ? step : left)) + { + fprintf (stderr, "Failed to process the data.\n" + "i: %u. step: %u.\n" + "Line: %u\n", (unsigned) i, (unsigned) step, + (unsigned int) __LINE__); + exit (49); + } + } + MHD_destroy_post_processor (pp); + if (want_off != want_end) + { + fprintf (stderr, + "Test failed in line %u: %u != %u\n", + (unsigned int) __LINE__, + want_off, + want_end); + return 1; } - i += delta; - } - MHD_destroy_post_processor (pp); - if (want_off != want_end) - { - fprintf (stderr, - "Test failed in line %u: %u != %u\n", - (unsigned int) __LINE__, - want_off, - want_end); - return 1; } return 0; }