startmacro
!
! Test for plotting image files (LayerImage)
!
! @bug     1546 LayerImage does not close resources (problem currently only
!               surfaces under Windows platforms)
! @bug     1854 PLOT: ImageFile x/y start and x/y delta qualifier override
! @bug     2196 Invert colors for LayerImage
! @author  Neon Ngo
!
  switch INTERACTIVE interAct GET DEF=TRUE SDEF=TRUE

  call setDatDir

  ! test case for Bug 1854 ImageFile x/y start and x/y delta qualifier override
  set xstart 10
  set ystart 20
  set xdelta .3
  set ydelta .4
  status ^{datDir}.Sunset.jpg{xs=^xstart,ys=^ystart,xd=^xdelta,yd=^ydelta} xstart=xs ystart=ys xdelta=xd ydelta=yd
  assert/text="ImageFile xstart qualifier override" xstart eq xs
  assert/text="ImageFile ystart qualifier override" ystart eq ys
  assert/text="ImageFile xdelta qualifier override" xdelta eq xd
  assert/text="ImageFile ydelta qualifier override" ydelta eq yd

  ! NTN: current test scenario for Bug 1546 is "non-interactive, but uses graphics,
  !      so allow tester to disable running test via the /interactive switch
  if interAct then
    ! file should not be saved to RAM AUX otherwise it won't show problem under Windows
    result imagefile "test_plot_layerimage.jpg"
    fname/parse imagefile name=layername
    file copy/f ^{datDir}.Sunset.jpg ^imagefile

    plot/id=idplot/bg ^imagefile

    ! test scenario (close image file layer, try to erase file, verify it has been deleted)
    message func=sendw id=idplot name=closefile data=^layername
    erase/all ^imagefile
    assert/text="BUG 1546: LayerImage does not close resource" ^imagefile NFEXISTS

    set xstart 10
    set ystart 20
    set xdelta .03
    set ydelta .04
    plot/id=idmap/bg ^{datDir}.world|^{datDir}.Sunset.jpg{xs=^xstart,ys=^ystart,xd=^xdelta,yd=^ydelta}
    pause 0.3
    assert/text="ImageFile on Map: xstart  override" xstart eq reg.idmap.layers.sunset.xs
    assert/text="ImageFile on Map: ystart  override" ystart eq reg.idmap.layers.sunset.ys
    assert/text="ImageFile on Map: xdelta  override" xdelta eq reg.idmap.layers.sunset.xdelta
    assert/text="ImageFile on Map: ydelta  override" ydelta eq reg.idmap.layers.sunset.ydelta

    message func=sendw id=idplot name=exit
    message func=sendw id=idmap name=exit
  endif

  ! NTN interactive portion of test case
  if interAct then
    pipe on
      panel/controls=gc/setup
      gcontrol label  macro   "MACRO"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}
      set instructions "Select invert colors for both images to see the respective layer's &
                        color get inverted (similar to a photographic negative effect). &
                        Invert again to get back to original colors."

      gcontrol text idtext "Instructions" "^instructions" 24 10 /title
      gcontrol button invertBtn "Invert Colors for" "SUNSET,ICON56"

      status ^{datDir}.Sunset.jpg xdelta=xd ydelta=yd
      
      ! /all added in 3.3.3 for Bug 2748
      plot/id=idplot/all ^{datDir}.Sunset.jpg|nxm.sys.test.icon56.png{xs=0.5,ys=-0.5,xd=xd*4,yd=yd*4}
    pipe off
  endif
endmacro

!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: user indicated" msg.data eqss "PASS"
    pipe stop

  elseif msg.name eqs "invertBtn" then
    ! test for Bug 2196 invert colors in a layer
    invoke ,, reg.idplot.layers.^{msg.data}.invertColorMap()
  else
    ! do nothing
    say "Unhandled message name: ^msg.name from fid: ^msg.fid dats: ^msg.data"
  endif

return

!******************************************************************************!
! Set the dat directory
!******************************************************************************!
procedure setDatDir
  invoke nxmMajor env.nmversion.subString(0,1)
  invoke major java.lang.Integer.valueOf(nxmMajor)
  if major GE 4 then
    invoke s:datDir           nxm.sys.test.DatLocator.getDatDirLocation()
    invoke s:datDirSlash      nxm.sys.test.DatLocator.getDatDirSlashLocation()
    invoke z:sysDatFull       nxm.sys.test.DatLocator.sysDatFull()
    invoke z:sysTestDatExists nxm.sys.test.DatLocator.sysTestDatExists()
  else
    set s:datDir           "nxm.sys.dat"
    set s:datDirSlash      "nxm/sys/dat"
    set z:sysDatFull       true
    set z:sysTestDatExists false
  endif
return
