!******************************************************************************!
! Test using sinkfile with the /rtfile switch
!
! @bug      2640 SINKFILE: Add /NFN Option to match X-Midas
! @author:  J Bauer
! @version: $Id: test_sinkfile_rt.mm,v 1.3 2012/12/04 17:29:47 jwb Exp $
!******************************************************************************!
startmacro
    TIMEX NOW D:dtime

    pipe on
      
      waveform _wavec form=sf shape=ramp elem=inf 
      headermod _wavec timecode=dtime
      sinkfile/rtfile _wavec test_outsinkpipe.tmp start=0 duration=100k
      
      set counter 0
      set this.timer(0) .5
      
    pipe off

endmacro

!******************************************************************************!
! Main process message for this macro. Should be right after the ENDMACRO.
!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    erase/quiet test_outsinkpipe.tmp
    pipe stop
  
  elseif msg.name eqs "TIMER" then
    stat test_outsinkpipe size=filesize
    if filesize ne 100k then 
      assert/text="^reg.main.name: circular buffer size constant" filesize eq 100k
      message send main name="MAIN" data="FAIL"
    endif
    calc counter counter 1 +
    if counter > 5
      assert/text="^reg.main.name: circular buffer size constant" filesize eq 100k
      message send main name="MAIN" data="PASS"
    endif
  else
    say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
! If an unexpected exception is caught, mark test as failed, unless it is expected
!******************************************************************************!
procedure processException m:emsg
  if expectedException REXISTS then
    assert/text="^reg.main.name: Expected ERROR starts with: ^{expectedException}" expectedException EQSS emsg.data.message
    remove expectedException
  else
    assert/text="^reg.main.name: Caught unexpected exception ^{emsg.data}" "FALSE" isTrue
    if "Trace" SUBS ENV.DEBUG then invoke ,, emsg.data.printStackTrace()
  endif
return
