aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rwxr-xr-xt/01packdrakeng.t83
1 files changed, 56 insertions, 27 deletions
diff --git a/t/01packdrakeng.t b/t/01packdrakeng.t
index 5f7f77c..27f0527 100755
--- a/t/01packdrakeng.t
+++ b/t/01packdrakeng.t
@@ -2,24 +2,24 @@
# $Id$
-use Test::More tests => 8;
+use Test::More tests => 16;
use Digest::MD5;
use_ok('packdrakeng');
-sub clean_random_files {
+sub clean_test_files {
-d "test" or return;
unlink glob("test/*");
}
#
-sub create_random_files {
+sub create_test_files {
my ($number) = @_;
my %created;
-d test or mkdir test;
foreach my $n (1 .. $number||10) {
my $size = int(rand(1024));
- push(@created, "test/$size");
+ # push(@created, "test/$size");
system("dd if=/dev/urandom of=test/$size bs=1024 count=$size >/dev/null 2>&1");
open(my $h, "test/$size");
$created{"test/$size"} = Digest::MD5->new->addfile($h)->hexdigest;
@@ -28,42 +28,71 @@ sub create_random_files {
%created
}
+sub create_know_file {
+ foreach my $letter (a..z) {
+ open(my $h, "> test/$letter");
+ foreach (1 .. 3456) {
+ printf $h "%s\n", $letter x 33;
+ }
+ close($h);
+ open($h, "test/$letter");
+ $created{"test/$letter"} = Digest::MD5->new->addfile($h)->hexdigest;
+ close($h);
+ }
+ %created
+}
+
sub check_files {
my %files = @_;
my $ok = 1;
foreach my $f (keys %files) {
open(my $h, $f);
- Digest::MD5->new->addfile($h)->hexdigest ne $files{$f} and $ok = 0;
+ Digest::MD5->new->addfile($h)->hexdigest ne $files{$f} and do {
+ print STDERR "$f differ\n";
+ $ok = 0;
+ };
close $h;
}
$ok
}
+###################################
+# #
+# Test series, packing, unpacking #
+# #
+###################################
-# Test: creating
-clean_random_files();
-my %createdfiles = create_random_files(50);
+sub test_packing {
+ my ($pack_param, $listfiles) = @_;
-ok(my $pack = packdrakeng->new(archive => "packtest.cz"), "Creating an archive");
-ok($pack->add(undef, keys %createdfiles), "Adding files to the archive");
-$pack = undef; # closing the archive.
+ ok(my $pack = packdrakeng->new(%$pack_param), "Creating an archive");
+ ok($pack->add(undef, keys %$listfiles), "packing files");
+ $pack = undef; # closing the archive.
+
+ clean_test_files();
+
+ ok($pack = packdrakeng->open(%$pack_param), "Re-opening the archive");
+ ok($pack->extract(undef, keys(%createdfiles)), "extracting files");
+ ok(check_files(%createdfiles), "Checking md5sum for extracted files");
-clean_random_files();
-ok($pack = packdrakeng->open(archive => "packtest.cz"), "Re-opening the archive");
-$pack->dump;
-
-# Test: all files are packed
-my (undef, $packedfiles, undef) = $pack->getcontent();
-ok(@$packedfiles > 0, "Archive contains files");
-
-{
-my %fex = %createdfiles;
-foreach (@$packedfiles) {
- delete $fex{$_};
-}
-ok(! keys(%fex), "All files has been packed");
+ $pack = undef;
}
-ok($pack->extract(undef, keys(%createdfiles)), "extracting files");
-ok(check_files(%createdfiles), "Checking md5sum for extracted files");
+print "Test: using internal gzip function:\n";
+ clean_test_files();
+ test_packing({ archive => "packtest.cz" }, { create_test_files(30) });
+ clean_test_files();
+ unlink("packtest.cz");
+
+print "Test: using external gzip function:\n";
+ clean_test_files();
+ test_packing({ archive => "packtest.cz", compress => "gzip", extern => 1}, { create_test_files(30) });
+ clean_test_files();
+ unlink("packtest.cz");
+
+print "Test: using external bzip function:\n";
+ clean_test_files();
+ test_packing({ archive => "packtest.cz", compress => "bzip2", extern => 1}, { create_test_files(30) });
+ clean_test_files();
+ unlink("packtest.cz");