test_postprocessor: integrated one check into unified testing

This commit is contained in:
Evgeny Grin (Karlson2k)
2021-09-15 14:14:15 +03:00
parent 292b565629
commit cec8013b70
+5 -57
View File
@@ -1,6 +1,7 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2007, 2013, 2019, 2020 Christian Grothoff
Copyright (C) 2021 Evgeny Grin (Karlson2k)
libmicrohttpd is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -21,6 +22,7 @@
* @file test_postprocessor.c
* @brief Testcase for postprocessor
* @author Christian Grothoff
* @author Karlson2k (Evgeny Grin)
*/
#include "platform.h"
#include "microhttpd.h"
@@ -270,6 +272,9 @@ test_urlencoding (void)
errorCount += test_urlencoding_case (URL_NOVALUE2_START,
URL_NOVALUE2_END,
URL_NOVALUE2_DATA);
errorCount += test_urlencoding_case (URL_EMPTY_VALUE_START,
URL_EMPTY_VALUE_END,
URL_EMPTY_VALUE_DATA);
if (0 != errorCount)
fprintf (stderr,
"Test failed in line %u with %u errors\n",
@@ -523,63 +528,6 @@ test_nested_multipart (void)
}
static int
test_empty_value (void)
{
struct MHD_Connection connection;
struct MHD_HTTP_Header header;
struct MHD_PostProcessor *pp;
unsigned int want_off = URL_EMPTY_VALUE_START;
size_t i;
size_t delta;
size_t size;
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 = strlen (header.header);
header.value_size = strlen (header.value);
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_EMPTY_VALUE_DATA);
while (i < size)
{
delta = 1 + MHD_random_ () % (size - i);
if (MHD_YES != MHD_post_process (pp,
&URL_EMPTY_VALUE_DATA[i],
delta))
{
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);
}
i += delta;
}
MHD_destroy_post_processor (pp);
if (want_off != URL_EMPTY_VALUE_END)
{
fprintf (stderr,
"Test failed in line %u at offset %d\n",
(unsigned int) __LINE__,
(int) want_off);
return 8;
}
return 0;
}
static enum MHD_Result
value_checker2 (void *cls,
enum MHD_ValueKind kind,