!******************************************************************************!
! Test extra errors thrown by LIST2 OPENTEMPLATE
!
! @bug      2639 LIST2: Deceptive Error Messages 
! @author:  J Bauer
!******************************************************************************!
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 "You should see a blank pane and a Shellgui.\n\n&
                      Push the SWAP button repeatedly.\n\n&
                      A LIST2 should appear. You should not see any stack traces."
    
    call setupFiles
    
    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 8 /title
      
      gcontrol button myButt "UPDATE LIST2" "SWAP" 
      
      list2/id=list1 
      shellgui/id=idshellgui/attach
      
      !set this.timer(0) 1   ! give things a second to settle
      
    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"
    erase test_tmpl_blue.tbl test_tmpl_red.tbl
    pipe stop
  
  else
    say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^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

!******************************************************************************!
! This should override ProcessMessage Procedure for the 'TIMER' message
!******************************************************************************!
procedure processTimerMessage m:msg
   set this.timer(0) 0.0   ! turn off the timer
   do count 1 10 1
     call swapFiles
     pause .25
   enddo
   erase test_tmpl_blue.tbl test_tmpl_red.tbl
   !pipe stop
return
!******************************************************************************!
! This should override ProcessMessage Procedure for the 'MYBUTT' message
!******************************************************************************!
procedure processMyButtMessage m:msg
   call swapFiles
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

!******************************************************************************!
! Swap out the file and templae being used by the LIST2 via messages
!******************************************************************************!
procedure swapFiles
  if currFile eqs "^{datDir}.testxy3000.prm" then
    set currFile "^{datDir}.test3000.prm"
    set currTempl "test_tmpl_red.tbl"
  else 
    set currFile "^{datDir}.testxy3000.prm" 
    set currTempl "test_tmpl_blue.tbl" 
  endif
  
  message func=send id=list1 name="OPENFILE" data="^currFile"
  message func=send id=list1 name="OPENTEMPLATE" data=currTempl  

return

!******************************************************************************!
! Setup the files and templates being used by the LIST2 
!******************************************************************************!
procedure setupFiles
    ! create the templates
    table {_GLOBAL_={TYPE="LIST2",LABELS="COL",GRID="OFF",AUTOHIDE="OFF"},ORD={BGCOLOR=BLUE},ABSC={FGCOLOR=BLUE,FORMAT="#"}} save test_tmpl_blue.tbl 
    table {INPU={BGCOLOR=RED,FGCOLOR="BLUE"},CONN={FGCOLOR=RED}} save test_tmpl_red.tbl 
    
    ! Set the current values to be used by the LIST2
    res currFile "^{datDir}.testxy3000.prm" 
    res currTempl "test_tmpl_blue.tbl" 

return