!******************************************************************************!
! NeXtMidas test macro for testing fcalc when pipe on and df.getSize=0.0
!
! Arguments: None
!
! @bug      NXM-2954 fcalc does not operate in piped mode
! @author:  Elizabeth Ryan
!******************************************************************************!

startmacro

pipe on
  ! Set SIZE=0 in file header (despite there being 32,768 elements) to simulate
  ! what happens if SIZE is unset on the pipe and defaults to 0, which is typical
  ! of many piped primitives (since they don’t know what their ultimate size
  ! will be).

  waveform _wave ELEM=32768
  headermod _wave SIZE=0     ! test NXM-2945 with header size == 0

  ! In NeXtMidas 3.6.0/3.6.1 and 3.7.0 this next line will cause the macro to
  ! hang since it ends up computing an internal transfer length of 0.0 (which
  ! is clearly wrong).

  fcalc _pow _wave

  statistics _pow ELEM=actElements
pipe off

assert/TEXT="FCALC can handle Type 1000 file with SIZE=0 (pipe on)" actElements EQ 32768

! Set SIZE=0 in file header (despite there being 32,768 elements) to simulate
! what happens if SIZE is unset and defaults to 0. No pipe in this test.

  waveform testfile elem=32768 
  !This sets ELEM to 0.0
  headermod testfile SIZE=0
  fcalc pow testfile
  statistics pow ELEM=actElements
  assert/TEXT="FCALC can handle Type 1000 file with SIZE=0 (no pipe on)" actElements EQ 0.0

endmacro

!******************************************************************************!
procedure processMessage m:msg
  !say "msg.name ^msg.name, data ^msg.data"

  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop
  elseif msg.name eqs "MULTIPLIER" then

  endif
return

!******************************************************************************!
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
