! Tests the setting of JVM options when starting the shared JavaVM in NeXtOpt
!
! @author  Neon Ngo
! @version $Id: test_nm_jvmoptions.txt,v 1.4 2013/07/22 13:16:53 ntn Exp $
!******************************************************************************!
startmacro u:resTests["numTested"] u:resFails["numFailed"]

  !---------- INITIALIZATION -------------------------------------------------
  local test_count,fail_count,expected
  res test_count 0
  res fail_count 0

  !---------- test setting JVMOPTIONS ----------------------------------------
  res expected "MixedCaseStr1"
  nm/on/bg/id=999/jvmoptions="-DNEXTMIDAS_TEST1=MixedCaseStr1 -DNEXTMIDAS_SECOND_TEST=21"
  nm invoke xm.test_val1 java.lang.System.getProperty("NEXTMIDAS_TEST1")
  nm invoke xm.test_val2 java.lang.System.getProperty("NEXTMIDAS_SECOND_TEST")

  if test_val1 eqs "MIXEDCASESTR1" then
    ! X-Midas 4.6.0 and higher should have this fixed
    say "WARN: Your X-Midas version is upper casing all switch options to NM;NXM"
    res expected "MIXEDCASESTR1"
  endif

  call assert_str "NM/JVMOPTIONS with string"   test_count fail_count expected test_val1
  call assert_str "NM/JVMOPTIONS second option" test_count fail_count "21"     test_val2
  nm/off

  !---------- test setting JVMOPTIONS with a result parameter (BUG 1550) -----
  ! to allow mixed case arguments to be passed under X-Midas versions prior to 4.6.0 (Bug 1550)
  result test_options "-DNEXTMIDAS_test2=MixedCaseStr2 -DNEXTMIDAS_another_test=NEXTOPT"
  nm/on/bg/id=999/jvmoptions=test_options
  nm invoke xm.test_val3 java.lang.System.getProperty("NEXTMIDAS_test2")
  nm invoke xm.test_val4 java.lang.System.getProperty("NEXTMIDAS_another_test")

  call assert_str "NM/JVMOPTIONS with result parameter (Mixed-case string)" test_count fail_count "MixedCaseStr2" test_val3
  call assert_str "NM/JVMOPTIONS with result parameter (UPPER-case string)" test_count fail_count "NEXTOPT" test_val4
  nm/off

  !---------- Begin test -DNOIMPORTXMPATH in JVMOPTIONS (BUG 2279) -----------
  import XM_PATH orig_xmpath
  ! add SITE option tree (defined with all X-Midas installations) to path so that
  ! we can check that it does NOT get added to the PATH in the NeXtMidas session
  xmpath +SITE
  res expectedPath "SYS"
  nm/on/bg/id=999/jvmoptions="-DNOIMPORTXMPATH=TRUE"
  nm res xm.test_val1 opt.path

  call assert_str "NM/JVMOPTIONS (-DNOIMPORTXMPATH)"  test_count fail_count expectedPath test_val1
  nm/off
  export orig_xmpath XM_PATH
  !---------- End test -DNOIMPORTXMPATH JVMOPTION (BUG 2279) -----------------

  !---------- CLEANUP --------------------------------------------------------
  rem/quiet test_val*
  rem/quite test_options

  ! update test counts/failed (results)
  res ^resTests test_count
  res ^resFails fail_count
endmacro

!******************************************************************************!
include "%xm_assert" ! Includes the assertion subroutines
