diff _test/Test/DOM/Builder.pm @ 37:c2e7f7c96bcd

performance improvements, DOM reworked (a little)
author Sergey
date Mon, 23 Nov 2009 00:59:06 +0300
parents 1828103371d0
children 16ada169ca75
line wrap: on
line diff
--- a/_test/Test/DOM/Builder.pm	Fri Nov 20 16:48:08 2009 +0300
+++ b/_test/Test/DOM/Builder.pm	Mon Nov 23 00:59:06 2009 +0300
@@ -12,6 +12,7 @@
 require IMPL::DOM::Navigator::Builder;
 require IMPL::DOM::Navigator::SimpleBuilder;
 require IMPL::DOM::Document;
+require IMPL::DOM::XMLReader;
 
 BEGIN {
     public property schemaDoc => prop_all;
@@ -56,18 +57,12 @@
         $this->schemaDoc
     );
     
-    use Time::HiRes qw(gettimeofday tv_interval);
-    
-    my $t = [gettimeofday];
-    
     $builder->NavigateCreate('personInfo', version => '1');
         $builder->NavigateCreate('firstName')->nodeValue('Nemo');
         $builder->Back();
         $builder->NavigateCreate('lastName')->nodeValue('Nobel');
         $builder->Back();
-        $builder->NavigateCreate('lastName')->nodeValue('Gardum');
-        $builder->Back();
-        for(1..100) {
+        for(1..10) {
             $builder->NavigateCreate('address', local => 1);
                 $builder->NavigateCreate('street')->nodeValue('Hellroad');
                 $builder->Back();
@@ -77,10 +72,8 @@
         }
     $builder->Back();
     
-    print "Build: ",tv_interval($t,[gettimeofday]),"\n";
-    $t = [gettimeofday];
-    print $_->Message,"\n" foreach $this->schemaDoc->Validate($builder->Document);
-    print "Validate: ",tv_interval($t,[gettimeofday]),"\n";
+    my @errors = $this->schemaDoc->Validate($builder->Document);
+    failed ("The built document doesn't pass a validation",@errors) if @errors;
     
     return 1;
 };
@@ -90,18 +83,12 @@
     
     my $builder = IMPL::DOM::Navigator::SimpleBuilder->new();
     
-    use Time::HiRes qw(gettimeofday tv_interval);
-    
-    my $t = [gettimeofday];
-    
     $builder->NavigateCreate('personInfo', version => '1');
         $builder->NavigateCreate('firstName')->nodeValue('Nemo');
         $builder->Back();
         $builder->NavigateCreate('lastName')->nodeValue('Nobel');
         $builder->Back();
-        $builder->NavigateCreate('lastName')->nodeValue('Gardum');
-        $builder->Back();
-        for(1..100) {
+        for(1..10) {
             $builder->NavigateCreate('address', local => 1);
                 $builder->NavigateCreate('street')->nodeValue('Hellroad');
                 $builder->Back();
@@ -111,20 +98,28 @@
         }
     $builder->Back();
     
-    print "Build: ",tv_interval($t,[gettimeofday]),"\n";
-    $t = [gettimeofday];
-    print $_->Message,"\n" foreach $this->schemaDoc->Validate($builder->Document);
-    print "Validate: ",tv_interval($t,[gettimeofday]),"\n";
-    
-    $t = [gettimeofday];
-    for (1...100) {
-        my $node = new IMPL::DOM::Node(nodeName => 'dummy', foo => 'bar');
-        $node->nodeValue('dummy content');
-    }
-    print "Create a set of nodes: ",tv_interval($t,[gettimeofday]),"\n";
+    my @errors = $this->schemaDoc->Validate($builder->Document);
+    failed ("The built document doesn't pass a validation",@errors) if @errors;
     
     return 1;
 };
 
+test BuildDocumentFromXml => sub {
+    my ($this) = @_;
+    
+    my $builder = IMPL::DOM::Navigator::SimpleBuilder->new();
+    my $reader = IMPL::DOM::XMLReader->new( Navigator => $builder );
+    
+    $reader->ParseFile("Resources/person_info.xml");
+    
+    my $doc = $builder->Document() or failed("No document was constrcuted");
+    
+    my @errors = $this->schemaDoc->Validate($doc);
+    failed("The document isn't correct", @errors) if @errors;
+    my $name = ($doc->selectNodes("firstName"))[0]->nodeValue;
+    failed("The firstName has a wrong value", "Expected: Norman", "Got: $name") unless $name eq "Norman";
+    
+};
+
 
 1;