!
!  Macro for testing a small MSGLOG with and without wrapping
!
!  @issue : NXM-3337 MJText / MSGLOG not handling wrapped text not rendering
!  @author: Jeanette McCall / Jay Hallam
!  @since : NeXtMidas 3.9.1
!
!
startmacro

  switch INTERACTIVE   interAct     GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch COREGRAPHICS  coregraphics GET DEF=FALSE SDEF=TRUE  

  if interAct then

    res instructions "You should see two small MSGLOG terminals at the bottom right.\n&
                      Use the Options control to Log a mix of messages\n\n&
                      After the first message:\n&
                      1) 'MsgLog no wrap' should always display the first line of &
                         latest message.\n&
                      2) 'MsgLog with wrap' should always display the last two lines &
                         of the latest message.\n\n&
                      The ShellGUI messages can be used for reference."

    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 17 /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=msglognwrap/msgid=main/file=logFile
    msglog/id=msglogwrap/msgid=main/wrap/file=logFile

    res INFO 0
    res WARNING 1
    res ERROR 2

    call logger "INFO"
    call logger "WARNING"
    call logger "ERROR"
  
    message send msglognwrap ,, LOG ,INFO, "another Informational message"
    message send msglognwrap ,, LOG ,WARNING, "another Warning message"
    message send msglognwrap ,, LOG ,ERROR, "another Error message"
    
    message send msglogwrap ,, LOG ,INFO, "another Informational message"
    message send msglogwrap ,, LOG ,WARNING, "another Warning message"
    message send msglogwrap ,, 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
  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 msglogwrap ,, LOG ,INFO, "Info message ^countTab.info  ( ^countTab.TOTAL )"
      message send msglognwrap ,, 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 msglogwrap ,, LOG ,WARNING, "Warning message ^countTab.WARN ( ^countTab.TOTAL )"
      message send msglognwrap ,, 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 msglogwrap ,, LOG ,ERROR, "Error message ^countTab.error ( ^countTab.TOTAL )"
      message send msglognwrap ,, 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.msglogwrap.close()
  invoke L:xxx reg.msglognwrap.close()
  stop
return
!******************************************************************************!
