Added: xerces/xerces-p/trunk/interface/Perl/typemaps.i URL: http://svn.apache.org/viewcvs/xerces/xerces-p/trunk/interface/Perl/typemaps.i?rev=365289&view=auto ============================================================================== --- xerces/xerces-p/trunk/interface/Perl/typemaps.i (added) +++ xerces/xerces-p/trunk/interface/Perl/typemaps.i Sun Jan 1 20:55:53 2006 @@ -0,0 +1,72 @@ +// +// FOR Perl*Handler MEMBER FUNCTIONS, SO PERL SCALAR DOESN'T GET WRAPPED +// +%typemap(in) SV * { + $1 = $input; +} + +// For setProperty() - store the SV* directly +%typemap(in) void * { + $1 = (void*) $input; +} + +%typemap(in) (const XMLByte* const srcDocBytes, + unsigned int byteCount) { + if (SvPOK($input)||SvIOK($input)||SvNOK($input)) { + STRLEN len; + XMLByte *xmlbytes = (XMLByte *)SvPV($input, len); + $2 = len; + $1 = new XMLByte[len]; + memcpy($1, xmlbytes, len); + } else { + SWIG_croak("Type error in argument 2 of $symname, Expected perl-string."); + } +} + +// XMLByte arrays are just unisgned char*'s +%typemap(out) const XMLByte* getRawBuffer() { + %set_output(SWIG_FromCharPtr((char*)result)); +} + +/* + * Adopting a validator + * + * we have to disown the validator, because Xerces will adopt it + * first we create a temp variable to store it's value in the + * 'in' typemap, and the after all conversion has succeeded + * the 'check' typemap will disown it. + */ +%typemap(in) XERCES_CPP_NAMESPACE::XMLValidator* valToAdopt (SV *temp) +{ + temp = $input; + if (SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,0) < 0) { + SWIG_Perl_TypeError("$1_mangle",$argnum,"$symname"); + } +} + +%typemap(check) XERCES_CPP_NAMESPACE::XMLValidator* valToAdopt +{ + SWIG_Disown(temp$argnum); +} + +// The typecheck functions are for use by SWIG's auto-overloading support +%typemap(typecheck, precedence=60) +SV* +{ + $1 = SvOK($input) ? 1 : 0; +} + +// The typecheck functions are for use by SWIG's auto-overloading support +%typemap(typecheck, precedence=60) +SV* +{ + $1 = SvOK($input) ? 1 : 0; +} + +// %typemap(typecheck, precedence=70) +// as long as the SV is not undef, convert it to a string +%typecheck(SWIG_TYPECHECK_UNISTRING) +XMLCh*, const XMLCh* +{ + $1 = SvOK($input) ? 1 : 0; +} \ No newline at end of file
Modified: xerces/xerces-p/trunk/interface/defines.i URL: http://svn.apache.org/viewcvs/xerces/xerces-p/trunk/interface/defines.i?rev=365289&r1=365288&r2=365289&view=diff ============================================================================== --- xerces/xerces-p/trunk/interface/defines.i (original) +++ xerces/xerces-p/trunk/interface/defines.i Sun Jan 1 20:55:53 2006 @@ -91,13 +91,6 @@ #include "xercesc/validators/datatype/InvalidDatatypeValueException.hpp" #include "xercesc/validators/schema/identity/XPathException.hpp" -#include "PerlCallbackHandler.hpp" -#include "PerlErrorCallbackHandler.hpp" -#include "PerlDocumentCallbackHandler.hpp" -#include "PerlContentCallbackHandler.hpp" -#include "PerlEntityResolverHandler.i" -#include "PerlNodeFilterCallbackHandler.i" - XERCES_CPP_NAMESPACE_USE // we initialize the static UTF-8 transcoding info @@ -109,103 +102,24 @@ static bool DEBUG_UTF8_OUT = 0; static bool DEBUG_UTF8_IN = 0; -SV* -XMLString2Perl(const XMLCh* input) { - SV *output; - unsigned int charsEaten = 0; - int length = XMLString::stringLen(input); // string length - // use +1 to make room for the '\0' at the end of the string - // in the pathological case when each character of the string - // is UTF8_MAXLEN bytes long - XMLByte* res = new XMLByte[(length * UTF8_MAXLEN) + 1]; // output string - - unsigned int total_chars = - UTF8_TRANSCODER->transcodeTo((const XMLCh*) input, - (unsigned int) length, - (XMLByte*) res, - (unsigned int) (length*UTF8_MAXLEN), - charsEaten, - XMLTranscoder::UnRep_Throw - ); - res[total_chars] = '\0'; - -#if (0) - if (DEBUG_UTF8_OUT) { - printf("Xerces out length = %d: ",total_chars); - for (int i=0;i<length;i++){ - printf("<0x%.4X>",res[i]); - } - printf("\n"); - } -#endif - - output = sv_newmortal(); - sv_setpv((SV*)output, (char *)res ); - SvUTF8_on((SV*)output); - delete[] res; - return output; -} - -XMLCh* -Perl2XMLString(SV* input){ - XMLCh* output; - - STRLEN length; - char *ptr = (char *)SvPVutf8(input,length); - -#if (0) - if (DEBUG_UTF8_IN) { - printf("Perl in length = %d: ",length); - for (unsigned int i=0;i<length;i++){ - printf("<0x%.4X>",ptr[i]); - } - printf("\n"); - } -#endif +%} - if (SvUTF8(input)) { - unsigned int charsEaten = 0; - unsigned char* sizes = new unsigned char[length+1]; - output = new XMLCh[length+1]; - unsigned int chars_stored = - UTF8_TRANSCODER->transcodeFrom((const XMLByte*) ptr, - (unsigned int) length, - (XMLCh*) output, - (unsigned int) length, - charsEaten, - (unsigned char*)sizes - ); - delete [] sizes; - -#if (0) - if (DEBUG_UTF8_IN) { - printf("Xerces in length = %d: ",chars_stored); - for (unsigned int i=0;i<chars_stored;i++){ - printf("<0x%.4X>",output[i]); - } - printf("\n"); - } +/* + * Import the language specific includes + */ + +#ifdef SWIGPERL +%include "interface/Perl/defines.i" +%include "interface/Perl/transcode.i" +%include "interface/Perl/errors.i" #endif - // indicate the end of the string - output[chars_stored] = '\0'; - } else { - output = XMLString::transcode(ptr); - -#if (0) - if (DEBUG_UTF8_IN) { - printf("Xerces: "); - for (int i=0;output[i];i++){ - printf("<0x%.4X>",output[i]); - } - printf("\n"); - } -#endif - } - return(output); -} +// These get wrapped by SWIG so that we can modify them from the scripting language +bool DEBUG_UTF8_OUT; +bool DEBUG_UTF8_IN; +%{ XMLException* copyXMLException(const XMLException& e) { @@ -297,9 +211,12 @@ { return (XMLException*)((XPathException*)&e)->duplicate(); } + else + { + SWIG_Perl_SetErrorf("Unknown Exception type: %d", e.getType()); + } } -// These exception creation methods make the Xerces.cpp code *much* smaller void makeXMLException(const XMLException& e){ SV *error = ERRSV; @@ -325,8 +242,3 @@ } %} - -// These get wrapped by SWIG so that we can modify them within Perl -bool DEBUG_UTF8_OUT; -bool DEBUG_UTF8_IN; - Modified: xerces/xerces-p/trunk/interface/parsers.i URL: http://svn.apache.org/viewcvs/xerces/xerces-p/trunk/interface/parsers.i?rev=365289&r1=365288&r2=365289&view=diff ============================================================================== --- xerces/xerces-p/trunk/interface/parsers.i (original) +++ xerces/xerces-p/trunk/interface/parsers.i Sun Jan 1 20:55:53 2006 @@ -7,34 +7,42 @@ %include "xercesc/parsers/XercesDOMParser.hpp" %include "xercesc/parsers/SAXParser.hpp" -// -// define the exceptions for SAX2XMLReader -// +/* + * the SAX2XMLReader methods gets a special exception handler + * 'goto fail' must be called - either explicitly, or via SWIG_croak() + * to ensure that any variable cleanup is done - to avoid memory leaks. + * We make this a macro to be similar to the other exception handlers. + */ +%{ +#define CATCH_SAX_EXCEPTION \ + catch (const XMLException& e) \ + { \ + makeXMLException(e); \ + goto fail; \ + } \ + catch (const SAXNotSupportedException& e) \ + { \ + makeSAXNotSupportedException(e); \ + goto fail; \ + } \ + catch (const SAXNotRecognizedException& e) \ + { \ + makeSAXNotRecognizedException(e); \ + goto fail; \ + } \ + catch (...) \ + { \ + SWIG_croak("Handling Unknown exception"); \ + goto fail; \ + } +%} + %define SAXEXCEPTION(method) %exception method { try { $action } - catch (const XMLException& e) - { - makeXMLException(e); - goto fail; - } - catch (const SAXNotSupportedException& e) - { - makeSAXNotSupportedException(e); - goto fail; - } - catch (const SAXNotRecognizedException& e) - { - makeSAXNotRecognizedException(e); - goto fail; - } - catch (...) - { - SWIG_croak("Handling Unknown exception"); - goto fail; - } + CATCH_SAX_EXCEPTION } %enddef Modified: xerces/xerces-p/trunk/interface/typemaps-general.i URL: http://svn.apache.org/viewcvs/xerces/xerces-p/trunk/interface/typemaps-general.i?rev=365289&r1=365288&r2=365289&view=diff ============================================================================== --- xerces/xerces-p/trunk/interface/typemaps-general.i (original) +++ xerces/xerces-p/trunk/interface/typemaps-general.i Sun Jan 1 20:55:53 2006 @@ -15,19 +15,20 @@ */ /* + * Scripting languages are not going to change the default memory manager + * so we always default this argument + */ +%typemap(in,numinputs=0) XERCES_CPP_NAMESPACE::MemoryManager* const manager "$1 = XERCES_CPP_NAMESPACE::XMLPlatformUtils::fgMemoryManager;" + +/* * MemBufInputSource::MemBufInputSource() * - * - * * ALWAYS ADOPT BUFFER (I.E. MAKE A COPY OF IT) SINCE IT IS TAKEN FROM - * PERL, AND WHO KNOWS WHAT WILL HAPPEN TO IT AFTER IT IS GIVEN TO THE + * THE SCRIPTING LANGUAGE, AND WHO KNOWS WHAT WILL HAPPEN TO IT AFTER + * IT IS GIVEN TO THE * CONSTRUCTOR */ -// -// Perl should ignore these arguments -// - // %typemap(in,numinputs=0) (unsigned int byteCount) "$1 = 0;" /* @@ -40,48 +41,6 @@ %typemap(in,numinputs=0) const bool adoptBuffer "$1 = true;" // for MemBufInputSource /* - * Scripting languages are not going to change the default memory manager - * so we always default this argument - */ -%typemap(in,numinputs=0) XERCES_CPP_NAMESPACE::MemoryManager* const manager "$1 = XERCES_CPP_NAMESPACE::XMLPlatformUtils::fgMemoryManager;" - -%typemap(in) (const XMLByte* const srcDocBytes, - unsigned int byteCount) { - if (SvPOK($input)||SvIOK($input)||SvNOK($input)) { - STRLEN len; - XMLByte *xmlbytes = (XMLByte *)SvPV($input, len); - $2 = len; - $1 = new XMLByte[len]; - memcpy($1, xmlbytes, len); - } else { - SWIG_croak("Type error in argument 2 of $symname, Expected perl-string."); - } -} - -// XMLByte arrays are just char*'s -%apply char * { XMLByte * } - -/* - * Adopting a validator - * - * we have to disown the validator, because Xerces will adopt it - * first we create a temp variable to store it's value in the - * 'in' typemap, and the after all conversion has succeeded - * the 'check' typemap will disown it. - */ -%typemap(in) XERCES_CPP_NAMESPACE::XMLValidator* valToAdopt (SV *temp) -{ - temp = $input; - if (SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,0) < 0) { - SWIG_type_error("$1_mangle",$argnum,"$symname") - } -} -%typemap(check) XERCES_CPP_NAMESPACE::XMLValidator* valToAdopt -{ - SWIG_Disown(temp$argnum); -} - -/* * Dynamic Casts * * This very cool SWIG feature enables use to return the correct object @@ -116,44 +75,6 @@ } %} - -/* - * PerlCallbackHandler* - this is broken and useless - */ - -%typemap(out) XERCES_CPP_NAMESPACE::PerlCallbackHandler * = SWIGTYPE *DYNAMIC; - -DYNAMIC_CAST(SWIGTYPE_p_PerlCallbackHandler, PerlCallbackHandler_dynamic_cast); - -%{ -static swig_type_info * -PerlCallbackHandler_dynamic_cast(void **ptr) { - PerlCallbackHandler **nptr = (PerlCallbackHandler **) ptr; - if (*nptr == NULL) { - return NULL; - } - short int type = (*nptr)->type(); - if (type == PERLCALLBACKHANDLER_BASE_TYPE) { - die("Can't cast a PerlCallbackHandler base type node\n"); - } - if (type == PERLCALLBACKHANDLER_ERROR_TYPE) { - return SWIGTYPE_p_PerlErrorCallbackHandler; - } - if (type == PERLCALLBACKHANDLER_ENTITY_TYPE) { - return SWIGTYPE_p_PerlEntityResolverHandler; - } - if (type == PERLCALLBACKHANDLER_CONTENT_TYPE) { - return SWIGTYPE_p_PerlContentCallbackHandler; - } - if (type == PERLCALLBACKHANDLER_DOCUMENT_TYPE) { - return SWIGTYPE_p_PerlDocumentCallbackHandler; - } - if (type == PERLCALLBACKHANDLER_NODE_TYPE) { - return SWIGTYPE_p_PerlNodeFilterCallbackHandler; - } - return NULL; -} -%} /* * DOM_Node* Modified: xerces/xerces-p/trunk/interface/typemaps.i URL: http://svn.apache.org/viewcvs/xerces/xerces-p/trunk/interface/typemaps.i?rev=365289&r1=365288&r2=365289&view=diff ============================================================================== --- xerces/xerces-p/trunk/interface/typemaps.i (original) +++ xerces/xerces-p/trunk/interface/typemaps.i Sun Jan 1 20:55:53 2006 @@ -21,5 +21,8 @@ /**************/ %include typemaps-general.i -%include typemaps-xmlch.i +#ifdef SWIGPERL +%include "interface/Perl/typemaps.i" +%include "interface/Perl/typemaps-xmlch.i" +#endif \ No newline at end of file Added: xerces/xerces-p/trunk/t/01utf8.t URL: http://svn.apache.org/viewcvs/xerces/xerces-p/trunk/t/01utf8.t?rev=365289&view=auto ============================================================================== --- xerces/xerces-p/trunk/t/01utf8.t (added) +++ xerces/xerces-p/trunk/t/01utf8.t Sun Jan 1 20:55:53 2006 @@ -0,0 +1,332 @@ +# use blib; +use XML::Xerces; +use Cwd; +use Test::More tests => 42; +use vars qw($text); +use utf8; +use lib 't'; +use TestUtils qw($PERSONAL_NO_DOCTYPE); + +pass("loaded"); + + # NOTICE: We must now explicitly call XMLPlatformUtils::Initialize() + # when the module is loaded. Xerces.pm no longer does this. + # + # +XML::Xerces::XMLPlatformUtils::Initialize(); + +my $utf8_text = "\x{66}\x{128}\x{144}"; +my $ascii_text = "just a test"; +my $utf8_document = <<XML; +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<text>$utf8_text</text> +XML + +my $ascii_document = <<XML; +<?xml version="1.0" encoding="ASCII" standalone="yes"?> +<text>$ascii_text</text> +XML + +package MyContentHandler; +use strict; +use base qw(XML::Xerces::PerlContentHandler); + +sub start_element { + my ($self, $uri, $localname, $qname, $attrs) = @_; +# print STDERR "Start element: uri: $uri, localname: $localname, qname: $qname, attrs: $attrs\n"; + push(@{$self->{start_elem_list}}, {localname=>$localname, + uri=>$uri, + qname=>$qname, + }); + push(@{$self->{attr_list}}, $attrs); +} + +sub end_element { + my ($self, $uri, $localname, $qname) = @_; +# print STDERR "End element: uri: $uri, localname: $localname, qname: $qname\n"; + push(@{$self->{end_elem_list}}, {localname=>$localname, + uri=>$uri, + qname=>$qname, + }); +} + +sub characters { + my ($self,$str,$len) = @_; +# print STDERR "Characters: len: $len, str: $str\n"; + $::text .= $str; +} +sub ignorable_whitespace { + my ($self,$str,$len) = @_; +} + +sub processing_instruction { + my ($self,$target,$data) = @_; + push(@{$self->{pi_list}}, {target=>$target, + data=>$data, + }); +} + +sub reset_document { + my ($self) = @_; + $self->{start_elem_list} = []; + $self->{end_elem_list} = []; + $self->{attr_list} = []; + $self->{pi_list} = []; + $self->{map_start} = undef; + $self->{map_end} = undef; + $::text = ''; +} + +sub start_prefix_mapping { + my ($self,$prefix,$uri) = @_; +# print STDERR "Prefix mapping start: prefix: $prefix, uri: $uri\n"; + $self->{map_start} = {prefix=>$prefix, + uri=>$uri, + }; +} + +sub end_prefix_mapping { + my ($self,$prefix) = @_; +# print STDERR "Prefix mapping end: prefix: $prefix\n"; + $self->{map_end} = {prefix=>$prefix, + }; +} + +package MyDocumentHandler; +use strict; +use base qw(XML::Xerces::PerlDocumentHandler); + +sub start_element { + my ($self, $name, $attrs) = @_; +# print STDERR "Start element: name: $name, attrs: $attrs\n"; + push(@{$self->{start_elem_list}}, {name=>$name, + }); + push(@{$self->{attr_list}}, $attrs); +} + +sub end_element { + my ($self, $name) = @_; +# print STDERR "End element: uri: $uri, name: $name\n"; + push(@{$self->{end_elem_list}}, {name=>$name, + }); +} + +sub characters { + my ($self,$str,$len) = @_; +# print STDERR "Characters: len: $len, str: $str\n"; + $::text .= $str; +} +sub ignorable_whitespace { + my ($self,$str,$len) = @_; +} + +sub processing_instruction { + my ($self,$target,$data) = @_; + push(@{$self->{pi_list}}, {target=>$target, + data=>$data, + }); +} + +sub reset_document { + my ($self) = @_; + $self->{start_elem_list} = []; + $self->{end_elem_list} = []; + $self->{attr_list} = []; + $self->{pi_list} = []; + $::text = ''; +} + +package main; +my $SAX2 = XML::Xerces::XMLReaderFactory::createXMLReader(); +isa_ok($SAX2, "XML::Xerces::SAX2XMLReader"); + +$SAX2->setFeature("$XML::Xerces::XMLUni::fgSAX2CoreValidation", 0); +$SAX2->setFeature("$XML::Xerces::XMLUni::fgXercesDynamic", 0); + +my $ERROR_HANDLER = XML::Xerces::PerlErrorHandler->new(); +isa_ok($ERROR_HANDLER, "XML::Xerces::PerlErrorHandler"); + +$SAX2->setErrorHandler($ERROR_HANDLER); + +my $CONTENT_HANDLER = MyContentHandler->new(); +isa_ok($CONTENT_HANDLER, "MyContentHandler"); +isa_ok($CONTENT_HANDLER, "XML::Xerces::PerlContentHandler"); + +$SAX2->setContentHandler($CONTENT_HANDLER); + +my $SAX = XML::Xerces::SAXParser->new(); +isa_ok($SAX, "XML::Xerces::SAXParser"); + +$SAX->setValidationScheme ($XML::Xerces::SAXParser::Val_Never); +$SAX->setErrorHandler($ERROR_HANDLER); + +my $DOCUMENT_HANDLER = MyDocumentHandler->new(); +isa_ok($DOCUMENT_HANDLER, "MyDocumentHandler"); +isa_ok($DOCUMENT_HANDLER, "XML::Xerces::PerlDocumentHandler"); + +$SAX->setDocumentHandler($DOCUMENT_HANDLER); + + +# +# parse a document with only ASCII characters +# +$CONTENT_HANDLER->reset_document(); + +my $is = eval {XML::Xerces::MemBufInputSource->new($ascii_document)}; +XML::Xerces::error($@) if $@; +isa_ok($is, "XML::Xerces::MemBufInputSource"); + +eval {$SAX2->parse($is)}; +XML::Xerces::error($@) if $@; + +is($text, $ascii_text, "ASCII text content - SAX2"); + +$DOCUMENT_HANDLER->reset_document(); + +eval {$SAX->parse($is)}; +XML::Xerces::error($@) if $@; + +is($text, $ascii_text, "ASCII text content - SAX"); + +# +# parse a document with UTF8 characters +# +$CONTENT_HANDLER->reset_document(); + +$is = eval {XML::Xerces::MemBufInputSource->new($utf8_document)}; +XML::Xerces::error($@) if $@; +isa_ok($is, "XML::Xerces::MemBufInputSource"); + +eval {$SAX2->parse($is)}; +XML::Xerces::error($@) if $@; + +is($text, $utf8_text, "UTF8 text content - SAX2"); + +$DOCUMENT_HANDLER->reset_document(); + +eval {$SAX->parse($is)}; +XML::Xerces::error($@) if $@; + +is($text, $utf8_text, "UTF8 text content - SAX"); + +$CONTENT_HANDLER->reset_document(); + +# +# parse a document with UTF8 element names +# +my $uri = "http://www.boyscouts.$utf8_text/"; +my $ns = "ns_$utf8_text"; + +my $elem_name = "elem_$utf8_text"; +my $qname = "$ns:$elem_name"; +$utf8_document = <<XML; +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<test xmlns:$ns="$uri"><$ns:$elem_name>$utf8_text</$ns:$elem_name></test> +XML + +$is = eval {XML::Xerces::MemBufInputSource->new($utf8_document)}; +XML::Xerces::error($@) if $@; +isa_ok($is, "XML::Xerces::MemBufInputSource"); + +eval {$SAX2->parse($is)}; +XML::Xerces::error($@) if $@; + +is($CONTENT_HANDLER->{start_elem_list}->[-1]->{localname}, $elem_name, "UTF8 element name - start handler"); +is($CONTENT_HANDLER->{start_elem_list}->[-1]->{uri}, $uri, "UTF8 uri - start handler"); +is($CONTENT_HANDLER->{start_elem_list}->[-1]->{qname}, $qname, "UTF8 qname - start handler"); + +is($CONTENT_HANDLER->{end_elem_list}->[0]->{localname}, $elem_name, "UTF8 element name - end handler"); +is($CONTENT_HANDLER->{end_elem_list}->[0]->{uri}, $uri, "UTF8 uri - end handler"); +is($CONTENT_HANDLER->{end_elem_list}->[0]->{qname}, $qname, "UTF8 qname - end handler"); + +is($text, $utf8_text, "UTF8 text content"); + +is($CONTENT_HANDLER->{map_start}->{prefix}, $ns, "UTF8 namespace - map start handler"); +is($CONTENT_HANDLER->{map_start}->{uri}, $uri, "UTF8 uri - map start handler"); + +is($CONTENT_HANDLER->{map_end}->{prefix}, $ns, "UTF8 namespace - map end handler"); + +$DOCUMENT_HANDLER->reset_document(); + +eval {$SAX->parse($is)}; +XML::Xerces::error($@) if $@; + +is($DOCUMENT_HANDLER->{start_elem_list}->[-1]->{name}, "$ns:$elem_name", "UTF8 element name - start handler"); +is($DOCUMENT_HANDLER->{end_elem_list}->[0]->{name}, "$ns:$elem_name", "UTF8 element name - end handler"); + +is($text, $utf8_text, "UTF8 text content"); + +$CONTENT_HANDLER->reset_document(); + +# +# parse a document with UTF8 attr names and values +# +my $attr_name = "attr_$utf8_text"; +$qname = "$ns:$attr_name"; + +$utf8_document = <<XML; +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<test xmlns:$ns="$uri"><text $ns:$attr_name="$utf8_text">$utf8_text</text></test> +XML + +$is = eval {XML::Xerces::MemBufInputSource->new($utf8_document)}; +XML::Xerces::error($@) if $@; +isa_ok($is, "XML::Xerces::MemBufInputSource"); + +eval {$SAX2->parse($is)}; +XML::Xerces::error($@) if $@; + +is($CONTENT_HANDLER->{attr_list}->[-1]->getLocalName(0), $attr_name, "UTF8 attr name"); +is($CONTENT_HANDLER->{attr_list}->[-1]->getValue(0), $utf8_text, "UTF8 attr value"); +is($CONTENT_HANDLER->{attr_list}->[-1]->getQName(0), $qname, "UTF8 attr qname"); +is($CONTENT_HANDLER->{attr_list}->[-1]->getURI(0), $uri, "UTF8 attr uri"); + +is($text, $utf8_text, "UTF8 text content"); + +$DOCUMENT_HANDLER->reset_document(); + +eval {$SAX->parse($is)}; +XML::Xerces::error($@) if $@; + +is($DOCUMENT_HANDLER->{attr_list}->[-1]->getName(0), "$ns:$attr_name", "UTF8 attr name - SAX"); +is($DOCUMENT_HANDLER->{attr_list}->[-1]->getValue(0), $utf8_text, "UTF8 attr value - SAX"); + +is($text, $utf8_text, "UTF8 text content - SAX"); + +$CONTENT_HANDLER->reset_document(); + +# +# parse a document with UTF8 processing instruction +# +my $pi_name = "pi_$utf8_text"; +$utf8_document = <<XML; +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<?$pi_name $utf8_text?> +<test/> +XML + +$is = eval {XML::Xerces::MemBufInputSource->new($utf8_document)}; +XML::Xerces::error($@) if $@; +isa_ok($is, "XML::Xerces::MemBufInputSource"); + +eval {$SAX2->parse($is)}; +XML::Xerces::error($@) if $@; + +is($CONTENT_HANDLER->{pi_list}->[-1]->{target}, $pi_name, "UTF8 processing instruction name"); +is($CONTENT_HANDLER->{pi_list}->[-1]->{data}, $utf8_text, "UTF8 processing instruction data"); + +$DOCUMENT_HANDLER->reset_document(); + +eval {$SAX->parse($is)}; +XML::Xerces::error($@) if $@; + +is($DOCUMENT_HANDLER->{pi_list}->[-1]->{target}, $pi_name, "UTF8 processing instruction name - SAX"); +is($DOCUMENT_HANDLER->{pi_list}->[-1]->{data}, $utf8_text, "UTF8 processing instruction data - SAX"); + +END { + # NOTICE: We must now explicitly call XMLPlatformUtils::Terminate() + # when the module is unloaded. Xerces.pm no longer does this for us + # + # + XML::Xerces::XMLPlatformUtils::Terminate(); +} Modified: xerces/xerces-p/trunk/t/DOMNode.t URL: http://svn.apache.org/viewcvs/xerces/xerces-p/trunk/t/DOMNode.t?rev=365289&r1=365288&r2=365289&view=diff ============================================================================== --- xerces/xerces-p/trunk/t/DOMNode.t (original) +++ xerces/xerces-p/trunk/t/DOMNode.t Sun Jan 1 20:55:53 2006 @@ -61,7 +61,8 @@ my @persons2 = $doc2->getElementsByTagName('person'); my @names2 = $doc1->getElementsByTagName('name'); -ok($root1 != $root2); +ok(($root1 != $root2), + "root1 and root2 are different"); # importing a child from a different document eval { @@ -69,9 +70,12 @@ $root1->appendChild($copy); }; ok(!$@ && - scalar @persons1 < scalar ($root1->getElementsByTagName('person'))); + scalar @persons1 < scalar ($root1->getElementsByTagName('person')), + "import node"); # test the equality operators my @people = $doc1->getElementsByTagName('person'); -ok($root1 != $root2); -ok($people[0] == $persons1[0]); +ok(($root1 != $root2), + "root nodes are unequal"); +ok(($people[0] == $persons1[0]), + "nodes are equal"); Modified: xerces/xerces-p/trunk/t/DOMWriter.t URL: http://svn.apache.org/viewcvs/xerces/xerces-p/trunk/t/DOMWriter.t?rev=365289&r1=365288&r2=365289&view=diff ============================================================================== --- xerces/xerces-p/trunk/t/DOMWriter.t (original) +++ xerces/xerces-p/trunk/t/DOMWriter.t Sun Jan 1 20:55:53 2006 @@ -51,6 +51,8 @@ my $doc = $dom->getDocument(); $writer->writeNode($target,$doc); my $output = $target->getRawBuffer(); -ok($output); -ok($output eq $document); + +ok($output, "output written"); +is($output, $document, "got expected document"); + Modified: xerces/xerces-p/trunk/t/MemBufInputSource.t URL: http://svn.apache.org/viewcvs/xerces/xerces-p/trunk/t/MemBufInputSource.t?rev=365289&r1=365288&r2=365289&view=diff ============================================================================== --- xerces/xerces-p/trunk/t/MemBufInputSource.t (original) +++ xerces/xerces-p/trunk/t/MemBufInputSource.t Sun Jan 1 20:55:53 2006 @@ -9,7 +9,7 @@ use Carp; # use blib; use XML::Xerces; -use Test::More tests => 5; +use Test::More tests => 6; use lib 't'; use TestUtils qw($DOM $PERSONAL_NO_DOCTYPE); @@ -23,19 +23,20 @@ my $is = eval{XML::Xerces::MemBufInputSource->new($PERSONAL_NO_DOCTYPE,'foo')}; XML::Xerces::error($@) if $@; -ok(UNIVERSAL::isa($is,'XML::Xerces::InputSource') - && $is->isa('XML::Xerces::MemBufInputSource') - ); +isa_ok($is, 'XML::Xerces::InputSource'); +isa_ok($is, 'XML::Xerces::MemBufInputSource'); eval {$DOM->parse($is)}; XML::Xerces::error($@) if $@; my $serialize = $DOM->getDocument->serialize; -ok($serialize eq $PERSONAL_NO_DOCTYPE); +is($serialize, $PERSONAL_NO_DOCTYPE, + "doctype"); # now test that the fake system ID is optional $is = eval{XML::Xerces::MemBufInputSource->new($PERSONAL_NO_DOCTYPE)}; XML::Xerces::error($@) if $@; -ok($is->getSystemId() eq 'FAKE_SYSTEM_ID'); +is($is->getSystemId(), 'FAKE_SYSTEM_ID', + "system id"); # test that a blank document does not segfault $is = eval{XML::Xerces::MemBufInputSource->new('')}; --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
