! Tests calls to PROCEDURE.
!
startmacro

  call setDatDir

  result tp1 44
  call testproc1
  call testproc2 1 2 3
  call testproc3
  call testproc4 4 5 6
  call testproc5
  assert/test=pass tp1 eq 101
  assert/test=pass tp2 eq 102
  call test_fn "^{datDir}.Sunset.jpg"
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

! Test simple procedure call
procedure testproc1
  assert/text="%TEST_PROCEDURE: ACCESS TO REGISTRY" reg.main.name REXISTS
return

! Test procedure call with arguments
procedure testproc2 I:int F:float S:string
  assert/test=pass int    eq  1
  assert/test=pass float  eq  2.0
  assert/test=pass string eqs "3"
return
        
! Test procedure call with defaults
procedure testproc3 I:int[1] F:float[2] S:string["3"]
  assert/test=pass int    eq  1
  assert/test=pass float  eq  2.0
  assert/test=pass string eqs "3"
return

! Test procedure call overriding defaults
procedure testproc4 I:int[1] F:float[2] S:string["3"]
  assert/test=pass int    eq  4
  assert/test=pass float  eq  5.0
  assert/test=pass string eqs "6"
return

! Test procedure scoping
procedure testproc5
  assert/test=pass tp1 eq 44
  result tp2 102
  set tp1 101
return

procedure test_fn fn:infile
! Bug 1868:
!   Before NXM 2.7.1 qualifiers would attach to the input result, 
!   changing the original input result name!
!
!   Before this fix:
!      "^infile" ==> "Sunset.jpg{xs=10,ys=20,xd=0.03,yd=0.04}"
!
status infile{xs=10,ys=20,xd=0.03,yd=0.04} xstart=xs ystart=ys xdelta=xd ydelta=yd
assert/text="Bug 1868: Filename (fn:) input qualifiers attach to result" "^infile" eqs "Sunset.jpg"

return
