! Tests the REGISTRY command. This uses %test_registry_macro to test some of
! the functions related to a macro entry in the registry.
!
! @author  J. Czechowski IV
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

  registry copy shell tempshell
  assert/text="^reg.main.name: COPY" reg.tempshell REXISTS
  rem reg.tempshell

  call test_get_performance

  if interAct then
    res inst "You should see: \n&
             1. a dump of the registry.\n&
             2. a listing for REG.MYPRIM.\n&
             3. a listing for MYMACRO1 that includes MAIN and WAVEFORM.\n&
             4. a warning saying that duplicate entries for /ID=WAVE1 were found.\n\n&
             Note: this test may need to be run stand-alone"
    pipe on
      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}

      gcontrol text idtext "INSTRUCTIONS" inst 24 14 /title

      %test_registry_macro/id=mymacro1/bg
      %test_registry_macro/id=mymacro2/bg

      shellgui/attach/id=myprim
      say ""
      say "nM> REGISTRY"
      REGISTRY
      say ""
      say "nM> REGISTRY SHOW MYPRIM"
      REGISTRY SHOW MYPRIM
      say ""
      say "nM> REGISTRY SHOW MYMACRO1"
      REGISTRY SHOW MYMACRO1
      say ""
      say "nM> WAVEFORM/ID=WAVE1 OUT=NULL ELEM=INF"
      WAVEFORM/ID=WAVE1 OUT=_pipe1 ELEM=INF
      say "nM> WAVEFORM/ID=WAVE1 OUT=NULL ELEM=INF"
      WAVEFORM/ID=WAVE1 OUT=_pipe2 ELEM=INF
    pipe off

    popup notClosed "YesNo" "Did you get a 'Timeout closing...' message in the OS shell?" "QUEST" /BLOCKING=Macro
    assert/text="^reg.main.name: No error closing macros" notClosed isFalse
  endif

endmacro

!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: Tests for REGISTRY SHOW" msg.data eqss "PASS"

    ! Check for running macros
    assert/text="^reg.main.name: REG.MYMACRO1 found" REG.MYMACRO1 rexists
    assert/text="^reg.main.name: REG.MYMACRO2 found" REG.MYMACRO2 rexists

    ! Stop the macros
    message send mymacro1 ,, STOPWAVEFORM
    set reg.mymacro2.state FINISH
    pause 2

    ! Did the macros stop?
    assert/text="^reg.main.name: REG.MYMACRO1 removed" REG.MYMACRO1 nrexists
    assert/text="^reg.main.name: REG.MYMACRO2 removed" REG.MYMACRO2 nrexists

    pipe stop
  else
    ! do nothing
    say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
! test nxm.sys.lib.Registry.get(String name,int wait) performance for wait=0 (no wait).
! since 3.3.2 to test performance regression caused by BUG 2689
subroutine test_get_performance L:numItems[100]
  ! this is a VERY relaxed max processing time, just in case we are running on a really really slow system
  calc maxProcessingTime 0.01 numItems *
  set registry reg.main.M.registry
  timer set
  do ii 1 numItems
    invoke obj registry.get("TestRegistryGetPerformance",0)
  enddo
  timer ELAPSE elapsedTime
  assert/text="^reg.main.name: Registry get performance for wait=0, ^numItems items (^elapsedTime sec)." elapsedTime <= maxProcessingTime
return
