tests/falsecolor_test.pl
author Axel Jacobs <axel@jaloxa.eu>
Mon, 27 Jun 2011 23:42:35 +0100
changeset 26 a9f74601ca3c
parent 22 617fa1f9ccb3
permissions -rw-r--r--
xyzimage seems to work now. Upped status to 2.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     1
#!/usr/bin/perl
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     2
17
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
     3
# falsecolor_test.pl
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
     4
# This file is part of the testsuite of the Radiance csh2perl project.
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
     5
# You may copy and modify this file as basis for other tests.
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
     6
#
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
     7
# (c) Axel Jacobs, 26 June 2011
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
     8
16
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     9
use strict;
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    10
use warnings;
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    11
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    12
my $script = "falsecolor";
20
a29baf51b980 Bug fixes in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 17
diff changeset
    13
my $csh = "../orig/$script.csh";
a29baf51b980 Bug fixes in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 17
diff changeset
    14
my $perl = "../bin/$script.perl";
16
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    15
print "script: $script\n";
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    16
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    17
use File::Temp qw/ tempdir /;
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    18
my $tmpdir = tempdir( CLEANUP => 0 );
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    19
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    20
my $img = "data/images/street-rgbe_rle_400x400.hdr";
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    21
17
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    22
# Options are arrays of [STDIN, command-line options].
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    23
# Please include the pipe symbol as part of STDIN.
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    24
# Put a leading space in front of STDIN to line up the output.
16
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    25
my @options = (
17
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    26
		["", "-ip $img"],
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    27
		["", "-ip $img -l cd/m2"],   # Label now defaults to cd/m2, not nits.
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    28
		["", "-i $img -p $img -l cd/m2"],
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    29
		["", "-ip $img -cl -l cd/m2"],
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    30
		["", "-ip $img -n 10 -l cd/m2"],
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    31
		["", "-ip $img -s 2000 -l cd/m2"],
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    32
		[" cat $img |", "-ip - -s 2000 -l cd/m2"],   # take image from STDIN.
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    33
		["", "-ip $img -lw 200 -lh 300 -l cd/m2"],   # scale is slightly higher now.
16
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    34
);
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    35
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    36
# Run old CSH and new Perl script with different options,
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    37
# compare the resulting images.
17
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    38
my $total = 0;
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    39
my $fail = 0;
16
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    40
my $index = 0;
17
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    41
my $opts;
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    42
foreach $opts (@options) {
22
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    43
	my $stdin = @$opts[0];
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    44
	my $args = @$opts[1];
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    45
	$total++;
17
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    46
22
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    47
	my $cshout = "$tmpdir/${script}_csh$index.hdr";
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    48
	my $cshcmd = "$script.csh $args > $cshout";
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    49
	print " $stdin $cshcmd\n";
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    50
	system "$stdin csh ../orig/$cshcmd";
16
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    51
22
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    52
	my $perlout = "$tmpdir/${script}_perl$index.hdr";
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    53
	my $perlcmd = "$script.pl $args > $perlout";
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    54
	print " $stdin $perlcmd\n";
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    55
	system "$stdin perl ../bin/$perlcmd";
16
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    56
22
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    57
	my $diffimg = "$tmpdir/${script}_diff$index.hdr";
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    58
	my $uval = &compare_images("$cshout", "$perlout", "$diffimg");
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    59
	if( $uval > 0 ) {
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    60
		print "      Error: Diff image $diffimg contains $uval unique values (should be one).\n";
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    61
		system "ximage $diffimg";
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    62
		$fail++;
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    63
	} else {
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    64
		print "      Ok: Images $cshout and $perlout are identical.\n";
617fa1f9ccb3 Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents: 20
diff changeset
    65
	}
16
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    66
}
17
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    67
e4ebb10e4697 Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents: 16
diff changeset
    68
print "$fail of $total tests failed.\n";
16
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    69
print "temp dir $tmpdir not removed. Please remove manually.\n";
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    70
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    71
sub compare_images() {
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    72
	my $in1 = shift;
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    73
	my $in2 = shift;
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    74
	my $out = shift;
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    75
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    76
	my $cmd = "pcomb $in1 -s -1 $in2 > $out";
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    77
	print "    $cmd\n";
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    78
	system "$cmd";
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    79
	my $unique = `pvalue -h -H -d -u $out`;
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    80
	my $unique_cnt = scalar( split( '\n', $unique ) );
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    81
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    82
	return $unique_cnt;
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    83
}
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    84
7174511d4983 Added test script for falsecolor.
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    85
#EOF