Mercurial > pub > Impl
diff _test/Test/DOM/Navigator.pm @ 24:7f00786f8210
Первая рабочая реазизация схемы и навигаторов
author | Sergey |
---|---|
date | Mon, 05 Oct 2009 00:48:49 +0400 |
parents | 75980091813b |
children | 1828103371d0 |
line wrap: on
line diff
--- a/_test/Test/DOM/Navigator.pm Wed Sep 30 17:43:52 2009 +0400 +++ b/_test/Test/DOM/Navigator.pm Mon Oct 05 00:48:49 2009 +0400 @@ -5,7 +5,39 @@ use IMPL::Test qw(test failed); use IMPL::DOM::Navigator; +use IMPL::DOM::Navigator::SchemaNavigator; use IMPL::DOM::Node; +use IMPL::DOM::Schema; +use IMPL::Class::Property; + +BEGIN { + public property doc => prop_all; +} + +sub CTOR { + my ($this) = @_; + + $this->doc( + IMPL::DOM::Node->new(nodeName => 'root')->appendRange( + IMPL::DOM::Node->new(nodeName=> 'age', nodeValue => 21), + IMPL::DOM::Node->new(nodeName=> 'address')->appendRange( + IMPL::DOM::Node->new(nodeName=>'city', nodeValue=>'moscow'), + IMPL::DOM::Node->new(nodeName=>'street', nodeValue=>'main'), + IMPL::DOM::Node->new(nodeName=>'phone',nodeValue=>'123-456'), + ), + IMPL::DOM::Node->new(nodeName=> 'address')->appendRange( + IMPL::DOM::Node->new(nodeName=>'city', nodeValue=>'San Francisco'), + IMPL::DOM::Node->new(nodeName=>'street', nodeValue=>'Libertador'), + ), + IMPL::DOM::Node->new(nodeName=> 'contacts')->appendRange( + IMPL::DOM::Node->new(nodeName=>'phone',nodeValue=>'123-123'), + IMPL::DOM::Node->new(nodeName=>'phone',nodeValue=>'1-233-434-34-54'), + IMPL::DOM::Node->new(nodeName=>'email',nodeValue=>'some@mail.none') + ) + + ) + ); +} test Creation => sub { my ($this) = @_; @@ -64,8 +96,66 @@ failed ("Current node has a wrong value","Current: $curr","Expected: $doc") if $doc != $curr; }; +test selectNodes1 => sub { + my ($this) = @_; + + my $navi = new IMPL::DOM::Navigator($this->doc); + my @result = $navi->selectNodes('contacts','phone'); + failed "Expected to get two entries, but got:",map($_->nodeName,@result) unless @result == 2; +}; +test selectNodes2 => sub { + my ($this) = @_; + + my $navi = new IMPL::DOM::Navigator($this->doc); + my @result = $navi->selectNodes(undef,'phone'); + failed "Expected to get three entries, but got:",map($_->nodeName,@result) unless @result == 3; +}; +test FetchDoeachState => sub { + my ($this) = @_; + + my $navi = new IMPL::DOM::Navigator($this->doc); + + $navi->Navigate(undef,'phone'); + + $navi->saveState(); + + my @result; + doeach $navi sub { + push @result,$_; + }; + + failed "Expected to get three nodes, but got: ", map($_->nodeName,@result) unless @result == 3; + + $navi->restoreState(); + @result = (); + + push @result, $_ while fetch $navi; + + failed "Expected to get three nodes, but got: ", map($_->nodeName,@result) unless @result == 3; +}; + +test NavigateSchema => sub { + my $navi = new IMPL::DOM::Navigator::SchemaNavigator(IMPL::DOM::Schema->MetaSchema); + + my $root = $navi->NavigateName('schema') or failed "Failed to navigate to the root element"; + + $navi->saveState; + $navi->NavigateName('Node') or failed "Failed to navigate to a simple node"; + $navi->restoreState; + + failed "Can't navigate from simple node" if $navi->NavigateName('Property'); + + $navi->NavigateName('ComplexType') or failed "Failed to navigate to a complex node"; + $navi->NavigateName('NodeSet') or failed "Failed to navigate to NodeSet"; + $navi->SchemaBack(); + $navi->NavigateName('NodeList') or failed "Failed to navigate to NodeList"; + $navi->NavigateName('SimpleNode') or failed "Failed to navigate to SimpleNode"; + $navi->NavigateName('Enum') or failed "Failed to navigate to Enum"; + $navi->NavigateName('Item') or failed "Failed to navigate to Item"; + +}; 1;