! This will test the functionality of RMIF for a NeXtMidas to NextMidas
! connection.
!
! This relies heavily on the SD360 macro.
!
! <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.
! <sHost>      The server's hostname (usually "localhost").
!
! @author  J. Czechowski IV
!
startmacro l:waitPeriod[4] l:sPort[9000] l:cPort[9000] s:sHost["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

  pipe init
    say "      Starting interactive test of RMIF on localhost."
    say "        Testing NeXtMidas <--> NeXtMidas connections."
    panel/msgid=MAIN/setup/controls=gc
    gcontrol label macro "MACRO"
    gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
    set gc.main.itemColors {PASS=GREEN,FAIL=RED}

    textdisplay/id=tdisp text=""
    sd360/bg/id="SD360T"/server=^sPort/STATEM=^statemachine/DEBUG=^debug/VERBOSE=^verbose
    sd360/bg/id="SD360B"/client=^cPort/REMOTE="^sHost:^sPort"/STATEM=^statemachine/DEBUG=^debug/VERBOSE=^verbose


    message send tdisp,,"APPENDL",,"Interactive RMIF Test on localhost"
    message send tdisp,,"APPENDL",,"----------------------------------"
    message send tdisp,,"APPENDL",,"  Step 1: In the 'Client' pane, click the"
    message send tdisp,,"APPENDL",,"          'OPEN' button."
    message send tdisp,,"APPENDL",,""
    message send tdisp,,"APPENDL",,"  Step 2: Check to see that the Client and"
    message send tdisp,,"APPENDL",,"          Server plots interact with each"
    message send tdisp,,"APPENDL",,"          other."
    message send tdisp,,"APPENDL",,""
    message send tdisp,,"APPENDL",,"  Step 3: Click 'PAUSE' in the Server pane"
    message send tdisp,,"APPENDL",,"          and verify that the data pauses"
    message send tdisp,,"APPENDL",,"          in both plots."
    message send tdisp,,"APPENDL",,""
    message send tdisp,,"APPENDL",,"  Step 4: Click 'Run' in the Server pane"
    message send tdisp,,"APPENDL",,"          and verify that the data resumes"
    message send tdisp,,"APPENDL",,"          in both plots."
    message send tdisp,,"APPENDL",,""
    message send tdisp,,"APPENDL",,"  Step 5: Click 'CLOSE' in the Client pane"
    message send tdisp,,"APPENDL",,"          and verify that the data is not"
    message send tdisp,,"APPENDL",,"          updated on the Client pane."
    message send tdisp,,"APPENDL",,""
    message send tdisp,,"APPENDL",,"  Step 6: Click 'OPEN' in the Client pane"
    message send tdisp,,"APPENDL",,"          and verify that the Client and"
    message send tdisp,,"APPENDL",,"          Server plots interact with each"
    message send tdisp,,"APPENDL",,"          other."
    if sPort eq cPort then  ! test instruction for Bug 1920 (/prange= message)
      message send tdisp,,"APPENDL",,""
      message send tdisp,,"APPENDL",,"  Step 7: In the console, you should see an"
      message send tdisp,,"APPENDL",,"          INFO (not WARN) message: Port "
      message send tdisp,,"APPENDL",,"          ^cPort not available"
    endif
    message send tdisp,,"APPENDL",,""
    message send tdisp,,"APPENDL",," Finally: If all tests are successful click"
    message send tdisp,,"APPENDL",,"          the 'PASS' button, if any failed,"
    message send tdisp,,"APPENDL",,"          click the 'FAIL' button."
    message send tdisp,,"APPENDL",,""
    message send tdisp,,"APPENDL",,"          Once either 'PASS' or 'FAIL' is"
    message send tdisp,,"APPENDL",,"          clicked the window will begin to"
    message send tdisp,,"APPENDL",,"          close. Note that it may take up"
    message send tdisp,,"APPENDL",,"          to 10 seconds to stop the RMIF"
    message send tdisp,,"APPENDL",,"          processes and close the window."
    message send tdisp,,"APPENDL",,""
    message send tdisp,,"APPENDL",,""
    message send tdisp,,"APPENDL",,"  Note: Do not press the 'EXIT' button in"
    message send tdisp,,"APPENDL",,"        either the 'Server' or 'Client'"
    message send tdisp,,"APPENDL",,"        panes."

  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 "MAIN" then
    assert/text="RMIF NM to NM tests" msg.data eqss "PASS"
    say "        Closing Client"
    pause waitPeriod
    message SEND SD360B ,, "STATE" ,, "EXIT"
    say "        Closing Server"
    pause waitPeriod
    message SEND SD360T ,, "STATE" ,, "EXIT"
    say "        Done"
    pipe stop
  endif
return
