| author | Axel Jacobs <axel@jaloxa.eu> |
| Sun, 11 Dec 2011 23:02:02 +0000 | |
| changeset 33 | 02f1d30160d0 |
| parent 30 | a853d5280041 |
| permissions | -rw-r--r-- |
| 19 | 1 |
#!/usr/bin/perl |
2 |
||
3 |
# objpict_test.pl |
|
4 |
# This file is part of the testsuite of the Radiance csh2perl project. |
|
5 |
# You may copy and modify this file as basis for other tests. |
|
6 |
# |
|
7 |
# (c) Axel Jacobs, 26 June 2011 |
|
8 |
||
9 |
use strict; |
|
10 |
use warnings; |
|
11 |
||
12 |
my $script = "objpict"; |
|
13 |
my $csh = "../orig/$script.csh"; |
|
14 |
my $perl = "../bin/$script.perl"; |
|
15 |
print "script: $script\n"; |
|
16 |
||
17 |
use File::Temp qw/ tempdir /; |
|
18 |
my $tmpdir = tempdir( CLEANUP => 0 ); |
|
19 |
||
|
30
a853d5280041
Minor fiddling with objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
23
diff
changeset
|
20 |
my $objects = "data/objects/mybox.rad data/objects/anotherbox.rad"; |
| 19 | 21 |
my $material = "data/objects/objects.mat"; |
22 |
||
23 |
# Options are arrays of [STDIN, command-line options]. |
|
24 |
# Please include the pipe symbol as part of STDIN. |
|
25 |
# Put a leading space in front of STDIN to line up the output. |
|
26 |
my @options = ( |
|
|
30
a853d5280041
Minor fiddling with objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
23
diff
changeset
|
27 |
["", "$material $objects"], |
|
a853d5280041
Minor fiddling with objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
23
diff
changeset
|
28 |
[" cat $material $objects |", ""], |
| 19 | 29 |
); |
30 |
||
31 |
# Run old CSH and new Perl script with different options, |
|
32 |
# compare the resulting images. |
|
33 |
my $total = 0; |
|
34 |
my $fail = 0; |
|
35 |
my $index = 0; |
|
36 |
my $opts; |
|
37 |
foreach $opts (@options) {
|
|
|
23
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
38 |
my $stdin = @$opts[0]; |
|
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
39 |
my $args = @$opts[1]; |
|
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
40 |
$total++; |
| 19 | 41 |
|
|
23
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
42 |
my $cshout = "$tmpdir/${script}_csh$index.hdr";
|
|
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
43 |
my $cshcmd = "$script.csh $args > $cshout"; |
|
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
44 |
print " $stdin $cshcmd\n"; |
|
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
45 |
system "$stdin csh ../orig/$cshcmd"; |
| 19 | 46 |
|
|
23
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
47 |
my $perlout = "$tmpdir/${script}_perl$index.hdr";
|
|
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
48 |
my $perlcmd = "$script.pl $args > $perlout"; |
|
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
49 |
print " $stdin $perlcmd\n"; |
|
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
50 |
system "$stdin perl ../bin/$perlcmd"; |
| 19 | 51 |
|
|
23
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
52 |
my $diffimg = "$tmpdir/${script}_diff$index.hdr";
|
|
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
53 |
my $uval = &compare_images("$cshout", "$perlout", "$diffimg");
|
|
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
54 |
if( $uval > 0 ) {
|
|
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
55 |
print " Error: Diff image $diffimg contains $uval unique values (should be one).\n"; |
|
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
56 |
system "ximage $diffimg"; |
|
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
57 |
$fail++; |
|
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
58 |
} else {
|
|
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
59 |
print " Ok: Images $cshout and $perlout are identical.\n"; |
|
e0b112e25bab
Removed excessive indentation in objpict_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
19
diff
changeset
|
60 |
} |
| 19 | 61 |
} |
62 |
||
63 |
print "$fail of $total tests failed.\n"; |
|
64 |
print "temp dir $tmpdir not removed. Please remove manually.\n"; |
|
65 |
||
66 |
sub compare_images() {
|
|
67 |
my $in1 = shift; |
|
68 |
my $in2 = shift; |
|
69 |
my $out = shift; |
|
70 |
||
71 |
my $cmd = "pcomb $in1 -s -1 $in2 > $out"; |
|
72 |
print " $cmd\n"; |
|
73 |
system "$cmd"; |
|
74 |
my $unique = `pvalue -h -H -d -u $out`; |
|
75 |
my $unique_cnt = scalar( split( '\n', $unique ) ); |
|
76 |
||
77 |
return $unique_cnt; |
|
78 |
} |
|
79 |
||
80 |
#EOF |