1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 24);
12 use_ok('Bio::Biblio');
13 use_ok('Bio::Biblio::IO');
17 my $verbose = test_debug();
19 my $testfile = test_input_file('stress_test_medline.xml');
20 my $testfile2 = test_input_file('stress_test_pubmed.xml');
24 test_skip(-tests => 1, -requires_module => 'SOAP::Lite');
25 ok my $biblio = Bio::Biblio->new(-location => 'http://localhost:4567');
28 # check MEDLINE XML parser
31 test_skip(-tests => 4, -requires_module => 'XML::Parser');
33 ok defined ($io = Bio::Biblio::IO->new('-format' => 'medlinexml',
37 print "Reading and parsing MEDLINE XML file...\n" if $verbose;
38 is ($io->next_bibref->{'medlineID'}, 'Text1', 'citation 1');
39 is ($io->next_bibref->{'medlineID'}, 'Text248', 'citation 2');
40 is ($io->next_bibref->{'medlineID'}, 'Text495', 'citation 3');
44 print "Getting citations using callback...\n" if $verbose;
45 my (@ids) = ('Text1', 'Text248', 'Text495');
46 my $callback_used = 'no';
47 $io = Bio::Biblio::IO->new('-format' => 'medlinexml',
49 #'-result' => 'medline2ref', # this is default
50 '-callback' => \&callback);
52 is ( $callback_used, 'yes', 'calling callback');
56 $callback_used = 'yes';
57 is ($citation->{'_identifier'}, shift @ids);
61 test_skip(-tests => 2, -requires_module => 'XML::Parser');
63 $io = Bio::Biblio::IO->new('-format' => 'medlinexml',
67 <MedlineID>12345678</MedlineID>
68 <Article><Journal></Journal></Article>
71 <MedlineID>abcdefgh</MedlineID>
72 <Article><Journal></Journal></Article>
76 '-result' => 'medline2ref');
78 is ($io->next_bibref->{'_identifier'}, '12345678', 'citation 1');
79 is ($io->next_bibref->{'_identifier'}, 'abcdefgh', 'citation 2');
83 test_skip(-tests => 2, -requires_modules => [qw(XML::Parser IO::String)]);
85 print "Reading and parsing XML string handle...\n" if $verbose;
89 <MedlineID>87654321</MedlineID>
90 <Article><Journal></Journal></Article>
93 <MedlineID>hgfedcba</MedlineID>
94 <Article><Journal></Journal></Article>
99 $io = Bio::Biblio::IO->new('-format' => 'medlinexml',
100 '-fh' => IO::String->new ($data));
101 is (eval { $io->next_bibref->identifier }, '87654321', 'citation 1');
102 is (eval { $io->next_bibref->identifier }, 'hgfedcba', 'citation 2');
106 test_skip(-tests => 5, -requires_module => 'XML::Parser');
108 # check PUBMED XML parser
109 ok defined (eval { $io = Bio::Biblio::IO->new('-format' => 'pubmedxml',
110 '-file' => $testfile2,
111 '-result' => 'pubmed2ref') });
113 print "Reading and parsing PUBMED XML file...\n" if $verbose;
115 is ($io->next_bibref->identifier, '11223344', 'citation 1');
116 is ($io->next_bibref->identifier, '21583752', 'citation 2');
117 is ($io->next_bibref->identifier, '21465135', 'citation 3');
118 is ($io->next_bibref->identifier, '21138228', 'citation 4');
124 my @expvals = qw(11223344 21583752 21465135 21138228);
125 print "Testing FH\n" if $verbose;
127 $fh = Bio::Biblio::IO->newFh('-format' => 'pubmedxml',
128 '-file' => $testfile2,
129 '-result' => 'pubmed2ref');
131 is($_->identifier,shift @expvals);
135 skip("unable to use pubmedxml",4);