! Tests for the FNAME command.
!
! @Bug 2717 Macro: quoted DOS path treated as escape sequence
! @author  unknown / J. Czechowski IV
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

  ! save off AUX.DAT and switch to DAT with all the test files
  call setDatDir
  invoke test_dat_area datDirSlash.subString(8)
  

  ! ==== SINGLE CHAR LABEL =====================================================
  ! Check for existence of this macro file! There was a bug for SINGLE character
  ! label, that is why this test is written
  FNAME,LABEL=f,AREA=test,NAME=test_fname,EXT=mm,OPT=SYS
  assert/text="^reg.MAIN.name: single char label" f FEXISTS

  ! ==== PARSE FULLNAME RESULT =================================================
  !  Test the ability to parse the fullname result into its path (given by the
  !  AREA tag), NAME, EXT and  OPTION
  fname,LABEL=fullname,AREA=test,NAME=test_fname,EXT=mm,OPT=SYS
  fname,LABEL=sysTestPath,AREA=TEST,NAME="",EXT="",OPT=SYS
  fname/parse,LABEL=fullname,AREA=pathRes,NAME=nameRes,EXT=extRes,OPT=optRes
  assert/text="^reg.MAIN.name: /PARSE path"      pathRes EQS sysTestPath
  assert/text="^reg.MAIN.name: /PARSE root name" nameRes EQS "test_fname"
  assert/text="^reg.MAIN.name: /PARSE extension" extRes EQS "mm"

  ! ==== USING OPT=AUX OPTION ==================================================
  FNAME,LABEL=myWriteDir,AREA=^{aux.write},NAME="",EXT="",OPT=AUX
  assert/text="^reg.MAIN.name: write aux ^myWriteDir exists" myWriteDir DEXISTS

  ! ==== TEST MIXED CASE FILE NAMES ============================================
  ! Much of this is already included in the FileName unit tests, but wanted a few
  ! additional sanity checks, particularly after Bug 1534 (NeXtMidas 3.3.1).
  fname netName   OPT=SYS AREA=^test_dat_area  NAME="NeTwOrK"   EXT="PNG" /FNCASE=LowerCase
  fname arrowName OPT=SYS AREA=test NAME="TestArrow" EXT="PNG" /FNCASE=KeepCase
  ! Check path to see if NMROOT path has an upper case letter in path.  If it does,
  ! the network.png files will not be found.
  res additionalInstr ""
  invoke pathIsAllLowerCase env.nmroot.matches("[^A-Z]*")
  if (pathIsAllLowerCase ISFALSE) then
    ! Since 3.8.0 - mixed case works fine on DOS
    if (env.OSTYPE NEQS "DOS") then
      res additionalInstr "\n\nNote: Since your NMROOT contains upper case letters, the &
                           files holding the computer images will not be found"
    endif
  endif

  if (interAct) then
    pipe on
      res inst "Should see four pictures. The top two should show green arrows, &
                the bottom two should show pairs of computers. ^additionalInstr"

      panel/msgid=MAIN/setup/controls=gc
      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" "^inst" 24 24 /title

      plot/ID=NM_NET   ^{datDir}.NeTwOrK.PNG{FNCASE=LowerCase}
      plot/ID=NM_ARROW "nxm.sys.test.TestArrow.PNG{FNCASE=KeepCase}"

      !!! TODO: Remove the if check below once we handle the Windows path
      !!!       separator better in Macro.java execBranch(int, int)  (BUG 2717)
      if env.ostype eqs "DOS" then
        plot/ID=FN_ARROW ^arrowName
        plot/ID=FN_NET   ^netName
      else
        plot/ID=FN_ARROW "^arrowName"
        plot/ID=FN_NET   "^netName"
      endif

    pipe off
  endif

endmacro

!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop
  else
    say "^reg.main.name: 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
