! purpose: Test the DISPLAY primitive
!
! author : JPH
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  set L:failedTests 0
  res maxv 10

  call setDatDir

if interAct then

  res instructions "There should be 2 windows outside the main window.  &
                    One should show the capital of Ireland in a large font.  &
                    In the second, the MAXV ('Maximum') should be displayed twice: once with &
                    the default separator ' ==> ' and once with a 10 dot(.) separator.&
                    MAXV should be incrementing every 2 seconds. You should not be able &
                    to close the displays by clicking on the [X] because this is a piped macro.&
                    "
  pipe on

  panel/msgid=MAIN/controls=gc/setup

  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" "^instructions" 24 12 /title

  ! TODO: Known Problem: DISPLAY windows do not configure. (hence using /WPOS=(x,y)
  display/FONTSZ=24/wpos=(420,25) FILE(^{datDir}.capital_cities.prm).data(1,NAME)/"Capital of Ireland"

  display/wpos=(420,120) MAXV/"Maximum" MAXV/"Maximum"//".........."

  set this.timer(0) 2
  pipe off

endif

endmacro

!******************************************************************************!
procedure processMessage m:msg

!info "^reg.main.name: info name ^msg"
if msg.name eqs "MAIN"
  if failedTests EQ 0 then
    assert/text="^reg.main.name: user indicated" msg.data eqs "PASS"
  else
    assert/text="^reg.main.name: detected ^failedTests failures" "FAIL"
  endif
  pipe stop

elseif msg.name EQS "TIMER" then
  calc maxv maxv 1 +

else
  ! do nothing
  say "Unhandled message name: ^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 failedATest s:msg
  assert/text="^reg.main.name: ^msg" FALSE
  calc L:failedTests failedTests 1 +
return
