annotate _test/Test/DOM/Builder.pm @ 36:1828103371d0

DOM in works
author Sergey
date Fri, 20 Nov 2009 16:48:08 +0300
parents f25d021780b3
children c2e7f7c96bcd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
1 package Test::DOM::Builder;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
2 use strict;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
3 use warnings;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
4
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
5 use base qw(IMPL::Test::Unit);
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
6 __PACKAGE__->PassThroughArgs;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
7
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
8 use IMPL::Class::Property;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
9 use IMPL::Test qw(test failed shared);
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
10
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
11 require IMPL::DOM::Schema;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
12 require IMPL::DOM::Navigator::Builder;
36
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
13 require IMPL::DOM::Navigator::SimpleBuilder;
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
14 require IMPL::DOM::Document;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
15
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
16 BEGIN {
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
17 public property schemaDoc => prop_all;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
18 }
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
19
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
20 sub CTOR {
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
21 my ($this) = @_;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
22
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
23 my $schema = new IMPL::DOM::Schema;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
24 $schema->appendRange(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
25 IMPL::DOM::Schema::ComplexNode->new( name => 'personInfo' )->appendRange(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
26 IMPL::DOM::Schema::NodeSet->new()->appendRange(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
27 new IMPL::DOM::Schema::SimpleNode( name => 'firstName' ),
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
28 new IMPL::DOM::Schema::SimpleNode( name => 'lastName' ),
35
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
29 new IMPL::DOM::Schema::ComplexNode( name => 'address', maxOccur => 'unbounded' )->appendRange(
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
30 IMPL::DOM::Schema::NodeSet->new()->appendRange(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
31 new IMPL::DOM::Schema::SimpleNode( name => 'street' ),
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
32 new IMPL::DOM::Schema::SimpleNode( name => 'line', minOccur => 0 )
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
33 )
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
34 )
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
35 )
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
36 )
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
37 );
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
38
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
39 $this->schemaDoc( $schema );
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
40 }
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
41
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
42 test CreateBuilder => sub {
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
43 my ($this) = @_;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
44
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
45 my $builder = IMPL::DOM::Navigator::Builder->new(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
46 new IMPL::DOM::Document(nodeName => 'personInfo'),
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
47 $this->schemaDoc
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
48 );
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
49 };
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
50
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
51 test BuildDocument => sub {
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
52 my ($this) = @_;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
53
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
54 my $builder = IMPL::DOM::Navigator::Builder->new(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
55 'IMPL::DOM::Document',
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
56 $this->schemaDoc
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
57 );
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
58
35
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
59 use Time::HiRes qw(gettimeofday tv_interval);
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
60
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
61 my $t = [gettimeofday];
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
62
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
63 $builder->NavigateCreate('personInfo', version => '1');
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
64 $builder->NavigateCreate('firstName')->nodeValue('Nemo');
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
65 $builder->Back();
35
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
66 $builder->NavigateCreate('lastName')->nodeValue('Nobel');
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
67 $builder->Back();
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
68 $builder->NavigateCreate('lastName')->nodeValue('Gardum');
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
69 $builder->Back();
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
70 for(1..100) {
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
71 $builder->NavigateCreate('address', local => 1);
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
72 $builder->NavigateCreate('street')->nodeValue('Hellroad');
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
73 $builder->Back();
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
74 $builder->NavigateCreate('line')->nodeValue($_);
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
75 $builder->Back();
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
76 $builder->Back();
35
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
77 }
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
78 $builder->Back();
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
79
35
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
80 print "Build: ",tv_interval($t,[gettimeofday]),"\n";
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
81 $t = [gettimeofday];
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
82 print $_->Message,"\n" foreach $this->schemaDoc->Validate($builder->Document);
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
83 print "Validate: ",tv_interval($t,[gettimeofday]),"\n";
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
84
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
85 return 1;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
86 };
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
87
36
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
88 test BuildSimpleDocument => sub {
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
89 my ($this) = @_;
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
90
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
91 my $builder = IMPL::DOM::Navigator::SimpleBuilder->new();
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
92
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
93 use Time::HiRes qw(gettimeofday tv_interval);
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
94
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
95 my $t = [gettimeofday];
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
96
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
97 $builder->NavigateCreate('personInfo', version => '1');
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
98 $builder->NavigateCreate('firstName')->nodeValue('Nemo');
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
99 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
100 $builder->NavigateCreate('lastName')->nodeValue('Nobel');
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
101 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
102 $builder->NavigateCreate('lastName')->nodeValue('Gardum');
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
103 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
104 for(1..100) {
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
105 $builder->NavigateCreate('address', local => 1);
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
106 $builder->NavigateCreate('street')->nodeValue('Hellroad');
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
107 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
108 $builder->NavigateCreate('line')->nodeValue($_);
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
109 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
110 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
111 }
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
112 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
113
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
114 print "Build: ",tv_interval($t,[gettimeofday]),"\n";
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
115 $t = [gettimeofday];
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
116 print $_->Message,"\n" foreach $this->schemaDoc->Validate($builder->Document);
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
117 print "Validate: ",tv_interval($t,[gettimeofday]),"\n";
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
118
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
119 $t = [gettimeofday];
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
120 for (1...100) {
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
121 my $node = new IMPL::DOM::Node(nodeName => 'dummy', foo => 'bar');
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
122 $node->nodeValue('dummy content');
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
123 }
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
124 print "Create a set of nodes: ",tv_interval($t,[gettimeofday]),"\n";
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
125
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
126 return 1;
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
127 };
1828103371d0 DOM in works
Sergey
parents: 35
diff changeset
128
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
129
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
130 1;