File: 03_cache.t

package info (click to toggle)
libapt-pkg-perl 0.1.20
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 240 kB
  • ctags: 100
  • sloc: perl: 1,072; ansic: 198; makefile: 39
file content (288 lines) | stat: -rw-r--r-- 5,853 bytes parent folder | download
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/perl

# $Id: 03_cache.t,v 1.1 2003-06-09 12:26:56 bod Exp $
# AptPkg::Cache tests

BEGIN { print "1..63\n" }

sub check_keys
{
    my ($test, $thing, $expect) = @_;
    for my $key (keys %$expect)
    {
	print $thing->{$key} eq $expect->{$key}
	    ? "ok $test\n"
	    : "not ok $test # $thing->{$key} != $expect->{$key}\n";

	$test++;
    }

    $test;
}

use AptPkg::Config '$_config';
use AptPkg::System '$_system';
use AptPkg::Cache;

$_config->init;
$_config->read_file('t/cache/etc/apt.conf');
$_system = $_config->system;

print "ok 1\n";

my $cache = AptPkg::Cache->new;

# cache created
unless ($cache)
{
    print "not ok 2\n";
    exit;
}

my $verfile; # for ->packages test

# package "b" exists
if (my $b = $cache->{b})
{
    print "ok 2\n";

    # check some string values
    check_keys 3, $b, {
	Name => 'b',
	Section => 'test',
	SelectedState => 'Install',
	InstState => 'Ok',
	CurrentState => 'Installed',
    };

    # expected current version
    print 'not ' unless $b->{CurrentVer}{VerStr} eq '0.2-1';
    print "ok 8\n";

    # installed and new versions are available
    print 'not ' unless @{$b->{VersionList}} == 2;
    print "ok 9\n";

    # new version is first
    print 'not ' unless $b->{VersionList}[0]{VerStr} eq '0.3-1';
    print "ok 10\n";

    if (my $f = $b->{VersionList}[0]{FileList})
    {
	$verfile = $f->[0];
    }
    else
    {
	print 'not ';
    }

    print "ok 11\n";

    # followed by current version
    print 'not ' unless $b->{VersionList}[1]{VerStr} eq '0.2-1';
    print "ok 12\n";

    # check rev depends
    print 'not ' unless @{$b->{RevDependsList}} == 1;
    print "ok 13\n";

    my $r = $b->{RevDependsList}[0];

    print 'not ' unless $r->{DepType} eq 'Depends';
    print "ok 14\n";

    print 'not ' unless $r->{TargetPkg}{Name} eq 'b';
    print "ok 15\n";

    print 'not ' unless $r->{CompType} eq '>=';
    print "ok 16\n";

    print 'not ' unless $r->{TargetVer} eq '0.2-3';
    print "ok 17\n";
}
else
{
    print "not ok 2 # package b missing\n";
    print "ok $_ # skip\n" for 3..17;
}

# package "a" exists
if (my $a = $cache->{a})
{
    print "ok 18\n";

    # check some string values
    check_keys 19, $a, {
	Name => 'a',
	Section => 'test',
	SelectedState => 'Purge',
	InstState => 'Ok',
	CurrentState => 'NotInstalled',
    };

    # expect one version to be available
    print 'not ' unless @{$a->{VersionList}} == 1;
    print "ok 24\n";

    # check version
    print 'not ' unless $a->{VersionList}[0]{VerStr} eq '0.1';
    print "ok 25\n";

    # check provides
    print 'not ' unless @{$a->{VersionList}[0]{ProvidesList}} == 1;
    print "ok 26\n";

    my $p = $a->{VersionList}[0]{ProvidesList}[0];
    print 'not ' unless $p->{OwnerPkg}{Name} eq 'a';
    print "ok 27\n";

    print 'not ' unless $p->{OwnerVer}{VerStr} eq '0.1';
    print "ok 28\n";

    # check depends
    my $d = $a->{VersionList}[0]{DependsList};
    my $depend;
    my $conflict;

    if ($d and @$d == 2)
    {
	for my $i (0, 1)
	{
	    for ($d->[$i]{DepType})
	    {
		/^Depends$/   and $depend = $i;
		/^Conflicts$/ and $conflict = $i;
	    }
	}
    }

    if (defined $depend and defined $conflict)
    {
	print "ok 29\n";

	print 'not ' unless $d->[$depend]{TargetPkg}{Name} eq 'b';
	print "ok 30\n";

	print 'not ' unless $d->[$depend]{CompType} eq '>=';
	print "ok 31\n";

	print 'not ' unless $d->[$depend]{TargetVer} eq '0.2-3';
	print "ok 32\n";

	print 'not ' unless $d->[$conflict]{TargetPkg}{Name} eq 'foo';
	print "ok 33\n";
    }
    else
    {
	print "not ok 29 # bad depends\n";
	print "ok $_ # skip\n" for 30..33;
    }
}
else
{
    print "not ok 18 # package b missing\n";
    print "ok $_ # skip\n" for 19..33;
}

# test files
my $f = $cache->files;
my $status;
my $packages;

if ($f and @$f == 2)
{
    for my $i (0, 1)
    {
	for ($f->[$i]{FileName})
	{
	    /\bstatus$/  and $status = $i;
	    /_Packages$/ and $packages = $i;
	}
    }
}

if (defined $status and defined $packages)
{
    print "ok 34\n";

    check_keys 35, $f->[$status], {
	FileName => 't/cache/var/status',
	IsOk => 1,
	Archive => 'now',
	IndexType => 'Debian dpkg status file',
    };

    check_keys 39, $f->[$packages], {
	FileName => 't/cache/var/lists/_test_dists_stable_main_binary-i386_Packages',
	IsOk => 1,
	Origin => 'Debian',
	Label => 'Debian',
	Archive => 'stable',
	Architecture => 'i386',
	Version => '3.0',
	Component => 'main',
	IndexType => 'Debian Package Index',
    };
}
else
{
    print "not ok 34 # bad ->files\n";
    print "ok $_ # skip\n" for 35..47;
}

if (my $p = $cache->packages)
{
    # check by name
    if (my $a = $p->lookup('a'))
    {
	print "ok 48\n";

	check_keys 49, $a, {
	    Name => 'a',
	    Section => 'test',
	    VerStr => '0.1',
	    Maintainer => 'Brendan O\'Dea <bod@debian.org>',
	    FileName => 'pool/main/a/a/a_0.1_i386.deb',
	    MD5Hash => '0123456789abcdef0123456789abcdef',
	    ShortDesc => 'Test Package "a"',
	    LongDesc => qq/Test Package "a"\n This is a bogus package for the AptPkg::Cache test suite./,
	};
    }
    else
    {
	print "not ok 48 # lookup by name failed\n";
	print "ok $_ # skip\n" for 49..56;
    }

    # check by verfile
    if ($verfile)
    {
	if (my $b = $p->lookup($verfile))
	{
	    print "ok 57\n";

	    check_keys 58, $b, {
		Name => 'b',
		Maintainer => 'Brendan O\'Dea <bod@debian.org>',
		FileName => 'pool/main/b/b/b_0.3-1_i386.deb',
		MD5Hash => '0123456789abcdef0123456789abcdef',
		ShortDesc => 'Test Package "b"',
		LongDesc => qq/Test Package "b"\n This is a bogus package for the AptPkg::Cache test suite./,
	    };
	}
	else
	{
	    print "not ok 57 # lookup by verfile failed\n";
	    print "ok $_ # skip\n" for 58..63;
	}
    }
    else
    {
	print "ok $_ # skip\n" for 57..63;
    }
}
else
{
    print "not ok 48 # bad ->packages\n";
    print "ok $_ # skip\n" for 49..63;
}