!******************************************************************************!
! Test swapping a template in LIST2 using .tbl files
!
! @bug      2602 LIST2: doesn't support using .tbl files when swapping templates
! @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 "Press the buttons below to swap the LIST2 template between &
                      RED text and BLUE TEXT."

    call setupTemplateFiles
    res curCol RED
    set curFile "test_tmpl_red.tbl"

    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

      list2/id=list1 ^{datDir}.testxy3000.prm template=curFile
      
      gcontrol button buttMess "" "Swap Template via Message" 
      gcontrol button buttSet ""  "Swap via setTemplate()"
      !gcontrol button buttUpd ""  "Swap via updateTemplate()"  ! Does not override
      
      
    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
    erase test_tmpl_red.tbl
    pipe stop
    
  elseif msg.name eqs "BUTTMESS" then
    call updateVars
    message send list1 name="OPENTEMPLATE" data=curFile
  elseif msg.name eqs "BUTTSET" then
    call updateVars
    set reg.list1.settemplate curFile
  elseif msg.name eqs "BUTTUPD" then
    !call updateVars
    !invoke ,, reg.list1.updateTemplate(curFile)
    
  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

!******************************************************************************!
! Setup the .tbl files to be used as templates
!******************************************************************************!
procedure setupTemplateFiles
  table {ORD={BGCOLOR=BLUE},ABSC={FGCOLOR=BLUE,FORMAT="#"}} save test_tmpl_blue.tbl  
  table {ORD={BGCOLOR=RED},ABSC={FGCOLOR=RED,FORMAT="#"}} save test_tmpl_red.tbl  
return

!******************************************************************************!
! Change the current color and file expected
!******************************************************************************!
procedure updateVars
  if curCol eqs "RED" then
    set curCol BLUE
    set curFile "test_tmpl_blue.tbl"
  else 
    set curCol RED
    set curFile "test_tmpl_red.tbl"
  endif
return