6 use Test::More 'no_plan';
7 use File::Basename qw(dirname);
10 use OpenILS::Utils::MFHD;
20 foreach my $subfield (split(/\|/, $holding->subfield('x'))) {
21 next unless $subfield;
23 my ($key, $val) = unpack('aa*', $subfield);
24 $answer->{$key} = $val;
34 my $testfile = dirname(__FILE__) . "/mfhddata.txt";
35 open(my $testdata, "<", $testfile) or die("Cannot open '$testfile': $!");
37 while ($rec = testlib::load_MARC_rec($testdata, $testno++)) {
38 $rec = MFHD->new($rec);
40 foreach my $cap (sort { $a->tag <=> $b->tag } $rec->field('85.')) {
44 ($htag = $cap->tag) =~ s/^85/86/;
45 @holdings = $rec->holdings($htag, $cap->subfield('8'));
47 if (!ok(scalar @holdings, "holdings defined " . $cap->subfield('8'))) {
51 foreach my $field (@holdings) {
53 local $TODO = "unimplemented"
54 if ($field->subfield('z') =~ /^TODO/);
55 is_deeply($field->next, right_answer($field),
56 $field->subfield('8') . ': ' . $field->subfield('z'));
58 if ($field->subfield('y')) {
59 is($field->chron_to_date(), $field->subfield('y'), 'Chron-to-date test');
68 # test: passthru_open_ended
69 open($testdata, "<mfhddata2.txt") or die("Cannot open 'mfhddata2.txt': $!");
71 $rec = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
72 my $rec2 = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
74 my @holdings_a = $rec->get_decompressed_holdings(($rec->captions('853'))[0], {'passthru_open_ended' => 1});
75 my @holdings_b = $rec2->holdings_by_caption(($rec2->captions('853'))[0]);
77 is_deeply(\@holdings_a, \@holdings_b, 'passthru open ended');
79 # test: compressed to last
82 $rec = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
83 $rec2 = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
85 @holdings_a = $rec->holdings_by_caption(($rec->captions('853'))[0]);
86 @holdings_b = $rec2->holdings_by_caption(($rec2->captions('853'))[0]);
88 is_deeply($holdings_a[0]->compressed_to_last, $holdings_b[0], 'compressed to last, normal');
89 is($holdings_a[1]->compressed_to_last, undef, 'compressed to last, open ended');
91 # test: get compressed holdings, open ended member
94 $rec = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
95 $rec2 = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
97 @holdings_a = $rec->get_compressed_holdings(($rec->captions('853'))[0]);
98 @holdings_b = $rec2->holdings_by_caption(($rec2->captions('853'))[0]);
100 is_deeply(\@holdings_a, \@holdings_b, 'get compressed holdings, open ended member');
102 # test comparisons, for all operands, for all types of holdings
105 $rec = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
106 $rec2 = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
108 @holdings_a = $rec->holdings_by_caption(($rec->captions('853'))[0]);
109 @holdings_b = $rec2->holdings_by_caption(($rec2->captions('853'))[0]);
111 unshift(@holdings_a, "zzz I am NOT a holding");
112 push(@holdings_b, "zzz I am NOT a holding");
114 push(@holdings_a, undef);
115 unshift(@holdings_b, undef);
117 @holdings_a = sort { $a cmp $b } @holdings_a;
119 foreach my $holding (@holdings_a) {
121 $holding->seqno($seqno);
126 is_deeply(\@holdings_a, \@holdings_b, 'comparison testing via sort');