! Tests the reference to the Midas Terminal (BUG 2149)
!
! Author:  J. Bauer
!
startmacro l:number[1] l:index[1] 
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

  ! Start Interactive test section
  if interAct then
     res orig  "Macro ^index Orig  PIPE=OFF terminal = ^{this.M.terminal}"
     set s:text "Macro ^index PIPE=OFF"
     res text 
     invoke ,, shell.info("^text from SHELL.INFO")
     pipe on
       res mid "Macro ^index Piped PIPE=ON  terminal = ^{this.M.terminal}"
       set text "Macro ^index PIPE=ON"
       res text 
       invoke ,, shell.info("^text from SHELL.INFO")
     pipe off
       res done "Macro ^index Final PIPE=OFF terminal = ^{this.M.terminal}"
       set text "Macro ^index PIPE=OFF"
       res text 
       invoke ,, Shell.info("^text from SHELL.INFO")
       
     if number gt 1 then
       calc newnumber number 1 -
       calc newIndex index 1 +
       %test_terminal  ^newnumber ^newIndex /bg
     endif
       
     res after "After spawns: PIPE=OFF terminal = ^{this.M.terminal}"
  
    pipe on
      panel/msgid=MAIN/setup/controls=gc
      gcontrol label macro "MACRO"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}

      set instructions "Should see terminal references displayed."
      gcontrol text idtext  "Instructions" "^instructions" 24 3 /title

      shellgui/id=idshellgui/attach
      say "This is macro ^index"
      
      say "^orig from SAY in SHELLGUI"
      invoke ,, shell.info("^orig from SHELL.INFO in SHELLGUI")
      say "^mid from SAY in SHELLGUI"
      invoke ,, shell.info("^mid from SHELL.INFO in SHELLGUI")
      say "^done from SAY in SHELLGUI"
      invoke ,, shell.info("^done from SHELL.INFO in SHELLGUI")
      res currTerm "Macro ^index Current terminal=^{this.M.terminal}"
      say "^currTerm from SAY in SHELLGUI"
      invoke ,, shell.info("^currTerm from SHELL.INFO in SHELLGUI")
      if number gt 1 then 
        say "^after from SAY in SHELLGUI"
      endif
      
      
    pipe off
    
  endif


  
endmacro

!****************************************************************************!
! process messages for interactive tests
!****************************************************************************!
procedure processMessage m:msg
  !say "msg.name ^msg.name, data ^msg.data"

  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: Tests" msg.data eqss "PASS"
    pipe stop
  else
    say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

