05247f08cd6882d59bb0f11dc47f945dc72f1112
[p5sagit/Devel-PeekPoke.git] / t / 03torture.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5
6 use Devel::PeekPoke qw/peek poke peek_address poke_address/;
7 use Devel::PeekPoke::Constants qw/PTR_SIZE PTR_PACK_TYPE/;
8
9 my $str = 'for mutilation and mayhem';
10 my $len = length($str);
11 my $str_pv_addr = unpack(PTR_PACK_TYPE, pack('p', $str) );
12
13 is( peek($str_pv_addr, $len + 1), $str . "\0", 'peek as expected (with NUL termination)' );
14
15 for my $poke_size (2 .. $len) {
16   my $replace_chunk = 'a' . ( '0' x ($poke_size-1) );
17   for my $poke_start ( 0 .. ($len - $poke_size) ) {
18     $replace_chunk++;
19
20     my $expecting = $str;
21     substr($expecting, $poke_start, $poke_size, $replace_chunk);
22
23     poke($str_pv_addr+$poke_start, $replace_chunk);
24     is($str, $expecting, 'String matches expectation after poke');
25   }
26 }
27
28 done_testing;