1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
BEGIN{
# Set perl to not try to resolve all symbols at startup
# The default behavior causes some problems because
# the PGPLOT code defines interfaces for all PGPLOT functions
# whether or not they are linked.
$ENV{'PERL_DL_NONLAZY'}=0;
}
use strict;
use warnings;
use Test::More;
use PGPLOT;
BEGIN {
eval {require PDL};
plan skip_all => "No PDL, can't test this ($@)" if $@;
plan skip_all => "DISPLAY environment variable not set"
if !exists $ENV{'DISPLAY'} and !exists $ENV{HARNESS_ACTIVE};
}
use PDL;
use PDL::Graphics::PGPLOT;
use PDL::Graphics::PGPLOT::Window;
sub get_answer () {
print STDERR "Does this look OK (y/n, y is default)? :";
my $answer = <STDIN>;
return $answer !~ m/n/i;
}
my $tick_txt = <<'EOD';
PGPLOT X device... you should see a 6 inch (153 mm) x 4 inch (102 mm)
X window with four plots in it. All four images should have tick marks
on the outside of the axes.
[ Scaled image of m51; scale [Scaled image of m51 with scale from
in pixels on both axes ] X=[-1.8, 2.0],Y=[-1.9, 1.9] arcmin,
with cal. wedge, centered in rect. frame]
[ Square image of m51; scale [Square image of m51 with scale as above,
in pixels on both axes; ``shrink-wrapped'']
``shrinkwrapped'' ]
EOD
my $pitch_txt = <<'EOD';
==============================================================
You should see four plots demonstrating pitch setting, justification,
and alignment:
[ Square image of m51 scaled to [Short, squat image of m51 with
300 ppi (1.25 inches wide), aligned aspect ratio 1:2, width 1.25 inch,
to bottom left corner of rect. plot and height 0.625 inch, shrinkwrapped
box and cropped at the top. ] and placed at lower left of plot rgn]
[ Square image of m51 scaled to [Tall, narrow image of m51 with
300 ppi (1.25 inches wide), aligned aspect ratio 2:1, width 0.625 inch,
to upper right corner of rect. plot and height 1.25 inch, shrinkwrapped
box and cropped at the bottom. ] and placed at upper right of plot rgn]
EOD
my $fib_txt = <<'EOD';
==============================================================
You should see two windows:
One with two graphs, left with Fibonacci curve
One with one graph
EOD
sub interactive ($$) {
my $flag = shift;
return unless $flag; # ie not interactive
my $num = shift;
if (1 == $num) {
print STDERR $tick_txt;
} elsif (2 == $num) {
print STDERR $pitch_txt;
} elsif (3 == $num) {
print STDERR $fib_txt;
} else {
die "Internal error: unknown test number $num for interactive()!\n";
}
return get_answer();
}
my $interactive = exists($ENV{'PDL_INT'});
my $skip_interactive_msg = "no interactive tests as env var PDL_INT not set";
my $interactive_ctr = 0;
my $dev = $ENV{'PGPLOT_DEV'} || "/xw";
$dev = '/null' if exists $ENV{HARNESS_ACTIVE} and not $interactive;
my $w = PDL::Graphics::PGPLOT::Window->new(
Dev => $dev,
Size=> [6,4],
NX=>2, NY=>2,
Ch=>2.5, HardCH=>2.5
);
isa_ok($w, "PDL::Graphics::PGPLOT::Window");
# try and find m51.fits
my @f = qw(PDL Demos m51.fits);
our $m51file = undef;
foreach my $path ( @INC ) {
my $file = File::Spec->catfile( $path, @f );
if ( -f $file ) { $m51file = $file; last; }
}
die "Unable to find m51.fits within the perl libraries.\n"
unless defined $m51file;
my $x = rfits($m51file);
##############################
# Page 1
#
foreach my $str (
'$w->imag($x,{Title=>"\$w->imag(\$x);"} );',
'$w->fits_imag($x,{Title=>"\$w->fits_imag(\$x);"});',
'$w->imag($x,{J=>1,Title=>"\$w->imag(\$x,{J=>1});"});',
'$w->fits_imag($x,{J=>1,Title=>"\$w->fits_imag(\$x,{J=>1});"});'
) {
my $result = eval $str;
is $@, '', "eval '$str'";
isnt $result, 0, 'returned true';
}
$interactive_ctr++;
SKIP: {
skip $skip_interactive_msg, 1 unless $interactive;
ok(interactive($interactive, $interactive_ctr), "interactive tests");
}
##############################
# Page 2
#
foreach my $str ( (
'$w->imag($x,{Pitch=>300,Align=>"LB",Title=>"\$w->imag(\$x,{Pitch=>300,Align=>LB})"});',
'$w->imag($x,{J=>.5,Pitch=>300,Align=>"LB",Title=>"\$w->imag(\$x,{J=>.5,Pitch=>300,Align=>LB})"});',
'$w->imag($x,{Pitch=>300,Align=>"RT",Title=>"\$w->imag(\$x,{Pitch=>300,Align=>RT})"});',
'$w->imag($x,{J=>2,Pitch=>600,Align=>"RT",Title=>"\$w->imag(\$x,{J=>2,Pitch=>600,Align=>RT}) ."});',
) ) {
my $result = eval $str;
is $@, '', "eval '$str'";
isnt $result, 0, 'returned true';
}
$interactive_ctr++;
SKIP: {
skip $skip_interactive_msg, 1 unless $interactive;
ok(interactive($interactive, $interactive_ctr), "interactive tests");
}
my $result = eval '$w->close';
is $@, '', "close window";
isnt $result, 0, 'returned true';
my @opts = (Device => $dev, Aspect => 1, WindowWidth => 5);
my $rate_win = PDL::Graphics::PGPLOT::Window->new(@opts, NXPanel => 2);
my $area_win = PDL::Graphics::PGPLOT::Window->new(@opts);
isa_ok($rate_win, "PDL::Graphics::PGPLOT::Window");
isa_ok($area_win, "PDL::Graphics::PGPLOT::Window");
foreach my $str ( (
q($rate_win->env(0, 10, 0, 1000, {XTitle => 'Days', YTitle => '#Rabbits'})),
q($rate_win->env(0, 10, 0, 100, {Xtitle=>'Days', Ytitle => 'Rabbits/day'})),
q($area_win->env(0, 1, 0, 1, {XTitle => 'Km', Ytitle => 'Km'})),
q($rate_win->line(sequence(10), fibonacci(10), {Panel => [1, 1]})),
) ) {
my $result = eval $str;
is $@, '', "eval '$str'";
isnt $result, 0, 'returned true';
}
$interactive_ctr++;
SKIP: {
skip $skip_interactive_msg, 1 unless $interactive;
ok(interactive($interactive, $interactive_ctr), "interactive tests");
}
for my $win ($rate_win, $area_win) {
my $result = eval { $win->close };
is $@, '', "close window";
isnt $result, 0, 'returned true';
}
diag 'On X you need to close the X window to continue' if $interactive;
done_testing;
|