!******************************************************************************!
! Tests for DATALIST command.
!
!   Author : J. Czechowski IV
!******************************************************************************!
startmacro/tsetup=nxm.sys.test.test_datalist_setup.tbl
  switch INTERACTIVE  interAct     GET DEF=TRUE SDEF=TRUE  ! for normal interactive test(s)
  switch STANDALONE   standalone   GET DEF=TRUE SDEF=TRUE
  switch COREGRAPHICS coregraphics GET DEF=FALSE SDEF=TRUE  ! for a quick check of graphics - more extreme tests - since 3.8.1

  call setDatDir
  res  z:runningFromJar    false
  res  expectedException "JarResource: seek location beyond end of file"

  set instructions "Verify the output from DATALIST."

  if ^{env.NMROOT} EQS "classpath:" then
    res z:runningFromJar    true
    res expectedInfo "%TEST_DATALIST_ERROR: Expected ERROR starts with: JarResource: seek location beyond end of file..PASS"
    set instructions "^{instructions}\n\n&
                      Note: If running confidence tests, you may need to open a separate terminal to run the test successfully."
    DATALIST/bg ^{datDir}.testxy3000.prm START=10
  endif

  if interAct OR coreGraphics then
    pipe on
      panel/msgid=MAIN/setup/controls=gc

      if standalone isTrue then
        gcontrol label macro "MACRO"
        gcontrol menu MAIN "Exit with Status = " "PASS,FAIL" /tleft
        set gc.MAIN.itemColors {PASS=GREEN,FAIL=RED}
      endif

      gcontrol text idtext "INSTRUCTIONS" ^{instructions} 24 7 /title

      shellgui/id=idshellgui/attach
      say "EXPECTED OUTPUT:"
      if runningFromJar then
        INFO "^expectedInfo"
        INFO "^expectedInfo"
      else
        say "  <No Output>"
      endif
      say ""
      say ""
      say "ACTUAL OUTPUT:"
      DATALIST/bg ^{datDir}.testxy3000.prm START=10

    pipe off
  endif

endmacro

!******************************************************************************!
procedure processMessage m:msg
  if msg.name EQS "MAIN" then
    if msg.data EQS "EXIT" then
      pipe stop
    else
      assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
      pipe stop
    endif
  else
    say "Unhandled messagename: ^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
  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
