xerces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jas...@apache.org
Subject cvs commit: xml-xerces/perl/t EntityResolver.t
Date Thu, 02 Aug 2001 02:31:19 GMT
jasons      01/08/01 19:31:19

  Added:       perl/t   EntityResolver.t
  Log:
  	Finally implemented the EntityResolver interface
  
  Revision  Changes    Path
  1.1                  xml-xerces/perl/t/EntityResolver.t
  
  Index: EntityResolver.t
  ===================================================================
  # Before `make install' is performed this script should be runnable
  # with `make test'. After `make install' it should work as `perl
  # EntityResolver.t'
  
  ######################### We start with some black magic to print on failure.
  
  # Change 1..1 below to 1..last_test_to_print .
  # (It may become useful if the test is moved to ./t subdirectory.)
  
  BEGIN { $| = 1; print "1..5\n"; }
  END {print "not ok 1\n" unless $loaded;}
  use Carp;
  use blib;
  use XML::Xerces;
  use Cwd;
  
  use lib 't';
  use TestUtils qw(result $PERSONAL_FILE_NAME $PERSONAL_DTD_NAME);
  use vars qw($i $loaded $file $test);
  use strict;
  
  $loaded = 1;
  $i = 1;
  result($loaded);
  
  ######################### End of black magic.
  
  # Insert your test code below (better if it prints "ok 13"
  # (correspondingly "not ok 13") depending on the success of chunk 13
  # of the test code):
  
  package MyEntityResolver;
  use strict;
  use vars qw(@ISA $test);
  use TestUtils qw($PERSONAL_DTD_NAME);
  @ISA = qw(XML::Xerces::PerlEntityResolver);
  
  sub new {
    return bless {}, shift;
  }
  
  sub resolve_entity {
    my ($self,$pub,$sys) = @_;
  # print STDERR "Got PUBLIC: $pub\n";
  # print STDERR "Got SYSTEM: $sys\n";
    $main::test = 1;
    return XML::Xerces::LocalFileInputSource->new($PERSONAL_DTD_NAME);
  }
  
  package main;
  $test = 0;
  my $DOM = new XML::Xerces::DOMParser;
  my $ERROR_HANDLER = XML::Xerces::PerlErrorHandler->new();
  $DOM->setErrorHandler($ERROR_HANDLER);
  
  # see if we can create and set an entity resolver
  my $ENTITY_RESOLVER = MyEntityResolver->new();
  $DOM->setEntityResolver($ENTITY_RESOLVER);
  result(1);
  
  # now lets see if the resolver gets invoked
  $DOM->parse($PERSONAL_FILE_NAME);
  result($test);
  
  my $doc = $DOM->getDocument();
  result(ref $doc && $doc->isa('XML::Xerces::DOM_Document'));
  
  my $root = $doc->getDocumentElement();
  result(ref $root && 
         $root->isa('XML::Xerces::DOM_Element') &&
         $root->getNodeName() eq 'personnel'
        );
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org


Mime
View raw message