!------------------------------------------------------------------------------!
! Tests for LIST command.
! NOTE:  this is an interactive test and requires operator verification
!        in order to determine test success.
!
!   Author : J. Hallam
!
!------------------------------------------------------------------------------!

startmacro

switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE
if interAct then
  ! INPUT files used for tests
  fname infile1 area=test name=input_test_list_01 ext=tmp opt=sys
  fname infile2 area=test name=input_test_list_02 ext=tmp opt=sys

  pipe init
  
    panel/msgid=MAIN/id=panel/setup/controls=gc
    list/grid=on/msgid=MAIN/win=pane1/id=idlist

    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" "Select each button under TESTS for &
                          more detailed instructions." 24 7 /title
    gcontrol/nc=3 button nextlist "TESTS" &
            "none,ColSpacing,Templates,Scrollend,Insert,Color" none
    gcontrol/nc=2 button SCROLLEND "SCROLLEND" "ON,OFF" off

  pipe off

  ! Erase temporary files
  erase/quiet/warn=no temp_list_colspacing
  erase/quiet/warn=no temp_list_scrollend
  erase/quiet/warn=no temp_list_insert

  %test_list_select
  %test_list_template
  %test_list_template_color_enum
  %test_list_poll
  %test_list_256ascii
  if baseline then
    %test_dr506539
    %test_list_jsetup  ! Bug 2228, 2229, 2230
    %test_list_addrow  ! Bug 2228, 2230
  endif

endif

endmacro

!------------------------------------------------------------------------------!
procedure processMessage m:msg
!
! Procedure for handling all messages
!
  if msg.fid EQS "IDLIST" then
    say "Got ^msg.name from ^msg.fid"
  elseif msg.name EQS "NEXTLIST" then
    if msg.data EQS "COLSPACING" then
      call test_column_spacing
    elseif msg.data EQS "TEMPLATES" then
      call test_templates
    elseif msg.data EQS "SCROLLEND" then
      call test_scrollEnd
    elseif msg.data EQS "INSERT" then
      call test_insertrows
    elseif msg.data EQS "COLOR" then
      call test_color
    else
      ! NONE
      call test_none
    endif
  elseif msg.name EQS "SCROLLEND" then
    if msg.data EQS "ON" then
      result tempState 1
    else
      result tempState 0
    endif
    set reg.idlist.scrollend ^tempState
    mess send idlist,,"OPENFILE" ,, temp_list_scrollend

  elseif msg.name EQS "MAIN" then
    assert/text="List tests" "PASS" SUBS msg.data
    pipe stop
  elseif msg.name EQS "SHOWN" then
    ! Do nothing
  
  else
    say "Unhandled messagename: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif


return

!------------------------------------------------------------------------------!
procedure test_none
  mess send idlist,,"CLOSEFILE" ,,""
  mess send idlist,,"OPENFILE" ,,""
  set reg.panel.controls.idtext.value "List should be empty."

return
!-----------------------------------------------------------------
procedure test_column_spacing
!
!   Test list display of large window with evenly spaced columns"
!
  waveform temp_list_colspacing sb 144 white 3
  headermod temp_list_colspacing format=sb type=2000 fs=12 size=12
  mess send idlist ,,"OPENFILE",,temp_list_colspacing  
  set reg.panel.controls.idtext.value &
      "You should see 12 rows in the list window, &
      with each column evenly spaced."


return
!-----------------------------------------------------------------
procedure test_templates
!   Test list template processing, allowing color by enum or field
!
!   This test is used to verify DR370-1 and DR5500-1.  Originally the
!   formatting for a template file would show up in the column where the 
!   data was initially, not where the template reordered it to be, plus you
!   couldn't specifiy COLOR by enum (MCOLORS) or by FIELD.

  mess send idlist,,"OPENFILE" ,, "^infile1"
  mess send idlist,,"OPENTEMPLATE" ,, "^infile2"
  set reg.panel.controls.idtext.value &
               "Colors in column SR01 should match SR02. &
                Column SR02: Each 'One' should be in red, &
                'Two' in yellow', Three' in green.  Column SR03 &
                should be in green text. Column SR04 should be in red text. &
                Column labels should be centered."

return

!-----------------------------------------------------------------

procedure test_scrollend
!
!   Test the SCROLLEND method when displaying lists
!
  waveform temp_list_scrollend sf 1k
  mess send idlist,,"OPENFILE" ,, temp_list_scrollend
  
  set reg.panel.controls.idtext.value &
      "Press the SCROLLEND button (below) to display the bottom or top of file."

return
!------------------------------------------------------------------------------
procedure test_insertrows
!
! Test ADDROW, SELECTROW methods
!
  noop infile1(0:10) temp_list_insert
  mess send idlist,,"OPENFILE" ,, temp_list_insert
  
  ! Build the table to add (SR01, SR02, ...)
  result t {SR01=111,SR02=222,SR03=333,SR04=444}
  set reg.panel.controls.idtext.value "Note how many rows are in the pane &
                                       initially. Click ADDROW to add an &
                                       entry to the bottom."
  gcontrol/wait BUTTON temp "ADDROW" "ADDROW,CANCEL" 1
  if temp EQS "CANCEL" return

  set reg.idlist.addrow t

  res L:rowNum 5
  set reg.panel.controls.idtext.value "This should add a row at the bottom of &
                                       the list. Click INSERTROW to INSERT an &
                                       entry at row ^rowNum."
  gcontrol/wait BUTTON temp "INSERTROW" "INSERTROW,CANCEL" 1
  if temp EQS "CANCEL" return
  set t.LIST__POS ^rowNum
  set reg.idlist.addrow t

  set reg.panel.controls.idtext.value "This should INSERT a row at row ^rowNum. &
                                       Click ADDROW to ADD an entry at the end."

  gcontrol/wait BUTTON temp "ADDROW" "ADDROW,CANCEL" 1
  if temp EQS "CANCEL" return
  set t.LIST__POS 0
  set reg.idlist.addrow t
  result selRow 10
  set reg.panel.controls.idtext.value "This should again add a row at the end. &
                                       Click SELECTROW to highlight row ^selRow."

  gcontrol/wait BUTTON temp "SELECTROW" "SELECTROW,CANCEL" 1
  if temp EQS "CANCEL" return

  set reg.idlist.selectrow ^selRow
  set reg.panel.controls.idtext.value "List should jump to the highlighted row."

return
!------------------------------------------------------------------------------!
procedure test_color
  mess send idlist,,"OPENFILE" ,, "^infile1"
  status infile1 size=fileSize
  set item 1
  set reg.panel.controls.idtext.value "Left click and select either ROW or COL."
  !gcontrol/wait/legacy=true CHOICE type "ROWORCOL" "ROW,COL" "ROW"
  gcontrol/wait CHOICE type "ROWORCOL" "ROW,COL" "ROW"
  
  set reg.panel.controls.idtext.value "Set the ^type number and then right click on ^type number."
  !gcontrol/wait/legacy=true LVAL item "^type number" 1 1 fileSize 1
  gcontrol/wait LVAL item "^type number" 1 1 fileSize 1
  
  set reg.panel.controls.idtext.value "Select the color by left clicking."
  !gcontrol/wait/legacy=true CHOICE Color "COLOR" "^reg.IDLIST.colorChoices" "RED"
  gcontrol/wait CHOICE Color "COLOR" "^reg.IDLIST.colorChoices" "RED"
  
  if type EQS "ROW" then
    set reg.IDLIST.setRowColors {ROW=^item,BG="^color"}
  else
    set reg.IDLIST.setColColors {COLUMN=^item,BG="^color"}
  endif
  set str "^type ^item should be ^color, or back to initial setting &
           if THEME is chosen."
  set reg.panel.controls.idtext.value "^str"

return
