1 # This is -*-Perl-*- code
2 ## Bioperl Test Harness Script for Modules
6 # Before `make install' is performed this script should be runnable with
7 # `make test'. After `make install' it should work as `perl Biblio.t'
10 use vars qw($NUMTESTS);
15 # to handle systems with no installed Test module
16 # we include the t dir (where a copy of Test.pm is located)
18 eval { require Test; };
30 ## End of black magic.
32 ## Insert additional test code below but remember to change
33 ## the print "1..x\n" in the BEGIN block to reflect the
34 ## total number of tests that will be run.
36 my $serror = 0; my $serror2 = 0;
37 my $ferror = 0; my $ferror2 = 0;
40 my $format = ($ENV{'TEST_DETAILS'} ? '%-25s' : '');
42 unless (eval "require SOAP::Lite; 1;") {
43 print STDERR "SOAP::Lite not installed. Skipping some tests.\n";
47 unless (eval "require IO::String; 1;") {
48 print STDERR "IO::String not installed. Skipping some tests.\n";
52 unless (eval "require XML::Parser; 1;") {
53 print STDERR "XML::Parser not installed. Skipping some tests.\n";
58 my $testfile = Bio::Root::IO->catfile ('t','data','stress_test_medline.xml');
59 unless (-e $testfile) {
60 print STDERR "Cannot find testing data '$testfile'. Skipping some tests.\n";
63 my $testfile2 = Bio::Root::IO->catfile ('t','data','stress_test_pubmed.xml');
64 unless (-e $testfile2) {
65 print STDERR "Cannot find testing data '$testfile2'. Skipping some tests.\n";
71 eval { require Bio::Biblio };
72 print sprintf ($format, 'use Bio::Biblio'); ok (%Bio::Biblio::);
77 eval { $biblio = new Bio::Biblio (-location => 'http://localhost:4567'); };
78 print sprintf ($format, "new Bio::Biblio "); skip ($serror, defined $biblio);
82 # check 'use ...IO...'
83 eval { require Bio::Biblio::IO };
84 print sprintf ($format, "use Bio::Biblio::IO "); ok (%Bio::Biblio::IO::);
88 # check MEDLINE XML parser
89 print sprintf ($format, "new Bio::Biblio::IO (1)");
90 skip ($ferror || $xerror,
91 defined (eval { $io = new Bio::Biblio::IO ('-format' => 'medlinexml',
93 '-result' => 'raw') }));
96 print "Reading and parsing MEDLINE XML file...\n";
97 print sprintf ($format, " citation 1 "); skip ($ferror || $xerror, eval { $io->next_bibref->{'medlineID'} }, 'Text1');
98 print sprintf ($format, " citation 2 "); skip ($ferror || $xerror, eval { $io->next_bibref->{'medlineID'} }, 'Text248');
99 print sprintf ($format, " citation 3 "); skip ($ferror || $xerror, eval { $io->next_bibref->{'medlineID'} }, 'Text495');
101 print "Getting citations using callback...\n";
102 my (@ids) = ('Text1', 'Text248', 'Text495');
103 my $callback_used = 'no';
104 if ($ferror || $xerror) {
105 foreach my $i (1..3) {
106 print sprintf ($format, " citation $i "); skip (1,1);
109 $io = new Bio::Biblio::IO ('-format' => 'medlinexml',
110 '-file' => $testfile,
111 # '-result' => 'medline2ref', # this is default
112 '-callback' => \&callback);
114 print sprintf ($format, " calling callback "); skip ($ferror || $xerror, $callback_used, 'yes');
117 my $citation = shift;
118 $callback_used = 'yes';
119 print sprintf ($format, ' citation ' . (@ids+0) . ' '); skip ($ferror, $citation->{'_identifier'}, shift @ids);
122 print "Reading and parsing XML string...\n";
124 print sprintf ($format, " citation 1 "); skip (1, 1);
125 print sprintf ($format, " citation 2 "); skip (1, 1);
127 $io = new Bio::Biblio::IO ('-format' => 'medlinexml',
128 '-data' => <<XMLDATA,
131 <MedlineID>12345678</MedlineID>
132 <Article><Journal></Journal></Article>
135 <MedlineID>abcdefgh</MedlineID>
136 <Article><Journal></Journal></Article>
138 </MedlineCitationSet>
140 '-result' => 'medline2ref',
142 print sprintf ($format, " citation 1 "); ok ($io->next_bibref->{'_identifier'}, '12345678');
143 print sprintf ($format, " citation 2 "); ok ($io->next_bibref->{'_identifier'}, 'abcdefgh');
146 print "Reading and parsing XML string handle...\n";
148 if ($xerror || $serror2) {
149 print sprintf ($format, " citation 1 "); skip (1,1);
150 print sprintf ($format, " citation 2 "); skip (1,1);
152 my $data = <<XMLDATA;
155 <MedlineID>87654321</MedlineID>
156 <Article><Journal></Journal></Article>
159 <MedlineID>hgfedcba</MedlineID>
160 <Article><Journal></Journal></Article>
162 </MedlineCitationSet>
165 $io = new Bio::Biblio::IO ('-format' => 'medlinexml',
166 '-fh' => IO::String->new ($data),
168 print sprintf ($format, " citation 1 "); ok (eval { $io->next_bibref->identifier }, '87654321');
169 print sprintf ($format, " citation 2 "); ok (eval { $io->next_bibref->identifier }, 'hgfedcba');
172 # check PUBMED XML parser
173 print sprintf ($format, "new Bio::Biblio::IO (2)");
174 skip ($ferror2 || $xerror,
175 defined (eval { $io = new Bio::Biblio::IO ('-format' => 'pubmedxml',
176 '-file' => $testfile2,
177 '-result' => 'pubmed2ref') }));
178 print "Reading and parsing PUBMED XML file...\n";
180 foreach my $i (1..4) {
181 print sprintf ($format, " citation $i "); skip (1,"Can't read citation from PUBMED XML");
184 print sprintf ($format, " citation 1 "); skip ($ferror2, eval { $io->next_bibref->identifier }, '11223344');
185 print sprintf ($format, " citation 2 "); skip ($ferror2, eval { $io->next_bibref->identifier }, '21583752');
186 print sprintf ($format, " citation 3 "); skip ($ferror2, eval { $io->next_bibref->identifier }, '21465135');
187 print sprintf ($format, " citation 4 "); skip ($ferror2, eval { $io->next_bibref->identifier }, '21138228');
192 my @expvals = qw(11223344 21583752 21465135 21138228);
193 print "Testing FH\n";
195 $fh = Bio::Biblio::IO->newFh('-format' => 'pubmedxml',
196 '-file' => $testfile2,
197 '-result' => 'pubmed2ref');
199 ok($_->identifier,shift @expvals);
203 foreach ( 1..4 ) { skip(1,"unable to use pubmedxml"); }