Mercurial > pub > Impl
diff _test/Test/DOM/Schema.pm @ 49:16ada169ca75
migrating to the Eclipse IDE
author | wizard@linux-odin.local |
---|---|
date | Fri, 26 Feb 2010 10:49:21 +0300 |
parents | 6d33f75c6e1f |
children | d8dc6cad3f55 |
line wrap: on
line diff
--- a/_test/Test/DOM/Schema.pm Fri Feb 26 01:43:42 2010 +0300 +++ b/_test/Test/DOM/Schema.pm Fri Feb 26 10:49:21 2010 +0300 @@ -1,104 +1,104 @@ -package Test::DOM::Schema; -use strict; -use warnings; - -use base qw(IMPL::Test::Unit); -use IMPL::Test qw(test failed shared); -use IMPL::Class::Property; - -__PACKAGE__->PassThroughArgs; - -require IMPL::DOM::Schema; - -BEGIN { - shared public property SampleSchema => prop_all; -} - -test GetMetaSchema => sub { - my $metaSchema = IMPL::DOM::Schema->MetaSchema(); -}; - -test AutoverifyMetaSchema => sub { - my $metaSchema = IMPL::DOM::Schema->MetaSchema(); - - if (my @errors = $metaSchema->Validate($metaSchema)) { - failed "Self verification failed", map $_ ? $_->Message : 'unknown', @errors; - } -}; - -test VerifyCorrectSchema => sub { - my ($this) = @_; - my $metaSchema = IMPL::DOM::Schema->MetaSchema(); - - my $schema = new IMPL::DOM::Schema; - $schema->appendRange( - IMPL::DOM::Schema::ComplexNode->new( name => 'personInfo' )->appendRange( - IMPL::DOM::Schema::NodeSet->new()->appendRange( - new IMPL::DOM::Schema::SimpleNode( name => 'firstName' ), - new IMPL::DOM::Schema::SimpleNode( name => 'lastName' ), - new IMPL::DOM::Schema::ComplexNode( name => 'address' )->appendRange( - IMPL::DOM::Schema::NodeSet->new()->appendRange( - new IMPL::DOM::Schema::SimpleNode( name => 'street' ), - new IMPL::DOM::Schema::SimpleNode( name => 'line', minOccur => 0 ) - ) - ) - ) - ) - ); - - $this->SampleSchema($schema); - - my @errors = $metaSchema->Validate($schema); - failed "Failed to validate a wellformed schema", map $_->Message, @errors if @errors; -}; - -test VerifyWrongSchema => sub { - my $metaSchema = IMPL::DOM::Schema->MetaSchema(); - - my $schema = new IMPL::DOM::Schema; - $schema->appendRange( - IMPL::DOM::Schema::ComplexNode->new( name => 'personInfo' )->appendRange( - new IMPL::DOM::Schema::ComplexType( type => 'someType' ), - new IMPL::DOM::Schema::SimpleNode( name => 'lastName' ), - new IMPL::DOM::Schema::ComplexNode( name => 'address' )->appendRange( - new IMPL::DOM::Schema::SimpleNode( name => 'street' ), - new IMPL::DOM::Schema::SimpleNode( name => 'line' ) - ) - ) - ); - - my @errors = $metaSchema->Validate($schema); - failed "A not wellformed schema validated correctly" unless @errors; -}; - -test ValidateCorrectData => sub { - my ($this) = @_; - - my $data = IMPL::DOM::Node->new(nodeName => 'personInfo')->appendRange( - IMPL::DOM::Node->new(nodeName => 'firstName', nodeValue => 'John'), - IMPL::DOM::Node->new(nodeName => 'lastName', nodeValue => 'Smith'), - IMPL::DOM::Node->new(nodeName => 'address')->appendRange( - IMPL::DOM::Node->new(nodeName => 'street', nodeValue => 'main road') - ) - ); - - if (my @errors = $this->SampleSchema->Validate($data)) { - failed "Failed to validate a correct data", map $_->Message , @errors; - } -}; - -test ValidateWrongData => sub { - my ($this) = @_; - - my $data = IMPL::DOM::Node->new(nodeName => 'personInfo')->appendRange( - IMPL::DOM::Node->new(nodeName => 'firstName', nodeValue => 'John'), - IMPL::DOM::Node->new(nodeName => 'address')->appendRange( - IMPL::DOM::Node->new(nodeName => 'street', nodeValue => 'main road') - ) - ); - - failed "A wrong data validated corretly" unless $this->SampleSchema->Validate($data); -}; - - -1; +package Test::DOM::Schema; +use strict; +use warnings; + +use base qw(IMPL::Test::Unit); +use IMPL::Test qw(test failed shared); +use IMPL::Class::Property; + +__PACKAGE__->PassThroughArgs; + +require IMPL::DOM::Schema; + +BEGIN { + shared public property SampleSchema => prop_all; +} + +test GetMetaSchema => sub { + my $metaSchema = IMPL::DOM::Schema->MetaSchema(); +}; + +test AutoverifyMetaSchema => sub { + my $metaSchema = IMPL::DOM::Schema->MetaSchema(); + + if (my @errors = $metaSchema->Validate($metaSchema)) { + failed "Self verification failed", map $_ ? $_->Message : 'unknown', @errors; + } +}; + +test VerifyCorrectSchema => sub { + my ($this) = @_; + my $metaSchema = IMPL::DOM::Schema->MetaSchema(); + + my $schema = new IMPL::DOM::Schema; + $schema->appendRange( + IMPL::DOM::Schema::ComplexNode->new( name => 'personInfo' )->appendRange( + IMPL::DOM::Schema::NodeSet->new()->appendRange( + new IMPL::DOM::Schema::SimpleNode( name => 'firstName' ), + new IMPL::DOM::Schema::SimpleNode( name => 'lastName' ), + new IMPL::DOM::Schema::ComplexNode( name => 'address' )->appendRange( + IMPL::DOM::Schema::NodeSet->new()->appendRange( + new IMPL::DOM::Schema::SimpleNode( name => 'street' ), + new IMPL::DOM::Schema::SimpleNode( name => 'line', minOccur => 0 ) + ) + ) + ) + ) + ); + + $this->SampleSchema($schema); + + my @errors = $metaSchema->Validate($schema); + failed "Failed to validate a wellformed schema", map $_->Message, @errors if @errors; +}; + +test VerifyWrongSchema => sub { + my $metaSchema = IMPL::DOM::Schema->MetaSchema(); + + my $schema = new IMPL::DOM::Schema; + $schema->appendRange( + IMPL::DOM::Schema::ComplexNode->new( name => 'personInfo' )->appendRange( + new IMPL::DOM::Schema::ComplexType( type => 'someType' ), + new IMPL::DOM::Schema::SimpleNode( name => 'lastName' ), + new IMPL::DOM::Schema::ComplexNode( name => 'address' )->appendRange( + new IMPL::DOM::Schema::SimpleNode( name => 'street' ), + new IMPL::DOM::Schema::SimpleNode( name => 'line' ) + ) + ) + ); + + my @errors = $metaSchema->Validate($schema); + failed "A not wellformed schema validated correctly" unless @errors; +}; + +test ValidateCorrectData => sub { + my ($this) = @_; + + my $data = IMPL::DOM::Node->new(nodeName => 'personInfo')->appendRange( + IMPL::DOM::Node->new(nodeName => 'firstName', nodeValue => 'John'), + IMPL::DOM::Node->new(nodeName => 'lastName', nodeValue => 'Smith'), + IMPL::DOM::Node->new(nodeName => 'address')->appendRange( + IMPL::DOM::Node->new(nodeName => 'street', nodeValue => 'main road') + ) + ); + + if (my @errors = $this->SampleSchema->Validate($data)) { + failed "Failed to validate a correct data", map $_->Message , @errors; + } +}; + +test ValidateWrongData => sub { + my ($this) = @_; + + my $data = IMPL::DOM::Node->new(nodeName => 'personInfo')->appendRange( + IMPL::DOM::Node->new(nodeName => 'firstName', nodeValue => 'John'), + IMPL::DOM::Node->new(nodeName => 'address')->appendRange( + IMPL::DOM::Node->new(nodeName => 'street', nodeValue => 'main road') + ) + ); + + failed "A wrong data validated corretly" unless $this->SampleSchema->Validate($data); +}; + + +1;