[Bps-public-commit] r14339 - in Data-Plist: . lib/Data/Plist
kyoki at bestpractical.com
kyoki at bestpractical.com
Mon Jul 21 16:29:34 EDT 2008
Author: kyoki
Date: Mon Jul 21 16:29:31 2008
New Revision: 14339
Modified:
Data-Plist/ (props changed)
Data-Plist/lib/Data/Plist/BinaryReader.pm
Data-Plist/lib/Data/Plist/BinaryWriter.pm
Data-Plist/t/binary-load.t
Data-Plist/t/binary-write.t
Log:
r29852 at nyx: kyoki | 2008-07-21 16:29:20 -0400
more tests
Modified: Data-Plist/lib/Data/Plist/BinaryReader.pm
==============================================================================
--- Data-Plist/lib/Data/Plist/BinaryReader.pm (original)
+++ Data-Plist/lib/Data/Plist/BinaryReader.pm Mon Jul 21 16:29:31 2008
@@ -264,7 +264,7 @@
or $OffsetTableOffset > $end
or $OffsetTableOffset + $NumObjects * $OffsetSize > $end )
{
- die "Invalid offset table address (overlap with header or footer:\n OTO: $OffsetTableOffset\n NO: $NumObjects\n OS: $OffsetSize\n e: $end)\n";
+ die "Invalid offset table address (overlap with header or footer.";
}
# get the offset table
Modified: Data-Plist/lib/Data/Plist/BinaryWriter.pm
==============================================================================
--- Data-Plist/lib/Data/Plist/BinaryWriter.pm (original)
+++ Data-Plist/lib/Data/Plist/BinaryWriter.pm Mon Jul 21 16:29:31 2008
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use YAML;
+use Storable;
use Math::BigInt;
use Digest::MD5;
@@ -13,12 +13,12 @@
$self = $self->new() unless ref $self;
my ( $fh, $object ) = @_;
- $object = $self->serialize($object) if ($self->{serialize});
+ $object = $self->serialize($object) if ( $self->{serialize} );
binmode $fh;
- $self->{fh} = $fh;
- $self->{index} = [];
- $self->{size} = $self->count($object);
- $self->{objcache}= {};
+ $self->{fh} = $fh;
+ $self->{index} = [];
+ $self->{size} = $self->count($object);
+ $self->{objcache} = {};
if ( $self->{size} >= 2**8 ) {
$self->{refsize} = 2;
}
@@ -33,7 +33,7 @@
print $fh ( pack $self->pack_in($offset_size), $_ );
}
print $fh ( pack "x6CC", ( $offset_size + 1 ), $self->{refsize} );
- print $fh ( pack "x4N", scalar keys %{$self->{objcache}} );
+ print $fh ( pack "x4N", scalar keys %{ $self->{objcache} } );
print $fh ( pack "x4N", $top_index );
print $fh ( pack "x4N", $table_offset );
close $fh;
@@ -45,7 +45,7 @@
my ($arrayref) = @_;
my $type = $arrayref->[0];
my $method = "write_" . $type;
- my $digest = Digest::MD5::md5_hex( YAML::Dump( $arrayref->[1] ) );
+ my $digest = eval{Digest::MD5::md5_hex( Storable::freeze( $arrayref ) )};
die "Can't $method" unless $self->can($method);
$self->{objcache}{$digest} = $self->$method( $arrayref->[1] )
unless ( exists $self->{objcache}{$digest} );
@@ -205,11 +205,12 @@
my ($data) = @_;
use bytes;
my $len = length $data;
- my $obj = $self->make_type(4, $len) . $data;
+ my $obj = $self->make_type( 4, $len ) . $data;
return $self->binary_write($obj);
}
sub count {
+
# this might be slightly over, since it doesn't take into account duplicates
my $self = shift;
my ($arrayref) = @_;
@@ -269,7 +270,7 @@
sub pack_in {
my $self = shift;
- my ($power ) = @_;
+ my ($power) = @_;
if ( $power == 4 ) {
die "Cannot encode 2**4 byte integers";
}
Modified: Data-Plist/t/binary-load.t
==============================================================================
--- Data-Plist/t/binary-load.t (original)
+++ Data-Plist/t/binary-load.t Mon Jul 21 16:29:31 2008
@@ -1,4 +1,4 @@
-use Test::More no_plan => 1;
+use Test::More tests => 59;
use strict;
use warnings;
@@ -96,6 +96,27 @@
isa_ok( $ret, "Data::Plist" );
is_deeply( $ret->raw_data => [ null => 0 ], "Has a null");
+### Trailer
+
+# Invalid offset sizes
+$ret = eval {$read->open_string("bplist00" . pack("Cnx6CC(x4N)3", 0,8,5,1,1,0,9))};
+ok( not ($ret), "Invalid offset");
+like ("$@", qr/invalid offset/i, "Threw an error");
+
+# Invalid refsize
+$ret = eval {$read->open_string("bplist00" . pack("Cnx6CC(x4N)3", 0,8,2,3,1,0,9))};
+ok( not ($ret), "Invalid refsize");
+like ("$@", qr/invalid reference/i, "Threw an error");
+
+# Invalid top object index
+$ret = eval {$read->open_string("bplist00" . pack("Cnx6CC(x4N)3", 0,8,2,1,1,1,9))};
+ok( not ($ret), "Invalid top object id");
+like ("$@", qr/invalid top/i, "Threw an error");
+
+# Invalid offset table address
+$ret = eval {$read->open_string("bplist00" . pack("Cnx6CC(x4N)3", 0,8,2,1,2,0,9))};
+ok( not ($ret), "Invalid offset table address");
+like ("$@", qr/invalid offset/i, "Threw an error");
### More complex testing
@@ -105,6 +126,12 @@
isa_ok( $ret, "Data::Plist" );
ok( $ret->raw_data, "Has data inside" );
+# ustring
+$ret = $read->open_file("t/data/ustring.binary.plist");
+ok ($ret, "Got a value from open with a filename" );
+isa_ok($ret, "Data::Plist" );
+ok($ret->raw_data, "Has data inside" );
+
# Load from fh
my $fh;
open( $fh, "<", "t/data/basic.binary.plist");
Modified: Data-Plist/t/binary-write.t
==============================================================================
--- Data-Plist/t/binary-write.t (original)
+++ Data-Plist/t/binary-write.t Mon Jul 21 16:29:31 2008
@@ -1,4 +1,4 @@
-use Test::More tests => 200;
+use Test::More tests => 204;
use strict;
use warnings;
@@ -14,7 +14,7 @@
# Dict containing stuff
round_trip( { 'kitteh' => 'Angleton', 'MoL' => 42, 'array' => ['Cthulhu'] },
- 93 );
+ 93 );
# Empty array
round_trip( [], 42 );
@@ -43,6 +43,17 @@
# Long string (where long means "more than 15 characters")
round_trip( "The kyokeach is cute", 64 );
+# Ustring
+my $writer = Data::Plist::BinaryWriter->new(serialize => 0);
+my $reader = Data::Plist::BinaryReader->new;
+my $ustring = eval{$reader->open_file("t/data/ustring.binary.plist")};
+ok ($ustring->raw_data, "Got data");
+$ustring = $ustring->raw_data;
+my $orig = $writer->write($ustring);
+ok ($orig, "Created data structure");
+like( $orig, qr/^bplist00/, "Bplist begins with correct header" );
+is( "$@", '', "No errors thrown." );
+
# Real number
round_trip( 3.14159, 50 );
@@ -74,7 +85,7 @@
my $fail = Data::Plist::BinaryWriter->new( serialize => 0);
my $ret = eval{$fail->write([ random => 0 ])};
ok (not ($ret), "Binary plist didn't write.");
-like ($@, qr/Can't/i, "Threw an error.");
+like ($@, qr/can't/i, "Threw an error.");
sub round_trip {
my $write = Data::Plist::BinaryWriter->new;
More information about the Bps-public-commit
mailing list