!
! Test for MAPDEMO. Direct access to web servers is required.
! Additionally GMap tests are only run with /GMAP switch
! since Google Maps limits number of connections per day.
!
! Since 3.5.3 - switched to using geoserver for WMS portion of test
!
! Author:  J. Czechowski
!
startmacro S:wmsURL["http://nextmidas.com:8800/geoserver/ows"] S:nmsURL["http://nextmidas.com:8080/nms"]
  switch INTERACTIVE interAct   GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline   GET DEF=FALSE SDEF=TRUE
  switch GMAP        google     GET DEF=FALSE SDEF=TRUE
  switch ALTTESTENV  alttestenv GET DEF=FALSE SDEF=TRUE

  invoke z:jvmHangFix nxm.sys.lib.Shell.getJVMHangWorkaround()
  res z:mytrue true
  invoke ,, nxm.sys.lib.Shell.setJVMHangWorkaround(^mytrue)

  if interAct then
    set z:wms true
    set z:nms true
    set wmsInstr "\n  WMS"
    set nmsInstr "\n  NMS"

    if alttestenv then
      res urlFileAltWms "nextmidas_url_alt_wms.txt"
      if urlFileAltWms nfexists then
        warn "^reg.main.name: SKIPPING WMS portion since running in alternate test environment but ^{urlFileAltWms} not found"
        set z:wms false
        set wmsInstr ""
      else
        file open tag urlFileAltWms
        file read tag wmsURL
        file close tag
      endif

      res urlFileAltNms "nextmidas_url_alt_nms.txt"
      if urlFileAltNms nfexists then
        warn "^reg.main.name: SKIPPING NMS portion since running in alternate test environment but ^{urlFileAltNms} not found"
        set z:nms false
        set nmsInstr ""
      else
        file open tag urlFileAltNms
        file read tag nmsURL
        file close tag
      endif
    endif

    if google then
      set googleInstr "\n  GOOGLE"
    else
      set googleInstr ""
      info "^reg.main.name: SKIPPING Google portion. Add /GMAP to include Google Maps (disabled by default &
            due to Google's limiting on number of downloads)."
    endif

    if wms OR nms OR google then
      set instructions "Should see maps in the following tabs:&
                        ^{wmsInstr}^{nmsInstr}^{googleInstr}\n\n&
                        **DO NOT CLICK QUIT**"
      pipe init
        panel/msgid=MAIN/setup/controls=gc

        if wms then
          mapdemo/bg/id=wmsdemo  TYPE="WMS"  URL="^{wmsURL}"
          set instructions "^{instructions}\n\nIn the WMS tab click 'Configure' to add &
                            map layers."
        endif
        if nms then
          mapdemo/bg/id=nmsdemo  TYPE="NMS"  URL="^{nmsURL}"
        endif
        if google then
          mapdemo/bg/id=gmapdemo TYPE="GMap"
        endif

        gcontrol label  macro   "MACRO"
        gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
        set gc.main.itemColors {PASS=GREEN,FAIL=RED}
        gcontrol text idtext "Instructions" "^{instructions}" 24 10 /title

      pipe off
    endif

  endif

  invoke ,, nxm.sys.lib.Shell.setJVMHangWorkaround(^jvmHangFix)
endmacro


procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    if reg.wmsdemo  rexists then message send wmsdemo  ,, STATE ,, QUIT
    if reg.nmsdemo  rexists then message send nmsdemo  ,, STATE ,, QUIT
    if reg.gmapdemo rexists then message send gmapdemo ,, STATE ,, QUIT

    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop
  else
    say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return
