!******************************************************************************!
! Test the instanceof DataFile code in Convert
!
! Arguments: None
!
! @bug      NXM-3594
! @since    NeXtMidas 3.9.4
! @author:  Zachary Matthews
!******************************************************************************!
startmacro
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE  ! for defects or more obscure test case(s)
  switch KEEP        keep     GET DEF=FALSE SDEF=TRUE

  set S:fileName        "ChildDataFile1000.tmp"
  set S:fileNameNoop    "ChildDataFile1000Noop.tmp"
  set S:fileNameConvert "ChildDataFile1000Convert.tmp"

  invoke dfOutput,nxm.sys.lib.DataFile.OUTPUT
  new nxm.sys.test.ChildDataFile(null,fileName,"1000","CF",dfOutput,"hello") cldDF
  invoke ,, cldDF.open(dfOutput)
  invoke kw,cldDF.getKeywordsObject()
  invoke ,, kw.setKey("S:TESTKEY", "This is a test")
  invoke ,, cldDF.close()

  NOOP fileName fileNameNoop
  CONVERT fileName IEEE fileNameConvert

  assert/text="^reg.main.name: The newly converted child datafile exists" fileNameConvert FEXISTS

  call cleanupTempFiles

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"
    pipe stop
  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

!******************************************************************************!
! Remove any existing temp files
!******************************************************************************!
procedure cleanupTempFiles
  if keep isFalse then
    IF fileName         FEXISTS THEN ERASE fileName
    IF fileNameNoop     FEXISTS THEN ERASE fileNameNoop
    IF fileNameConvert  FEXISTS THEN ERASE fileNameConvert
  else
    info "Not erasing ^{fileName},^{fileNameNoop},^{fileNameConvert}"
  endif
return
