! This will test the RMIF maximum window setting for RDP (Receiving side of link).
!
! @bug 927
! @author  Jay Hallam
!------------------------------------------------------------------------------!
startmacro O:cntrl L:port L:wndwSz[16] L:msgCnt[256]
  switch DEBUG   debug        GET DEF=false SDEF=true
  switch VERBOSE verbose      GET DEF=false SDEF=true
  switch STATEM  statemachine GET DEF=false SDEF=true

  set reg.cntrl cntrl

  set wait     5      ! Number of extra seconds to wait for extra messages
  set index    0      ! Expected index of next message
  set count    0      ! Total messages received
  set passFail "PASS" ! Overall status

  pipe on
    rmif/id=RECEIVER/msgid=main/STATEM=^statemachine/VERBOSE=^verbose ^port
    message FUNC=send ID=cntrl NAME=SERVER_STARTED INFO=0 DATA={TEST=PASS}
  pipe off
endmacro

!******************************************************************************!
procedure processMessage m:msg
  if debug then
    say "^reg.main.name: Got message name=^msg.name fid=^msg.fid info=^msg.info data=^msg.data"
  endif

  if msg.name eqs "START_TEST" then
    ! do nothing, waiting for client to send packets

  elseif msg.name eqs "STOP_TEST" then
    rem reg.cntrl ! we put this in manually, now remove it
    pipe stop ! sent by ctrl

  elseif msg.name eqs "OPEN" then
    ! ignore - get this twice for some reason...

  elseif msg.name eqs "SET" then
    if index lt msg.data.index then
      WARN "index=^index < mdindex=^msg.data.index info=^msg.info"
      message FUNC=send ID=cntrl NAME=SERVER_TEST INFO=0 &
              DATA={TEXT="got message ^msg.data.index when looking for ^index",TEST=FALSE}
    else
      calc L:index index 1 +
    endif
    calc L:count count 1 +
    if msg.data.index eq msgCnt-1 then
      ! We should be done now, but wait a few seconds to see if extra messages
      ! are sent... prior to fixing the windowing DR (Bug 927) extra messages
      ! would get here.
      set this.timer(0) wait
    endif

  elseif msg.name eqss "CLOSE" then
    ! ignore CLOSE and CLOSED messages

  elseif msg.name eqs "NULL" then
    ! ignore

  elseif msg.name eqs "TIMER" then
    ! done waiting for any extra messages
    set ok TEST(count,eq,msgCnt)
    message FUNC=send ID=cntrl NAME=SERVER_TEST &
            DATA={TEXT="received ^msgCnt messages (count=^count)",TEST=^ok}
    message FUNC=send ID=cntrl NAME=SERVER_DONE DATA={TEST=^passFail}

  else
    !warn "^reg.main.name: Unhandled Message: Got message name=^msg.name from ^msg.fid"
    message FUNC=send ID=cntrl NAME=CLIENT_TEST INFO=0 &
            DATA={TEXT="got unhandled message name=^msg.name",TEST=FALSE}
  endif
return
