1b39c5158Smillert#!perl -w 2b39c5158Smillert 3b39c5158Smillertuse strict; 4*256a93a4Safresh1use warnings; 5*256a93a4Safresh1 6b39c5158Smillertuse Digest::MD5 qw(md5_hex); 7b39c5158Smillert 8*256a93a4Safresh1print "1..6\n"; 9*256a93a4Safresh1 10b39c5158Smillertmy $a = Digest::MD5->new; 11b39c5158Smillert$a->add("a"); 12b39c5158Smillertmy $b = $a->clone; 13b39c5158Smillert 14b39c5158Smillertprint "not " unless $b->clone->hexdigest eq md5_hex("a"); 15b39c5158Smillertprint "ok 1\n"; 16b39c5158Smillert 17b39c5158Smillert$a->add("a"); 18b39c5158Smillertprint "not " unless $a->hexdigest eq md5_hex("aa"); 19b39c5158Smillertprint "ok 2\n"; 20b39c5158Smillert 21b39c5158Smillertprint "not " unless $a->hexdigest eq md5_hex(""); 22b39c5158Smillertprint "ok 3\n"; 23b39c5158Smillert 24b39c5158Smillert$b->add("b"); 25b39c5158Smillertprint "not " unless $b->clone->hexdigest eq md5_hex("ab"); 26b39c5158Smillertprint "ok 4\n"; 27b39c5158Smillert 28b39c5158Smillert$b->add("c"); 29b39c5158Smillertprint "not " unless $b->clone->hexdigest eq md5_hex("abc"); 30b39c5158Smillertprint "ok 5\n"; 31b39c5158Smillert 32b39c5158Smillert# Test that cloning picks up the correct class for subclasses. 33b39c5158Smillert{ 34b39c5158Smillert package MD5; 35b39c5158Smillert @MD5::ISA = qw(Digest::MD5); 36b39c5158Smillert} 37b39c5158Smillert 38b39c5158Smillert$a = MD5->new; 39b39c5158Smillert$a->add("a"); 40b39c5158Smillert$b = $a->clone; 41b39c5158Smillert 42b39c5158Smillertprint "not " unless ref($b) eq "MD5" && $b->add("b")->hexdigest eq md5_hex("ab"); 43b39c5158Smillertprint "ok 6\n"; 44