!******************************************************************************!
! Tests the STATUS command for the new "start time" and time string feature added
! in NXM-2037.
!
! Arguments: None
!
! @bug      NXM-2037 STATUS: display "Start time" and it's source and time str
!                    next to xstart/ystart that is a time unit
! @since    NeXtMidas 2.9.0
! @author:  Neon Ngo
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

  if interAct then
    call setDatDir

    res inst "Click on each test file to STATUS\n\n&
              1) verify that the 'Start time' output reflects what was selected\n\n&
              2) check the XStart field to see that it has a time string in parens after the value (if it is not zero).\n\n&
              Note:\n&
              xStart is labeled 'Abscissa Start'\n&
              yStart is labeled 'Secondary Start'"

    set format   sb
    set elements 16
    set amp      10

    set testfile0 "^{datDir}.world.prm"
    set testfile1 "ram:test_status_tc"
    set testfile2 "ram:test_status_tc_tcprec"
    set testfile3 "ram:test_status_tc_tcprec_xs"
    set testfile4 "ram:test_status_tc_xs"
    set testfile5 "ram:test_status_tcprec_xs"
    set testfile6 "ram:test_status_xs"
    set testfile7 "ram:test_status_tc_ys"
    set testfile8 "ram:test_status_timeline"

    timex now yis=yis

    ! testfile1: timecode (start of this year)
    wave out=testfile1 form=format elem=elements shape=sin amp=amp start=0
    header testfile1 tc=^yis
    ! testfile2: timecode + tc_prec
    noop testfile1 testfile2
    keyword/scope=main file=testfile2 func="SET" name="TC_PREC" value="5e-7"
    ! testfile3: timecode + tc_prec + xstart
    noop testfile2 testfile3{XStart="11:22:33.123456"}
    ! testfile4: timecode + xstart
    noop testfile1 testfile4{XStart="11:22:33.123456"}
    ! testfile5: tc_prec + xstart
    noop testfile2{TimeCode=0} testfile5{XStart="11:22:33.123456"}
    ! testfile6: xstart
    noop testfile1{TimeCode=0} testfile6{XStart="11:22:33.123456"}
    ! testfile7: timecode + ystart
    fft testfile1 testfile7

    pipe on
      panel/msgid=MAIN/setup/controls=gc
      gcontrol label macro "MACRO"
      gcontrol menu MAIN "Exit with Status = " "PASS,FAIL" /tleft
      set gc.MAIN.itemColors {PASS=GREEN,FAIL=RED}
      gcontrol text idtext "INSTRUCTIONS" "^inst" 24 16 /title

      gcontrol menu starttime "Test files to STATUS" "0.No Start Time,&
                                                      1.Timecode,&
                                                      2.Timecode+TC_PREC,&
                                                      3.Timecode+TC_PREC+XStart,&
                                                      4.TimeCode+XStart,&
                                                      5.TC_PREC+XStart,&
                                                      6.XStart,&
                                                      7.TimeCode+YStart,&
                                                      " ! 8.TimeLine" see %test_timeline for now
                                                      ! button /flags=TTop|ChkBox|ToggleList /nc=1
      shellgui/id=idshellgui/attach

    pipe off

  endif  ! end if interAct
endmacro

!**************************************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: Interactive tests for STATUS" msg.data eqss "PASS"
    pipe stop
  elseif msg.name eqs "STARTTIME" then
    ! clear text in SHELLGUI before next test case
    message func=sendx id=idshellgui name="CLEAR"

    if msg.data eqs "0.NO START TIME" then
      set testfile testfile0
    elseif msg.data eqs "1.TIMECODE" then
      set testfile testfile1
    elseif msg.data eqs "2.TIMECODE+TC_PREC" then
      set testfile testfile2
    elseif msg.data eqs "3.TIMECODE+TC_PREC+XSTART" then
      set testfile testfile3
    elseif msg.data eqs "4.TIMECODE+XSTART" then
      set testfile testfile4
    elseif msg.data eqs "5.TC_PREC+XSTART" then
      set testfile testfile5
    elseif msg.data eqs "6.XSTART" then
      set testfile testfile6
    elseif msg.data eqs "7.TIMECODE+YSTART" then
      set testfile testfile7
    elseif msg.data eqss "8.TIMELINE" then
      set testfile testfile8
    else
      say "^reg.main.name: unknown start time file: ^msg.data"
    endif

    say "nM> STATUS ^testfile
    status testfile
  else
    say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  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
