!******************************************************************************!
! This will test the functionality of RMIF.
!
! @author  J. Czechowski IV
!
! <waitPeriod> The waitPeriod is the amount of time to pause while waiting for
!              GUI messages to process. This needs to be long enough that slow
!              systems (and those using JProbe) have enough time.
! <sPort>      The server's port number.
! <cPort>      The client's port number.
! <aPort>      The alternate client's port number (for X-Midas testing).
! <sHost>      The server's hostname (usually "localhost").
!******************************************************************************!
startmacro l:waitPeriod[4] l:sPort[9000] l:cPort[9002] s:sHost["localhost"] l:aPort[9000]
  switch INTERACTIVE interAct     GET DEF=true           SDEF=true  ! for normal interactive test(s)
  switch DEBUG       debug        GET DEF=false          SDEF=true
  switch VERBOSE     verbose      GET DEF=false          SDEF=true
  switch STATEM      statemachine GET DEF=false          SDEF=true

  ! ----- Automatic tests -----
  call testMessageHandler
  ! test the GET and SET functions.
  %test_rmif_get_set/INTERACTIVE=^interAct/STATEM=^statemachine/DEBUG=^debug/VERBOSE=^verbose
  ! test for the /HTTP switch
  %test_rmif_http/INTERACTIVE=^interAct/STATEM=^statemachine/DEBUG=^debug/VERBOSE=^verbose
  ! test MFTP protocol
  %test_rmif_mftp/INTERACTIVE=^interAct/STATEM=^statemachine/DEBUG=^debug/VERBOSE=^verbose

  ! Run the interactive NeXtMidas <-> NeXtMidas tests on localhost
  if interAct then
    ! ORIG 2.7.1 %test_rmif_nm_to_nm ^waitPeriod ^sPort ^cPort ^sHost
    ! NTN: Using sPort for client port to simulate INFO message for Bug 1920
    %test_rmif_nm_to_nm/STATEM=^statemachine/DEBUG=^debug/VERBOSE=^verbose ^waitPeriod ^sPort ^sPort ^sHost

    say "      It is possible to test NeXtMidas <-> X-Midas connections on"
    say "      the localhost. However, this will only work on a unix system"
    say "      that has X-Midas installed."
    say ""
    ask xmTest "      Test NeXtMidas <-> X-Midas RMIF connections? [NO] "
    say ""
    if xmTest then
      if statemachine then warn "STATEMACHINE mode is NOT FULLY COMPATIBLE with X-Midas"
      %test_rmif_nm_to_xm/STATEM=^statemachine/DEBUG=^debug/VERBOSE=^verbose ^waitPeriod ^sPort ^cPort ^sHost ^aPort
    else
      say "      Skipping NeXtMidas <-> X-Midas RMIF tests"
    endif
  endif

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
return

!******************************************************************************!
! test default message handler is MAIN (this macro)
! test setting message handler propagates to Rmif library (Bug 2684)
! @since 3.3.0
!******************************************************************************!
procedure testMessageHandler
  ! bind on any port (and default /msgid SHOULD be MAIN (this) macro)
  rmif/STATEM=^statemachine/VERBOSE=^verbose/BG/ID=myrmif 0

  assert/text="Default /MSGID=MAIN (this macro)" reg.main OEQ reg.myrmif.messageHandler
  ! next assert is only available in 3.3.0
  assert/text="Rmif library's MessageHandler == MAIN (this macro)" reg.main OEQ reg.myrmif.rmif.messageHandler

  ! test Bug 2684 (setting a different message handler)
  new nxm.sys.lib.MessageQueue(this.M,this) myMQ
  set reg.myrmif.messageHandler myMQ
  assert/text="Set new MessageHandler" myMQ OEQ reg.myrmif.messageHandler
  assert/text="Rmif library's MessageHandler == new MessageHandler" myMQ OEQ reg.myrmif.rmif.messageHandler

  SENDTO myrmif "EXIT"
  rem myMQ
return
