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 my $testfile2 = dirname(__FILE__) . "/mfhddata2.txt";
70 open($testdata, "<", $testfile2) or die("Cannot open '$testfile2': $!");
72 $rec = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
73 my $rec2 = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
75 my @holdings_a = $rec->get_decompressed_holdings(($rec->captions('853'))[0], {'passthru_open_ended' => 1});
76 my @holdings_b = $rec2->holdings_by_caption(($rec2->captions('853'))[0]);
78 is_deeply(\@holdings_a, \@holdings_b, 'passthru open ended');
80 # test: compressed to last
83 $rec = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
84 $rec2 = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
86 @holdings_a = $rec->holdings_by_caption(($rec->captions('853'))[0]);
87 @holdings_b = $rec2->holdings_by_caption(($rec2->captions('853'))[0]);
89 is_deeply($holdings_a[0]->compressed_to_last, $holdings_b[0], 'compressed to last, normal');
90 is($holdings_a[1]->compressed_to_last, undef, 'compressed to last, open ended');
92 # test: get compressed holdings, open ended member
95 $rec = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
96 $rec2 = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
98 @holdings_a = $rec->get_compressed_holdings(($rec->captions('853'))[0]);
99 @holdings_b = $rec2->holdings_by_caption(($rec2->captions('853'))[0]);
101 is_deeply(\@holdings_a, \@holdings_b, 'get compressed holdings, open ended member');
103 # test comparisons, for all operands, for all types of holdings
106 $rec = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
107 $rec2 = MFHD->new(testlib::load_MARC_rec($testdata, $testno));
109 @holdings_a = $rec->holdings_by_caption(($rec->captions('853'))[0]);
110 @holdings_b = $rec2->holdings_by_caption(($rec2->captions('853'))[0]);
112 unshift(@holdings_a, "zzz I am NOT a holding");
113 push(@holdings_b, "zzz I am NOT a holding");
115 push(@holdings_a, undef);
116 unshift(@holdings_b, undef);
118 @holdings_a = sort { $a cmp $b } @holdings_a;
120 foreach my $holding (@holdings_a) {
122 $holding->seqno($seqno);
127 is_deeply(\@holdings_a, \@holdings_b, 'comparison testing via sort');