!------------------------------------------------------------------------------!
! Include file used to handle a templatized set of tests. See %test_list2 for an
! example of how to use this.
!
! The table of tests should be created using:
!  fname dir area=test name="" ext="" opt=sys
!  res tests {ID1={TITLE="Title 1",SETUP={...},MACRO="^{dir}test_macro_1.mm"},&
!            {ID2={TITLE="Title 2",SETUP={...},MACRO="^{dir}test_macro_2.mm"},&
!            {ID3={TITLE="Title 3",SETUP={...},MACRO="^{dir}test_macro_3.mm"}}
!
!
!   Author : J. Czechowski IV
!   Version: $Id: multi_test_template.mm,v 1.7 2014/05/22 21:38:01 ntn Exp $
!------------------------------------------------------------------------------!

! Makes the setup table
!  tests - The table of tests
!  setup - An empty table to insert the setup into.
procedure makeSetupTable t:tests t:setup
  res setup.POS    {TYPE=POS,X=25,Y=25,W=1000,H=550}
  res setup.BORDER {TYPE=BORDERS,MASK=0x8000000F}
  res setup.LINE_1 {TYPE=LINE,INDEX=1,DIR=1,X=0.0,Y=0.5,I1=0,I2=0,FP=226}
  res setup.LINE_2 {TYPE=LINE,INDEX=2,DIR=1,X=1.0,Y=0.5,I1=0,I2=0,FP=0}
  res setup.LINE_3 {TYPE=LINE,INDEX=3,DIR=2,X=0.5,Y=0.0,I1=1,I2=2,FP=0}
  res setup.LINE_4 {TYPE=LINE,INDEX=4,DIR=2,X=0.5,Y=1.0,I1=1,I2=2,FP=0}
  res setup.PANE_0 {TYPE=PANE,INDEX=0,NAME=PANE0,TITLE=null,TH=0,IX1=1,IX2=2,IY1=3,IY2=4}

  res L:index 1
  foreach key INTABLE tests
    res setup.PANE_^{key} { }
    res setup.PANE_^{key}.TYPE PANE
    res setup.PANE_^{key}.INDEX ^{index}
    res setup.PANE_^{key}.NAME  "^{key}"
    res setup.PANE_^{key}.TITLE "^{TESTS.^{key}.TITLE}"
    res setup.PANE_^{key}.TH    12
    res setup.PANE_^{key}.IX1    1
    res setup.PANE_^{key}.IX2    2
    res setup.PANE_^{key}.IY1    3
    res setup.PANE_^{key}.IY2    4

    calc L:index index 1 +
  endfor
return

! Starts the tests
!  tests - The table of tests
procedure startTests t:tests
  ! The tests need to be started in reverse order so
  ! that the first one will be in the top/active tab

  table tests getkeys keyarray
  invoke size keyarray.getsize
  calc L:index size 1 -
  while index ge 0
    set key keyarray(^{index})
    if TESTS.^{key}.SETUP NREXISTS then
      %temp/mfn="^{TESTS.^{key}.MACRO}"/bg/id=^{key}/standalone=false
    elseif "^{TESTS.^{key}.SETUP}" EQS "NONE" then
      %temp/mfn="^{TESTS.^{key}.MACRO}"/bg/id=^{key}/standalone=false
    else
      %temp/mfn="^{TESTS.^{key}.MACRO}"/tsetup=^{TESTS.^{key}.SETUP}/bg/id=^{key}/standalone=false
    endif
    calc L:index index 1 -
  endwhile
return

! Exits the sub test macros by sending the "MAIN"="EXIT" message to each of them.
!  tests - The table of tests
procedure exitTests t:tests
  foreach key INTABLE tests
    if reg.^{key} rexists then
      sendto key "MAIN" "EXIT"
    elseif this.verbose then
      warn "Not sending EXIT message to non-running test ^key"
    endif
  endfor
return
