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