Salome HOME
Test1967: Update tolerance ratio for moving vs creating.
[modules/shaper.git] / CMakeCommon / UnitTest.cmake
index 57dc2924673f9301ec382df86b816dd432c85396..a1eca3d7312276cdabf7349fcff83f04a6503e5a 100644 (file)
@@ -1,7 +1,24 @@
-## Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+# Copyright (C) 2014-2023  CEA, EDF
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
 
 #
-# NewGeom unit test system
+# SHAPER unit test system
 # How to use:
 # INCLUDE(UnitTest)
 # ...
 # or
 # SET(PROJECT_UNIT_TESTS
 #     TestUndoRedo.py
-#     TestWhatever.py  
+#     TestWhatever.py
 #    )
 # ADD_UNIT_TESTS(${PROJECT_UNIT_TESTS})
 #
-# Where "TestUndoRedo.py" and "TestResultBody.py" are names 
+# Where "TestUndoRedo.py" and "TestResultBody.py" are names
 # of python test scripts in the "./Test" directory.
-# This macro will add "Subproject_" as prefix and 
-# remove ".py" for the test name automaticaly. 
-# 
+# This macro will add "Subproject_" as prefix and
+# remove ".py" for the test name automaticaly.
+#
 # Start building of the "RUN_TESTS" project in the Visual studio
 # or run "make test" on linux stations to start the testing procedure.
 #
 
 ENABLE_TESTING()
 
-MACRO(ADD_UNIT_TESTS)
-  if (WIN32) # different separators and path to libraries variable name
-    SET(_JUSTPATH "${CMAKE_INSTALL_PREFIX}/bin;${CMAKE_INSTALL_PREFIX}/swig;${CMAKE_INSTALL_PREFIX}/plugins;${SUIT_LIB_DIR};$ENV{PATH}")
-    STRING(REPLACE "\\" "/" _JUSTPATH "${_JUSTPATH}")
-    STRING(REPLACE ";" "\\;" _JUSTPATH "${_JUSTPATH}")
-    SET(_PYTHONPATH "${CMAKE_INSTALL_PREFIX}/swig;${CMAKE_INSTALL_PREFIX}/plugins;${CMAKE_INSTALL_PREFIX}/addons;${CMAKE_INSTALL_PREFIX}/pythonAPI;$ENV{PYTHONPATH}")
-    STRING(REPLACE "\\" "/" _PYTHONPATH "${_PYTHONPATH}")
-    STRING(REPLACE ";" "\\;" _PYTHONPATH "${_PYTHONPATH}")
-  else()
-    SET(_LD_LIBRARY_PATH "${CMAKE_INSTALL_PREFIX}/bin:${CMAKE_INSTALL_PREFIX}/swig:${CMAKE_INSTALL_PREFIX}/plugins:${SUIT_LIB_DIR}:$ENV{LD_LIBRARY_PATH}")
-    SET(_PYTHONPATH "${CMAKE_INSTALL_PREFIX}/swig:${CMAKE_INSTALL_PREFIX}/plugins:${CMAKE_INSTALL_PREFIX}/addons:${CMAKE_INSTALL_PREFIX}/pythonAPI:$ENV{PYTHONPATH}")
-  endif()
+function(GENERATE_TESTS PATH testdir TESTS)
+  SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
 
-  SET(_CONFIG_FILE "${CMAKE_INSTALL_PREFIX}/plugins")
   foreach(eachFileName ${ARGN})
-    # Strip the ".py" suffix 
+    # Strip the ".py" suffix
     GET_FILENAME_COMPONENT(aTestName ${eachFileName} NAME_WE)
 
     # Add "SubprojectName_" prefix
     GET_FILENAME_COMPONENT(aSubprojectName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
     SET(aTestName "${aSubprojectName}_${aTestName}")
 
-    # Full path to the python test file beeing executed 
-    SET(aTestFileName "${CMAKE_CURRENT_SOURCE_DIR}/Test/${eachFileName}")
+    # Full path to the python test file beeing executed
+    SET(aTestFileName "${testdir}/${eachFileName}")
+    IF(NOT EXISTS ${aTestFileName})
+      SET(aTestFileName "${testdir}/Test/${eachFileName}")
+    ENDIF(NOT EXISTS ${aTestFileName})
     IF(EXISTS ${aTestFileName})
       ADD_TEST(NAME ${aTestName}
                COMMAND ${PYTHON_EXECUTABLE} ${aTestFileName})
-      if (WIN32) # different path to libraries variable name
-        SET_TESTS_PROPERTIES(${aTestName} PROPERTIES
-               ENVIRONMENT "PATH=${_JUSTPATH};PYTHONPATH=${_PYTHONPATH};NEW_GEOM_CONFIG_FILE=${_CONFIG_FILE}")
-      else()
-        SET_TESTS_PROPERTIES(${aTestName} PROPERTIES
-               ENVIRONMENT "LD_LIBRARY_PATH=${_LD_LIBRARY_PATH};PYTHONPATH=${_PYTHONPATH};NEW_GEOM_CONFIG_FILE=${_CONFIG_FILE}")
-      endif()
+      SET_TESTS_PROPERTIES(${aTestName} PROPERTIES
+               ENVIRONMENT "${tests_env};SHAPER_UNIT_TEST_IN_PROGRESS=1"
+               LABELS "${aSubprojectName}")
       # Debug output...
       #MESSAGE(STATUS "Test added: ${aTestName} file: ${aTestFileName}")
     ELSE(EXISTS ${aTestFileName})
-      MESSAGE(WARNING "Can not find the test file: ${aTestFileName}")
+      MESSAGE(WARNING "Can not find the test file: ${eachFileName}")
+      MESSAGE(STATUS "Search paths are: ${testdir}")
+      MESSAGE(STATUS "                  ${testdir}/Test")
     ENDIF(EXISTS ${aTestFileName})
   endforeach(eachFileName ${ARGN})
-ENDMACRO(ADD_UNIT_TESTS)
+endfunction(GENERATE_TESTS)
+
+function(ADD_UNIT_TESTS)
+  GENERATE_TESTS(PATH "${CMAKE_CURRENT_SOURCE_DIR}" TESTS ${ARGN})
+endfunction(ADD_UNIT_TESTS)
+
+function(ADD_UNIT_TESTS_API)
+  GENERATE_TESTS(PATH "${CMAKE_CURRENT_SOURCE_DIR}" TESTS ${ARGN})
+endfunction(ADD_UNIT_TESTS_API)
+
 
+function(ADD_RESTRICTED_TESTS)
+  SET(RESTRICTED_ROOT_DIR $ENV{RESTRICTED_ROOT_DIR} CACHE PATH "Path to the restricted repository")
+
+  if (EXISTS ${RESTRICTED_ROOT_DIR})
+    GENERATE_TESTS(PATH "${RESTRICTED_ROOT_DIR}/SHAPER/bugs" TESTS ${ARGN})
+  else()
+    message(WARNING "RESTRICTED_ROOT_DIR is not specified to run restricted tests")
+  endif()
+endfunction(ADD_RESTRICTED_TESTS)