!******************************************************************************!
! Test case to show handling of a Table by keyObject. Not specifically a plot
! issue, but plot has the mechanism to throw a warning for duplicate keys.
!
! @bug      2563 PLOT / KEYOBJECT: Annoying warning when using setup Table
! @author:  J Bauer
!******************************************************************************!
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)
  switch ALTTESTENV  alttestenv GET DEF=FALSE SDEF=TRUE

  call setDatDir

  if interAct AND sysDatFull then
    if alttestenv then
      info "^reg.main.name: Skipping since this test can be covered under test_plot_layerwms_configure &
            when running in alternate test environment.\n&
            NOTE: Adding this test in test_plot_layerwms_configure for alternate test environment is a TODO."
    else
      set instructions "You should see a plot with a map of the world and WMS overlay. \n\nYou should NOT see &
                       any warnings in the shellgui about duplicate WMS layers. "

      pipe on
        panel/msgid=MAIN/setup/controls=gc
        gcontrol label macro "Test MACRO"
        gcontrol menu  main "Exit with Status =" "PASS,FAIL" TABLE={ItemColors={PASS="GREEN",FAIL="RED"}} /tleft
        gcontrol text  idtext "Instructions" instructions 24 12 /title

        shellgui/id=idshellgui/attach

        plot/id=idplot setup=nxm.sys.test.plot_keyobject_setup.tbl
      pipe off
    endif
  endif
endmacro

!******************************************************************************!
! Main process message for this macro. 
!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop
  else
    say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
! If an unexpected exception is caught, mark test as failed, unless it is expected
!******************************************************************************!
procedure processException m:emsg
  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

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