postprocessor_large_test.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00027 #include "config.h"
00028 #include "microhttpd.h"
00029 #include "internal.h"
00030 #include <stdlib.h>
00031 #include <string.h>
00032 #include <stdio.h>
00033
00034 #ifndef WINDOWS
00035 #include <unistd.h>
00036 #endif
00037
00038 static int
00039 value_checker (void *cls,
00040 enum MHD_ValueKind kind,
00041 const char *key,
00042 const char *filename,
00043 const char *content_type,
00044 const char *transfer_encoding,
00045 const char *data, size_t off, size_t size)
00046 {
00047 unsigned int *pos = cls;
00048 #if 0
00049 fprintf (stderr,
00050 "VC: %u %u `%s' `%s' `%s' `%s' `%.*s'\n",
00051 off, size,
00052 key, filename, content_type, transfer_encoding, size, data);
00053 #endif
00054 if (size == 0)
00055 return MHD_YES;
00056 *pos += size;
00057 return MHD_YES;
00058
00059 }
00060
00061
00062 static int
00063 test_simple_large ()
00064 {
00065 struct MHD_Connection connection;
00066 struct MHD_HTTP_Header header;
00067 struct MHD_PostProcessor *pp;
00068 int i;
00069 int delta;
00070 size_t size;
00071 char data[102400];
00072 unsigned int pos;
00073
00074 pos = 0;
00075 memset (data, 'A', sizeof(data));
00076 memcpy (data, "key=", 4);
00077 data[sizeof(data)-1] = '\0';
00078 memset (&connection, 0, sizeof (struct MHD_Connection));
00079 memset (&header, 0, sizeof (struct MHD_HTTP_Header));
00080 connection.headers_received = &header;
00081 header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
00082 header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED;
00083 header.kind = MHD_HEADER_KIND;
00084 pp = MHD_create_post_processor (&connection,
00085 1024, &value_checker, &pos);
00086 i = 0;
00087 size = strlen (data);
00088 while (i < size)
00089 {
00090 delta = 1 + random () % (size - i);
00091 MHD_post_process (pp, &data[i], delta);
00092 i += delta;
00093 }
00094 MHD_destroy_post_processor (pp);
00095 if (pos != sizeof(data) - 5)
00096 return 1;
00097 return 0;
00098 }
00099
00100 int
00101 main (int argc, char *const *argv)
00102 {
00103 unsigned int errorCount = 0;
00104
00105 errorCount += test_simple_large ();
00106 if (errorCount != 0)
00107 fprintf (stderr, "Error (code: %u)\n", errorCount);
00108 return errorCount != 0;
00109 }