aboutsummaryrefslogtreecommitdiff
path: root/tests/getpart.pm
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-11-29 12:10:09 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-11-29 12:10:09 +0000
commit0eb8414750456a7a2584a8863b1e217e8bff88cd (patch)
treebd5c9d2ecd88446c8b1ea2f8e14e303fe9718db6 /tests/getpart.pm
parent09717d3fc82a858620026538600c311a851dfe14 (diff)
Enable test cases to provide sections base64-encoded to be able to test
with binary data.
Diffstat (limited to 'tests/getpart.pm')
-rw-r--r--tests/getpart.pm33
1 files changed, 30 insertions, 3 deletions
diff --git a/tests/getpart.pm b/tests/getpart.pm
index 969dfd066..1dffe353c 100644
--- a/tests/getpart.pm
+++ b/tests/getpart.pm
@@ -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;
}