Change 16340 by jhi@alpha on 2002/05/02 12:44:23

        Subject: [PATCH] 1/3rd of utf8
        From: Nicholas Clark <[EMAIL PROTECTED]>
        Date: Wed, 1 May 2002 22:58:42 +0100
        Message-ID: <[EMAIL PROTECTED]>

Affected files ...

.... //depot/perl/ext/Storable/t/malice.t#7 edit

Differences ...

==== //depot/perl/ext/Storable/t/malice.t#7 (text) ====
Index: perl/ext/Storable/t/malice.t
--- perl/ext/Storable/t/malice.t.~1~    Thu May  2 07:00:05 2002
+++ perl/ext/Storable/t/malice.t        Thu May  2 07:00:05 2002
@@ -31,7 +31,7 @@
 
 use strict;
 use vars qw($file_magic_str $other_magic $network_magic $major $minor
-            $minor_write);
+            $minor_write $fancy);
 $file_magic_str = 'pst0';
 $other_magic = 7 + length($Config{byteorder});
 $network_magic = 2;
@@ -40,7 +40,16 @@
 $minor_write = $] > 5.007 ? 5 : 4;
 
 use Test;
-BEGIN { plan tests => 334 + length($Config{byteorder}) * 4}
+BEGIN {
+  # If it's 5.7.3 or later the hash will be stored with flags, which is
+  # 2 extra bytes. There are 2 * 2 * 2 tests per byte in the body and header
+  # common to normal and network order serialised objects (hence the 8)
+  # There are only 2 * 2 tests per byte in the parts of the header not present
+  # for network order, and 2 tests per byte on the 'pst0' "magic number" only
+  # present in files, but not in things store()ed to memory
+  $fancy = ($] > 5.007 ? 2 : 0);
+  plan tests => 334 + length($Config{byteorder}) * 4 + $fancy * 8;
+}
 
 use Storable qw (store retrieve freeze thaw nstore nfreeze);
 
@@ -49,7 +58,12 @@
 
 END { while (-f $file) {unlink $file or die "Can't unlink '$file': $!" }}
 
-my %hash = (perl => 'rules');
+# The chr 256 is a hack to force the hash to always have the utf8 keys flag
+# set on 5.7.3 and later. Otherwise the test fails if run with -Mutf8 because
+# only there does the hash has the flag on, and hence only there is it stored
+# as a flagged hash, which is 2 bytes longer
+my %hash = (perl => 'rules', chr 256, '');
+delete $hash{chr 256};
 
 sub test_hash {
   my $clone = shift;
@@ -225,7 +239,7 @@
 
 ok (defined store(\%hash, $file));
 
-my $expected = 20 + length ($file_magic_str) + $other_magic;
+my $expected = 20 + length ($file_magic_str) + $other_magic + $fancy;
 my $length = -s $file;
 
 die "Don't seem to have written file '$file' as I can't get its length: $!"
@@ -253,7 +267,7 @@
 
 ok (defined nstore(\%hash, $file));
 
-$expected = 20 + length ($file_magic_str) + $network_magic;
+$expected = 20 + length ($file_magic_str) + $network_magic + $fancy;
 $length = -s $file;
 
 die "Don't seem to have written file '$file' as I can't get its length: $!"
End of Patch.

Reply via email to