1#!/usr/bin/perl 2use strict; 3use warnings; 4 5use Test::More; 6use Digest::MD5; 7 8foreach my $string ( map { 'a' x $_ } 9 1..17, 10 31..33, 11 64..65, 12 127..129, 13 191..193, 14 1023..1025, 15 2047..2049, 16) { 17 my $expect = do { 18 my $ctx = Digest::MD5->new; 19 $ctx->add($string); 20 $ctx->add($string); 21 $ctx->add($string); 22 $ctx->hexdigest; 23 }; 24 25 my $got = do { 26 my $ctx1 = Digest::MD5->new; 27 $ctx1->add($string); 28 29 my $ctx2 = Digest::MD5->new; 30 $ctx2->context( $ctx1->context ); 31 $ctx2->add($string); 32 33 my $ctx3 = Digest::MD5->new; 34 $ctx3->context( $ctx2->context ); 35 $ctx3->add($string); 36 37 $ctx3->hexdigest; 38 }; 39 40 is $got, $expect, length($string) . " saved context"; 41} 42 43done_testing; 44