!******************************************************************************!
! Test the plotting of files for ALL layers.
!
! Author:  J. Hallam / J. Czechowski / Neon Ngo
!******************************************************************************!
startmacro S:baseline_resume_section["BEGINNING"]
  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 COREGRAPHICS  coreGraphics GET DEF=FALSE SDEF=TRUE  ! for a quick check of graphics - more extreme tests - since 3.8.1
  switch ALTTESTENV    alttestenv   GET DEF=FALSE SDEF=TRUE

  if interAct then
    res resetAxisIndex false

    ! save off AUX.DAT and switch to DAT with all the test files
    call setDatDir
    res origDatAux "^{aux.dat}"
    invoke nm_root nxm.sys.lib.Shell.getNmRoot()
    res aux.dat "^{nm_root}^{datDirSlash}"

    pipe init
      panel/msgid=MAIN/setup/controls=gc
      plot/id=idplot/READOUT="+OnAxis|+DateString"

      ! Prior to the fix for Bug 1001 the next line would cause an exception
      set reg.idplot.type "LINE"
      set reg.idplot.type "NONE"    ! Set it back to default of NONE

      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" "initializing..." 24 12 /title

      gcontrol/nc=3 button nextplot "TESTS" &
          "None,1D-Real,1D-Complex,2D,Poly,Multi,Multi-cols,XY,Geo,&
           T5-Cone,T5-ConeFlag,T5-Ellipse,T5-EllipseFlag,T5-Positions,T5-Filled,&
           Image,ImageTbl,CSV-Multi,CSV-XY,Geodetic,&
           DateString,LineThickness,TinyDelta" None /ttop

    pipe off

    erase/quiet/warn=n "temp_testplot_layer1d_real"
    erase/quiet/warn=n "temp_testplot_layer1d_complex"
    erase/quiet/warn=n "temp_testplot_layermulti"
    erase/quiet/warn=n "temp_testplot_layerxy"
    erase/quiet/warn=n "temp_testplot_csv.csv"
    res aux.dat "^origDatAux"  ! restore original AUX.DAT
  endif

  ! Additional non-interactive tests, run all the time /INTERACTIVE is set since they require
  ! the graphics to come up even though they don't require user interaction.
  if interAct then
    %test_plot_bug1659          ! Bug 1659
    %test_plot_mimic_auto       ! Bug 2910
    call test_colormap          ! Bug 2456
  endif

  ! Additional interactive tests, only run with /BASELINE
  if interAct AND baseline then

    ! Allow resuming by section 3.5.2
    res include_all         true  ! call all baseline tests - beginning
    res include_layerk      true  ! include tests starting in the first section with layerk...
    res include_part2_all   true  ! include all baseline tests in the 2nd section
    res include_part2_k     true  ! includes the last half of the 2nd section
    if baseline_resume_section STARTS "LAYERK" then
      res include_all       false
    elseif baseline_resume_section STARTS "PART2_ALL" then
      res include_all       false
      res include_layerk    false
    elseif baseline_resume_section STARTS "PART2_K" then
      res include_all       false
      res include_layerk    false
      res include_part2_all false
    elseif baseline_resume_section STARTS "UCL_ONLY" then
      res include_all       false
      res include_layerk    false
      res include_part2_all false
      res include_part2_k   false
    endif

    if include_all then
      %test_layer                                              ! old test of Jay's
      %test_plot_layer_autoscale/ALTTESTENV=^alttestenv        ! NXM-2937 NXM-2984
      %test_plot_layer_transparent_dragbox                     ! NXM-3961
      %test_plot_layer1d/BASELINE                              ! Bug 70
      %test_plot_layer2d/BASELINE                              ! Bug 606
      %test_plot_layerdrawable/BASELINE                        ! Bug 2792
      %test_plot_layergeo/BASELINE/display=Maximized           ! in 3.1.2, added /display=Maximized for testing Bug 2551
      %test_plot_layergeojson/BASELINE                         ! NXM-3679
      %test_plot_layergeojson/PLAINJSON                        ! NXM-3679
      %test_plot_layerimage                                    ! Bug 1546 Bug 1854 Bug 2196
    endif ! end of beginning/all section
    if include_layerk then
      info "%TEST_PLOT can be RESUMED at this point USING the argument LAYERK"
      %test_plot_layerkml/BASELINE/ALTTESTENV=^alttestenv      ! Bug 1623
      %test_plot_layermap_https_port/ALTTESTENV=^alttestenv    ! NXM 2944
      %test_plot_layermulti/BASELINE                           ! Bug 954 Bug 1210
      %test_plot_layermulti2d                                  ! Bug 954 Bug 1210
      %test_plot_layernms/ALTTESTENV=^alttestenv               ! NXM-1267
      %test_plot_layerpoly                                     ! Bug 1162 Bug 1225
      %test_plot_layerscatter/BASELINE                         ! Bug 2544
      %test_plot_layershape/BASELINE                           ! Bug 817
      %test_plot_layert5/BASELINE                              ! Bug ??
      %test_plot_layervehicle                                  ! Bug 888
      if alttestenv isFalse then
        %test_plot_layerwms/BASELINE                           ! Bug 1230 Bug 1233
      else
        %test_plot_layerwms_configure                          ! NXM-3684
      endif
      %test_plot_layerxy                                       ! NXM-3496 added to automated testing in 3.7.2
    endif
    ! NOTE: keep above and below in alpha order (two lists), add note on why if deviate
    if include_part2_all then
      info "%TEST_PLOT can be RESUMED at this point USING the argument PART2_ALL"
      %test_plot_adjust_labels                                 ! Bug 945
      %test_plot_all                                           ! Bug 892 Bug 1018 made by Jay in 2013, but just added to baseline in 3.9.4
      %test_plot_all_sticky                                    ! NXM-3699
      %test_plot_autoscale                                     ! Bug 2734
      %test_plot_axis                                          ! Bug 2494
      %test_plot_axisindex                                     ! Bug 1924
      %test_plot_axislabels                                    ! Bug 2505
      %test_plot_baselayer                                     ! Bug 2894
      %test_plot_blank_spaces                                  ! Bug 1254 Bug 1544 Bug 2091
      %test_plot_bstore_warn                                   ! Bug 1516
      %test_plot_buttonaction                                  ! Bug 2868
      %test_plot_canvas                                        ! Bug 2266
      %test_plot_cleardata                                     ! Bug 429
      %test_plot_coneflags5000                                 ! Bug 871
      %test_plot_cones                                         ! NXM-3753
      %test_plot_cursor                                        ! Bug 1230 Bug 2249
      %test_plot_cut                                           ! NXM-2921
      %test_plot_dateformat                                    ! Bug 2753
      %test_plot_drag_drop                                     ! Bug 2120 Bug 1984
      %test_plot_dragzoom                                      ! Bug 2183
      %test_plot_drangeunits                                   ! Bug 910
      %test_plot_export_image                                  ! Bug 429
      %test_plot_feat_race                                     ! Bug 2113
      %test_plot_feature_hidden                                ! Bug 2802
      %test_plot_feature_type                                  ! Bug 2549
      %test_plot_file_swap                                     ! Bug 2151
      %test_plot_flicker                                       ! NXM-2841
      %test_plot_gotolocation_flags                            ! NXM-2890
      %test_plot_high_zoom                                     ! NXM-3131
      %test_plot_hold_refreshes                                ! Bug 1813
      %test_plot_inputs_layer/interactive=f                    ! Bug ?? JPH -- this test can be non-interactive
      %test_plot_invalid_arg                                   ! Bug 1716 Bug 1897
      %test_plot_jinternalframe                                ! NXM-2981
    endif ! end first part of part 2 baseline
    if include_part2_k then
      info "%TEST_PLOT can be RESUMED at this point USING the argument PART2_K"
      %test_plot_keyobject/ALTTESTENV=^alttestenv              ! Bug 2563
      %test_plot_lat_lon_cont_axis_labels                      ! NXM-3583
      %test_plot_lat_lon_cont_xmargin                          ! NXM-3417
      %test_plot_lat_lon_cont_zoom_xmargin                     ! NXM-3981
      %test_plot_lat_lon_continuous/ADDKML/ADDVEHICLE/ADDIMAGE ! NXM-3284
      %test_plot_legend                                        ! Bug 1839
      %test_plot_many/plottype=LINE                            ! Bug 2689
      %test_plot_many/plottype=RASTER                          ! Bug 2689
      %test_plot_map_resize                                    ! NXM-2919
      !%test_plot_mark                                         ! Bug 2239 ! disabled until we figure out what we want
      %test_plot_maxscale                                      ! Bug 2187
      %test_plot_mimic                                         ! Bug 2910
      %test_plot_move_display                                  ! Bug 1206 Bug 2712
      %test_plot_msg_event_data                                ! Bug 2927
      %test_plot_mtag                                          ! Bug 2576
      %test_plot_mtag_xgeo                                     ! NXM-3094
      %test_plot_no_panel                                      ! NXM-3213
      %test_plot_not_found                                     ! Bug 1651
      %test_plot_not_found_openwarn                            ! Bug 2867
      %test_plot_openfile_args                                 ! Bug 2710
      %test_plot_openfile_invoke                               ! BUG 2457
      %test_plot_openfile_race                                 ! BUG 2248
      !%test_plot_parse_table                                  ! Bug 2460 - covered in test_plot_layerwms_defaultsize
      %test_plot_pipe_restarts/DURATION=180                    ! Bug 2991 (3 minutes is adequate to detect the ArrayIndexOutOfBounds, but not the memory leak)
      %test_plot_pop                                           ! Bug 42, ???
      %test_plot_prescaler                                     ! NXM-3078
      %test_plot_race_condition/interactive=f                  ! Bug 72 Bug 1520 JPH -- this test can be non-interactive
      %test_plot_range                                         ! Bug 1869
      %test_plot_readout                                       ! Bug 944 Bug 1397 Bug 2740
      %test_plot_rescale                                       ! BUG 1521
      %test_plot_setup_java_behavior                           ! NXM-4097
      %test_plot_scale_all                                     ! Bug 1502 Bug 2478
      %test_plot_symbol                                        ! BUG 1738
      %test_plot_theme                                         ! Bug 2618
      %test_plot_theme /shareTheme                             ! Bug 2618 backwards compatibility
      %test_plot_unzoom                                        ! Bug 2235 Bug 2238
      %test_plot_view3dgraph                                   ! NXM-3500
      %test_plot_view_precision                                ! NXM-3624
      %test_plot_viewgeo_partially_hidden                      ! NXM-3995
      %test_plot_wh_gui                                        ! NXM-3213
      %test_plot_xycut                                         ! BUG 1831
      %test_plot_yaxis                                         ! Bug 2479
      %test_plot_zoom_in_out                                   ! Bug 1487
      %test_plot_zoom_linked                                   ! Bug 2722
      %test_plot_zoom_mouseposition                            ! NXM-3261
      %test_plot_zoom_pixel_slam_top                           ! NXM-3413
      %test_plot_zoomx_pan                                     ! NXM-3537
      %test_sd360_many                                         ! NXM-3213
      %test_snapper                                            ! NXM-3821 Imitates Jeff's snapapp & snapper a little
    endif
    if sysTestDatExists then
      warn "Skipping UCL tests since running from sys.test.dat"
    else
      ! run tests that use PLOT features in UCL option tree
      info "%TEST_PLOT can be RESUMED at this point USING the argument UCL_ONLY"
      call run_ucl_macros
    endif
    if ENV.OSNAME EQSS "Windows" then
      res testSd360LoopScript "test_sd360_loop.bat"
    else
      res testSd360LoopScript "test_sd360_loop.sh"
    endif
    popup reminder OK "Remember to run the following overnight (100 hour) tests as part of release testing: \n&
                       -test_plot_pipe_restarts \n&
                       -test_plot_framesize_updates/WPOS=(0,0,600,300) \n  &
                         (both in DEFAULT mode of using invoke to open files and also with alternate \n  &
                          /DOINVOKE=false to use messages)\n&
                       as well as the test script ^{testSd360LoopScript}"

  ! If COREGRAPHICS run a short list of extreme tests that tend to be the ones to show graphical issues
  elseif coreGraphics then
    %test_plot_flicker/COREGRAPHICS                                       ! NXM-2841
    %test_plot_high_zoom/COREGRAPHICS                                     ! NXM-3131
    %test_plot_jinternalframe/COREGRAPHICS                                ! NXM-2981
    %test_plot_lat_lon_cont_zoom_xmargin/COREGRAPHICS                     ! NXM-3981
    %test_plot_lat_lon_continuous/COREGRAPHICS/ADDKML/ADDVEHICLE/ADDIMAGE ! NXM-3284
    %test_plot_layer_transparent_dragbox/COREGRAPHICS                     ! NXM-3961
    %test_plot_layer2d/COREGRAPHICS/INTERACTIVE=false                     ! Bug 606
    %test_plot_layerdrawable/COREGRAPHICS/INTERACTIVE=false               ! Bug 2792
    %test_plot_layert5/COREGRAPHICS                                       ! Bug ??
    if alttestenv isFalse then %test_plot_layerwms/COREGRAPHICS           ! Bug 1230 Bug 1233
    %test_plot_map_resize/COREGRAPHICS                                    ! NXM-2919
    %test_plot_prescaler/COREGRAPHICS                                     ! NXM-3078
    %test_plot_wh_gui/COREGRAPHICS                                        ! NXM-3213
    %test_plot_view3dgraph/COREGRAPHICS                                   ! NXM-3500
    %test_plot_viewgeo_partially_hidden/COREGRAPHICS                      ! NXM-3995
    %test_plot_xycut/COREGRAPHICS                                         ! BUG 1831 NXM-3567
    %test_plot_zoom_pixel_slam_top/COREGRAPHICS                           ! NXM-3413
    %test_snapper/COREGRAPHICS                                            ! NXM-3821 Imitates Jeff's snapapp & snapper a little
    ! keep these two at bottom
    %test_sd360_many/COREGRAPHICS                                         ! NXM-3213
    %test_plot_pipe_restarts/COREGRAPHICS/DURATION=60                     ! Bug 2991
  endif
endmacro

!******************************************************************************!
procedure processMessage m:msg
!say "got ^{msg.toString(NAME|DATA)}"

if msg.name eqs "MAIN" then
  assert/text="Plot files tests" msg.data eqss "PASS"
  pipe stop
elseif msg.name eqs "NEXTPLOT" then
  if     msg.data EQS "NONE" then
    call test_plot_none
  elseif msg.data EQS "1D-REAL" then
    call test_plot_layer1d_real
  elseif msg.data EQS "1D-COMPLEX" then
    call test_plot_layer1d_complex
  elseif msg.data EQS "2D" then
    call test_plot_layer2d
  elseif msg.data EQS "POLY" then
    call test_plot_layerpoly
  elseif msg.data EQS "MULTI" then
    call test_plot_layermulti
  elseif msg.data EQS "MULTI-COLS" then
    call test_plot_layermulti_columns
  elseif msg.data EQS "XY" then
    call test_plot_layerxy
  elseif msg.data EQS "GEO" then
    call test_plot_layergeo
  elseif msg.data EQSS "T5" then
    if msg.data EQS "T5-CONE" then
      call test_plot_layerT5_cone
    elseif msg.data EQS "T5-CONEFLAG" then
      call test_plot_layerT5_coneflags
    elseif msg.data EQS "T5-ELLIPSE" then
      call test_plot_layert5_ellipse
    elseif msg.data EQS "T5-ELLIPSEFLAG" then
      call test_plot_layert5_ellipseflags
    elseif msg.data EQS "T5-POSITIONS" then
      call test_plot_layert5_positions
    elseif msg.data EQS "T5-FILLED" then
      call test_plot_layert5_filled
    endif
  elseif msg.data EQS "SHAPE" then
    call test_plot_shape
  elseif msg.data EQS "SHAPE-OPAQ" then
    call test_plot_shape_opaq
  elseif msg.data EQS "IMAGE" then
    call test_plot_image
  elseif msg.data EQS "IMAGETBL" then
    call test_plot_imagetbl
  elseif msg.data EQS "CSV-MULTI" then
    call test_plot_csv_multi
  elseif msg.data EQS "CSV-XY" then
    call test_plot_csv_xy
  elseif msg.data EQS "GEODETIC" then
    call test_plot_geodetic
  elseif msg.data EQS "DATESTRING" then
    call test_plot_datestring
  elseif msg.data EQS "LINETHICKNESS" then
    call test_plot_linethickness
  elseif msg.data eqs "TINYDELTA" then
    call test_plot_tinydelta
  else
    warning "Do not know ^msg.data layer"
  endif
else
  ! do nothing
  say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
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

!******************************************************************************!
procedure open
  call setInstructions "Click one of the 'TESTS' buttons to display plot."
return

!******************************************************************************!
procedure newplot s:plotstring s:instructions
  !message FUNC=send ID=IDPLOT NAME=CLOSEFILE DATA="*"
  set reg.idplot.axis   "DEF"
  if resetAxisIndex eqs TRUE then
    set reg.idplot.axisindex "FALSE"
    set resetAxisIndex false
  endif
  foreach item intable testfiles
   if testfiles.^item nFEXISTS then
    warning "Could not generate/find ^testfiles.^item"
    return
   endif
  endfor
  call setInstructions instructions

  ! passing info=-1 to close all previous files
  message FUNC=sendw ID=IDPLOT NAME=OPENFILE INFO=-1 DATA=plotstring /wait=2

return

!******************************************************************************!
procedure run_ucl_macros
  info "%TEST_PLOT running UCL option tree tests"
  res savepath opt.path  ! save previous path

  path add ucl
  !make code ucl  ! only need to bld a few classes

  if nxm.ucl.prim.beandemo.class nfexists then
    bld beandemo
    bld psdpanel
    bld psdpanellive libg ucl
    bld whtabpanel libg ucl
    assert/text="^reg.main.name: Compiled beandemo" nxm.ucl.prim.beandemo.class fexists
  endif
  if nxm.ucl.prim.multiplot.class nfexists then
    bld multiplot
    assert/text="^reg.main.name: Compiled multiplot" nxm.ucl.prim.multiplot.class fexists
  endif
  if nxm.ucl.libg.LayerAircraft.class nfexists then
    bld layeraircraft libg ucl
    assert/text="^reg.main.name: Compiled LayerAircraft" nxm.ucl.libg.LayerAircraft.class fexists
  endif

  %test_plot_beandemo         ! NXM-3213
  nxm.ucl.mcr.plotbug         ! test for BUG 1905
  nxm.ucl.prim.beandemo       ! test for BUG 1520
  home test ucl
  %test_multiplot             ! Bug 561
  %test_multiplot_strip_chart ! NXM-3410
  %test_plot_layeraircraft    ! Bug 2304
  home /restore

  path set ^savepath  ! restore previous path
return

!******************************************************************************!
procedure test_plot_none
  result testfiles {}
  ! NTN: Added instructions to test fix for Bug 1945
  call newplot "" "Should see a blank screen. To test fix for Bug 1945: MMB on plot, &
                   select Files -> AddNew. In the OpenFile popup, click on AuxList, &
                   then DAT (to check it). Next select DAT/Sunset.jpg and then click &
                   the Submit button. The sunset image should be displayed."
return

!******************************************************************************!
procedure test_plot_layer1d_real
  result testfile "temp_testplot_layer1d_real"
  result testfiles {file=^testfile}
  waveform testfile FORM=SF ELEM=1K
  call newplot testfile "Expected: a sine wave line"
  message send idplot,,view,,yx
return

!******************************************************************************!
procedure test_plot_layer1d_complex
  result testfile "temp_testplot_layer1d_complex"
  result testfiles {file=^testfile}
  waveform testfile FORM=CF ELEM=1K
  call newplot testfile "Expected: 2 lines\n&
                         - One line for the real component and\n&
                         - darker line for the imaginary component."
  message send idplot,,view,,yx
return

!******************************************************************************!
procedure test_plot_layerpoly
! 1998/1999 files
!
!  DEPENDENCIES:
!     1) Must be able to find test file "world.prm"
!
!  NOTE: This test was modified to plot "world.prm" instead of "world".
!        Additional tests for filenames without an extension can be found elsewhere

  result testfile "world.prm"
  result testfiles {file=^testfile}
  call newplot testfile "Expected: a world plot"
  message send idplot,,view,,latlon
return

!******************************************************************************!
procedure test_plot_layer2d
  result testfile "apenny.prm"
  result testfiles {file=^testfile}
  call newplot testfile "Expected: a penny plot"
  message send idplot,,view,,yx
return

!******************************************************************************!
procedure test_plot_layermulti
!
!  DEPENDENCIES:
!     1) file command: for creating type 3000 file
!
!  RESTRICTIONS:
!    1) The plotted file must be "homogeneous", that is, all records must be
!       of the same type!
!
  result testfile "temp_testplot_layermulti"
  result testfiles {file=^testfile}
  file open/d/n tag testfile{SR=(ORD1/SD,ORD2/SD,ORD3/SD)}
  result nels 100
  do i 0 nels-1
    result tag.setdata(i,ORD1) 10+i
    result tag.setdata(i,ORD2) 20+i
    result tag.setdata(i,ORD3) 30+i
  enddo
  file close tag
  headermod testfile format=sd xs=0 xd=1
  ! Bug 1345: test ColorTable={...} settings
  call newplot testfile{Layer={ColorTable={_GLOBAL_=red,ORD1=blue,ORD2=#00FF00}}} &
       "Expected: 3 constant slope lines of different colors (red, green, and then blue)"
  message send idplot,,view,,yx
return

!******************************************************************************!
procedure test_plot_layermulti_columns
  result testfiles {}
  result testfiles.absc  "testxy3000.prm"
  result testfiles.ord1  "testxy3000.prm"
  result testfiles.ord23 "testxy3000.prm"

  call newplot "^{testfiles.ord1}{Tag="ORD1",Layer={LT="Multi",COLUMNS="ORD"}}|&
      ^{testfiles.absc}{Tag="ABSC",Layer={LT="Multi",COLUMNS="ABSC"}}|&
                ^{testfiles.ord23}{Tag="ORD23",Layer={LT="Multi",COLUMNS="ORD2|ORD3"}}" &
            "Expected: four lines\n\n&
             Note: You may need to resize the display to see lines after turning off a layer\n\n&
             1) toggling the ABSC layer in the legend =>\n   &
                turns on/off the green line\n&
             2) ORD1 toggles the blue line\n&
             3) ORD23 toggles both the red and white lines."
  message send idplot,,view,,yx

  ! show legend automatically to save test user two clicks
  invoke ,, reg.idplot.showLegend(TOPLEFT)
return

!******************************************************************************!
procedure test_plot_layerxy
!
!  DEPENDENCIES:
!     1) file command: for creating type 3000 file
!
  result testfile "temp_testplot_layerxy"
  result testfiles {file=^testfile}
  file open/d/n tag testfile{SR=(REC1/SD,REC2/SD,ALT/SD,CITY/XA)}
  result nels 100
  do i 0 nels-1
    result tag.setdata(i,REC1) 3e9+i ! Note: these values are chosen to test
    result tag.setdata(i,REC2) 2e9+i ! whether Layer XY can handle double precision
    result tag.setdata(i,ALT)  20+i
    result tag.setdata(i,CITY) "CITY^i" ! city "names" added in 3.9.3 for NXM-3495
  enddo
  file close tag
  call newplot "^{testfile}{LAYER={LT=XY,X=REC1,Y=REC2,NAME=CITY}}" "Expected: a constant slope line"
  message send idplot,,view,,yx
return

!******************************************************************************!
procedure test_plot_layerT5_cone
  result testfiles {}
  result testfiles.world    "world.prm"
  result testfiles.capitals "capital_cities.prm"
  result testfiles.cone     "cone5000.prm"

  call newplot "^{testfiles.world}|^{testfiles.cone}{Layer={symbol=star,color=red}}" &
            "Expected: a world plot with\n&
            - a RED *\n&
            - a cone"
  message send idplot,,view,,latlon
return

!******************************************************************************!
procedure test_plot_layerT5_coneflags
  result testfiles {}
  result testfiles.world    "world.prm"
  result testfiles.coneflags "coneflags5000.prm{LAYER={COLORMAP=(RED,GREEN,BLUE)}}" ! changed colormap for Bug 2459

  call newplot "^{testfiles.world}|^{testfiles.coneflags}" &
    "Expected: a world plot with\n&
     - a GREEN cross named LABEL1 inside a GREEN cone\n&
     - a BLUE cross named LABEL2 inside a BLUE cone\n&
     - and a BLUE circle named LABEL3 w/o a cone\n\n&
     There should be no other cones, crosses, labels or stars."
  message send idplot,,view,,latlon

return

!******************************************************************************!
procedure test_plot_layerT5_filled
  result testfiles {}
  result testfiles.world    "world.prm"
  result testfiles.coneflags "coneflags5000.prm{layer={flags=+fillcones}}"

  call newplot "^{testfiles.world}|^{testfiles.coneflags}" &
    "Expected: a world plot with\n&
    - a GREEN cross named LABEL1 inside a GREEN cone\n&
    - a YELLOW cross named LABEL2 inside a YELLOW cone\n&
    - a RED circle named LABEL3 w/o a cone\n\n&
    The cones should be filled with a semi-transparent color."
  message send idplot,,view,,latlon

return

!******************************************************************************!
procedure test_plot_layert5_ellipseflags
  result testfiles {}
  result testfiles.world    "world.prm"
  result testfiles.ellipse  "ellipseflags5000.prm"

  call newplot "^{testfiles.world}|^{testfiles.ellipse}" &
    "Expected: a world plot with\n&
     - 6 colored points\n&
     - 5 named TONY5,..,TONY9 of alternating colors\n  &
       with 1 ellipse around each\n&
     - 1 one named TONY\n  &
       with 4 multi-colored ellipses around it."
  message send idplot,,view,,latlon

return

!******************************************************************************!
procedure test_plot_layert5_ellipse
  result testfiles {}
  result testfiles.world    "world.prm"
  result testfiles.ellipse  "ellipse5000.prm"

  call newplot "^{testfiles.world}|^{testfiles.ellipse}" &
    "Expected: a world plot with\n&
     - 6 green points\n&
     - 5 with 1 ellipse around each\n&
     - 1 with 4 ellipses around it"
  message send idplot,,view,,latlon

return

!******************************************************************************!
procedure test_plot_layert5_positions
  result testfiles {}
  result testfiles.world    "world.prm"
  result testfiles.cities   "cities.prm"

  call newplot "^{testfiles.world}|^{testfiles.cities}" &
    "Expected: world plot with\n&
     - many of the major cities\n  indicated by a green cross\n\n&
     1) Zoom in on Ireland =>\n   &
        the cities of 'Dublin' and 'Belfast'\n   should be indicated by name."
  message send idplot,,view,,latlon

return

!******************************************************************************!
procedure test_plot_layergeo
  result testfiles {}
  result testfiles.world   "world.prm"

  call newplot "^{testfiles.world}" "Expected:\n&
                                     - a GEO layer\n&
                                     - a RED oval with a label GEO\n&
                                     - label SVA at (0,-143) LAT/LON\n&
                                     - label SVB at (5.2,-111)\n&
                                     - a MYSITE label at (30,-110)."
  message send idplot,,view,,latlon

  pause 0.1  ! Otherwise plot looks a little funny ...
  layer "Geo" geoLayer {NAME=GL,SVA=sv1.prm,SVB=sv2.prm,&
                        SVALABEL="SVA",SVBLABEL="SVB",&
                        SITE=site.prm,SITELABEL="MYSITE",&
                        CONIC=0,TDOAMODE=Region,FDOAMODE=Region,&
                        FLINKT=1e6,FLINKA=-1e6,FLINKB=-1e6,&
                        FLAGS=ALL,TDOA=0,FDOA=0,DTDOA=1e-5,DFDOA=0.5} idplot
  assert/text="LayerGeo: SVA, SVB and SITE labels" geoLayer.svalabel EQS "SVA" AND &
                                         geoLayer.svblabel EQS "SVB" AND &
                                         geoLayer.sitelabel EQS "MYSITE"


return

!******************************************************************************!
procedure test_plot_geodetic
  result testfiles {}
  result testfiles.world   "world.prm"
  result testfiles.cities  cities.prm{LAYER={SELECTIONKEYS="NAME,POS",AUTOSELECTENABLE=CLICK}}

  call newplot "^{testfiles.world}|^{testfiles.cities}" &
    "Expected: a geographic plot of the world\n&
     - like a globe\n&
     - major cities marked\n\n&
     1) Hold down the RMB and move the mouse =>\n   &
        the globe should rotate\n&
     2) Click near a city =>\n   &
        should select it AND\n   &
        display it's name and position."
  message send idplot,,view,,geo

return

!******************************************************************************!
procedure test_plot_datestring
  noop sinewave.prm ram:mysine
  timex now date
  headermod ram:mysine XS=^date

  result testfiles {}
  result testfiles.mysine   "ram:mysine"

  call newplot "^{testfiles.mysine}" &
    "Expected:\n&
     - sinewave plot with timecode embedded\n&
     - date is displayed in horizontal title\n&
     - tics are displayed as time strings"
  set reg.idplot.xunits TIME
  message send idplot,,view,,yx

return

!******************************************************************************!
procedure test_plot_image
  result testfiles {}
  result testfiles.img  "^{datDir}.Sunset.jpg"

  call newplot "^{testfiles.img}" "Expected:\n&
                - zoomed in picture of a sunset (JPG),\n  &
                  with no axis or readout\n&
                - small network image (PNG) in middle of plot\n\n&
                1) Use MMB -> readout to adjust readout\n   &
                   MMB select all the options you want\n\n&
                2) Right click on plot to unzoom."
  message send idplot,,view,,yx
  set reg.idplot.axis   0  ! Bug 1835 (Should see No Axis )
  set reg.idplot.readout 0 ! Bug 1835 (Should see No Readout)

  ! test case for Bug 1925 (OPENFILE imagefile causes plot to unzoom)
  calc xZoomDelta reg.idplot.xmax  reg.idplot.xmin + 5 / abs
  calc yZoomDelta reg.idplot.ymax  reg.idplot.ymin + 5 / abs
  calc xmin reg.idplot.xmin xZoomDelta +
  calc xmax reg.idplot.xmax xZoomDelta -
  calc ymin reg.idplot.ymin yZoomDelta +
  calc ymax reg.idplot.ymax yZoomDelta -
  message FUNC=sendw ID=IDPLOT NAME=ZOOM DATA={xmin=^{xmin},xmax=^{xmax},ymin=^{ymin},ymax=^{ymax}}

  ! continue test case for Bug 1925
  calc xs reg.idplot.xmax   reg.idplot.xmin + 2 /
  calc ys reg.idplot.ymax   reg.idplot.ymin + 2 /
  set  xd reg.idplot.xdelta
  set  yd reg.idplot.ydelta
  message FUNC=send  ID=IDPLOT NAME=OPENFILE DATA="^{datDir}.network.png{xstart=^xs, ystart=^ys, xdelta=^xd, ydelta=^yd}"

return

!******************************************************************************!
procedure test_plot_imagetbl
  if sysTestDatExists then
    warn "skipping imageTble test when dat in sys.test.dat"
  else
    result testfiles {}
    result testfiles.world "world.prm"
    result testfiles.img   "nxm.sys.test.test_plot_tblfile.tbl"
  
    call newplot "^{testfiles.world}|^{testfiles.img}" &
                 "Expected: a picture of a sunset\n&
                  - covering up South America\n&
                  - from 180'00'00W to 000'00'00W\n  &
                    and   90'00'00S to  00'00'00S."
    message send idplot,,view,,latlon
  endif
return

!******************************************************************************!
procedure test_plot_csv_multi
  result testfiles {}
  result testfiles.row1   "temp_testplot_csv.csv{HEADERROWS=1,COLUMNNAMES=SF:A|SF:B,&
                                                 LAYER={COLUMNS=A},TAG=A}"
  result testfiles.row2   "temp_testplot_csv.csv{HEADERROWS=1,COLUMNNAMES=SF:A|SF:B,&
                                                 LAYER={COLUMNS=B},TAG=B}"

  file open/t/n filetag temp_testplot_csv.csv{FLAGS=FORCEABORT}
  file write filetag "X,Y"
  file write filetag "0,4"
  file write filetag "1,3"
  file write filetag "2,2"
  file write filetag "3,1"
  file write filetag "4,0"
  file close filetag

  call newplot "^{testfiles.row1}|^{testfiles.row2}" &
    "Expected: 2 lines intersecting at (2,2)."
  message send idplot,,view,,latlon
return

!******************************************************************************!
procedure test_plot_csv_xy
  res quals {HEADERROWS=L:1,COLUMNNAMES="NAME|CODE|F:LAT|F:LON",&
             LAYER={LT="XY",X="LON",Y="LAT",LINE={COLOR="red",TYPE="symbol"}}}

  result testfiles {}
  result testfiles.world     "^{datDir}.world.shp{LAYER={LABEL=NAME}}"
  result testfiles.airports  "^{datDir}.airports.csv^{quals}"

  call newplot "^{testfiles.world}|^{testfiles.airports}" &
    "Expected:\n&
     - a plot of the airports with scheduled flights\n  to/from Australia.\n&
     - each airport should be marked with a red 'X'\n&
     - countries should be colored in."
  message send idplot,,view,,latlon
return

!******************************************************************************!
procedure test_plot_linethickness
  set testfiles {}
  set testfiles.thick "temp_testplot_lines_thick.tmp"
  set testfiles.thin  "temp_testplot_lines_thin.tmp"
  set nels 512

  waveform ^{testfiles.thick} FORM=SF ELEM=nels SHAPE=SAWTOOTH
  waveform ^{testfiles.thin}  FORM=SF ELEM=nels SHAPE=SQUARE
  call newplot "^{testfiles.thick}{LAYER={LINE={THICKNESS=12,COLOR=RED}}}&
                |^{testfiles.thin}{LAYER={LINE={THICKNESS=6,COLOR=BLUE}}}" &
               "Expected: two waveforms\n&
               - square wave is blue\n&
               - ramp wave is red\n&
               - red line is almost twice as thick as the blue"
  message send idplot,,view,,yx
  !BUG 1744
  erase/quiet/warn=n temp_testplot_lines_thick
  erase/quiet/warn=n temp_testplot_lines_thin
return

!******************************************************************************!
procedure test_plot_tinydelta
  set testfiles {}
  set testfiles.tinydelta "temp_tinydelta.tmp"

  waveform ^{testfiles.tinydelta}  start=1.444e38
  say "-----YOU SHOULD SEE A FORMATTED WARNING MESSAGE BELOW--------"
  call newplot "^{testfiles.tinydelta}" "Expected:\n&
               - a Popup warning\n&
               - a terminal warning informing you that &
               your Axis values are beyond precision\n\n&
               Also, prior to fix for &
               Bug 1913, this plot would crash your system."
  message send idplot,,view,,yx
  set resetAxisIndex true  ! ensure back at default

  !BUG 1744
  erase/quiet/warn=n temp_tinydelta
return

!******************************************************************************!
! Test for Bug 2456. Not strictly a plot, but ColorMap is used in plots...
procedure test_colormap
  invoke cmap1=nxm.sys.libg.MColor.getColorMap("(gray,red,yellow,green,blue)",-1)
  invoke cmap2=nxm.sys.libg.MColor.getColorMap("(gray, red, yellow, green, blue)",-1)
  invoke same java.util.Arrays.equals(cmap1,cmap2)

  assert/text="%TEST_PLOT_BUG2456: ColorMap Array Length" same isTrue

return

!******************************************************************************!
procedure setInstructions s:msgString
  set reg.panel.controls.idtext.value msgString
return
