X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F22_internal_copy.t;h=bda4b1d13b303a569930b7630aa00de0d9852f17;hb=4f0f6fff0474a896cad8bbb80d8c0ccce3d87bf9;hp=000519f86c773d4095c171364ee41139e0267023;hpb=95967a5ee0a385bc0107632a13233a2be0f36613;p=dbsrgits%2FDBM-Deep.git diff --git a/t/22_internal_copy.t b/t/22_internal_copy.t index 000519f..bda4b1d 100644 --- a/t/22_internal_copy.t +++ b/t/22_internal_copy.t @@ -3,24 +3,25 @@ ## use strict; use Test::More tests => 13; +use t::common qw( new_fh ); use_ok( 'DBM::Deep' ); -unlink "t/test.db"; -my $db = DBM::Deep->new( "t/test.db" ); +my ($fh, $filename) = new_fh(); +my $db = DBM::Deep->new( $filename ); ## # Create structure in $db ## -$db->import( - hash1 => { - subkey1 => "subvalue1", - subkey2 => "subvalue2", - }, +$db->import({ + hash1 => { + subkey1 => "subvalue1", + subkey2 => "subvalue2", + }, hash2 => { subkey3 => 'subvalue3', }, -); +}); is( $db->{hash1}{subkey1}, 'subvalue1', "Value imported correctly" ); is( $db->{hash1}{subkey2}, 'subvalue2', "Value imported correctly" ); @@ -44,21 +45,23 @@ is( scalar(keys %{$db->{hash1}}), 1, "... and only 1 key in the original" ); $db->{copy} = $db->{hash2}; is( $db->{copy}{subkey3}, 'subvalue3', "After the second copy, we're still good" ); - my $max_keys = 1000; -unlink 't/test2.db'; +my ($fh2, $filename2) = new_fh(); { - my $db = DBM::Deep->new( 't/test2.db' ); + my $db = DBM::Deep->new( file => $filename2, fh => $fh2, ); $db->{foo} = [ 1 .. 3 ]; for ( 0 .. $max_keys ) { $db->{'foo' . $_} = $db->{foo}; } + ## Rewind handle otherwise the signature is not recognised below. + ## The signature check should probably rewind the fh? + seek $db->_get_self->_engine->storage->{fh}, 0, 0; } { - my $db = DBM::Deep->new( 't/test2.db' ); + my $db = DBM::Deep->new( fh => $fh2, ); my $base_offset = $db->{foo}->_base_offset; my $count = -1;