postprocessor_large_test.c

Go to the documentation of this file.
00001 /*
00002      This file is part of libmicrohttpd
00003      (C) 2008 Christian Grothoff
00004 
00005      libmicrohttpd is free software; you can redistribute it and/or modify
00006      it under the terms of the GNU General Public License as published
00007      by the Free Software Foundation; either version 2, or (at your
00008      option) any later version.
00009 
00010      libmicrohttpd is distributed in the hope that it will be useful, but
00011      WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013      General Public License for more details.
00014 
00015      You should have received a copy of the GNU General Public License
00016      along with libmicrohttpd; see the file COPYING.  If not, write to the
00017      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018      Boston, MA 02111-1307, USA.
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) /* minus 0-termination and 'key=' */
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;       /* 0 == pass */
00109 }

Generated on Fri Oct 3 15:58:28 2008 for GNU libmicrohttpd by  doxygen 1.5.6