!******************************************************************************!
! Tests interrupt a command (BUG 2150 & BUG 2718)
!
! Author:  JC4, J. Bauer, J. McCall
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)

  call setDatDir

  if interAct then
    ! test case #1 interrupting primitive command that takes a long time during it's open method
    ! for BUG 2718 (Cntrl_C) this calls a submacro to call the primitive command
    %test_interrupt_with_submacro_pt2
    info "====> Returned from test1 <===="
    

if env.osname neqs "LINUX" then
  ! NTN: There is a known issue under non-Linux based OS (e.g. Windows and Solaris) where
  !      the default interrupt signal handler gets restored after the initial ctrl+c
  !      which causes subsequent ctrl+c to kill the JVM. A potential workaround to
  !      that would be to update NTerminal.c to restore our signal handler after
  !      we process an interrupt.
  ! TODO: until the above issue is addressed, we will be skipping the rest of the tests
  warn "^reg.main.name: Skipping the rest of the interrupt tests for non-Linux platforms..."
else
    ! test case #2 interrupting a primitive command outside of pipe section
    info "Directions: Use CTRL+C to exit the plot."
    plot ^{datDir}.world.prm
    assert/text="^reg.main.name: Ctrl+C (interrupt) command run outside the pipe section." TRUE

    ! test case #3 interrupting a child macro (sub-macro) that is piped
    info "Directions: Use CTRL+C to exit the DEMO macro."
    DEMO;SYS
    assert/text="^reg.main.name: Ctrl+C (interrupt) piped sub-macro." TRUE

    ! test case #4 interrupting long running series of piped sub-macros (test scenario for ICE)
    !info "Directions: Press CTRL+C very quickly twice to interrupt the loop that calls a long running piped macro"
    !do ii 1 20
      ! todo check
    !enddo
    !assert/text="^reg.main.name: Ctrl+C (interrupt) piped sub-macros in loop." TRUE
endif

  endif

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
