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