!******************************************************************************!
! Tests the functionality of customizing the dotted keywords and making them
! flat by default
!
! Arguments: None
!
! @bug     NXM-3311 Keywords tget cannot handle dotted keywords by default
! @since   3.9.1
! @author: Kevin Esterheld
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE  ! for defects or more obscure test case(s)

  ENV GET IOOPTIONS origIOOptions

  !This is the exception we get when we have not change any settings for it to work correctly
  set expectedException "KeyObject: Can not access 'YYY' in Data when given no arguments: No methods found."
  ! will throw exception
  call runTestProcess
  ! will use the switch to make it false
  call runTestProcessFlatSwitch

  ENV SET IOOPTIONS +SetKeywordDefaultFlatValueToFalse
  ! The rest will work correctly
  call runTestProcess

  invoke origDotSubstitute nxm.sys.lib.Keywords.getDotSubstitute()
  invoke nxm.sys.lib.Keywords.setDotSubstitute("***dot***")
  ! will work with different keyword dot substitute (functionality unittested in KeywordsTest.java)
  call runTestProcess

  invoke nxm.sys.lib.Keywords.setDotSubstitute(origDotSubstitute)

  ENV SET IOOPTIONS origIOOptions
endmacro

!******************************************************************************!
! This will run the test. Use this when testing different environments
!******************************************************************************!
procedure runTestProcess
  waveform temp{aux=ram}
  key temp{aux=ram} put XXX.YYY 10
  key temp{aux=ram} put simpleky 10
  key temp{aux=ram} put XXX 20
  key temp{aux=ram} tget mykey
  res/all mykey
return

procedure runTestProcessFlatSwitch
  waveform temp{aux=ram}
  key temp{aux=ram} put XXX.YYY 10
  key temp{aux=ram} put simpleky 10
  key temp{aux=ram} put XXX 20
  key/flat=false temp{aux=ram} tget mykey
  res/all mykey
return
!******************************************************************************!
! If an unexpected exception is caught, mark test as failed, unless it is expected
!******************************************************************************!
procedure processException m:emsg
say ^emsg.data.message
  if expectedException REXISTS then

    assert/text="^reg.main.name: Expected ERROR starts with: ^{expectedException}" expectedException EQSS emsg.data.message
    remove expectedException
  else
    assert/text="^reg.main.name: Caught unexpected exception ^{emsg.data}" "FALSE" isTrue
    if "Trace" SUBS ENV.DEBUG then invoke ,, emsg.data.printStackTrace()
  endif
return