! This will test RMIF's ability to contend with malformed tables. (Sending side of link).
!
! @author  Jim Roush
!
! <port>       The KNOWN port of the server.  Client uses any available port.
! <sendString> The string that represents the table to be sent over RMIF
!
startmacro O:cntrl L:port S:host["localhost"]
  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
  res tablesSent FALSE

  pipe on
    rmif/id=SENDER/msgid=main/STATEM=^statemachine/VERBOSE=^verbose -1 ! -1 = use any available port
    message sendw SENDER ,, "OPEN" ,, {ID=RECEIVER,HP="^host:^port"}
  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
    call send_tables
    message send cntrl ,, CLIENT_DONE 0 {TEST=PASS}

  elseif msg.name eqs "OPENED" then
    message send cntrl ,, CLIENT_STARTED 0 {TEST=PASS}

  elseif msg.name eqs "SET" then
    ! do nothing
  elseif msg.name eqss "CLOSE" then
    ! ignore CLOSE and CLOSED messages
  elseif msg.name eqs "NULL"
    ! ignore
  else
    message send cntrl ,, CLIENT_TEST 0 {TEXT="Got unhandled message name=^msg.name",TEST=FALSE}
  endif
return

!******************************************************************************!
procedure send_tables
  ! The following invoke gets the Remote Object and puts it in "REMOTEHOST"
  invoke remotehost SENDER.getRemote(reg.RECEIVER)

  ! The following invoke generates and sends a preconfigured packet "SET" message to the
  ! specified remote host.
  ! 101 = the SET function
  ! 0   = info variable for send packet
  ! 0   = flags controls how the data is to be sent
  res s:good "{D:NUM=42}"
  res buf1 good.getBytes
  invoke ,, SENDER.getNextLink.sendPacket(101, 0, buf1, REMOTEHOST, 0)

  info "The following test displays an ERROR '.. Unable to convert GREEN to D..'on the server side"
  res s:bad  "{D:NUM=GREEN}"
  res buf2 bad.getBytes
  invoke ,, SENDER.getNextLink.sendPacket(101, 0, buf2, REMOTEHOST, 0)

return
