! This will test the functionality of RMIF for a NeXtMidas to X-Midas
! connection.
!
! This relies heavily on the SD360 macro (both in NeXtMidas and X-Midas).
!
! <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 (client #1).
! <aPort>      The alternate client's port number (client #2).
! <sHost>      The server's hostname (usually "localhost").
!
! @author  J. Czechowski IV
!
startmacro L:waitPeriod[4] L:sPort[9000] L:cPort[9002] S:sHost["localhost"] L:aPort[9003]
  switch DEBUG   debug        GET DEF=false SDEF=true
  switch VERBOSE verbose      GET DEF=false SDEF=true
  switch STATEM  statemachine GET DEF=false SDEF=true

  say "      Start the X-Midas Server:"
  say "        Open a new terminal window and run the following:"
  say "          $ xmstart"
  say "          $ xm xmopt nxm $NMROOT/nxm/sys"
  say "          $ xm xmpath +nxm"
  say "          $ xm xmbopt nxm"
  say "          $ xm sd360/server ,, ^sPort"
  say ""
  say "        In the 'SD360;NXM' window that comes up click 'RUN' to"
  say "        start the server (note that nothing will appear to happen"
  say "        in the 'SD360;NXM' window when 'RUN' is clicked, this is"
  say "        to be expected."
  say ""
  say "      Once the server is running, press enter."
  say ""
  ask answer "      [PRESS ENTER TO CONTINUE]"
  say ""
  say "      Starting the tests."

  pipe init
    say "      Starting interactive test of RMIF on localhost."
    say "        Testing NeXtMidas <--> NeXtMidas connections."
    panel/msgid=MAIN/setup
    gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft

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


    message send tdisp,,"APPENDL",,"NeXtMidas <-> X-Midas Test"
    message send tdisp,,"APPENDL",,"--------------------------"
    message send tdisp,,"APPENDL",,"  Step 1: In each of the Client panes,"
    message send tdisp,,"APPENDL",,"          click the 'OPEN' button."
    message send tdisp,,"APPENDL",,""
    message send tdisp,,"APPENDL",,"  Step 2: Check to see that the two Client"
    message send tdisp,,"APPENDL",,"          plots interact with each other."
    message send tdisp,,"APPENDL",,""
    message send tdisp,,"APPENDL",,"  Step 3: 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 'TOP' or 'BOTTOM'"
    message send tdisp,,"APPENDL",,"        panes."

  pipe off

  say ""
  say "      Closing the X-Midas Server:"
  say "        In the 'SD360;NXM' window click 'STOP' to close the server."
  say ""
  say "        Once the window closes, run the following in the terminal"
  say "        that X-Midas was running in:"
  say "          $ xmend"
  say ""
  say "      Once the server is closed, press enter."
  say ""
  ask answer "      [PRESS ENTER TO CONTINUE]"

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 XM tests" msg.data eqss "PASS"
    say "        Closing Client 2"
    pause waitPeriod
    message SEND SD360B ,, "STATE" ,, "EXIT"
    say "        Closing Client 1"
    pause waitPeriod
    message SEND SD360T ,, "STATE" ,, "EXIT"
    say "        Done"
    pipe stop
  endif
return
