SET(TEST_PATH "ParaView")
# initialize these to emtpy
SET(PARAVIEW_MPI_RUN_ONE )
SET(PARAVIEW_CS_EXECUTABLE ${EXECUTABLE_OUTPUT_PATH}/pvTestDriver)
IF (VTK_USE_MPI)
  SEPARATE_ARGUMENTS(VTK_MPI_PREFLAGS)
  SEPARATE_ARGUMENTS(VTK_MPI_POSTFLAGS)
    IF (VTK_MPIRUN_EXE)
    SET(PARAVIEW_MPI_POST_FLAGS ${VTK_MPI_POSTFLAGS})
    # This is the tricky part.
    # if we have mpirun, then do not run paraview directly,
    # because some mpi implementations require that mpi programs
    # be run only with mpirun.  So change the paraview executable
    # to be pvTestDriver instead of paraview.  The pvTestDriver
    # command knows about mpi and will use the correct mpi settings.
    # These are configured into pvTestDriverConfig.h.
    SET(PARAVIEW_EXECUTABLE ${EXECUTABLE_OUTPUT_PATH}/pvTestDriver)
    # some runs of paraview must never be run with more than one mpi
    # process.  This is a special option to pvTestDriver that forces
    # it to use -np 1
    SET(PARAVIEW_MPI_RUN_ONE "--one-mpi-np")
  ELSE(VTK_MPIRUN_EXE)
    MESSAGE("ParaView has been built with MPI, but VTK_MPIRUN_EXE has not been set, tests may not run correctly")
    ENDIF (VTK_MPIRUN_EXE)
ENDIF (VTK_USE_MPI)

SET(PROJECT_TESTS
  ArrayMenuChangeInput
  Arrow
  Axes
  BlowTest
  BoundsDisplay
  CalcInput
  Calculator
  ClipCut
  ColorMap
  CombustorTest
  #Composite
  ConeCubeCylSQ
  CTH
  CutContours
  Data
  Delete
  DeleteSource
  EnSight
  Extrusion
  ExtractGrid
  ExtractPart
  Glyph
  Group
  Transform
  ImageReader
  Mandelbrot
  Maze
  MouseInteraction
  OrientationWidget
  ProbeLine
  ProbePoint
  ReadPVD
  ScalarBar
  ScalarRangeLabel
  ScalarSelection
  ScalarsSphereClip
  SphereTest
  TestDemo
  TestPackage
  Threshold
  ThresholdAttrMode
  Trace
  VectorTextSpace
  Write
  TestPolyDataIO
  TestUnstructuredGridIO
  TestRectilinearGridIO
  TestImageDataIO
  VolumeGroup
  XdmfRead
  )

# Foreach test add the following:
# 1. the test (possibly with mpirun)
# 2. the test with compositing and possibly mpi
# 3. the test in client server mode
# 4. the test in client server render server mode
# 

FOREACH (tfile ${PROJECT_TESTS})
  ADD_TEST(${tfile}-ParaView 
      ${PARAVIEW_EXECUTABLE} --disable-registry
      ${PVClientTests_SOURCE_DIR}/Tcl/${tfile}.pvs
      -D ${PVClientTestData}
      -C ${PVCompareImages}
      -T ${ParaView_BINARY_DIR}/Testing/Temporary
      -V ${PVClientTestData}/Baseline/${tfile}.png
    )
  # repeat test in composite mode if test composite is on
    IF (PARAVIEW_TEST_COMPOSITING)
    ADD_TEST(${tfile}-ParaView-COMPOSITE-MPI 
        ${PARAVIEW_EXECUTABLE} --disable-registry
        ${PVClientTests_SOURCE_DIR}/Tcl/${tfile}.pvs
        -UC
        -D ${PVClientTestData}
        -C ${PVCompareImages}
        -T ${ParaView_BINARY_DIR}/Testing/Temporary
        -V ${PVClientTestData}/Baseline/${tfile}.png
      )
    ENDIF (PARAVIEW_TEST_COMPOSITING)
    # repeat the test with the client server driver
  ADD_TEST("${tfile}ClientServer-ParaView" 
    ${PARAVIEW_CS_EXECUTABLE}
    --test-server
      --disable-registry
      ${PVClientTests_SOURCE_DIR}/Tcl/${tfile}.pvs
      -D ${PVClientTestData}
      -C ${PVCompareImages}
      -T ${ParaView_BINARY_DIR}/Testing/Temporary
      -V ${PVClientTestData}/Baseline/${tfile}.png)
    # repeat the test with the client server driver in render server mode
  ADD_TEST("${tfile}RenderServer-ParaView" 
    ${PARAVIEW_CS_EXECUTABLE}
      --test-render-server
      --disable-registry
      ${PVClientTests_SOURCE_DIR}/Tcl/${tfile}.pvs
      -D ${PVClientTestData}
      -C ${PVCompareImages}
      -T ${ParaView_BINARY_DIR}/Testing/Temporary
      -V ${PVClientTestData}/Baseline/${tfile}.png)
ENDFOREACH (tfile)


IF(VTK_PRINT_SELF_CHECK_TCL AND TCL_TCLSH)
  ADD_TEST(PrintSelf-${TEST_PATH} ${TCL_TCLSH}
    ${VTK_PRINT_SELF_CHECK_TCL}
    ${PVGUIClientDir})
ENDIF(VTK_PRINT_SELF_CHECK_TCL AND TCL_TCLSH)

IF(VTK_FIND_STRING_TCL AND TCL_TCLSH)
  ADD_TEST(TestSetObjectMacro-${TEST_PATH} ${TCL_TCLSH}
    ${VTK_FIND_STRING_TCL}
    "${PVGUIClientDir}/vtk\\\\*.h"
    "vtkSetObjectMacro")
ENDIF(VTK_FIND_STRING_TCL AND TCL_TCLSH)

# run these test with mpi 1 process if mpi is around, or just run the test
FOREACH(test otherPrint TestSetGet)
  ADD_TEST(${test}-ParaView 
    ${PARAVIEW_EXECUTABLE} ${PARAVIEW_MPI_RUN_ONE} --batch
    ${PVClientTests_SOURCE_DIR}/Tcl/${test}.pvb
    )
ENDFOREACH(test)
  
ADD_TEST(OtherTests-ParaView 
  ${PARAVIEW_EXECUTABLE} ${PARAVIEW_MPI_RUN_ONE} --disable-registry --start-empty
    ${PVClientTests_SOURCE_DIR}/Tcl/Other.pvs
    -D ${PVClientTestData}
    -A ${VTK_TCL_HOME}
    )
  
ADD_TEST (AnimationImages-ParaView 
  ${PARAVIEW_EXECUTABLE} ${PARAVIEW_MPI_RUN_ONE} --disable-registry
    ${PVClientTests_SOURCE_DIR}/Tcl/AnimationImages.pvs
    -D ${PVClientTestData}
    -T ${ParaView_BINARY_DIR}/Testing/Temporary
    -C ${PVClientTests_SOURCE_DIR}/Tcl/ComparePNGs.tcl
  -V ${PVClientTestData}/Baseline/AnimationImages.png
  )
  
