! This will test RMIF's ability to contend with malformed tables. (Receiving side of link).
!
! @author  Jim Roush
!------------------------------------------------------------------------------!
startmacro o:cntrl l:port
  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 gotGoodTable FALSE

  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 "STOP_TEST" then
    rem reg.cntrl ! we put this in manually, now remove it
    pipe stop     ! sent by ctrl

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

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

  elseif msg.name eqs "SET" then
    ! First thing sent is a good table {NUM=42}
    set gotGoodTable TEST(msg.data.num,eq,42)
    message send cntrl ,, NAME=SERVER_TEST INFO=0 DATA={TEXT="got good table",TEST=^gotGoodTable}

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

  elseif msg.name eqs "LINKERR" then
    if "GREEN" subs "^msg.data" then
      message FUNC=send ID=cntrl NAME=SERVER_TEST INFO=0 DATA={TEXT="got expected error",TEST=TRUE}
      message FUNC=send ID=cntrl NAME=SERVER_DONE INFO=0 DATA={TEST=TRUE}
    else
      message FUNC=send ID=cntrl NAME=SERVER_TEST INFO=0 DATA={TEXT="got unexpected error",TEST=FALSE}
    endif
  else
    message FUNC=send ID=cntrl NAME=SERVER_TEST INFO=0 DATA={TEXT="got unhandled message name=^msg.name",TEST=FALSE}
  endif
return
