!
!  Macro for testing the capabilities of MSGLOG
!
!  Note: To test properly for Bug 2872 the size of the MSGLOG must not be 
!  changed or the instructions will need to be updated. The new instructions 
!  are checking that the calculations of available screen rows is correct.
!
!  @author: Jay Hallam
!
!
startmacro

  switch INTERACTIVE   interAct     GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch COREGRAPHICS  coregraphics GET DEF=FALSE SDEF=TRUE  ! for a quick check of graphics - more extreme tests - since 3.8.1

  if interAct then

    res instructions "You should see a MSGLOG terminal with six messages and a &
                      shellgui (which prints java util logging messages) with &
                      three messages. Modify the &
                      selection in OPTIONS and verify:\n&
                      1) Each selection creates 2 additional logger messages &
                         (2 additional lines in both MSGLOG and shellgui)\n&
                      2) A full 10 lines (of INFO, WARN,and ERROR messages) can &
                         be displayed in the MSGLOG."

    pipe init

    panel/msgid=main/controls=gc/setup
    fname label=logFile area=^{AUX.WRITE} name="temp_test_messagelog" ext="log" OPT="AUX"
    gcontrol label macro "MACRO"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}
      gcontrol text idtext "Instructions" "^instructions" 24 15 /title
    gcontrol label macro "OPTIONS" AlwaysOpen
      gcontrol choice logAmessage "Log a Message of type:" "Info,Warning,Error"

    shellgui/id=idshellgui/attach/msgid=main
    !msglog/id=msglog/msgid=main/file="^logFile"
    msglog/id=msglog/msgid=main/file=logFile

    res INFO 0
    res WARNING 1
    res ERROR 2

    call logger "INFO"
    call logger "WARNING"
    call logger "ERROR"
  
    message send msglog ,, LOG ,INFO, "another Informational message"
    message send msglog ,, LOG ,WARNING, "another Warning message"
    message send msglog ,, LOG ,ERROR, "another Error message"

    ! Uniquely identify any additional messages going to the logger
    res countTab {TOTAL=0,INFO=0,WARN=0,ERROR=0}


    pipe run
    pipe wait
    pipe off

    !erase/all logFile

    %test_msglog_report

  endif
  if interact or coregraphics then
    %test_msglog_wrap_text
  endif
endmacro

!******************************************************************************!
procedure processMessage

  !say "Msg ^msg.name = ^msg.data "

  if msg.name eqs "MAIN"
    assert/text="^reg.main.name: user indicated" msg.data eqss "PASS"
    pipe stop

  elseif msg.name eqs "LOGAMESSAGE"
    ! Send each log message with two unique counters that let us know
    ! the order of arrival 
    res countTab.TOTAL countTab.TOTAL+1
    if msg.data eqs "INFO"
      res countTab.info countTab.info+1
      message send msglog ,, LOG ,INFO, "Info message ^countTab.info  ( ^countTab.TOTAL )"
      say "sent INFO message ^countTab.info "
      call logger "INFO"
    elseif msg.data eqs "WARNING"
      res countTab.WARN countTab.WARN+1
      message send msglog ,, LOG ,WARNING, "Warning message ^countTab.WARN ( ^countTab.TOTAL )"
      say "sent WARN message ^countTab.WARN "
      call logger "WARNING"
    elseif msg.data eqs "ERROR"
      res countTab.error countTab.error+1
      message send msglog ,, LOG ,ERROR, "Error message ^countTab.error ( ^countTab.TOTAL )"
      say "sent ERROR message ^countTab.error "
      call logger "ERROR"
    else 
      say "unrecognized request to log a message: msg.data = ^msg.data"
    endif

  elseif msg.fid eqss "PANEL"

  else 
    say "Unhandled message ^msg.name from ^msg.fid"
  endif
return
!******************************************************************************!
!               Test for Java Logger (BUG 1863)                                !
!******************************************************************************!
procedure logger s:type
  invoke logger java.util.logging.Logger.getAnonymousLogger()
  invoke logHandler THIS.M.createLogHandler()
  
  invoke logger.setUseParentHandlers(false)
  invoke logger.addHandler(logHandler)
  if type eqs "INFO" then
    invoke logger.info("an info message")
  elseif type eqs "WARNING" then
    invoke logger.warning("a warning message")
  elseif type eqs "ERROR" then
    invoke logger.severe("an error message")
  endif
  
return
!***
!******************************************************************************!
procedure close
  invoke L:xxx reg.msglog.close()
  stop
return
!******************************************************************************!
