!******************************************************************************!
! Test the Gcontrol CHOICE widget where there is a space in the item
!
! @bug      NXM-3545
! @author:  Jeanette McCall
! @since    NeXtMidas 3.9.3
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE SDEF=TRUE  ! for normal interactive test(s)

  set myInstructions "After the automatic test passes: \n\n&
                     1) Select one of the CHOICES\n\n&
                     2) Make sure no NPE is thrown\n\n&
                     3) Terminal should show the 'NPE' test passed."

  set this.timer(0) 0.3
  pipe on

    panel/msgid=MAIN/setup/controls=gc

    gcontrol label  macro "MACRO"
    gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
    gcontrol TEXT idtext INSTRUCTIONS "^myInstructions" 48 16 /title
    set gc.main.itemcolors {PASS=GREEN,FAIL=RED}
    gcontrol choice choiceWidget "CHOICES" "CHOICE 1,CHOICE 2,CHOICE 3,CHOICE 4" "CHOICE 2" /input /tooltip="^tipText"

  pipe off

endmacro

!**************************************************************************************************!
procedure processMessage m:msg

  if msg.name eqs "MAIN"
    assert/text="^reg.main.name: user indicated" msg.data eqs "PASS"
    pipe stop

  elseif msg.name eqs "CHOICEWIDGET"  then
    res selection msg.data
!    res gc.choiceWidget.itemCount
!    res gc.choiceWidget.items
    res previousCount gc.choiceWidget.itemCount
    invoke ,, gc.choiceWidget.remItem("^selection")
    res newCount gc.choiceWidget.itemCount
!    res gc.choiceWidget.items
!    res gc.choiceWidget.itemCount
  assert/text="^reg.main.name: removing user selected choice does not throw NPE" previousCount gt newCount

  elseif msg.name eqs "TIMER"  then
    res previousCount gc.choiceWidget.itemCount
    set gc.choiceWidget.remItem "Choice 4"
    res newCount gc.choiceWidget.itemCount
    assert/text="^reg.main.name: removing item decrements count" previousCount gt newCount
    set this.timer(0) 0.0   ! turn off the timer
    if interAct ISFALSE then pipe stop
  else
    !warning "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif

return

