annotate _test/Test/DOM/Builder.pm @ 35:f25d021780b3

DOM::Navigator::Builder working version
author Sergey
date Tue, 17 Nov 2009 17:46:24 +0300
parents a8086f85a571
children 1828103371d0
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;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
13 require IMPL::DOM::Document;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
14
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
15 BEGIN {
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
16 public property schemaDoc => prop_all;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
17 }
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
18
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
19 sub CTOR {
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
20 my ($this) = @_;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
21
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
22 my $schema = new IMPL::DOM::Schema;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
23 $schema->appendRange(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
24 IMPL::DOM::Schema::ComplexNode->new( name => 'personInfo' )->appendRange(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
25 IMPL::DOM::Schema::NodeSet->new()->appendRange(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
26 new IMPL::DOM::Schema::SimpleNode( name => 'firstName' ),
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
27 new IMPL::DOM::Schema::SimpleNode( name => 'lastName' ),
35
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
28 new IMPL::DOM::Schema::ComplexNode( name => 'address', maxOccur => 'unbounded' )->appendRange(
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
29 IMPL::DOM::Schema::NodeSet->new()->appendRange(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
30 new IMPL::DOM::Schema::SimpleNode( name => 'street' ),
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
31 new IMPL::DOM::Schema::SimpleNode( name => 'line', minOccur => 0 )
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
32 )
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 $this->schemaDoc( $schema );
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
39 }
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
40
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
41 test CreateBuilder => sub {
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
42 my ($this) = @_;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
43
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
44 my $builder = IMPL::DOM::Navigator::Builder->new(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
45 new IMPL::DOM::Document(nodeName => 'personInfo'),
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
46 $this->schemaDoc
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
47 );
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
48 };
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
49
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
50 test BuildDocument => sub {
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
51 my ($this) = @_;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
52
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
53 my $builder = IMPL::DOM::Navigator::Builder->new(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
54 'IMPL::DOM::Document',
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
55 $this->schemaDoc
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
56 );
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
57
35
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
58 use Time::HiRes qw(gettimeofday tv_interval);
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
59
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
60 my $t = [gettimeofday];
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
61
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
62 $builder->NavigateCreate('personInfo', version => '1');
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
63 $builder->NavigateCreate('firstName')->nodeValue('Nemo');
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
64 $builder->Back();
35
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
65 $builder->NavigateCreate('lastName')->nodeValue('Nobel');
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
66 $builder->Back();
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
67 $builder->NavigateCreate('lastName')->nodeValue('Gardum');
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
68 $builder->Back();
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
69 for(1..100) {
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
70 $builder->NavigateCreate('address', local => 1);
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
71 $builder->NavigateCreate('street')->nodeValue('Hellroad');
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
72 $builder->Back();
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
73 $builder->NavigateCreate('line')->nodeValue($_);
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
74 $builder->Back();
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
75 $builder->Back();
35
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
76 }
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
77 $builder->Back();
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
78
35
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
79 print "Build: ",tv_interval($t,[gettimeofday]),"\n";
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
80 $t = [gettimeofday];
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
81 print $_->Message,"\n" foreach $this->schemaDoc->Validate($builder->Document);
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
82 print "Validate: ",tv_interval($t,[gettimeofday]),"\n";
f25d021780b3 DOM::Navigator::Builder working version
Sergey
parents: 34
diff changeset
83
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
84 return 1;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
85 };
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
86
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
87
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
88 1;