annotate _test/Test/DOM/Navigator.pm @ 34:a8086f85a571

Dom Builder
author Sergey
date Mon, 16 Nov 2009 18:39:25 +0300
parents 7f00786f8210
children 1828103371d0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
1 package Test::DOM::Navigator;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
2 use base qw(IMPL::Test::Unit);
75980091813b DOM и навигация
Sergey
parents:
diff changeset
3
75980091813b DOM и навигация
Sergey
parents:
diff changeset
4 __PACKAGE__->PassThroughArgs;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
5
75980091813b DOM и навигация
Sergey
parents:
diff changeset
6 use IMPL::Test qw(test failed);
75980091813b DOM и навигация
Sergey
parents:
diff changeset
7 use IMPL::DOM::Navigator;
24
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
8 use IMPL::DOM::Navigator::SchemaNavigator;
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
9 use IMPL::DOM::Node;
24
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
10 use IMPL::DOM::Schema;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
11 use IMPL::Class::Property;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
12
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
13 BEGIN {
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
14 public property doc => prop_all;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
15 }
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
16
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
17 sub CTOR {
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
18 my ($this) = @_;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
19
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
20 $this->doc(
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
21 IMPL::DOM::Node->new(nodeName => 'root')->appendRange(
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
22 IMPL::DOM::Node->new(nodeName=> 'age', nodeValue => 21),
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
23 IMPL::DOM::Node->new(nodeName=> 'address')->appendRange(
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
24 IMPL::DOM::Node->new(nodeName=>'city', nodeValue=>'moscow'),
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
25 IMPL::DOM::Node->new(nodeName=>'street', nodeValue=>'main'),
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
26 IMPL::DOM::Node->new(nodeName=>'phone',nodeValue=>'123-456'),
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
27 ),
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
28 IMPL::DOM::Node->new(nodeName=> 'address')->appendRange(
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
29 IMPL::DOM::Node->new(nodeName=>'city', nodeValue=>'San Francisco'),
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
30 IMPL::DOM::Node->new(nodeName=>'street', nodeValue=>'Libertador'),
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
31 ),
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
32 IMPL::DOM::Node->new(nodeName=> 'contacts')->appendRange(
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
33 IMPL::DOM::Node->new(nodeName=>'phone',nodeValue=>'123-123'),
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
34 IMPL::DOM::Node->new(nodeName=>'phone',nodeValue=>'1-233-434-34-54'),
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
35 IMPL::DOM::Node->new(nodeName=>'email',nodeValue=>'some@mail.none')
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
36 )
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
37
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
38 )
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
39 );
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
40 }
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
41
75980091813b DOM и навигация
Sergey
parents:
diff changeset
42 test Creation => sub {
75980091813b DOM и навигация
Sergey
parents:
diff changeset
43 my ($this) = @_;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
44
75980091813b DOM и навигация
Sergey
parents:
diff changeset
45 my $doc = new IMPL::DOM::Node(nodeName => 'root');
75980091813b DOM и навигация
Sergey
parents:
diff changeset
46
75980091813b DOM и навигация
Sergey
parents:
diff changeset
47 my $obj = new IMPL::DOM::Navigator($doc) or failed "Failed to create instance" ;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
48 };
75980091813b DOM и навигация
Sergey
parents:
diff changeset
49
75980091813b DOM и навигация
Sergey
parents:
diff changeset
50 test Navigate => sub {
75980091813b DOM и навигация
Sergey
parents:
diff changeset
51 my $doc = new IMPL::DOM::Node(nodeName => 'root');
75980091813b DOM и навигация
Sergey
parents:
diff changeset
52 my $child = $doc->insertNode(
75980091813b DOM и навигация
Sergey
parents:
diff changeset
53 new IMPL::DOM::Node(
75980091813b DOM и навигация
Sergey
parents:
diff changeset
54 nodeName => 'Child'
75980091813b DOM и навигация
Sergey
parents:
diff changeset
55 )
75980091813b DOM и навигация
Sergey
parents:
diff changeset
56 );
75980091813b DOM и навигация
Sergey
parents:
diff changeset
57
75980091813b DOM и навигация
Sergey
parents:
diff changeset
58 my $navi = new IMPL::DOM::Navigator($doc);
75980091813b DOM и навигация
Sergey
parents:
diff changeset
59 my $navresult = $navi->Navigate("Child");
75980091813b DOM и навигация
Sergey
parents:
diff changeset
60
75980091813b DOM и навигация
Sergey
parents:
diff changeset
61 failed ("Navigate retuned unexpected result", "Recieved: $navresult", "Expected: $child") if $child != $navresult;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
62 my $curr = $navi->Current;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
63 failed ("Current node has a wrong value","Current: $curr","Expected: $child") if $child != $curr;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
64 };
75980091813b DOM и навигация
Sergey
parents:
diff changeset
65
75980091813b DOM и навигация
Sergey
parents:
diff changeset
66 test PathToString => sub {
75980091813b DOM и навигация
Sergey
parents:
diff changeset
67 my $doc = new IMPL::DOM::Node(nodeName => 'root');
75980091813b DOM и навигация
Sergey
parents:
diff changeset
68 my $child = $doc->insertNode(
75980091813b DOM и навигация
Sergey
parents:
diff changeset
69 new IMPL::DOM::Node(
75980091813b DOM и навигация
Sergey
parents:
diff changeset
70 nodeName => 'Child'
75980091813b DOM и навигация
Sergey
parents:
diff changeset
71 )
75980091813b DOM и навигация
Sergey
parents:
diff changeset
72 );
75980091813b DOM и навигация
Sergey
parents:
diff changeset
73
75980091813b DOM и навигация
Sergey
parents:
diff changeset
74 my $navi = new IMPL::DOM::Navigator($doc);
75980091813b DOM и навигация
Sergey
parents:
diff changeset
75 $navi->Navigate("Child");
75980091813b DOM и навигация
Sergey
parents:
diff changeset
76
75980091813b DOM и навигация
Sergey
parents:
diff changeset
77 my $expected = "root/Child";
75980091813b DOM и навигация
Sergey
parents:
diff changeset
78 my $res = $navi->PathToString;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
79 failed("Unexpected PathToString result","Recieved: $res","Expected: $expected") if $res ne $expected;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
80 };
75980091813b DOM и навигация
Sergey
parents:
diff changeset
81
75980091813b DOM и навигация
Sergey
parents:
diff changeset
82 test Back => sub {
75980091813b DOM и навигация
Sergey
parents:
diff changeset
83 my $doc = new IMPL::DOM::Node(nodeName => 'root');
75980091813b DOM и навигация
Sergey
parents:
diff changeset
84 my $child = $doc->insertNode(
75980091813b DOM и навигация
Sergey
parents:
diff changeset
85 new IMPL::DOM::Node(
75980091813b DOM и навигация
Sergey
parents:
diff changeset
86 nodeName => 'Child'
75980091813b DOM и навигация
Sergey
parents:
diff changeset
87 )
75980091813b DOM и навигация
Sergey
parents:
diff changeset
88 );
75980091813b DOM и навигация
Sergey
parents:
diff changeset
89
75980091813b DOM и навигация
Sergey
parents:
diff changeset
90 my $navi = new IMPL::DOM::Navigator($doc);
75980091813b DOM и навигация
Sergey
parents:
diff changeset
91 $navi->Navigate("Child");
75980091813b DOM и навигация
Sergey
parents:
diff changeset
92 my $navresult = $navi->Back;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
93
75980091813b DOM и навигация
Sergey
parents:
diff changeset
94 failed ("Back() retuned unexpected result", "Recieved: $navresult", "Expected: $doc") if $doc != $navresult;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
95 my $curr = $navi->Current;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
96 failed ("Current node has a wrong value","Current: $curr","Expected: $doc") if $doc != $curr;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
97 };
75980091813b DOM и навигация
Sergey
parents:
diff changeset
98
24
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
99 test selectNodes1 => sub {
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
100 my ($this) = @_;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
101
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
102 my $navi = new IMPL::DOM::Navigator($this->doc);
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
103 my @result = $navi->selectNodes('contacts','phone');
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
104 failed "Expected to get two entries, but got:",map($_->nodeName,@result) unless @result == 2;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
105 };
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
106
24
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
107 test selectNodes2 => sub {
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
108 my ($this) = @_;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
109
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
110 my $navi = new IMPL::DOM::Navigator($this->doc);
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
111 my @result = $navi->selectNodes(undef,'phone');
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
112 failed "Expected to get three entries, but got:",map($_->nodeName,@result) unless @result == 3;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
113 };
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
114
24
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
115 test FetchDoeachState => sub {
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
116 my ($this) = @_;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
117
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
118 my $navi = new IMPL::DOM::Navigator($this->doc);
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
119
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
120 $navi->Navigate(undef,'phone');
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
121
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
122 $navi->saveState();
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
123
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
124 my @result;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
125 doeach $navi sub {
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
126 push @result,$_;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
127 };
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
128
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
129 failed "Expected to get three nodes, but got: ", map($_->nodeName,@result) unless @result == 3;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
130
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
131 $navi->restoreState();
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
132 @result = ();
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
133
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
134 push @result, $_ while fetch $navi;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
135
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
136 failed "Expected to get three nodes, but got: ", map($_->nodeName,@result) unless @result == 3;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
137 };
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
138
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
139 test NavigateSchema => sub {
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
140 my $navi = new IMPL::DOM::Navigator::SchemaNavigator(IMPL::DOM::Schema->MetaSchema);
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
141
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
142 my $root = $navi->NavigateName('schema') or failed "Failed to navigate to the root element";
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
143
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
144 $navi->saveState;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
145 $navi->NavigateName('Node') or failed "Failed to navigate to a simple node";
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
146 $navi->restoreState;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
147
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
148 failed "Can't navigate from simple node" if $navi->NavigateName('Property');
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
149
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
150 $navi->NavigateName('ComplexType') or failed "Failed to navigate to a complex node";
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
151 $navi->NavigateName('NodeSet') or failed "Failed to navigate to NodeSet";
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
152 $navi->SchemaBack();
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
153 $navi->NavigateName('NodeList') or failed "Failed to navigate to NodeList";
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
154 $navi->NavigateName('SimpleNode') or failed "Failed to navigate to SimpleNode";
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
155 $navi->NavigateName('Enum') or failed "Failed to navigate to Enum";
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
156 $navi->NavigateName('Item') or failed "Failed to navigate to Item";
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
157
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 11
diff changeset
158 };
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
159
75980091813b DOM и навигация
Sergey
parents:
diff changeset
160
75980091813b DOM и навигация
Sergey
parents:
diff changeset
161 1;