annotate _test/Test/DOM/Navigator.pm @ 11:75980091813b

DOM и навигация
author Sergey
date Wed, 02 Sep 2009 17:47:44 +0400
parents
children 7f00786f8210
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;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
8 use IMPL::DOM::Node;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
9
75980091813b DOM и навигация
Sergey
parents:
diff changeset
10 test Creation => sub {
75980091813b DOM и навигация
Sergey
parents:
diff changeset
11 my ($this) = @_;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
12
75980091813b DOM и навигация
Sergey
parents:
diff changeset
13 my $doc = new IMPL::DOM::Node(nodeName => 'root');
75980091813b DOM и навигация
Sergey
parents:
diff changeset
14
75980091813b DOM и навигация
Sergey
parents:
diff changeset
15 my $obj = new IMPL::DOM::Navigator($doc) or failed "Failed to create instance" ;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
16 };
75980091813b DOM и навигация
Sergey
parents:
diff changeset
17
75980091813b DOM и навигация
Sergey
parents:
diff changeset
18 test Navigate => sub {
75980091813b DOM и навигация
Sergey
parents:
diff changeset
19 my $doc = new IMPL::DOM::Node(nodeName => 'root');
75980091813b DOM и навигация
Sergey
parents:
diff changeset
20 my $child = $doc->insertNode(
75980091813b DOM и навигация
Sergey
parents:
diff changeset
21 new IMPL::DOM::Node(
75980091813b DOM и навигация
Sergey
parents:
diff changeset
22 nodeName => 'Child'
75980091813b DOM и навигация
Sergey
parents:
diff changeset
23 )
75980091813b DOM и навигация
Sergey
parents:
diff changeset
24 );
75980091813b DOM и навигация
Sergey
parents:
diff changeset
25
75980091813b DOM и навигация
Sergey
parents:
diff changeset
26 my $navi = new IMPL::DOM::Navigator($doc);
75980091813b DOM и навигация
Sergey
parents:
diff changeset
27 my $navresult = $navi->Navigate("Child");
75980091813b DOM и навигация
Sergey
parents:
diff changeset
28
75980091813b DOM и навигация
Sergey
parents:
diff changeset
29 failed ("Navigate retuned unexpected result", "Recieved: $navresult", "Expected: $child") if $child != $navresult;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
30 my $curr = $navi->Current;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
31 failed ("Current node has a wrong value","Current: $curr","Expected: $child") if $child != $curr;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
32 };
75980091813b DOM и навигация
Sergey
parents:
diff changeset
33
75980091813b DOM и навигация
Sergey
parents:
diff changeset
34 test PathToString => sub {
75980091813b DOM и навигация
Sergey
parents:
diff changeset
35 my $doc = new IMPL::DOM::Node(nodeName => 'root');
75980091813b DOM и навигация
Sergey
parents:
diff changeset
36 my $child = $doc->insertNode(
75980091813b DOM и навигация
Sergey
parents:
diff changeset
37 new IMPL::DOM::Node(
75980091813b DOM и навигация
Sergey
parents:
diff changeset
38 nodeName => 'Child'
75980091813b DOM и навигация
Sergey
parents:
diff changeset
39 )
75980091813b DOM и навигация
Sergey
parents:
diff changeset
40 );
75980091813b DOM и навигация
Sergey
parents:
diff changeset
41
75980091813b DOM и навигация
Sergey
parents:
diff changeset
42 my $navi = new IMPL::DOM::Navigator($doc);
75980091813b DOM и навигация
Sergey
parents:
diff changeset
43 $navi->Navigate("Child");
75980091813b DOM и навигация
Sergey
parents:
diff changeset
44
75980091813b DOM и навигация
Sergey
parents:
diff changeset
45 my $expected = "root/Child";
75980091813b DOM и навигация
Sergey
parents:
diff changeset
46 my $res = $navi->PathToString;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
47 failed("Unexpected PathToString result","Recieved: $res","Expected: $expected") if $res ne $expected;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
48 };
75980091813b DOM и навигация
Sergey
parents:
diff changeset
49
75980091813b DOM и навигация
Sergey
parents:
diff changeset
50 test Back => 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 $navi->Navigate("Child");
75980091813b DOM и навигация
Sergey
parents:
diff changeset
60 my $navresult = $navi->Back;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
61
75980091813b DOM и навигация
Sergey
parents:
diff changeset
62 failed ("Back() retuned unexpected result", "Recieved: $navresult", "Expected: $doc") if $doc != $navresult;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
63 my $curr = $navi->Current;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
64 failed ("Current node has a wrong value","Current: $curr","Expected: $doc") if $doc != $curr;
75980091813b DOM и навигация
Sergey
parents:
diff changeset
65 };
75980091813b DOM и навигация
Sergey
parents:
diff changeset
66
75980091813b DOM и навигация
Sergey
parents:
diff changeset
67
75980091813b DOM и навигация
Sergey
parents:
diff changeset
68
75980091813b DOM и навигация
Sergey
parents:
diff changeset
69
75980091813b DOM и навигация
Sergey
parents:
diff changeset
70
75980091813b DOM и навигация
Sergey
parents:
diff changeset
71 1;