]> granicus.if.org Git - curl/commitdiff
Enable test cases to provide sections base64-encoded to be able to test
authorDaniel Stenberg <daniel@haxx.se>
Mon, 29 Nov 2004 12:10:09 +0000 (12:10 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 29 Nov 2004 12:10:09 +0000 (12:10 +0000)
with binary data.

tests/FILEFORMAT
tests/getpart.pm
tests/runtests.pl
tests/server/Makefile.am
tests/server/getpart.c
tests/server/getpart.h
tests/server/sws.c

index b65b6b2ca3aa43e9228e8e6d1d08aa57885768e8..92c7416b5263cb0df8d4254c44ffbb7669d4e7cd 100644 (file)
@@ -14,7 +14,7 @@ specified, that will be checked/used if specified. This document includes all
 the subsections currently supported.
 
 <reply>
-<data [nocheck=1] [sendzero=yes]>
+<data [nocheck=1] [sendzero=yes] [base64=yes]>
 §data to sent to the client on its request and later verified that it arrived
 safely. Set the nocheck=1 to prevent the test script to verify the arrival
 of this data.
@@ -31,6 +31,11 @@ for auth tests and similar.
 'sendzero' set to yes means that the (FTP) server will "send" the data even if
 the size is zero bytes. Used to verify curl's behaviour on zero bytes
 transfers.
+
+'base64' set to yes means that the data provided in the test-file is a chunk
+of data encoded with base64. It is the only way a test case can contain binary
+data. (This attribute can in fact be used on any section, but it doesn't make
+much sense for other sections than "data").
 </data>
 <dataNUM>
 Send back this contents instead of the <data> one. The num is set by:
index 969dfd06643deaa93bf73d4097ac6c581479478e..1dffe353c853ee29624879e81f8344e878c95c95 100644 (file)
@@ -56,6 +56,7 @@ sub getpart {
 
     my @this;
     my $inside=0;
+    my $base64=0;
 
  #   print "Section: $section, part: $part\n";
 
@@ -65,6 +66,10 @@ sub getpart {
             $inside++;
         }
         elsif((1 ==$inside) && ($_ =~ /^ *\<$part[ \>]/)) {
+            if($_ =~ /$part .*base64=/) {
+                # attempt to detect base64 encoded parts
+                $base64=1;
+            }
             $inside++;
         }
         elsif((2 ==$inside) && ($_ =~ /^ *\<\/$part/)) {
@@ -77,6 +82,13 @@ sub getpart {
             if(!@this && $warning) {
                 print STDERR "*** getpart.pm: $section/$part returned empty!\n";
             }
+            if($base64) {
+                # decode the whole array before returning it!
+                for(@this) {
+                    my $decoded = decode_base64($_);
+                    $_ = $decoded;
+                }
+            }
             return @this;
         }
         elsif(2==$inside) {
@@ -138,16 +150,31 @@ sub compareparts {
  my $sizefirst=scalar(@$firstref);
  my $sizesecond=scalar(@$secondref);
 
+ my $first;
+ my $second;
+
  for(1 .. $sizefirst) {
      my $index = $_ - 1;
      if($firstref->[$index] ne $secondref->[$index]) {
          (my $aa = $firstref->[$index]) =~ s/\r+\n$/\n/;
          (my $bb = $secondref->[$index]) =~ s/\r+\n$/\n/;
-         if($aa ne $bb) {
-             return 1+$index;
-         }
+         
+         $first .= $firstref->[$index];
+         $second .= $secondref->[$index];
      }
  }
+
+ # we cannot compare arrays index per index since with the base64 chunks,
+ # they may not be "evenly" distributed
+
+ # NOTE: this no longer strips off carriage returns from the arrays. Is that
+ # really necessary? It ruins the testing of newlines. I believe it was once
+ # added to enable tests on win32.
+
+ if($first ne $second) {
+     return 1;
+ }
+
  return 0;
 }
 
index 13a84d1c4d06a2bc7933defaa83cd3895c2374a7..9febc92f527186f1189d0ec53e50d1d140955780 100755 (executable)
@@ -23,6 +23,7 @@
 ###########################################################################
 # These should be the only variables that might be needed to get edited:
 
+use MIME::Base64;
 use strict;
 #use warnings;
 
index a655e3f632fe8a4e434f0ae2c6d213914d22bfd5..73cd3c2ce194fea44fc97d441f267e5185b4f181 100644 (file)
@@ -29,9 +29,16 @@ AUTOMAKE_OPTIONS = foreign
 
 INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/include
 
-noinst_PROGRAMS = sws
+noinst_PROGRAMS = sws getpart
 
-sws_SOURCES= sws.c getpart.c getpart.h $(top_srcdir)/lib/strequal.c
+sws_SOURCES= sws.c getpart.c getpart.h $(top_srcdir)/lib/strequal.c    \
+ $(top_srcdir)/lib/base64.c $(top_srcdir)/lib/mprintf.c                        \
+ $(top_srcdir)/lib/memdebug.c
 
-extra_DIST = config.h.in
+extra_DIST = base64.pl
 
+getpart_CPPFLAGS = -DGETPART_TEST
+
+getpart_SOURCES= getpart.c getpart.h $(top_srcdir)/lib/strequal.c      \
+ $(top_srcdir)/lib/base64.c $(top_srcdir)/lib/mprintf.c                        \
+ $(top_srcdir)/lib/memdebug.c
index 9cb919fe1f5b1bbc8c8cbd5f824d4e84e7517fdd..0ae6c391c822e2e2c929e59acd2ccd6bcc9b6624 100644 (file)
@@ -1,8 +1,8 @@
 /***************************************************************************
- *                                  _   _ ____  _     
- *  Project                     ___| | | |  _ \| |    
- *                             / __| | | | |_) | |    
- *                            | (__| |_| |  _ <| |___ 
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
  * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
@@ -10,7 +10,7 @@
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
  * are also available at http://curl.haxx.se/docs/copyright.html.
- * 
+ *
  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  * copies of the Software, and permit persons to whom the Software is
  * furnished to do so, under the terms of the COPYING file.
 #include <stdlib.h>
 #include "getpart.h"
 
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#include "base64.h"
+
+/* include memdebug.h last */
+#include "memdebug.h"
+
 #define EAT_SPACE(ptr) while( ptr && *ptr && isspace((int)*ptr) ) ptr++
 #define EAT_WORD(ptr) while( ptr && *ptr && !isspace((int)*ptr) && ('>' != *ptr)) ptr++
 
 #define show(x)
 #endif
 
+curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc;
+curl_free_callback Curl_cfree = (curl_free_callback)free;
+curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc;
+curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)strdup;
+curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
+
 static
 char *appendstring(char *string, /* original string */
                    char *buffer, /* to append */
                    size_t *stringlen, /* length of string */
-                   size_t *stralloc)  /* allocated size */
+                   size_t *stralloc,  /* allocated size */
+                   char base64) /* 1 if base64 encoded */
 {
   size_t len = strlen(buffer);
   size_t needed_len = len + *stringlen;
+  char buf64[256]; /* big enough? */
+
+  if(base64) {
+    /* decode the given buffer first */
+    len = Curl_base64_decode(buffer, buf64); /* updated len */
+    buffer = buf64;
+    needed_len = len + *stringlen; /* recalculate */
+  }
 
   if(needed_len >= *stralloc) {
     char *newptr;
@@ -57,7 +80,8 @@ char *appendstring(char *string, /* original string */
     else
       return NULL;
   }
-  strcpy(&string[*stringlen], buffer);
+  /* memcpy to support binary blobs */
+  memcpy(&string[*stringlen], buffer, len);
   *stringlen += len;
 
   return string;
@@ -77,6 +101,7 @@ const char *spitout(FILE *stream,
   char *string;
   size_t stringlen=0;
   size_t stralloc=256;
+  char base64 = 0; /* set to 1 if true */
 
   enum {
     STATE_OUTSIDE,
@@ -90,7 +115,7 @@ const char *spitout(FILE *stream,
     return NULL;
 
   string[0] = 0; /* zero first byte in case of no data */
-  
+
   while(fgets(buffer, sizeof(buffer), stream)) {
 
     ptr = buffer;
@@ -101,7 +126,7 @@ const char *spitout(FILE *stream,
     if('<' != *ptr) {
       if(display) {
         show(("=> %s", buffer));
-        string = appendstring(string, buffer, &stringlen, &stralloc);
+        string = appendstring(string, buffer, &stringlen, &stralloc, base64);
         show(("* %s\n", buffer));
       }
       continue;
@@ -138,7 +163,7 @@ const char *spitout(FILE *stream,
       /* this is the beginning of a section */
       end = ptr;
       EAT_WORD(end);
-      
+
       *end = 0;
       switch(state) {
       case STATE_OUTSIDE:
@@ -152,9 +177,19 @@ const char *spitout(FILE *stream,
       default:
         break;
       }
+
+      if(!end[1] != '>') {
+        /* There might be attributes here. Check for those we know of and care
+           about. */
+        if(strstr(&end[1], "base64=")) {
+          /* rought and dirty, but "mostly" functional */
+          /* Treat all data as base64 encoded */
+          base64 = 1;
+        }
+      }
     }
     if(display) {
-      string = appendstring(string, buffer, &stringlen, &stralloc);
+      string = appendstring(string, buffer, &stringlen, &stralloc, base64);
       show(("* %s\n", buffer));
     }
 
@@ -174,15 +209,16 @@ const char *spitout(FILE *stream,
   return string;
 }
 
-#ifdef TEST
+#ifdef GETPART_TEST
 int main(int argc, char **argv)
 {
   if(argc< 3) {
     printf("./moo main sub\n");
   }
   else {
-    int size;
-    char *buffer = spitout(stdin, argv[1], argv[2], &size);
+    size_t size;
+    const char *buffer = spitout(stdin, argv[1], argv[2], &size);
+    printf("%s", buffer);
   }
   return 0;
 }
index f50e122f06956dfbb26c88f37935c971ca4fae93..0ded4f73fa877f8d6c2ce8d65491c5555e7ffedd 100644 (file)
@@ -1,8 +1,8 @@
 /***************************************************************************
- *                                  _   _ ____  _     
- *  Project                     ___| | | |  _ \| |    
- *                             / __| | | | |_) | |    
- *                            | (__| |_| |  _ <| |___ 
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
  * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
@@ -10,7 +10,7 @@
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
  * are also available at http://curl.haxx.se/docs/copyright.html.
- * 
+ *
  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  * copies of the Software, and permit persons to whom the Software is
  * furnished to do so, under the terms of the COPYING file.
index db297917591d0357c19d71300ca840828b3299ee..a42f7ee90212744660e267bf4e52264baf0ebf35 100644 (file)
@@ -81,6 +81,9 @@
 static void win32_cleanup(void);
 #endif
 
+/* include memdebug.h last */
+#include "memdebug.h"
+
 #define REQBUFSIZ 150000
 #define REQBUFSIZ_TXT "149999"