!******************************************************************************!
! This test case checks to make sure extended header keywords propagate
! properly when converting from IEEE to EEEI.
!
! Arguments: None
!
! @bug      NXM-3633 Extended header keyword propagation from a IEEE to EEEI is broken
! @since    NeXtMidas 4.0.0
! @author:  Zachary Matthews
!******************************************************************************!
startmacro
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE  ! for defects or more obscure test case(s)

  call setDatDir

  if ^{env.NMROOT} EQS "classpath:" then
    res expectedException "JarResource: seek location beyond end of file" ! expected exception
  else
    res expectedException "chk found invalid keyword block" ! expected exception
  endif
  res fileIn            "^{datDir}.test1000_ieee.prm"     ! input ieee file
  res fileOut           ieee_keywords_fft_eeei.tmp        ! output eeei file
  res waveeeei          eeei_wave_and_keywords.tmp        ! default shell rep wave with keywords
  res waveieee          ieee_wave_and_keywords.tmp        ! ieee rep wave with keywords
  res fftofieee         fft_of_ieee_with_keywords.tmp     ! fft of ieee with keywords

  ! Run fft, and if the expected exception is not caught, then it is assumed that the eeei
  ! output file was successfully created
  fft fileIn fileOut
  assert/text="^reg.main.name: IEEE keyword block converted to EEEI" "TRUE" isTrue

  invoke convertExists reg.shell.M.dictionary.isDictionaryEntry(CONVERT)
  if convertExists then
    waveform waveeeei
    key waveeeei put d:mydouble 3.21
    key waveeeei put birthday someone
    key waveeeei put email sent
    convert waveeeei IEEE waveieee
    fft waveieee fftofieee
    key fftofieee GET birthday who
    assert/text="^reg.main.name: IEEE keyword block with multiple keywords converted to EEEI" "SOMEONE" EQS who

    erase waveeeei
    erase waveieee
    erase fftofieee
  endif

  ! Cleanup
  remove expectedException
  erase fileOut
endmacro

!******************************************************************************!
! 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: IEEE keyword block converted to EEEI: ^{expectedException}" expectedException SUBS emsg.data.message
    remove expectedException
    stop
  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

!******************************************************************************!
! Set the dat directory
!******************************************************************************!
procedure setDatDir
  invoke nxmMajor env.nmversion.subString(0,1)
  invoke major java.lang.Integer.valueOf(nxmMajor)
  if major GE 4 then
    invoke s:datDir           nxm.sys.test.DatLocator.getDatDirLocation()
    invoke s:datDirSlash      nxm.sys.test.DatLocator.getDatDirSlashLocation()
    invoke z:sysDatFull       nxm.sys.test.DatLocator.sysDatFull()
    invoke z:sysTestDatExists nxm.sys.test.DatLocator.sysTestDatExists()
  else
    set s:datDir           "nxm.sys.dat"
    set s:datDirSlash      "nxm/sys/dat"
    set z:sysDatFull       true
    set z:sysTestDatExists false
  endif
return
