!------------------------------------------------------------------------------!
! Tests for LIST2 command.
!
!   Author : J. Czechowski IV
!------------------------------------------------------------------------------!
startmacro/tsetup=nxm.sys.test.test_list2_getrow.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

  if interAct OR coreGraphics then
    set rows   {}
    set rows.1 {NUM=1,TEXT="ABC"}
    set rows.2 {NUM=2,TEXT="1:1197422519.747852"}  ! <-- Test case from Pete, see Bug 1219 and Bug 1218
    set rows.3 {NUM=3,TEXT=""}                     ! <-- Fails for BLUE files in 2.4.2

    set blueFile ram:mybluefile{FG=PRM,SR=(NUM/SL,TEXT/4A)}
    set csvFile  ram:mycsvfile{FG=CSV,HEADERROWS=1,COLUMNNAMES="NUM,TEXT"}

    call write_data rows blueFile
    call write_data rows csvFile

    pipe init
      panel/msgid=MAIN/controls=gc
      list2/id=blueList blueFile
      list2/id=csvList  csvFile

      call test_data rows "blueList"
      call test_data rows "csvList"

      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" "Done with automatic tests." 24 8 /title

    pipe off
  endif
endmacro

!------------------------------------------------------------------------------!
! Procedure for handling all messages
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"
  else
    say "Unhandled messagename: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return


!------------------------------------------------------------------------------!
! Verify that the data in LIST2 matches the DATA table
procedure write_data t:data fn:fname
  file open/n tag fname
  foreach row inTable/v data
    invoke ,, tag.insertData(-1,row)
  endfor
  file close tag
return

!------------------------------------------------------------------------------!
! Verify that the data in LIST2 matches the DATA table
procedure test_data t:data u:idlist
  calc L:i 1
  foreach row inTable/v data
    invoke r reg.^{idlist}.getRow(i)
    set t ^r
    assert/text="Checking ^idlist, row ^i NUM  is ^row.num"    row.num  eq  r.num
    assert/text="Checking ^idlist, row ^i TEXT is '^row.text'" row.text eqs r.text
    assert/text="Checking table, row ^i NUM  is ^row.num"      row.num  eq  t.num
    assert/text="Checking table, row ^i TEXT is '^row.text'"   row.text eqs t.text
    calc L:i i 1 +
  endfor
return

