summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-05-18 10:40:33 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-05-18 10:42:41 +0200
commitca6d7d2a6dcecefa0290734e4e1ad6b60e33c456 (patch)
tree63edb989d57016e1f6efab0ba9da072c86d2bab1
parentf3fab7c83bfac8a38e3591426761620a48daa46a (diff)
App::Hashl test: Verify that partial hashing actually works
-rw-r--r--t/29-app-hashl.t15
-rw-r--r--t/in/1k-firsthalfbin0 -> 512 bytes
2 files changed, 14 insertions, 1 deletions
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
--- /dev/null
+++ b/t/in/1k-firsthalf
Binary files differ