annotate _test/Test/DOM/Node.pm @ 21:fafe56cfcd69

temp commit
author Sergey
date Wed, 30 Sep 2009 10:25:41 +0400
parents 818c74b038ae
children 7f00786f8210
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
1 package Test::DOM::Node;
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
2 use strict;
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
3 use warnings;
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
4
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
5 use base qw(IMPL::Test::Unit);
18
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
6 use IMPL::Test qw(test shared failed cmparray);
14
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
7 use IMPL::Class::Property;
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
8
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
9 require IMPL::DOM::Node;
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
10
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
11 __PACKAGE__->PassThroughArgs;
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
12
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
13 BEGIN {
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
14 shared public property Root => prop_all;
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
15 }
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
16
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
17 test Create => sub {
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
18 my ($this) = @_;
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
19
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
20 $this->Root(new IMPL::DOM::Node(nodeName => 'Root')) or failed "Failed to create a node";
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
21 };
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
22
18
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
23 test InsertNode => sub {
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
24 my ($this) = @_;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
25 my $child = $this->Root->insertNode(new IMPL::DOM::Node(nodeName => 'Child')) or failed "Failed to insert a child node";
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
26 failed "fiestChild returned incorrect results" unless ($this->Root->firstChild || 0) == $child;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
27 };
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
28
14
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
29 test AppendNode => sub {
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
30 my ($this) = @_;
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
31
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
32 my $child = $this->Root->appendNode(new IMPL::DOM::Node(nodeName => 'Child')) or failed "Failed to append a child node";
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
33
18
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
34 my $lastChild = $this->Root->removeLast;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
35
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
36 failed "removeLast returned incorrect results" unless $lastChild == $child;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
37 };
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
38
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
39 test GetRootNode => sub {
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
40 my ($this) = @_;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
41
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
42 my $child = $this->Root->firstChild->appendNode(new IMPL::DOM::Node(nodeName => 'GrandChild')) or failed "Failed to append a child node";
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
43
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
44 failed "rootNode is undef" unless $child->rootNode;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
45 failed "rootNode returned incorrect value" unless $child->rootNode == $this->Root;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
46 };
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
47
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
48 test MoveNode => sub {
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
49 my ($this) = @_;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
50
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
51 my $grandChild = $this->Root->firstChild->firstChild;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
52 $this->Root->appendNode($grandChild);
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
53
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
54 failed "incorrect new parentNode value" unless ($grandChild->parentNode || 0) == $this->Root;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
55 failed "incorrect new rootNode value" unless ($grandChild->rootNode || 0) == $this->Root;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
56 };
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
57
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
58 test AppendRange => sub {
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
59 my ($this) = @_;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
60
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
61 my $count = $this->Root->childNodes->Count;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
62
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
63 $this->Root->appendRange(
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
64 map IMPL::DOM::Node->new(nodeName => "Item", nodeValue => $_),1..10
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
65 );
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
66
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
67 failed
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
68 "Wrong number of a child nodes",
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
69 "Expected: ".($count+10),
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
70 "Actual: ".$this->Root->childNodes->Count
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
71 unless $count + 10 == $this->Root->childNodes->Count;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
72 };
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
73
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
74 test SelectNodes => sub {
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
75 my ($this) = @_;
14
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
76
18
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
77 my @result = $this->Root->selectNodes("Item");
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
78
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
79 failed
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
80 "Wrong number of a selected nodes",
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
81 "Expected: 10",
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
82 "Actual: ".scalar(@result)
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
83 unless @result == 10;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
84 };
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
85
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
86 test SelectNodesByQuery => sub {
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
87 my ($this) = @_;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
88
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
89 my @result = $this->Root->selectNodes(sub { $_[0]->nodeName =~ /child/i } );
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
90 failed
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
91 "Wrong number of a selected nodes",
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
92 "Expected: 2",
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
93 "Actual: ".scalar(@result)
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
94 unless @result == 2;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
95 };
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
96
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
97 test CheckNodesValues => sub {
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
98 my ($this) = @_;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
99
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
100 my @expected = (1..10);
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
101
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
102 my @result = map $_->nodeValue, grep $_->nodeValue, $this->Root->selectNodes("Item");
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
103
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
104 failed
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
105 "Some nodes returned wrong node values or in a wrong order",
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
106 "Expected: ".join(', ',@expected),
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
107 "Recieved: ".join(', ',@result)
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
108 unless cmparray(\@expected,\@result);
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
109
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
110 failed
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
111 "a text property of a root node returned a wrong value",
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
112 "Expected: @expected",
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
113 "Recieved: ". $this->Root->text
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
114 unless $this->Root->text eq join '',@expected;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
115 };
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
116
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
117 test isComplex => sub {
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
118 my ($this) = @_;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
119
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
120 failed "property isComplex returned false for the root node" unless $this->Root->isComplex;
818c74b038ae DOM Schema + tests
Sergey
parents: 14
diff changeset
121 failed "property isComplex returned true for a simple node", $this->Root->firstChild->nodeName if $this->Root->firstChild->isComplex;
14
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
122 };
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
123
65a7bb156fb7 Дом модель и схема
Sergey
parents:
diff changeset
124 1;