!******************************************************************************!
! Test macro for the SHOW command (added in 3.1.1)
!
! @bug      2522 Add SHOW command
! @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)

  set s:TEST_SHOW_RESULT ""

  if interAct then
    ! NXM-3845 since NeXtMidas 4.1.1
    if ^{env.NMROOT} EQS "classpath:" then path add hwc ! Needed for HWC when running from a jar file

    set instructions "Press the buttons below to test the various functions &
                      of the SHOW command. Look at the output in the SHELLGUI &
                      and compare against the results specified in this text box."
                      
    set funcList "[DEF],ASCII,AUXES,CON,COMM,ENV,EXTEN,FILES,HELP,PACK,RESO,HW"

    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 12 /title
      
      gcontrol button myButt "SHOW functions" "^funcList" /nc=3  

      shellgui/id=sg1/attach
    pipe off

    if ^{env.NMROOT} EQS "classpath:" then path remove hwc
  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 "MYBUTT" then
    invoke ,, reg.sg1.clear()
    call updateText ^msg.data
    if msg.data eqs "[DEF]" then
      show label=TEST_SHOW_RESULT
    elseif msg.data eqs "HELP" then
      if ^{env.NMROOT} NEQS "classpath:" then show ^msg.data label=TEST_SHOW_RESULT ! HELP GUI fails when running from a jar file
    else
      show ^msg.data label=TEST_SHOW_RESULT
      if msg.data eqs CON or msg.data eqs EXTEN or msg.data eqs PACK or msg.data eqs RESO then
        res/global TEST_SHOW_RESULT
      endif
    endif
  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

!******************************************************************************!
! Update the text listed in the instruction box
!******************************************************************************!
procedure updateText s:func
  if func eqs "[DEF]" then
    set gc.idtext.value "You should see a listing of the various functions of SHOW"
  elseif func eqs "ASCII" then
   set gc.idtext.value "You should see a table of the ASCII character set. "
  elseif func eqs "AUXES" then
    set gc.idtext.value "You should see a listing of the AUXes"
  elseif func eqs "CON" then
    set gc.idtext.value "You should see a listing of the defined constants."
  elseif func eqs "COMM" then
    set gc.idtext.value "You should see a listing of the commands in the current path. Hit 'Q' then ENTER in the shellgui to move on..."
  elseif func eqs "ENV" then
    set gc.idtext.value "You should see a listing of the Environment."
  elseif func eqs "EXTEN" then
    set gc.idtext.value "You should see a listing of the file extensions and their handler class names."
  elseif func eqs "FILES" then
    set gc.idtext.value "You should see a listing of the files in the read aux."
  elseif func eqs "HELP" then
    if ^{env.NMROOT} EQS "classpath:" then
      set gc.idtext.value "The HELP button is disabled since the HELP GUI fails when running from a jar file."
    else
      set gc.idtext.value "You should see a help gui pop up."
    endif
  elseif func eqs "HW" then
    set gc.idtext.value "You should see a listing of the hardware config file (defined in ENV.HWCONFIG)."
  elseif func eqs "PACK" then
    set gc.idtext.value "You should see a listing of the defined packet types and their handler class."
  elseif func eqs "RESO" then
    set gc.idtext.value "You should see a listing of the supported file resource types."
  else
    say "^reg.main.name: Invalid function: ^func"
  endif
return
