! Tests the message handling using MSGECHO
!
! author:  J. Czechowski IV
! version: $Id: test_msgecho.mm,v 1.3 2006/02/24 23:01:19 jxc Exp $
!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE
  
  if interAct then
    set sendCount 0
    set recvCount 0
    set numMsg 5
    
    pipe init
      panel
      nxm.xbc.host.msgecho/msgid=MAIN/id=echoid numMsg
      
      gcontrol text idtext "Instructions" "Macro is running, this should take about 10 seconds." 24 5 /title
      set reg.panel.timer(0) 1
    pipe off
  else
    info "MSGECHO: Messaging tests must be run in interactive mode."
  endif
endmacro


procedure processMessage m:msg
  !say "got msg.name=^msg.name msg.info=^msg.info msg.data=^msg.data"
  
  if msg.name EQS "TIMER" then
    if sendCount lt numMsg then
      calc sendCount sendCount 1 +

      if sendCount lt 3 then
        ! Send a configured message.
        message send echoid MSGLOG MSGLOG ^sendCount &
          {severity=^sendCount,date_time="Today",source="My Macro",text="ABC"}
      else
        ! Send an unconfigured message.
        message send echoid SPAM SPAM ^sendCount &
          {type="ALL",args="3",VAL1="My Spam",VAL2=^sendCount,VAL3="42"}
      endif
    endif
    
  elseif msg.name EQS "MSGLOG" then
    calc recvCount recvCount 1 +
    assert/text="Message ^recvCount, MSGLOG msg.info"           msg.info              eq  ^recvCount
    assert/text="Message ^recvCount, MSGLOG msg.data.severity"  msg.data.severity     eq  ^recvCount
    assert/text="Message ^recvCount, MSGLOG msg.data.date_time" "^msg.data.date_time" eqs "Today"
    assert/text="Message ^recvCount, MSGLOG msg.data.source"    "^msg.data.source"    eqs "My Macro"
    assert/text="Message ^recvCount, MSGLOG msg.data.text"      "^msg.data.text"      eqs "ABC"
    
  elseif msg.name EQS "SPAM" then
    calc recvCount recvCount 1 +
    assert/text="Message ^recvCount, SPAM msg.info"   msg.info        eq  ^recvCount
    assert/text="Message ^recvCount, SPAM msg.data.val1" "^msg.data.val1"   eqs "My Spam"
    assert/text="Message ^recvCount, SPAM msg.data.val2" ^msg.data.val2     eq  ^recvCount
    assert/text="Message ^recvCount, SPAM msg.data.val3" ^msg.data.val3     eq  42
    
  elseif msg.name EQS "=SPAM" then
    calc recvCount recvCount 1 +
    assert/text="Message ^recvCount, =SPAM msg.info"   msg.info        eq  42
    assert/text="Message ^recvCount, =SPAM msg.data.val1" ^msg.data.val1     eq  42
    assert/text="Message ^recvCount, =SPAM msg.data.val2" ^msg.data.val2     eq  4
    assert/text="Message ^recvCount, =SPAM msg.data.val3" "^msg.data.val3"   eqs "Spam 2"
    
  elseif msg.name EQS "DONE" then
    calc recvCount recvCount 1 +
    assert/text="Message ^recvCount, DONE msg.info"   msg.info        eq  7
    assert/text="Message ^recvCount, DONE msg.data.val1" "^msg.data.val1"   eqs "Done"
    
    pipe stop
  else
    assert/text="Got unexpected message msg.name=^msg.name" false
    pipe stop
  endif

return
