aboutsummaryrefslogtreecommitdiffstats
path: root/t/rpmdb.t
blob: 8d93fd2527313cbeb5aa0f7b9ab7ee42cdd19c76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

use strict ;
use warnings ;

sub ok {
    my ($no, $ok) = @_ ;

    print "ok $no\n" if $ok ;
    print "not ok $no\n" unless $ok ;
    printf "# Failed test at line %d\n", (caller)[2] unless $ok ;
}

use URPM;

print "1..5\n";

my ($count, @all_pkgs_extern, @all_pkgs);
{
    my $db;
    ok(1, $db = URPM::DB::open);

    @all_pkgs_extern = sort { $a cmp $b } split '\n', `rpm -qa`;
    ok(2, @all_pkgs_extern > 0);

    $count = $db->traverse(sub {
			       my ($pkg) = @_;
			       my ($name, $version, $release, $arch) = $pkg->fullname;
			       #- arch is void for -pubkey- package.
			       push @all_pkgs, "$name-$version-$release";
			   });
}
ok(3, $count == @all_pkgs_extern);
ok(4, $count == @all_pkgs);

my @all_pkgs_sorted = sort { $a cmp $b } @all_pkgs;
my $bad_pkgs = 0;
foreach (0..$#all_pkgs_sorted) {
    $all_pkgs_sorted[$_] eq $all_pkgs_extern[$_] or ++$bad_pkgs;
}
ok(5, $bad_pkgs == 0);