bintools/rcomp/tsrc/localisation/epocrctest.pl
changeset 0 044383f39525
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 #
       
     2 # Copyright (c) 2000-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 the License "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 use strict;
       
    18 use warnings;
       
    19 use Cwd;		# for cwd
       
    20 use FindBin;		# for FindBin::Bin
       
    21 use File::Copy;		# for copy()
       
    22 
       
    23 my $curdrive="x";	    	# will be initialised when first needed
       
    24 my $PerlBinPath;	# fully qualified pathname of the directory containing this script
       
    25 
       
    26 # establish the path to the Perl binaries
       
    27 BEGIN {
       
    28 	require 5.005_03;		# check user has a version of perl that will cope
       
    29 	$PerlBinPath = $FindBin::Bin;	# X:/epoc32/tools
       
    30 	$PerlBinPath =~ s/\//\\/g;	# X:\epoc32\tools
       
    31 }
       
    32 use lib $PerlBinPath;
       
    33 
       
    34 print "$PerlBinPath\n";
       
    35 
       
    36 open EPOCRC_INPUT, "epocrc_input.txt";
       
    37 if(!(-d "test-data"))
       
    38 {
       
    39 	mkdir("test-data") || die "Cannot mkdir test-data: $!";
       
    40 }
       
    41 my $file_line;
       
    42 my $state = 0;
       
    43 my $line_number = 0;
       
    44 my $rss_number="";
       
    45 my $expected_stdout_file = "";
       
    46 my $expected_stderr_file = "";
       
    47 my $rls_file;
       
    48 my $rss_file;
       
    49 my @extra_args;
       
    50 
       
    51 while($file_line = <EPOCRC_INPUT>)
       
    52 {
       
    53 	$line_number++;
       
    54 	if($state == 0)
       
    55 	{
       
    56 		if($file_line=~/^\s*\+\+\+\+\s*$/)
       
    57 		{ $state = 1;	next; 
       
    58 		}
       
    59 		elsif($file_line=~/^\s*$/)
       
    60 		{ next; # do nothing as blank line
       
    61 		}
       
    62 		else 
       
    63 		{ 	print "Error on line number $line_number.\n";
       
    64 			exit(1); 
       
    65 		}
       
    66 	}
       
    67 	if($state == 1)
       
    68 	{
       
    69 		if($file_line=~/^\s*\*{4}Number:\s*(\d+)\s*$/)
       
    70 		{ $state = 2;	
       
    71 			$rss_number = "$1";
       
    72 			if(!(-d  "$PerlBinPath\\test-data\\$rss_number"))
       
    73 			{
       
    74 				mkdir "$PerlBinPath\\test-data\\$rss_number";
       
    75 			}
       
    76 			next; 
       
    77 		}
       
    78 		elsif($file_line=~/^\s*$/)
       
    79 		{ next; # do nothing as blank line
       
    80 		}
       
    81 		else 
       
    82 		{ 	print "Error on line number $line_number.\n";
       
    83 			exit(1);
       
    84 		}
       
    85 	}
       
    86 	if($state == 2)
       
    87 	{
       
    88 		if($file_line=~/^\s*\*{4}Extra args:(.*)$/)
       
    89 		{	
       
    90 			$state = 3;
       
    91 			if($1 ne "")
       
    92 			{
       
    93 				push @extra_args, $1;
       
    94 			}
       
    95 			else
       
    96 			{
       
    97 				push @extra_args, "";
       
    98 			}
       
    99 			next;
       
   100 		}
       
   101 	}
       
   102 	if($state == 3)
       
   103 	{
       
   104 		if($file_line=~/^\s*\*{4}Expected stdout:\s*$/)
       
   105 		{ 
       
   106 			$state = 4;
       
   107 			close RLS_FILE;
       
   108 			$expected_stdout_file = "$PerlBinPath\\test-data\\$rss_number\\expected.stdout";
       
   109 			open STDOUT_FILE, ">$expected_stdout_file";
       
   110 			next; 
       
   111 		}
       
   112 		elsif($file_line=~/^\s*$/)
       
   113 		{ 
       
   114 			next; # do nothing as blank line
       
   115 		}
       
   116 		else 
       
   117 		{ 	
       
   118 			print "Error on line number $line_number.\n";
       
   119 			exit(1);
       
   120 		}
       
   121 	}
       
   122 	if($state == 4)
       
   123 	{
       
   124 		if($file_line=~/^\s*\*{4}Expected stderr:\s*$/)
       
   125 		{ $state = 5;	
       
   126 			close STDOUT_FILE;
       
   127 			$expected_stderr_file = "$PerlBinPath\\test-data\\$rss_number\\expected.stderr";
       
   128 			open STDERR_FILE, ">$expected_stderr_file";
       
   129 			next; 
       
   130 		}
       
   131 		else 
       
   132 		{ print STDOUT_FILE $file_line;
       
   133 		}
       
   134 	}
       
   135 	if($state == 5)
       
   136 	{
       
   137 		if($file_line=~/^\s*\*{4}rss data:\s*$/)
       
   138 		{ $state = 6;	
       
   139 			close STDERR_FILE;
       
   140 			$rss_file = "$PerlBinPath\\test-data\\$rss_number\\test$rss_number\.rss";
       
   141 			open RSS_FILE, ">$rss_file";
       
   142 			next; 
       
   143 		}
       
   144 		else 
       
   145 		{ print STDERR_FILE $file_line;
       
   146 		}
       
   147 	}
       
   148 	if($state == 6)
       
   149 	{
       
   150 		if($file_line=~/^\s*\*{4}rls data:\s*$/)
       
   151 		{ $state = 7;	
       
   152 			close RSS_FILE;
       
   153 			$rls_file = "$PerlBinPath\\test-data\\$rss_number\\test$rss_number\.rls";
       
   154 			open RLS_FILE, ">$rls_file";
       
   155 			next; 
       
   156 		}
       
   157 		else 
       
   158 		{ print RSS_FILE $file_line;
       
   159 		}
       
   160 	}	
       
   161 	if($state == 7)
       
   162 	{
       
   163 		if($file_line=~/^\s*----\s*$/)
       
   164 		{ $state = 0;	
       
   165 			close RLS_FILE;
       
   166 			next; 
       
   167 		}
       
   168 		else 
       
   169 		{ print RLS_FILE $file_line;
       
   170 		}
       
   171 	}
       
   172 }
       
   173 close RLS_FILE;
       
   174 
       
   175 
       
   176 
       
   177 if($state)
       
   178 { 
       
   179 	print "Error: end of file reached while still processing.\n";
       
   180 	exit(1);
       
   181 }
       
   182 
       
   183 my $test_directory = "$PerlBinPath\\test-data\\";
       
   184 my $rsc_directory = "$PerlBinPath\\rsc-files\\";
       
   185 
       
   186 print $test_directory . "\n";
       
   187 my $epocrc = "";
       
   188 opendir DH, $test_directory or die "Couldn't open the test directory: $!";
       
   189 my $folder;
       
   190 while ($folder = readdir(DH))
       
   191 {
       
   192 	if($folder ne "\." && $folder ne "\.\.")
       
   193 	{
       
   194 		print "\n---$folder---\n";
       
   195 		my $this_test_dir = "$test_directory$folder\\";
       
   196 		my $test_name = $this_test_dir. "test$folder.rss";
       
   197 		my $rcomp = "rcomp";
       
   198 
       
   199 		if(!(-e $test_name))
       
   200 		{
       
   201 			print "Skipping $test_name, cannot find file.\n";
       
   202 		}
       
   203 		else
       
   204 		{
       
   205 			my $file_line;	
       
   206 			open EPOCRC_TEST, ">epocrc.test";
       
   207 			print EPOCRC_TEST "RCOMP: $rcomp\n";
       
   208 			print EPOCRC_TEST "TEST-NUMBER: $folder\n";
       
   209 			print EPOCRC_TEST "TEST-DIR: $this_test_dir\n";
       
   210 			close EPOCRC_TEST;
       
   211 			$epocrc = "epocrc $test_name -o$this_test_dir" . "test$folder\.rsc -h$this_test_dir" . "test$folder\.rsg -t$this_test_dir -v -u -la -epocrc-test $extra_args[$folder-1]";
       
   212 			print "$epocrc\n";
       
   213 			system($epocrc);
       
   214 		}
       
   215 	}
       
   216 }
       
   217 
       
   218 	
       
   219 # this stage will compare the stderr files of each test to check the output is as expected.
       
   220 # empty lines are ignored but the order in which the errors occur are kept to as these should be the same
       
   221 # in both files.
       
   222 opendir DH, $test_directory or die "Couldn't open the test directory: $!";
       
   223 print "\n\nComparing stderr files\n\n";
       
   224 while ($folder = readdir(DH))
       
   225 {
       
   226 	if($folder ne "\." && $folder ne "\.\.")
       
   227 	{
       
   228 		print "\n---$folder---\n";
       
   229 		my $this_test_dir = "$test_directory$folder\\";
       
   230 		if(!(-e $this_test_dir . "expected.stderr"))
       
   231 		{
       
   232 			print "Could not find " . $this_test_dir . "expected.stderr\n";
       
   233 			next;
       
   234 		}
       
   235 		if(!(-e $this_test_dir . "rcomp.stderr"))
       
   236 		{
       
   237 			print "Could not find " . $this_test_dir . "rcomp.stderr\n";
       
   238 			next;
       
   239 		}	
       
   240 
       
   241 		# read in the lines from the expected output ignoring whitespace only lines
       
   242 		my @expected_values;
       
   243 		my $file_line;
       
   244 		open EXPECTED, $this_test_dir . "expected.stderr";
       
   245 		while($file_line = <EXPECTED>)
       
   246 		{
       
   247 			if($file_line!~/^\s*$/)
       
   248 			{
       
   249 				push @expected_values, $file_line;
       
   250 			}
       
   251 		}
       
   252 		close EXPECTED;
       
   253 
       
   254 		# read in the lines from the actual output ignoring whitespace only lines
       
   255 		my @actual_values;
       
   256 		open ACTUAL, $this_test_dir . "rcomp.stderr";
       
   257 		while($file_line = <ACTUAL>)
       
   258 		{
       
   259 			if($file_line!~/^\s*$/)
       
   260 			{
       
   261 				push @actual_values, $file_line;
       
   262 			}
       
   263 		}
       
   264 		close ACTUAL;
       
   265 
       
   266 		if((scalar @expected_values) != (scalar @actual_values))
       
   267 		{
       
   268 			print "In " . $this_test_dir . ", actual and expected stderr have different sizes\n";
       
   269 			next;
       
   270 		}
       
   271 		my $expected_file;
       
   272 		my $expected_line_number;
       
   273 		my $expected_type;
       
   274 		my $expected_warning_number;
       
   275 		my $expected_non_loc_warning;
       
   276 		my $actual_file;
       
   277 		my $actual_line_number;
       
   278 		my $actual_type;
       
   279 		my $actual_warning_number;
       
   280 		my $actual_non_loc_warning;
       
   281 
       
   282 		for( my $i = 0 ; $i < scalar @expected_values ; $i++)
       
   283 		{
       
   284 			$expected_file = "";
       
   285 			$expected_line_number = "";
       
   286 			$expected_type = "";
       
   287 			$expected_warning_number = "";
       
   288 			$expected_non_loc_warning = "";
       
   289 			$actual_file = "";
       
   290 			$actual_line_number = "";
       
   291 			$actual_type = "";
       
   292 			$actual_warning_number = "";
       
   293 			$actual_non_loc_warning = "";
       
   294 
       
   295 			if($expected_values[$i]=~/^\s*\S+(test-data\S+)\((\d+)\)\s*\:\s*(Warning:)\s*\((\d+)\).*$/)
       
   296 			{
       
   297 				$expected_file = $1;
       
   298 				$expected_line_number = $2;
       
   299 				$expected_type = $3;
       
   300 				$expected_warning_number = $4;
       
   301 			}
       
   302 			else
       
   303 			{
       
   304 				$expected_non_loc_warning = $expected_values[$i];
       
   305 			}
       
   306 			if($actual_values[$i]=~/^\s*\S+(test-data\S+)\((\d+)\)\s*\:\s*(Warning:)\s*\((\d+)\).*$/)
       
   307 			{
       
   308 				$actual_file = $1;
       
   309 				$actual_line_number = $2;
       
   310 				$actual_type = $3;
       
   311 				$actual_warning_number = $4;
       
   312 			}
       
   313 			else
       
   314 			{
       
   315 				$actual_non_loc_warning = $actual_values[$i];
       
   316 			}
       
   317 
       
   318 			if($actual_non_loc_warning ne "")
       
   319 			{
       
   320 				if(	$actual_non_loc_warning != $expected_non_loc_warning )
       
   321 				{
       
   322 					print "In " . $this_test_dir . ", $actual_non_loc_warning doesn't match $expected_non_loc_warning\n"; 
       
   323 					
       
   324 				}
       
   325 			}
       
   326 			else
       
   327 			{
       
   328 				if( $actual_file ne $expected_file)
       
   329 				{
       
   330 					print "In " . $this_test_dir . ", $expected_values[$i] doens't have a matching file name.\n"; 
       
   331 					print "Actual: $actual_file, Expected: $expected_file\n";
       
   332 				}
       
   333 				elsif( $actual_line_number != $expected_line_number )
       
   334 				{
       
   335 					print "In " . $this_test_dir . ", $expected_values[$i] doens't have a matching line number.\n"; 
       
   336 				}
       
   337 				elsif( $actual_type ne $expected_type )
       
   338 				{
       
   339 					print "In " . $this_test_dir . ", $expected_values[$i] doens't have a matching warning type.\n"; 
       
   340 				}
       
   341 				elsif( $actual_warning_number ne $expected_warning_number )
       
   342 				{
       
   343 					print "In " . $this_test_dir . ", $expected_values[$i] doens't have a matching warning number.\n"; 
       
   344 				}
       
   345 			}
       
   346 		}
       
   347 	}
       
   348 }
       
   349 
       
   350 close DH;
       
   351 
       
   352 # this stage will compare the stdout files of each test to check the output is as expected.
       
   353 # empty lines are ignored but the order in which the output occur are kept to as these should be the same
       
   354 # in both files.
       
   355 opendir DH, $test_directory or die "Couldn't open the test directory: $!";
       
   356 
       
   357 print "\n\nComparing stdout files\n\n";
       
   358 while ($folder = readdir(DH))
       
   359 {
       
   360 	if($folder ne "\." && $folder ne "\.\.")
       
   361 	{
       
   362 		print "\n---$folder---\n";
       
   363 		my $this_test_dir = "$test_directory$folder\\";
       
   364 		if(!(-e $this_test_dir . "expected.stdout"))
       
   365 		{
       
   366 			print "Could not find " . $this_test_dir . "expected.stdout\n";
       
   367 			next;
       
   368 		}
       
   369 		if(!(-e $this_test_dir . "rcomp.stdout"))
       
   370 		{
       
   371 			print "Could not find " . $this_test_dir . "rcomp.stdout\n";
       
   372 			next;
       
   373 		}	
       
   374 
       
   375 		# read in the lines from the expected output ignoring whitespace only lines
       
   376 		my @expected_values;
       
   377 		my $file_line;
       
   378 		open EXPECTED, $this_test_dir . "expected.stdout";
       
   379 		while($file_line = <EXPECTED>)
       
   380 		{
       
   381 			if($file_line=~/^uidcrc\.exe (0x\S{8}) (0x\S{8}) (0x\S{8}) .*test-data(.*)$/)
       
   382 			{
       
   383 				push @expected_values, "$1,$2,$3,$4";
       
   384 			}
       
   385 			elsif($file_line!~/^\s*$/)
       
   386 			{
       
   387 				push @expected_values, $file_line;
       
   388 			}
       
   389 		}
       
   390 		close EXPECTED;
       
   391 
       
   392 		# read in the lines from the actual output ignoring whitespace only lines
       
   393 		my @actual_values;
       
   394 		open ACTUAL, $this_test_dir . "rcomp.stdout";
       
   395 		while($file_line = <ACTUAL>)
       
   396 		{
       
   397 			if($file_line=~/^uidcrc\.exe (0x\S{8}) (0x\S{8}) (0x\S{8}) .*test-data(.*)$/)
       
   398 			{
       
   399 				push @actual_values, "$1,$2,$3,$4";
       
   400 			}
       
   401 			elsif($file_line!~/^\s*$/)
       
   402 			{
       
   403 				push @actual_values, $file_line;
       
   404 			}
       
   405 		}
       
   406 		close ACTUAL;
       
   407 
       
   408 		if((scalar @expected_values) != (scalar @actual_values))
       
   409 		{
       
   410 			print "In " . $this_test_dir . ", actual and expected stdout have different sizes\n";
       
   411 			next;
       
   412 		}
       
   413 
       
   414 		for( my $i = 0 ; $i < scalar @expected_values ; $i++)
       
   415 		{
       
   416 			if($expected_values[$i] ne $actual_values[$i])
       
   417 			{
       
   418 				print "stdout files differ\n";
       
   419 				next;
       
   420 			}
       
   421 		}
       
   422 	}
       
   423 }
       
   424 
       
   425 close DH;
       
   426 
       
   427 # this stage will compare the compiled files of each test to check the output is as expected.
       
   428 opendir DH, $test_directory or die "Couldn't open the test directory: $!";
       
   429 
       
   430 print "\n\nComparing compiled files\n\n";
       
   431 while ($folder = readdir(DH))
       
   432 {
       
   433 	if($folder ne "\." && $folder ne "\.\.")
       
   434 	{
       
   435 		print "\n---$folder---\n";
       
   436 		my $controlFile = $rsc_directory . "test$folder\.rsc";
       
   437 		my $producedFile = $test_directory . $folder . "\\test$folder\.rsc";
       
   438 		my $testOutput = `diff $controlFile $producedFile --binary -s`;
       
   439 		my $differOutput = "Binary files $controlFile and $producedFile differ\n";
       
   440 		my $identicalOutput = "Files $controlFile and $producedFile are identical\n";
       
   441 		if($testOutput eq $identicalOutput)
       
   442 		{
       
   443 			# do nothing, blank output implies success
       
   444 		}
       
   445 		elsif($testOutput eq $differOutput)
       
   446 		{
       
   447 			print "$testOutput";
       
   448 		}
       
   449 		else
       
   450 		{
       
   451 			print "Unrecognised output: $testOutput";
       
   452 		}
       
   453 	}
       
   454 }
       
   455 
       
   456 close DH;
       
   457 
       
   458 unlink "epocrc.test";