+
+# test matching
+$hdr = Amanda::Header->new();
+$hdr->{'name'} = 'foo.bar.baz';
+$hdr->{'disk'} = '/foo/bar/baz';
+$hdr->{'datestamp'} = '20090102030405';
+$hdr->{'dumplevel'} = 31;
+$hdr->{'type'} = $Amanda::Header::F_DUMPFILE;
+
+ok(!header_matches_dumpspecs($hdr, []), "header doesn't match empty list of dumpspecs");
+
+ok(header_matches_dumpspecs($hdr, [Amanda::Cmdline::dumpspec_t->new('foo.bar.baz', undef, undef, undef, undef)]),
+ 'header matches exact host dumpspec');
+ok(header_matches_dumpspecs($hdr, [Amanda::Cmdline::dumpspec_t->new('foo', undef, undef, undef, undef)]),
+ 'header matches partial host dumpspec');
+ok(header_matches_dumpspecs($hdr, [Amanda::Cmdline::dumpspec_t->new('?a*', undef, undef, undef, undef)]),
+ 'header matches host pattern dumpspec');
+
+ok(header_matches_dumpspecs($hdr, [Amanda::Cmdline::dumpspec_t->new(undef, '/foo/bar/baz', undef, undef, undef)]),
+ 'header matches exact disk dumpspec');
+ok(header_matches_dumpspecs($hdr, [Amanda::Cmdline::dumpspec_t->new(undef, 'bar', undef, undef, undef)]),
+ 'header matches partial disk dumpspec');
+ok(header_matches_dumpspecs($hdr, [Amanda::Cmdline::dumpspec_t->new(undef, '*a?', undef, undef, undef)]),
+ 'header matches disk pattern dumpspec');
+
+ok(header_matches_dumpspecs($hdr, [Amanda::Cmdline::dumpspec_t->new(undef, undef, '20090102030405', undef, undef)]),
+ 'header matches exact datestamp dumpspec');
+ok(header_matches_dumpspecs($hdr, [Amanda::Cmdline::dumpspec_t->new(undef, undef, '2009', undef, undef)]),
+ 'header matches partial datestamp dumpspec');
+ok(header_matches_dumpspecs($hdr, [Amanda::Cmdline::dumpspec_t->new(undef, undef, '20090102030404-20090102030406', undef, undef)]),
+ 'header matches datestamp range dumpspec');
+ok(header_matches_dumpspecs($hdr, [Amanda::Cmdline::dumpspec_t->new(undef, undef, '2009-2010', undef, undef)]),
+ 'header matches datestamp year-only range dumpspec');
+ok(!header_matches_dumpspecs($hdr, [Amanda::Cmdline::dumpspec_t->new(undef, undef, '20090102030406-20090102030407', undef, undef)]),
+ "header doesn't match datestamp range dumpspec that it's outside of");
+
+ok(header_matches_dumpspecs($hdr, [Amanda::Cmdline::dumpspec_t->new(undef, undef, undef, '31', undef)]),
+ 'header matches exact level dumpspec');
+ok(header_matches_dumpspecs($hdr, [Amanda::Cmdline::dumpspec_t->new(undef, undef, undef, '30-32', undef)]),
+ 'header matches small level range dumpspec');
+ok(header_matches_dumpspecs($hdr, [Amanda::Cmdline::dumpspec_t->new(undef, undef, undef, '4-50', undef)]),
+ 'header matches large level range dumpspec');
+ok(!header_matches_dumpspecs($hdr, [Amanda::Cmdline::dumpspec_t->new(undef, undef, undef, '32-50', undef)]),
+ "header doesn't match level range it's outside of");
+
+ok(header_matches_dumpspecs($hdr, [
+ Amanda::Cmdline::dumpspec_t->new('foo.bar.baz', undef, undef, undef, undef),
+ Amanda::Cmdline::dumpspec_t->new(undef, '/foo/bar/baz', undef, undef, undef),
+ ]),
+ 'header matches when two dumpspecs are possible matches');
+ok(!header_matches_dumpspecs($hdr, [
+ Amanda::Cmdline::dumpspec_t->new(undef, undef, '20090102030406-20090102030407', undef, undef),
+ Amanda::Cmdline::dumpspec_t->new(undef, undef, undef, '32-50', undef),
+ ]),
+ 'header matches when two dumpspecs are given and neither should match');