!------------------------------------------------------------------------------!
! 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

  call setDatDir

  if interAct OR coreGraphics 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/controls=gc
      list2/grid=on/msgid=MAIN/id=idlist
      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" "Initializing..." 24 10 /title
      gcontrol/nc=2 button test "ListTest" &
              "FgColorByField,BgColorByField,FgColorByField_,BgColorByField_,&
               GlobalFgColor,ColorNamesMap,ColorNames,ColorMap,ColorHidden,Range" none

    pipe off

  endif
endmacro

!------------------------------------------------------------------------------!
procedure processMessage m:msg
!
! Procedure for handling all messages
!
  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 "FGCOLORBYFIELD" then
      call test_fgcolor_by_field
    elseif msg.data EQS "FGCOLORBYFIELD_" then
      call test_fgcolor_by_field_name
    elseif msg.data EQS "BGCOLORBYFIELD" then
      call test_bgcolor_by_field
    elseif msg.data EQS "BGCOLORBYFIELD_" then
      call test_bgcolor_by_field_name
    elseif msg.data EQS "GLOBALFGCOLOR" then
      call test_global_fg_color
    elseif msg.data EQS "COLORNAMESMAP" then
      call test_color_namesmap
    elseif msg.data EQS "COLORNAMES" then
      call test_color_names
    elseif msg.data EQS "COLORMAP" then
      call test_global_colormap
    elseif msg.data EQS "COLORHIDDEN" then
      call test_hidden
    elseif msg.data EQS "RANGE" then
      call test_range
    else
      call test_none
    endif
    
  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

!------------------------------------------------------------------------------!
procedure test_none
  set reg.idlist.openFile ""
  set reg.panel.controls.idtext.value "List should be empty"
return

!-----------------------------------------------------------------
!   Test list template processing, use XDATALIST color map.
procedure test_global_colormap
  ! To test this against X-Midas you need a .key file that matches:
  !     A:COMMENT=X-DataList template file
  !     A:COMMENT==X-DataList template file
  !     A:SECTION==XDATALIST
  !     F:VERSION==3.40
  !     L:TITLELINES==0
  !     A:LABELS==ON
  !     A:INDEX==RIGHT
  !     A:INDEXLABEL==Index
  !     L:INDEXRADIX==100
  !     L:SPACING==2
  !     L:FIELDS==2
  !     
  !     L:FIELD==1
  !     A:SUBR==COL1
  !     A:LABEL==COL1
  !     L:WIDTH==15
  !     A:COLOR==FIELD2
  !     A:DISPFORM==(1p1g15.6)
  !     
  !     L:FIELD==2
  !     A:SUBR==COL2
  !     A:LABEL==COL2
  !     L:WIDTH==15
  !     A:DISPFORM==(1p1g15.6)
  !     
  !     A:SECTION==END

  ! JC4: The color names are estimates... I just made them up!
  set t:fileData {ROW1={COL1=1,COL2="DarkGreen"},&
                  ROW2={COL1=2,COL2="Green"},&
                  ROW3={COL1=3,COL2="LightGreen"},&
                  ROW4={COL1=4,COL2="Aqua"},&
                  ROW5={COL1=5,COL2="LightBlue"},&
                  ROW6={COL1=6,COL2="DarkBlue"},&
                  ROW7={COL1=7,COL2="Violet"},&
                  ROW8={COL1=8,COL2="Purple"},&
                  ROW9={COL1=9,COL2="Pink"},&
                  ROW10={COL1=10,COL2="DarkRed"},&
                  ROW11={COL1=11,COL2="Red"},&
                  ROW12={COL1=12,COL2="Orange"},&
                  ROW13={COL1=13,COL2="DarkYellow"},&
                  ROW14={COL1=14,COL2="Yellow"},&
                  ROW15={COL1=15,COL2="LightYellow"},&
                  ROW16={COL1=16,COL2="White"}}

  set fileName temp_colormap_data{AUX="RAM",SR=(COL1/SL,COL2/2A)}

  file open/n tag ^fileName 
  foreach row intable/v fileData
    invoke ,, tag.insertData(-1,row)
  endfor
  file close tag

  !set reg.idlist.openFile    nxm.sys.test.test_list2_colors.csv
  set reg.idlist.openFile    "^fileName"
  set reg.idlist.setTemplate {_GLOBAL_={AUTOHIDE="FALSE",COLORMAP="XDATALIST",FGCOLOR=FIELD1}}
  
  set reg.panel.controls.idtext.value &
               "The foreground color for each row should be similar to the color &
                description given in the second column. (Note: The color names &
                are approximate and not exact descriptions.)"

return

!-----------------------------------------------------------------
!   Test list template processing, allowing color by enum or field
procedure test_color_namesmap
  set t:fileData {ROW1={TEXT="RED"},&
                  ROW2={TEXT="YELLOW"},&
                  ROW3={TEXT="GREEN"},&
                  ROW4={TEXT="BLUE"}}

  file open/n tag temp_csv{AUX=RAM,FG=CSV,HEADERROWS=1,COLUMNNAMES="TEXT"}
  foreach row intable/v fileData
    invoke ,, tag.insertData(-1,row)
  endfor
  file close tag

  set reg.idlist.openFile    temp_csv{AUX=RAM,FG=CSV,HEADERROWS=1}
  set reg.idlist.setTemplate {_GLOBAL_={FGCOLOR="FIELD_TEXT"},&
                              TEXT={COLORMAP={RED="red",YELLOW="YELLOW",GREEN="0x00FF00",BLUE="#0000FF"}}}
  
  set reg.panel.controls.idtext.value &
               "There should be four rows colored RED, YELLOW, GREEN, BLUE respectively."
return

!-----------------------------------------------------------------
!   Test list template processing, allowing color by enum or field
procedure test_color_names
  set t:fileData {ROW1={TEXT="RED"},&
                  ROW2={TEXT="YELLOW"},&
                  ROW3={TEXT="GREEN"},&
                  ROW4={TEXT="BLUE"},&
                  ROW5={TEXT="lightteal"},&
                  ROW6={TEXT="brightred"},&
                  ROW7={TEXT="brightyellow"}}

  file open/n tag temp_csv{AUX=RAM,FG=CSV,HEADERROWS=1,COLUMNNAMES="TEXT"}
  foreach row intable/v fileData
    invoke ,, tag.insertData(-1,row)
  endfor
  file close tag

  set reg.idlist.openFile    temp_csv{AUX=RAM,FG=CSV,HEADERROWS=1}
  set reg.idlist.setTemplate {_GLOBAL_={FGCOLOR="FIELD_TEXT",AUTOHIDE=FALSE}}
  
  set reg.panel.controls.idtext.value &
               "There should be seven rows where the foreground color of the row matches the text in &
                that row (e.g. "RED" is red)."
return

!-----------------------------------------------------------------
!   Test list template processing, allowing color by enum or field
procedure test_global_fg_color
  set reg.idlist.openFile    ^{datDir}.testxy3000.prm
  set reg.idlist.setTemplate {_GLOBAL_={FGCOLOR="FIELD1",BGCOLOR="white",AUTOHIDE=FALSE}}
  
  set reg.panel.controls.idtext.value &
               "Rows should have different foreground colors (none of which are &
                white). The background for all rows should be white."

return

!-----------------------------------------------------------------
!   Test list template processing, allowing color by enum or field
procedure test_fgcolor_by_field
  set reg.idlist.openFile ^{datDir}.testxy3000.prm
  set reg.idlist.setTemplate {ABSC={ALIGN="CENTER",MCOLORS="RED,YELLOW,GREEN,BLUE",&
                                    ENUM={1={LABEL="RED",   VALUE="1",COLOR="RED"},&
                                          2={LABEL="YELLOW",VALUE="2",COLOR="YELLOW"},&
                                          3={LABEL="GREEN", VALUE="3",COLOR="GREEN"},&
                                          4={LABEL="BLUE",  VALUE="4",COLOR="BLUE"}}},&
                              ORD3={FGCOLOR=FIELD1,ALIGN="CENTER",FORMAT="0"},&
                              ORD2={FGCOLOR=FIELD1,ALIGN="CENTER",FORMAT="0"},&
                              ORD={ FGCOLOR=FIELD1,ALIGN="CENTER",FORMAT="0"},&
                              _GLOBAL_={SORT=+ORD,AUTOORDER=F}}
  
  set reg.panel.controls.idtext.value &
               "There should be four columns visible (in this order: ABSC, ORD, ORD2, &
                ORD3). Each row should be colored according to the color specified in &
                the ABSC column. All values in the table should be centered."

return

!-----------------------------------------------------------------
!   Test list template processing, allowing color by enum or field
procedure test_bgcolor_by_field
  set reg.idlist.openFile ^{datDir}.testxy3000.prm
  set reg.idlist.setTemplate {ABSC={ALIGN="CENTER",MCOLORS="RED,YELLOW,GREEN,BLUE",&
                                    ENUM={1={LABEL="RED",   VALUE="1",COLOR="RED"},&
                                          2={LABEL="YELLOW",VALUE="2",COLOR="YELLOW"},&
                                          3={LABEL="GREEN", VALUE="3",COLOR="GREEN"},&
                                          4={LABEL="BLUE",  VALUE="4",COLOR="BLUE"}}},&
                              ORD3={FGCOLOR="BLACK",BGCOLOR=FIELD1,ALIGN="CENTER",FORMAT="0"},&
                              ORD2={FGCOLOR="BLACK",BGCOLOR=FIELD1,ALIGN="CENTER",FORMAT="0"},&
                              ORD={ FGCOLOR="BLACK",BGCOLOR=FIELD1,ALIGN="CENTER",FORMAT="0"},&
                              _GLOBAL_={SORT=+ORD,AUTOORDER=T}}
  
  set reg.panel.controls.idtext.value &
               "There should be four columns visible (in this order: ABSC, ORD3, &
                ORD2, ORD). The background of each ORDn column should match the &
                foreground of the ABSC column. The foreground of each ORDn column &
                should be black."

return

!-----------------------------------------------------------------
!   Test list template processing, allowing color by enum or field
procedure test_fgcolor_by_field_name
  set reg.idlist.openFile ^{datDir}.test3000
  set reg.idlist.setTemplate {INPU={},&
                              CONN={},&
                              OUTP={},&
                              USER={COLORMAP={AWD="GREEN",MJC="BLUE",ERF="RED",_DEFAULT_="FIELD_CLOC"}},&
                              RESY={},&
                              TCIN={},&
                              CLOC={COLORMAP={I="YELLOW",_DEFAULT_="ORANGE"}},&
                              _GLOBAL_={FGCOLOR="FIELD_USER"}}
  
  set reg.panel.controls.idtext.value &
               "Rows should be colored based on the value of the USER column: &
                AWD=GREEN, MJC=BLUE, ERF=RED and all others should be YELLOW."

return

!-----------------------------------------------------------------
!   Test list template processing, allowing color by enum or field
procedure test_bgcolor_by_field_name
  set reg.idlist.openFile ^{datDir}.test3000
  set reg.idlist.setTemplate {INPU={},&
                              CONN={},&
                              OUTP={},&
                              USER={COLORMAP={AWD="GREEN",MJC="BLUE",ERF="RED",_DEFAULT_="FIELD_CLOC"}},&
                              RESY={},&
                              TCIN={},&
                              CLOC={COLORMAP={I="YELLOW",_DEFAULT_="ORANGE"}},&
                              _GLOBAL_={BGCOLOR="FIELD_USER",FGCOLOR="BLACK"}}
  
  set reg.panel.controls.idtext.value &
               "Rows should be colored based on the value of the USER column: &
                AWD=GREEN, MJC=BLUE, ERF=RED and all others should be YELLOW."
return

!-----------------------------------------------------------------
!   Test list template processing, allowing color by enum or field
procedure test_hidden
  set reg.idlist.openFile ^{datDir}.test3000
  set reg.idlist.setTemplate {INPU={},&
                              USER={HIDE=TRUE,COLORMAP={AWD="GREEN",MJC="BLUE",ERF="RED",_DEFAULT_="FIELD_CLOC"}},&
                              CLOC={HIDE=TRUE,COLORMAP={I="YELLOW",_DEFAULT_="ORANGE"}},&
                              _GLOBAL_={BGCOLOR="FIELD_USER",FGCOLOR="BLACK"}}
  
  set reg.panel.controls.idtext.value &
               "Rows should be colored same as 'BgColorByField_' test, but only &
                the INPU column should be visible."
return

!-----------------------------------------------------------------
!   Test list template processing, allowing color by enum or field
procedure test_range
  set reg.idlist.openFile ^{datDir}.testxy3000.prm
  set reg.idlist.setTemplate {_GLOBAL_={AUTOHIDE=NO,FGCOLOR=FIELD_ABSC},&
                              ABSC={COLORMAP={_DEFAULT_=red,TEST(X,LT,3)=yellow}}}
  
  set reg.panel.controls.idtext.value &
               "Rows where the ABSC value is less than 3 should be colored yellow. &
                All others should be colored red."
return

