From ca6d7d2a6dcecefa0290734e4e1ad6b60e33c456 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 18 May 2011 10:40:33 +0200 Subject: App::Hashl test: Verify that partial hashing actually works --- t/29-app-hashl.t | 15 ++++++++++++++- t/in/1k-firsthalf | Bin 0 -> 512 bytes 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 t/in/1k-firsthalf diff --git a/t/29-app-hashl.t b/t/29-app-hashl.t index 325c3b2..fd8f95b 100644 --- a/t/29-app-hashl.t +++ b/t/29-app-hashl.t @@ -3,7 +3,7 @@ use strict; use warnings; use 5.010; -use Test::More tests => 28; +use Test::More tests => 31; use_ok('App::Hashl'); @@ -76,3 +76,16 @@ unlink('t/in/hashl.db'); is($hashl->file_in_db('t/in/4'), $IGNORED, 'file still ignored'); is_deeply([$hashl->files()], [], 'no files in db'); + +undef $hashl; + +my $hash_512 = App::Hashl->new(read_size => 512)->hash_file('t/in/1k'); +my $hash_1k = App::Hashl->new(read_size => 1024)->hash_file('t/in/1k'); +my $hash_2k = App::Hashl->new(read_size => 2048)->hash_file('t/in/1k'); + +my $hash_1k_half = App::Hashl->new()->hash_file('t/in/1k-firsthalf'); + +is($hash_1k, $hash_2k, + 'Same hash for read_size > filesize and read_size == file_size'); +isnt($hash_512, $hash_1k, 'Partial hashing does not hash full file'); +is($hash_512, $hash_1k_half, 'Partial hashing produces correct hash'); diff --git a/t/in/1k-firsthalf b/t/in/1k-firsthalf new file mode 100644 index 0000000..eda0143 Binary files /dev/null and b/t/in/1k-firsthalf differ -- cgit v1.2.3