testexecfw/tef/test/tools/filecompare2.pl
changeset 0 3e07fef1e154
equal deleted inserted replaced
-1:000000000000 0:3e07fef1e154
       
     1 #
       
     2 # Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 #
       
    16 
       
    17 
       
    18 #main program starts
       
    19 my ($srcdir, $dstdir) =@ARGV;
       
    20 if (@ARGV != 2)
       
    21 {
       
    22  print ("Usage: perl filecompare2.pl <template_dir> <test_result_dir> \n");
       
    23  print ("E.g. perl filecompare2.pl d:\template d:\testresult \n");
       
    24  print ("the compare result file is located at d:\compareresult.txt \n");
       
    25  exit;
       
    26 }
       
    27 print "$srcdir \n";
       
    28 print "$dstdir \n";
       
    29 open (CompareResultFile, ">d:\\compareresult.txt") || die ("open compareresult.txt failed");
       
    30 chdir ($srcdir) || die "chdir to $srcdir faield.\n";
       
    31 my $thisdir ;
       
    32 opendir ($thisdir, $srcdir);
       
    33 my @files = readdir($thisdir);
       
    34 closedir($thisdir);
       
    35 $count =1;
       
    36 my @srcfiles;
       
    37 my @dstfiles;
       
    38 
       
    39 my $count2=1;
       
    40 while ($count < @files) 
       
    41 {
       
    42  if ( (!-d @files[$count] )&&  (@files[$count] =~/dt-tef-command-line-/)) # (@files[$count] =~/\.htm/) to select all *.htm files
       
    43  {
       
    44    @srcfiles[$count2] =$srcdir . "\\" . "@files[$count]";
       
    45    print "@srcfiles[$count] \n";
       
    46    @dstfiles[$count2] = $dstdir ."\\" . "@files[$count]";
       
    47    print "@dstfiles[$count] \n" ;
       
    48    $count2++;
       
    49  }
       
    50   $count++;
       
    51 }
       
    52 $count = 1;
       
    53 while ($count < @srcfiles)
       
    54 {
       
    55 	&filecompare(@srcfiles[$count], @dstfiles[$count]);
       
    56 	$count++;
       
    57 }
       
    58 close( CompareResultFile);
       
    59 # end of the main program
       
    60 
       
    61 sub filecompare
       
    62 {
       
    63 my($srcfile, $dstfile) = @_;
       
    64 #open (BASELINEFILE, "$srcfile") || die ("Could not open Baseline file $srcfile"); 
       
    65 #open (TERESULTFILE, "$dstfile") || die ("Could not open Test Result file $dstfile"); 
       
    66  if ( ! -e $srcfile)
       
    67  {
       
    68    print  ("$srcfile does not exist \n");
       
    69    print CompareResultFile ("$srcfile does not exist \n");
       
    70    return;
       
    71  }
       
    72  elsif ( !-e $dstfile)
       
    73  {
       
    74   print ("$dstfile does not exist \n");
       
    75     print CompareResultFile ("$dstfile does not exist \n");
       
    76   return;
       
    77  } 
       
    78  if (open (BASELINEFILE, "$srcfile") && open (TERESULTFILE, "$dstfile") )
       
    79  {
       
    80 	my @baselinearray = <BASELINEFILE>;
       
    81 	my @testresultarray = <TERESULTFILE>;
       
    82 	my $MisMatchNum = 0;
       
    83 	close (BASELINEFILE);
       
    84 	close(TERESULTFILE);
       
    85 	my $linecount = 1; 
       
    86 	my $BaselineRowContent;
       
    87 	my $BaselineRowContentChop;
       
    88 	my $TestresultRowContent;
       
    89 	my $TestresultRowContentChop;
       
    90 	my $choplength = 25; # the first 26 characters contains time information and thread no which change every run.
       
    91     my $flag = 0;        
       
    92 		
       
    93 	while ($linecount <= @baselinearray) 
       
    94 	  {
       
    95 		  $BaselineRowContent =  lc(@baselinearray[$linecount-1]);
       
    96 		  $TestresultRowContent = lc(@testresultarray[$linecount-1]);
       
    97 		 
       
    98 		  if ($flag) # onlly the line after the "TestExecute Started " are to be compared, before that line are report title
       
    99 		  {
       
   100 			  $BaselineRowContentChop = $BaselineRowContent;
       
   101 			  $TestresultRowContentChop = $TestresultRowContent;
       
   102 		     
       
   103 			  substr ($BaselineRowContentChop,0,$choplength)="";
       
   104 			  substr ($TestresultRowContentChop,0,$choplength)="";
       
   105 			
       
   106 			   if ($BaselineRowContentChop ne $TestresultRowContentChop)
       
   107 			   { 
       
   108 					print ("$srcfile line $linecount does not match \n");
       
   109 					print CompareResultFile ("$srcfile line $linecount does not match \n");
       
   110 					$MisMatchNum++;
       
   111 			   }
       
   112 			   else #if two lines match
       
   113 			   {
       
   114 			    # comment the below because they print too much information, they can be uncommented when debugging
       
   115 				#print ("$srcfile line $linecount match \n");
       
   116 				#print CompareResultFile (" $srcfile line $linecount match \n");
       
   117 				#print CompareResultFile ("  $srcfile:    line $linecount: $BaselineRowContentChop \n");
       
   118 				#print CompareResultFile ("  $dstfile:    line $linecount: $TestresultRowContentChop \n");
       
   119 			   }
       
   120 			}
       
   121 			else
       
   122 			{
       
   123 			  if ( $BaselineRowContent =~/TestExecute Started/i)  # set flag if it meets the line containing "TestExecute Started " , the lines after that line are to be compared, before that line are report title
       
   124 			  {
       
   125 			   $flag++;
       
   126 			  # print "the flag is: $flag \n";
       
   127 			  	   
       
   128 			  }
       
   129 			}
       
   130 		  $linecount++;
       
   131 	  
       
   132 	  }
       
   133 	  if ($MisMatchNum == 0)
       
   134 	  {
       
   135 	    print ("$srcfile and $dstfile match \n");
       
   136 		print CompareResultFile (" $srcfile and $dstfile match \n");
       
   137 	  }
       
   138   }
       
   139   else
       
   140    {
       
   141      print ("$srcfile or $dstfile can not open \n");
       
   142 	 print CompareResultFile ("$srcfile or $dstfile can not open \n");
       
   143 	 close (BASELINEFILE);
       
   144 	 close(TERESULTFILE);
       
   145    }
       
   146 
       
   147 }