!******************************************************************************!
! Test case for the new option mask OPENWARN that allows the user to set how
! warnings are displayed when a file can not be found/opened
!
! @bug      2867 PLOT: need to be able to suppress File not found popups
! @author:  J McCall
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE  ! for defects or more obscure test case(s)

  call setDatDir

  if interAct then
    set instructions "1) /OPENWARN=NONE testing\n\n&
                      -You should see a blank plot and a plot of the world\n\n&
                      -No POPUP or terminal Warnings\n\n&
                      Even the file can not be opened.\n\n&  
                      2) Click the'Update Plot 2' button."

    pipe on
      panel/msgid=MAIN/setup/controls=gc
      gcontrol label macro "Test MACRO"
      gcontrol menu  main "Exit with Status =" "PASS,FAIL" TABLE={ItemColors={PASS="GREEN",FAIL="RED"}} /tleft

      gcontrol text  idtext "Instructions" instructions 24 15 /title

      ! Create two plots, one blank and one not blank
      ! plot1 will give both a popup warning and a warning in the terminal when the file is not found
      ! plot2 will not warn, even thought the file will not be found 
      plot/id=plot1/openwarn=none ^{datDir}.world.prm|no_file_openwarn_set_none.prm
      plot/id=plot2/openwarn="popup"
      plot/id=plot3/openwarn="print"
      gcontrol line

      ! create the buttons to send messages
      gcontrol button updatePlot2 "" "Update Plot 2"
      gcontrol button updatePlot3 "" "Update Plot 3"

    pipe off

  endif
endmacro

!******************************************************************************!
! Main process message for this macro. Should be right after the ENDMACRO.
!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop

  elseif msg.name eqs "UPDATEPLOT2" then
    message send plot2 name="OPENFILE" data=^{datDir}.world.prm|no_file_openwarn_set_popup_print2.prm info=0
    call set_instr2
  elseif msg.name eqs "UPDATEPLOT3" then
    info "A Warning for file not found should appear below this line"
    message send plot3 name="OPENFILE" data=^{datDir}.world.prm|no_file_openwarn_set_popup_print3.prm info=0
    call set_instr3
  else
    say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
! If an unexpected exception is caught, mark test as failed, unless it is expected
!******************************************************************************!
procedure processException m:emsg
  if expectedException REXISTS then
    assert/text="^reg.main.name: Expected ERROR starts with: ^{expectedException}" expectedException EQSS emsg.data.message
    remove expectedException
  else
    assert/text="^reg.main.name: Caught unexpected exception ^{emsg.data}" "FALSE" isTrue
    if "Trace" SUBS ENV.DEBUG then invoke ,, emsg.data.printStackTrace()
  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

!****************************************************************************************************
! Set the second set of instructions
!****************************************************************************************************
procedure set_instr2

  set str "3) /OPENWARN=POPUP testing\n\n&
           -You should see a blank plot and a plot of the world\n&
           -A POPUP WARNING but no terminal Warnings\n\n&
           4) Click the'Update Plot 3' button."
  set gc.idtext.value "^str"

return
!****************************************************************************************************
! Set the third set of instructions
!****************************************************************************************************
procedure set_instr3

  set str "5) /OPENWARN=PRINT testing\n\n&
            There should now be a warning in the TERMINAL saying:\n&
            'File no_file_openwarn_set_popup_print3.prm not found'\n\n&
           6) Please click PASS if everything was as described"
  set gc.idtext.value "^str"

return
