diff options
author | nanardon <nanardon@971eb68f-4bfb-0310-8326-d2484c010a4c> | 2005-10-04 04:08:46 +0000 |
---|---|---|
committer | nanardon <nanardon@971eb68f-4bfb-0310-8326-d2484c010a4c> | 2005-10-04 04:08:46 +0000 |
commit | 9e2966a33f9148fdc8ef81783bab1fe18e87bd34 (patch) | |
tree | 7497629483bdfca79e64991306f251dfdc9bdafb /RPM4/t/02header.t | |
parent | 588601a22c421404c9db24e0a47330d2186977f9 (diff) | |
download | perl-RPM4-9e2966a33f9148fdc8ef81783bab1fe18e87bd34.tar perl-RPM4-9e2966a33f9148fdc8ef81783bab1fe18e87bd34.tar.gz perl-RPM4-9e2966a33f9148fdc8ef81783bab1fe18e87bd34.tar.bz2 perl-RPM4-9e2966a33f9148fdc8ef81783bab1fe18e87bd34.tar.xz perl-RPM4-9e2966a33f9148fdc8ef81783bab1fe18e87bd34.zip |
- move to trunk
git-svn-id: svn+ssh://haiku.zarb.org/home/projects/rpm4/svn/trunk@36 971eb68f-4bfb-0310-8326-d2484c010a4c
Diffstat (limited to 'RPM4/t/02header.t')
-rw-r--r-- | RPM4/t/02header.t | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/RPM4/t/02header.t b/RPM4/t/02header.t new file mode 100644 index 0000000..7bba1a4 --- /dev/null +++ b/RPM4/t/02header.t @@ -0,0 +1,78 @@ +# $Id$ + +use strict; +use Test::More tests => 40; +use FindBin qw($Bin); +use RPM4; + +my $headerfile; + +{ +my $hdr = RPM4::Header->new(); +isa_ok($hdr, "RPM4::Header", "Creating empty header works"); +ok(! defined $hdr->tag(1000), "empty tag return nothings"); +} + +{ +my $hdr = RPM4::Header->new("$Bin/test-rpm-1.0-1mdk.src.rpm"); +isa_ok($hdr, "RPM4::Header", "instanciating an header from a source rpm works"); +ok($hdr->hastag(1000) eq 1, "Has tag 1000 (NAME), yes"); +ok($hdr->hastag("NAME") eq 1, "Has 'NAME', yes"); +ok($hdr->hastag(1106) eq 1, "Has tag 1106 (SOURCEPACKAGE), yes"); +ok($hdr->listtag(), "can list tag"); +is($hdr->tag(1000), "test-rpm", "accessing tag by id works"); +is($hdr->tag("NAME"), "test-rpm", "accessing tag by name works"); +is($hdr->NAME(), "test-rpm", "accessing tag directly works"); +ok($hdr->queryformat("%{NAME}-%{VERSION}-%{RELEASE}") eq "test-rpm-1.0-1mdk", "Queryformat is ok"); +ok($hdr->nevr() eq "test-rpm-1.0-1mdk", "header->nevr works"); +ok(scalar($hdr->fullname) eq "test-rpm-1.0-1mdk.src", "scalar fullname works"); +ok(join(",", $hdr->fullname) eq "test-rpm,1.0,1mdk,src", "wantarray fullname works"); +ok($hdr->issrc == 1, "Is a src, Yes !"); +ok($hdr->sourcerpmname eq "test-rpm-1.0-1mdk.src.rpm", "sourcerpmname works"); +ok($hdr->removetag(1000) == 0, "Removing a tag"); +ok(! defined $hdr->tag(1000), "tag is not present"); +ok($hdr->addtag(1000, 6, "new name") == 1, "Adding a tag (string type)"); +ok($hdr->tag(1000) eq "new name", "Added tag return good value"); +} + +{ +my $hdr = RPM4::Header->new("$Bin/test-rpm-1.0-1mdk.noarch.rpm"); +isa_ok($hdr, "RPM4::Header", "instanciating an header from a binary rpm works"); +ok($hdr->hastag(1000) eq 1, "Has tag 1000 (NAME), yes"); +ok($hdr->tagtype(1000) eq RPM4::tagtypevalue("STRING"), "can get type of a tag"); +ok($hdr->hastag(1106) eq 0, "Has tag 1106 (SOURCEPACKAGE), no"); +ok($hdr->listtag(), "can list tag"); +is($hdr->tag(1000), "test-rpm", "accessing tag by id works"); +is($hdr->tag("NAME"), "test-rpm", "accessing tag by name works"); +is($hdr->NAME(), "test-rpm", "accessing tag directly works"); +ok($hdr->queryformat("%{NAME}-%{VERSION}-%{RELEASE}") eq "test-rpm-1.0-1mdk", "Queryformat is ok"); +ok(scalar($hdr->fullname) eq "test-rpm-1.0-1mdk.noarch", "scalar fullname works"); +ok(join(",", $hdr->fullname) eq "test-rpm,1.0,1mdk,noarch", "wantarray fullname works"); +ok($hdr->issrc == 0, "Is a src, No !"); +ok($hdr->sourcerpmname eq "test-rpm-1.0-1mdk.src.rpm", "sourcerpmname works"); +$headerfile = scalar($hdr->fullname).".hdr"; + + +my $hdrcopy = $hdr->copy(); +ok(defined $hdrcopy, "copy works"); +ok($hdrcopy->tag(1000) eq 'test-rpm', "tag 1000 (NAME) from copy works"); + +open(my $hdfh, ">", $headerfile); +ok($hdr->write($hdfh), "Write the header works"); +close($hdfh); + +my $size = $hdr->hsize; +ok($size != 0, "Header size works"); +ok($size == (stat($headerfile))[7], "file size is same than in memory"); +} + +{ +open(my $hdfh, "< $headerfile"); +my $hdr2 = RPM4::Header->new($hdfh); +isa_ok($hdr2, "RPM4::Header", "instanciating an header from a stream works"); +close $hdfh; +unlink($headerfile); +ok($hdr2->tag(1000) eq 'test-rpm', "tag 1000 from header file works"); +} + + |