!******************************************************************************!
! Test MSGLOG with report
!
! @bug      2623 PANEL: /LOGGER does not display correctly if defined in setup file
! @author:  Norm Taylor / 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)

  if interAct then
    ! NXM-3845 since NeXtMidas 4.1.1
    if ^{env.NMROOT} EQS "classpath:" then
      info "SKIPPING ^reg.main.name since fails when running from a jar file - &
            this test involves creating a .mmp file and saving it inside a jar file"
    else
      set instructions "This is meant to run with no setup file. \n\n&
          You should see a slightly un-configured macro gui.\n\n&
          1. Expand the logger section of the macro.\n&
          2. Click the 'Save setup file' button to save the setup file (use default name).\n\n&
          3. Click the 'Re-Launch Macro' button to re-launch the macro. The logger should be displayed correctly."

      pipe on
        panel/msgid=MAIN/setup/controls=gc/logger

        gcontrol label macro "Test MACRO"
        gcontrol menu  main "Exit with Status =" "PASS,FAIL" TABLE={ItemColors={PASS="GREEN",FAIL="RED"}} /TTop

        gcontrol text  idtext "Instructions" instructions 24 15 /title

        report on mylog

        gcontrol button myButt "LOG MSG TYPE" "Info,Warning,Error"
        gcontrol line
        gcontrol button saveMMP "" "Save setup file"
        gcontrol line
        gcontrol button launchIt "" "Re-Launch Macro"

      pipe off
      report off
    endif

  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
    call doLog msg.data

  elseif msg.name eqs "SAVEMMP" then
    message send panel name="PANEL.CFG" data="SAVE"

  elseif msg.name eqs "LAUNCHIT" then
      ^{reg.main.name}/wpos=(600,100,600,500)

  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

!******************************************************************************!
! Send a msg to the logger
!******************************************************************************!
procedure doLog s:type

  loop 3 ii
    if type eqs "INFO" then
      INFO "INFO message ^ii"
      message send id=logger name=log info=0 data="Info message from ^{ENV.USER}"
    elseif type eqs "WARNING" then
      WARN "WARNing message ^ii"
    elseif type eqs "ERROR" then
      ERROR "Error message ^ii"
    endif
  endloop
return
