! Tests for the IMPORT command
!
!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

  invoke panelExists reg.shell.M.dictionary.isDictionaryEntry(PANEL)
  if panelExists isFalse then
    res z:interAct false
  endif

  call test_default_parameter

! TODO: This test case fails under Web Start for several reasons:
!       1. NMROOT is NOT defined on user's box
!       2. NMROOT is defined (e.g. /midas/nxmxxx) but NOT the same as ENV.NMROOT
!          (e.g. jar:http://nextmidas.com/nxm301/jars/nxm-sys.jar!/)
!       3. NM_PID is NOT defined, etc.
! If we add ENV.RUNMODE (for enhancement BUG 388) then we can make appropriate
! changes to this test case to skip this test case under Web Start mode
  if "^{reg.shell.class}" eqs "class nxm.sys.libxm.XmShell" then
    info "Tests for IMPORT skipped when running as an X-Midas option tree."
  elseif "^{reg.shell.parent.class}" eqs "class nxm.sys.lib.Webstart" then
    info "Tests for IMPORT skipped when running as a Java Web Start application."
  else
    if ^{env.NMROOT} EQS "classpath:" then
      invoke pathToJar nxm.sys.lib.Shell.getPathToOptJar(sys)
      if env.osname eqss "Windows" then
        invoke endIndex pathToJar.indexOf(\jars\)
      else
        invoke endIndex pathToJar.indexOf("/jars/")
      endif
      res pathNMROOT "^{pathToJar.substring(0,^{endIndex})}"
    else
      res pathNMROOT env.nmroot
    endif

    ! Checks for extra leading slash when running on Windows - NXM-3845 since NeXtMidas 4.1.1
    if ENV.OSNAME EQSS "Windows" then
      invoke pathNMROOT pathNMROOT.replace("/",\)
    endif

    import IN=NMROOT OUT=rootRes
    ! 2010-06-22 NTN: need to normalize path by getting absolutePath (to remove and extra path separators) for BUG 2205
    if rootRes NEQSS pathNMROOT then
      new java.io.File(rootRes) file
      res rootRes file.getAbsolutePath()
    endif
    ! May have a trailing / or \ added to ENV.NMROOT which the environment variable does not have
    assert/text="^reg.main.name: get NMROOT env variable" rootRes EQSS pathNMROOT

    result NMROOT "Already exists"
    import IN=NMROOT OUT=secondRootRes
    ! 2010-06-22 NTN: need to normalize path by getting absolutePath (to remove and extra path separators) for BUG 2205
    if secondRootRes NEQSS pathNMROOT then
      new java.io.File(secondRootRes) file
      res secondRootRes file.getAbsolutePath()
    endif
    ! May have a trailing / or \ added to ENV.NMROOT which the environment variable does not have
    assert/text="^reg.main.name: get NMROOT env var with existing NMROOT result" &
             secondRootRes EQSS pathNMROOT

    if ^{env.NMROOT} EQS "classpath:" then
      info "^reg.main.name: SKIPPING get NM_PID env variable since NM_PID gets set to 0000 &
            when running from a jar file"
    else
      import IN=NM_PID OUT=pidRes
      assert/text="^reg.main.name: get NM_PID env variable" pidRes EQ ^env.pid
    endif

    if interAct and baseline then
      %test_import_with_dot
    endif

    %test_import_size

  endif
endmacro

!******************************************************************************!
procedure test_default_parameter

  import "A_BOGUS_ENV_VAR" resname DEF="ExpectedDefaultValue"

  assert/text="IMPORT with DEF parameter for default env variable value." ^{resname} eqs "ExpectedDefaultValue"

return
