summaryrefslogtreecommitdiff
path: root/perl-RPM2/test.pl
blob: ff3229f0155bd9c37ece33f6aa5f0db237155553 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/perl -w
use strict;

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

#########################

# change 'tests => 1' to 'tests => last_test_to_print';
# comment to test checkin

use Test;
use strict;
BEGIN { plan tests => 35 };
use RPM2;
ok(1); # If we made it this far, we're ok.

#########################

# Insert your test code below, the Test module is use()ed here so read
# its man page ( perldoc Test ) for help writing this test script.

ok(RPM2::rpmvercmp("1.0", "1.1") == -1);
ok(RPM2::rpmvercmp("1.1", "1.0") == 1);
ok(RPM2::rpmvercmp("1.0", "1.0") == 0);

# UPDATE: the vercmp bug was finally fixed, and broke this test, heh
#  this is a bug case in rpmvervmp; good one for testing
#  ok(RPM2::rpmvercmp("1.a", "1.0") == RPM2::rpmvercmp("1.0", "1.a"));

my $db = RPM2->open_rpm_db();
ok(defined $db);

my @pkg;
my $i = $db->find_all_iter();

ok($i);
while (my $pkg = $i->next) {
  push @pkg, $pkg;
}

ok(@pkg);
ok($pkg[0]->name);

@pkg = ();
$i = $db->find_by_name_iter("kernel");
ok($i);
while (my $pkg = $i->next) {
  push @pkg, $pkg;
}
if (@pkg) {
  ok($pkg[0]->name);
}

@pkg = ();

$i = $db->find_by_provides_iter("kernel");
ok($i);
while (my $pkg = $i->next) {
  push @pkg, $pkg;
}
if (@pkg) {
  ok($pkg[0]->name);
}

@pkg = ();
foreach my $pkg ($db->find_by_file("/bin/sh")) {
  push @pkg, $pkg;
}
if (@pkg) {
  ok($pkg[0]->name);
}

@pkg = ();
foreach my $pkg ($db->find_by_requires("/bin/bash")) {
  push @pkg, $pkg;
}
if (@pkg) {
  ok($pkg[0]->name);
  ok(not defined $pkg[0]->filename);
}

my $pkg = RPM2->open_package("test-rpm-1.0-1.noarch.rpm");
ok($pkg);
ok($pkg->name eq 'test-rpm');
ok($pkg->tagformat("--%{NAME}%{VERSION}--") eq '--test-rpm1.0--');
ok($pkg->tagformat("--%{NAME}%{VERSION}--") ne 'NOT A MATCH');
ok(!$pkg->is_source_package);

$pkg = RPM2->open_package("test-rpm-1.0-1.src.rpm");
ok($pkg);
ok($pkg->name eq 'test-rpm');
ok($pkg->tagformat("--%{NAME}--") eq '--test-rpm--');
ok($pkg->is_source_package);

my $pkg2 = RPM2->open_package("test-rpm-1.0-1.noarch.rpm");
ok($pkg2->filename);
ok($pkg->compare($pkg2) == 0);
ok(($pkg <=> $pkg2) == 0);
ok(!($pkg < $pkg2));
ok(!($pkg > $pkg2));

# another rpm, handily provided by the rpmdb-redhat package
my $other_rpm_dir = "/usr/lib/rpmdb/i386-redhat-linux/redhat";
if (-d $other_rpm_dir) {
  my $db2 = RPM2->open_rpm_db(-path => $other_rpm_dir);
  ok(defined $db2);
  $db2 = undef;
}
else {
  print "Install the rpmdb-redhat package to test two simultaneous open databases\n";
  ok(1);
}

ok(RPM2->expand_macro("%%foo") eq "%foo");
RPM2->add_macro("rpm2_test_macro", "testval $$");
ok(RPM2->expand_macro("%rpm2_test_macro") eq "testval $$");
RPM2->delete_macro("rpm2_test_macro");
ok(RPM2->expand_macro("%rpm2_test_macro") eq "%rpm2_test_macro");

ok(RPM2->rpm_api_version == 4.1 or RPM2->rpm_api_version == 4.0);
ok(RPM2->rpm_api_version == 4.0 or RPM2->vsf_nosha1 == 65536);

#
# Clean up before transaction tests (close the database
$db  = undef;
$i   = undef;

# 
# Transaction tests.
my $t = RPM2->create_transaction();
ok(ref($t) eq 'RPM2::Transaction');
ok(ref($t) eq 'RPM2::Transaction');
$pkg = RPM2->open_package("test-rpm-1.0-1.noarch.rpm");
# Make sure we still can open packages.
ok($pkg);
# Add package to transaction
ok($t->add_install($pkg));
# Check element count
ok($t->element_count() == 1);
# Test depedency checks
ok($t->check());
# Order the transaction...see if we get our one transaction.
ok($t->order());
my @rpms = $t->elements();
ok($rpms[0] eq  $pkg->as_nvre());
ok(scalar(@rpms) == 1);
# Install package
ok($t->run());
$t = undef;

#
# See if we can find the rpm in the database now...
$db = RPM2->open_rpm_db();
ok(defined $db);
@pkg = ();
$i = $db->find_by_name_iter("test-rpm");
ok($i);
while (my $pkg = $i->next) {
  push @pkg, $pkg;
}
ok(scalar(@pkg) == 1);
$i  = undef;
$db = undef;

#
# OK, lets remove that rpm with a new transaction
my $t = RPM2->create_transaction();
ok(ref($t) eq 'RPM2::Transaction');
# We need to find the package we installed, and try to erase it
ok($t->add_erase($pkg[0]));
# Check element count
ok($t->element_count() == 1);
# Test depedency checks
ok($t->check());
# Order the transaction...see if we get our one transaction.
ok($t->order());
#my @rpms = $t->elements();
ok($rpms[0] eq  $pkg->as_nvre());
ok(scalar(@rpms) == 1);
# Install package
ok($t->run());
# Test closing the database
ok($t->close_db());