!------------------------------------------------------------------------------!
!  Tests for LIST2 command to check for null pointer when deleting selected row.
!
!  @bug NXM-3214 LIST2 control Null pointer exception
!  @since   3.9.1
!  @author: Kevin Esterheld
!------------------------------------------------------------------------------!
startmacro/tsetup=nxm.sys.test.test_list2_setup.tbl s:autoSelect[false]
  switch INTERACTIVE  interAct     GET DEF=TRUE
  switch standalone   standalone   GET DEF=TRUE
  switch COREGRAPHICS coregraphics GET DEF=FALSE SDEF=TRUE  ! for a quick check of graphics - more extreme tests - since 3.8.1

  call setDatDir

  if interAct OR coreGraphics then
    set instr {}
    set instr.Select "Select the last row or a cell in that row"
    set instr.Remove "Click to remove the last 3 rows"
    set instr.Result "Click any row, there should not be any exceptions and the selection should be successful."
    set complete FALSE
    set fname ^{datDir}.testxy3000.prm

    pipe init
      panel/msgid=MAIN/id=panel/controls=gc
      list2/grid=on/msgid=MAIN/win=panel/id=idlist fname /LEGACY
      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"  "^{instr.Select}" 24 10 /title
      gcontrol Button clearLast3 "Action" "Clear Last 3 Rows"
    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="LIST2 tests" "PASS" SUBS msg.data
      pipe stop
    endif
  elseif msg.name EQS "SELECT" then
    if ^complete then
      set gc.idtext.value "Test Complete"
    else
      set gc.idtext.value "^{instr.Remove}"
      set complete TRUE
    endif
  elseif msg.name EQS "CLEARLAST3" then
    set reg.idlist.removeRows(4,6)
    set gc.idtext.value "^{instr.Result}"

  else
    say "Unhandled messagename: ^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
