!------------------------------------------------------------------------------!
! Test debug with supertrace (BUG 1755).
!
! 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 test_store_restore

  set instructions &
      "Should see a stack trace for a Java Exception in the shellgui &
      that includes four lines of java code before and two lines after the Exception."

  if interAct then
    invoke hasSuperTrace env.debug.contains("|SuperTrace|")
    invoke hasTrace env.debug.contains("|Trace|")
    
    pipe init
      panel/msgid=MAIN/setup/controls=gc
      shellgui/id=idshellgui/attach

      debug on trace|supertrace
      say "nM> invoke ,, nxm.sys.test.TestUtil.throwAnonClassRuntimeException()"
      invoke ,, nxm.sys.test.TestUtil.throwAnonClassRuntimeException()

      gcontrol label mainLabel "Main"
        gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
        set gc.main.itemColors {PASS=GREEN,FAIL=RED}
      gcontrol text idtext "Instructions" "^instructions" 24 10 /title
      
    pipe off

    ! restore previous debug settings (by removing SuperTrace and Trace if they weren't previously ON
    if hasSuperTrace isFalse then debug off SuperTrace    
    if hasTrace      isFalse then debug off Trace    
  endif

  ! Additional interactive tests, only run with /BASELINE
  if interAct AND baseline then
    %test_debug_default ! NXM-3887
  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
  else
    ! do nothing
    say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

procedure test_store_restore

  ! Make sure LOCAL Debug flags are set to GLOBAL Debug flags -Since 3.7.2 
  env get Debug globalDebugFlags ! Same as: set globalDebugFlags ENV.DEBUG
  debug/load=globalDebugFlags
  
  ! store current debug settings as a string
  set storedDebug ENV.DEBUG

  ! store current Local (which are now the same as the Global) debug settings using intr
  debug/save

  ! set debug to only io
  debug off all
  assert/text="^reg.main.name: cleared debug mode" ENV.DEBUG EQS "|"
  debug on io
  assert/text="^reg.main.name: set io only" ENV.DEBUG EQS "|IO|"

  ! restore debug settings
  debug/load

  ! confirm that original debug settings are reset
  assert/text="^reg.main.name: /store and /restore" ENV.DEBUG EQS storedDebug
return
