!------------------------------------------------------------------------------!
! Tests for LIST2 command.
!
!   Author : J. Czechowski IV
!------------------------------------------------------------------------------!
startmacro/tsetup=nxm.sys.test.test_list2_setup.tbl
  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
  
  set origTemplate {TEXT={WIDTH=12,ALIGN=RIGHT},INT={WIDTH=12,ALIGN=RIGHT}}
  set thisTemplate ^{origTemplate}
  
  
  file open/n tag ram:test_file{COMPONENTS=(TEXT/1A/NONE/NONE,INT/SL/NONE/NONE)}
    invoke ,, tag.insertData(-1,{TEXT=100,INT=100})
    invoke ,, tag.insertData(-1,{TEXT=200,INT=200})
    invoke ,, tag.insertData(-1,{TEXT=300,INT=300})
    invoke ,, tag.insertData(-1,{TEXT=400,INT=400})
  file close tag

  
  if interAct OR coreGraphics then
    pipe init
      panel/msgid=MAIN/id=panel/controls=gc
      list2/grid=on/msgid=MAIN/id=idlist ,, thisTemplate
      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" "Should see two columns 'TEXT' (FORM=1A) &
                      and 'INT' (FORM=SL). Initially there is no data. Click &
                      'AutoTest' to run additional tests." 24 10 /title
      gcontrol/nc=2 button test "Test" "AutoTest" none

    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.fid EQS "IDLIST" then
    !say "Got ^msg.name from ^msg.fid"
  
  elseif msg.name EQS "TEST" then
    if msg.data eqs "AUTOTEST" then
      ! This test is related to Bug 917
      table thisTemplate EQUALS origTemplate status1
      assert/text="User template in macro not modified (initial)." status1 isTrue


      set reg.idlist.openFile ram:test_file
      table thisTemplate EQUALS origTemplate status2
      assert/text="User template in macro not modified (after openFile)." status2 isTrue


      if status1 isTrue and status2 isTrue then
        set reg.panel.controls.idtext.value "Automatic tests: PASS (should now see &
                   four rows ('100', '200', '300', '400'), the values in both &
                   columns for a given row should match)."
      else
        set reg.panel.controls.idtext.value "Automatic tests: FAIL (skip other tests)"
      endif
    endif
  else
    say "Unhandled messagename: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return
