!
! Tests for IMPORT setting the size in a header (BUG 2174)
!
! Author:  J. Bauer / N Ngo
!
startmacro

  call setDatDir

  ! Get the number of elements in the original file
  status ^{datDir}.cities.prm  size=origCitiesSize

     ! Copy the original files to make  'binaries'
  noop ^{datDir}.cities.prm   testcities1.bin
  noop ^{datDir}.cities.prm   testcities2.bin
  noop ^{datDir}.cities.prm   testcities3.bin
  noop ^{datDir}.sinewave.prm testsine1.bin
  noop ^{datDir}.sinewave.prm testsine2.bin

     ! Import the 'binary' as a type 3000 with the defined subrecords
  import/f in=testcities1.bin type=3000 form=nh sr=(POS/VD,NAME/4A) datastart=512
     ! Same as above but over-ride computed SIZE with given SIZE at FRONT of line
  import/f in=testcities2.bin size=10 type=3000 form=nh sr=(POS/VD,NAME/4A) datastart=512
     ! Same as above but over-ride computed SIZE with given SIZE at END of line
  import/f in=testcities3.bin type=3000 form=nh sr=(POS/VD,NAME/4A) datastart=512 size=10
     ! Import the 'binary' as a type 1000 with CF data and a pre-defined dataSize
  import/f in=testsine1.bin form=cf datastart=512  datasize=800   ! size should come out to 100 (DataSize / BytesPerElement)
     ! Import the 'binary' as a type 1000 with CF data and a pre-defined dataSize AND size
  import/f in=testsine2.bin size=50 form=cf datastart=512  datasize=800   ! size should come out to 50

     ! Get the number of elements in the new headers
  status testcities1.tmp size=copyCities1Size
  status testcities2.tmp size=copyCities2Size
  status testcities3.tmp size=copyCities3Size
  status testsine1.tmp   size=copySine1Size
  status testsine2.tmp   size=copySine2Size

     ! Compare the sizes
  assert/text="IMPORT size check: original size = ^origCitiesSize,  copied size = ^copyCities1Size" ^origCitiesSize eq ^copyCities1Size
  assert/text="IMPORT size check: size should be 10.0.... copied size = ^copyCities2Size" 10 eq ^copyCities2Size
  assert/text="IMPORT size check: size should be 10.0.... copied size = ^copyCities3Size" 10 eq ^copyCities3Size
  assert/text="IMPORT size check: size should be 100.0... copied size = ^copySine1Size" 100 eq ^copySine1Size
  assert/text="IMPORT size check: size should be 50.0.... copied size = ^copySine2Size" 50  eq ^copySine2Size

    ! Erase the temp files
  erase testcities1.tmp
  erase testcities2.tmp
  erase testcities3.tmp
  erase testsine1.tmp
  erase testsine2.tmp

endmacro

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