aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/postprocessor_large_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/postprocessor_large_test.c')
-rw-r--r--src/daemon/postprocessor_large_test.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/daemon/postprocessor_large_test.c b/src/daemon/postprocessor_large_test.c
new file mode 100644
index 00000000..549f606e
--- /dev/null
+++ b/src/daemon/postprocessor_large_test.c
@@ -0,0 +1,109 @@
1/*
2 This file is part of libmicrohttpd
3 (C) 2008 Christian Grothoff
4
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
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 libmicrohttpd is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with libmicrohttpd; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file postprocessor_large_test.c
23 * @brief Testcase with very large input for postprocessor
24 * @author Christian Grothoff
25 */
26
27#include "config.h"
28#include "microhttpd.h"
29#include "internal.h"
30#include <stdlib.h>
31#include <string.h>
32#include <stdio.h>
33
34#ifndef WINDOWS
35#include <unistd.h>
36#endif
37
38static int
39value_checker (void *cls,
40 enum MHD_ValueKind kind,
41 const char *key,
42 const char *filename,
43 const char *content_type,
44 const char *transfer_encoding,
45 const char *data, size_t off, size_t size)
46{
47 unsigned int *pos = cls;
48#if 0
49 fprintf (stderr,
50 "VC: %u %u `%s' `%s' `%s' `%s' `%.*s'\n",
51 off, size,
52 key, filename, content_type, transfer_encoding, size, data);
53#endif
54 if (size == 0)
55 return MHD_YES;
56 *pos += size;
57 return MHD_YES;
58
59}
60
61
62static int
63test_simple_large ()
64{
65 struct MHD_Connection connection;
66 struct MHD_HTTP_Header header;
67 struct MHD_PostProcessor *pp;
68 int i;
69 int delta;
70 size_t size;
71 char data[102400];
72 unsigned int pos;
73
74 pos = 0;
75 memset (data, 'A', sizeof(data));
76 memcpy (data, "key=", 4);
77 data[sizeof(data)-1] = '\0';
78 memset (&connection, 0, sizeof (struct MHD_Connection));
79 memset (&header, 0, sizeof (struct MHD_HTTP_Header));
80 connection.headers_received = &header;
81 header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
82 header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED;
83 header.kind = MHD_HEADER_KIND;
84 pp = MHD_create_post_processor (&connection,
85 1024, &value_checker, &pos);
86 i = 0;
87 size = strlen (data);
88 while (i < size)
89 {
90 delta = 1 + random () % (size - i);
91 MHD_post_process (pp, &data[i], delta);
92 i += delta;
93 }
94 MHD_destroy_post_processor (pp);
95 if (pos != sizeof(data) - 5) /* minus 0-termination and 'key=' */
96 return 1;
97 return 0;
98}
99
100int
101main (int argc, char *const *argv)
102{
103 unsigned int errorCount = 0;
104
105 errorCount += test_simple_large ();
106 if (errorCount != 0)
107 fprintf (stderr, "Error (code: %u)\n", errorCount);
108 return errorCount != 0; /* 0 == pass */
109}