startmacro S:nmrootpath["nmroot"] S:hostname["localhost"]
!
!
! Dependencies:
!  1) Requires a web server (i.e. apache (httpd)) running on this machine
!  configured to access Next-Midas
!
!  i.e) Make a link to the $NMROOT in /var/www/html ,or your webserver's
!       document root.
!
!  ln -s $NMROOT nmroot
!
!  2) file command: To generate a test file
result S:macroName "^reg.main.name"
if /DEBUG then
  result dbg 1
else
  result dbg -1
endif

if /VERBOSE then
  result verbose 1
else
  result verbose -1
endif

result outStatus 1

call setDatDir

if index.html{AUX=DAT} FEXISTS erase/all index.html{AUX=DAT}

if verbose GT 0 then
  res nmrootpath
endif

! Look for the world file in DAT without an index.html file.Successful if the
! DEFAULT EXIST qualifier is to check STATUS.
result url "http://^{hostname}/^{nmrootpath}^{datDirSlash}/world.prm"
result testName "Data w/o index.html file, default EXIST qualifier"
assert/dbg=^dbg/stat=tempStatus/text="^macroName: ^testName" "^url" FEXISTS
if "^tempStatus" NEQS "PASS" then
  res outStatus -1
endif
if verbose GT 0 then
  say "Status ^tempStatus, url ^url"
endif

! Look for the world file in DAT without an index.html file. Should pass
result url "http://^{hostname}/^{nmrootpath}/^{datDirSlash}/world.prm{EXIST=STATUS}"
result testName "Data w/o index.html file, EXIST=STATUS"
assert/dbg=^dbg/stat=tempStatus/text="^macroName: ^testName" "^url" FEXISTS
if "^tempStatus" NEQS "PASS" then
  res outStatus -1
endif
if verbose GT 0 then
  say "Status ^tempStatus, url ^url"
endif


info "SKIPPING ^reg.main.name test file exists in directory list {EXIST=list}. The test is not working as there is a change in code that prevents it."
! Successful if there is NO index.html in the DAT area
!result url "http://^{hostname}/^{nmrootpath}/^{datDirSlash}/world.prm{EXIST=list}"
!result testName "Data w/o index.html file, EXIST=LIST"
!assert/dbg=^dbg/stat=tempStatus/text="^macroName: ^testName" "^url" FEXISTS
!if "^tempStatus" NEQS "PASS" then
!  res outStatus -1
!endif
!if verbose GT 0 then
!  say "Status ^tempStatus, url ^url"
!endif


! This should ALWAYS fail, return code from the server (for the file) is used.
result url "http://^{hostname}/^{nmrootpath}/^{datDirSlash}/world.prm{EXIST=CGI}"
result testName "Data w/o index.html file, EXIST=CGI"
assert/dbg=^dbg/stat=tempStatus/text="^macroName: ^testName" "^url" NFEXISTS
if "^tempStatus" NEQS "PASS" then
  res outStatus -1
endif
if verbose GT 0 then
  say "Status ^tempStatus, url ^url"
endif

! This should PASS, because the DEFAULT is to NOT check status on files of this
! extension.
result s:url "http://^{hostname}/^{nmrootpath}/nxm/sys/dat/a_long_dummy_file.pl"
result testName "Perl file w/o index.html file, default EXIST qual"
assert/dbg=^dbg/stat=tempStatus/text="^macroName: ^testName" "^url" FEXISTS
if "^tempStatus" NEQS "PASS" then
  res outStatus -1
endif
if verbose GT 0 then
  say "Status ^tempStatus, url ^url"
endif

! This should ALWAYS pass, because it has a CGI extension.
result url "http://^{hostname}/^{nmrootpath}/nxm/sys/dat/a_long_dummy_file.pl{EXIST=CGI}"
result testName "Perl file without index.html file, EXIST=CGI"
assert/dbg=^dbg/stat=tempStatus/text="^macroName: ^testName" "^url" FEXISTS
if "^tempStatus" NEQS "PASS" then
  res outStatus -1
endif
if verbose GT 0 then
  say "Status ^tempStatus, url ^url"
endif

! DR-11873 -- When an index.html file existed in the same directory 
! with DATA file, we were not able to status the data file
!...so we create an index.html in the DAT area
file open/t/n tag index.html{aux=dat}{FLAGS=FORCEABORT}
file write tag "TEST_HTTPD: computer generated test file"
file close tag
result url "http://^{hostname}/^{nmrootpath}^{datDirSlash}/world.prm"
result testName "Data WITH index.html file, default EXIST"
assert/dbg=^dbg/stat=tempStatus/text="^macroName: ^testName" "^url" FEXISTS
if "^tempStatus" NEQS "PASS" res outStatus -1
if verbose GT 0 then
  say "Status ^tempStatus, url ^url"
endif

result url "http://^{hostname}/^{nmrootpath}/^{datDirSlash}/world"
result testName "Data(no ext.) WITH index.html file, default EXIST"
assert/dbg=^dbg/stat=tempStatus/text="^macroName: ^testName" "^url" FEXISTS
if "^tempStatus" NEQS "PASS" res outStatus -1
if verbose GT 0 then
  say "Status ^tempStatus, url ^url"
endif

info "SKIPPING ^reg.main.name test file exists in directory list {EXIST=list}. The test is not working as there is a change in code that prevents it."
! This should fail, since the index.html (an invalid one!) file is being 
! used to return a directory listing.
!result url "http://^{hostname}/^{nmrootpath}/^{datDirSlash}/world.prm{EXIST=list}"
!result testName "Data WITH index.html file, EXIST=LIST"
!assert/dbg=^dbg/stat=tempStatus/text="^macroName: ^testName" "^url" NFEXISTS
!if "^tempStatus" NEQS "PASS" res outStatus -1
!if verbose GT 0 then
!  say "Status ^tempStatus, url ^url"
!endif

! This should PASS, return code from the server (for the file) is used.
result url "http://^{hostname}/^{nmrootpath}/^{datDirSlash}/world.prm{EXIST=STATUS}"
result testName "Data WITH index.html file, EXIST=STATUS"
assert/dbg=^dbg/stat=tempStatus/text="^macroName: ^testName" "^url" FEXISTS
if "^tempStatus" NEQS "PASS" res outStatus -1
if verbose GT 0 then
  say "Status ^tempStatus, url ^url"
endif

! This should ALWAYS fail, because the extension is not a CGI extension
result url "http://^{hostname}/^{nmrootpath}/^{datDirSlash}/world.prm{EXIST=CGI}"
result testName "Data WITH index.html file, EXIST=CGI"
assert/dbg=^dbg/stat=tempStatus/text="^macroName: ^testName" "^url" NFEXISTS
if "^tempStatus" NEQS "PASS" res outStatus -1
if verbose GT 0 then
  say "Status ^tempStatus, url ^url"
endif


if outStatus LT 0 then
  info "^reg.main.name: Please verify the following server"
  info "information before running this test again."
  info "    NeXtMidas Host Name: ^{hostname}"
  info "    NeXtMidas Root Path: ^{nmrootpath}"
endif

endmacro

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