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