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 "platform.h"
00028 #include "microhttpd.h"
00029 #include "internal.h"
00030 
00031 #ifndef WINDOWS
00032 #include <unistd.h>
00033 #endif
00034 
00035 static int
00036 value_checker (void *cls,
00037                enum MHD_ValueKind kind,
00038                const char *key,
00039                const char *filename,
00040                const char *content_type,
00041                const char *transfer_encoding,
00042                const char *data, uint64_t off, size_t size)
00043 {
00044   unsigned int *pos = cls;
00045 #if 0
00046   fprintf (stderr,
00047            "VC: %llu %u `%s' `%s' `%s' `%s' `%.*s'\n",
00048            off, size,
00049            key, filename, content_type, transfer_encoding, size, data);
00050 #endif
00051   if (size == 0)
00052     return MHD_YES;
00053   *pos += size;
00054   return MHD_YES;
00055 
00056 }
00057 
00058 
00059 static int
00060 test_simple_large ()
00061 {
00062   struct MHD_Connection connection;
00063   struct MHD_HTTP_Header header;
00064   struct MHD_PostProcessor *pp;
00065   int i;
00066   int delta;
00067   size_t size;
00068   char data[102400];
00069   unsigned int pos;
00070 
00071   pos = 0;
00072   memset (data, 'A', sizeof (data));
00073   memcpy (data, "key=", 4);
00074   data[sizeof (data) - 1] = '\0';
00075   memset (&connection, 0, sizeof (struct MHD_Connection));
00076   memset (&header, 0, sizeof (struct MHD_HTTP_Header));
00077   connection.headers_received = &header;
00078   header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
00079   header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED;
00080   header.kind = MHD_HEADER_KIND;
00081   pp = MHD_create_post_processor (&connection, 1024, &value_checker, &pos);
00082   i = 0;
00083   size = strlen (data);
00084   while (i < size)
00085     {
00086       delta = 1 + RANDOM () % (size - i);
00087       MHD_post_process (pp, &data[i], delta);
00088       i += delta;
00089     }
00090   MHD_destroy_post_processor (pp);
00091   if (pos != sizeof (data) - 5) /* minus 0-termination and 'key=' */
00092     return 1;
00093   return 0;
00094 }
00095 
00096 int
00097 main (int argc, char *const *argv)
00098 {
00099   unsigned int errorCount = 0;
00100 
00101   errorCount += test_simple_large ();
00102   if (errorCount != 0)
00103     fprintf (stderr, "Error (code: %u)\n", errorCount);
00104   return errorCount != 0;       /* 0 == pass */
00105 }

Generated on 5 Apr 2011 for GNU libmicrohttpd by  doxygen 1.6.1