Blame src/microhttpd/test_postprocessor_large.c

Packit 875988
/*
Packit 875988
     This file is part of libmicrohttpd
Packit 875988
     Copyright (C) 2008 Christian Grothoff
Packit 875988
Packit 875988
     libmicrohttpd is free software; you can redistribute it and/or modify
Packit 875988
     it under the terms of the GNU General Public License as published
Packit 875988
     by the Free Software Foundation; either version 2, or (at your
Packit 875988
     option) any later version.
Packit 875988
Packit 875988
     libmicrohttpd is distributed in the hope that it will be useful, but
Packit 875988
     WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 875988
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 875988
     General Public License for more details.
Packit 875988
Packit 875988
     You should have received a copy of the GNU General Public License
Packit 875988
     along with libmicrohttpd; see the file COPYING.  If not, write to the
Packit 875988
     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Packit 875988
     Boston, MA 02110-1301, USA.
Packit 875988
*/
Packit 875988
Packit 875988
/**
Packit 875988
 * @file test_postprocessor_large.c
Packit 875988
 * @brief  Testcase with very large input for postprocessor
Packit 875988
 * @author Christian Grothoff
Packit 875988
 */
Packit 875988
Packit 875988
#include "platform.h"
Packit 875988
#include "microhttpd.h"
Packit 875988
#include "internal.h"
Packit 875988
#include "mhd_compat.h"
Packit 875988
Packit 875988
#ifndef WINDOWS
Packit 875988
#include <unistd.h>
Packit 875988
#endif
Packit 875988
Packit 875988
static int
Packit 875988
value_checker (void *cls,
Packit 875988
               enum MHD_ValueKind kind,
Packit 875988
               const char *key,
Packit 875988
               const char *filename,
Packit 875988
               const char *content_type,
Packit 875988
               const char *transfer_encoding,
Packit 875988
               const char *data, uint64_t off, size_t size)
Packit 875988
{
Packit 875988
  unsigned int *pos = cls;
Packit 875988
  (void)kind; (void)key; (void)filename; (void)content_type;  /* Unused. Silent compiler warning. */
Packit 875988
  (void)transfer_encoding; (void)data; (void)off;             /* Unused. Silent compiler warning. */
Packit 875988
#if 0
Packit 875988
  fprintf (stderr,
Packit 875988
           "VC: %llu %u `%s' `%s' `%s' `%s' `%.*s'\n",
Packit 875988
           off, size,
Packit 875988
           key, filename, content_type, transfer_encoding, size, data);
Packit 875988
#endif
Packit 875988
  if (size == 0)
Packit 875988
    return MHD_YES;
Packit 875988
  *pos += size;
Packit 875988
  return MHD_YES;
Packit 875988
Packit 875988
}
Packit 875988
Packit 875988
Packit 875988
static int
Packit 875988
test_simple_large ()
Packit 875988
{
Packit 875988
  struct MHD_Connection connection;
Packit 875988
  struct MHD_HTTP_Header header;
Packit 875988
  struct MHD_PostProcessor *pp;
Packit 875988
  size_t i;
Packit 875988
  size_t delta;
Packit 875988
  size_t size;
Packit 875988
  char data[102400];
Packit 875988
  unsigned int pos;
Packit 875988
Packit 875988
  pos = 0;
Packit 875988
  memset (data, 'A', sizeof (data));
Packit 875988
  memcpy (data, "key=", 4);
Packit 875988
  data[sizeof (data) - 1] = '\0';
Packit 875988
  memset (&connection, 0, sizeof (struct MHD_Connection));
Packit 875988
  memset (&header, 0, sizeof (struct MHD_HTTP_Header));
Packit 875988
  connection.headers_received = &header;
Packit 875988
  header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
Packit 875988
  header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED;
Packit 875988
  header.kind = MHD_HEADER_KIND;
Packit 875988
  pp = MHD_create_post_processor (&connection, 1024, &value_checker, &pos;;
Packit 875988
  i = 0;
Packit 875988
  size = strlen (data);
Packit 875988
  while (i < size)
Packit 875988
    {
Packit 875988
      delta = 1 + MHD_random_ () % (size - i);
Packit 875988
      MHD_post_process (pp, &data[i], delta);
Packit 875988
      i += delta;
Packit 875988
    }
Packit 875988
  MHD_destroy_post_processor (pp);
Packit 875988
  if (pos != sizeof (data) - 5) /* minus 0-termination and 'key=' */
Packit 875988
    return 1;
Packit 875988
  return 0;
Packit 875988
}
Packit 875988
Packit 875988
int
Packit 875988
main (int argc, char *const *argv)
Packit 875988
{
Packit 875988
  unsigned int errorCount = 0;
Packit 875988
  (void)argc; (void)argv;  /* Unused. Silent compiler warning. */
Packit 875988
Packit 875988
  errorCount += test_simple_large ();
Packit 875988
  if (errorCount != 0)
Packit 875988
    fprintf (stderr, "Error (code: %u)\n", errorCount);
Packit 875988
  return errorCount != 0;       /* 0 == pass */
Packit 875988
}