]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Simplify creation of the unit tests, rename example files according to the style...
authorSergey BELASH <belash.sergey@opencascade.com>
Fri, 18 Jul 2014 09:42:41 +0000 (13:42 +0400)
committerSergey BELASH <belash.sergey@opencascade.com>
Fri, 18 Jul 2014 09:42:41 +0000 (13:42 +0400)
CMakeCommon/UnitTest.cmake [new file with mode: 0644]
src/ConstructionPlugin/CMakeLists.txt
src/ConstructionPlugin/Test/CMakeLists.txt [deleted file]
src/ConstructionPlugin/Test/TestPointName.py [new file with mode: 0644]
src/ConstructionPlugin/Test/test_point_name.py [deleted file]
src/ModelAPI/CMakeLists.txt
src/ModelAPI/Test/CMakeLists.txt [deleted file]
src/ModelAPI/Test/TestUndoRedo.py [new file with mode: 0644]
src/ModelAPI/Test/test_undo.py [deleted file]

diff --git a/CMakeCommon/UnitTest.cmake b/CMakeCommon/UnitTest.cmake
new file mode 100644 (file)
index 0000000..b401ede
--- /dev/null
@@ -0,0 +1,47 @@
+#
+# NewGeom unit test system
+# How to use:
+# INCLUDE(UnitTest)
+# ...
+# ADD_UNIT_TESTS(TestUndoRedo.py
+#                TestResultBody.py)
+# or
+# SET(PROJECT_UNIT_TESTS
+#     TestUndoRedo.py
+#     TestWhatever.py  
+#    )
+# ADD_UNIT_TESTS(${PROJECT_UNIT_TESTS})
+#
+# 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. 
+# 
+# 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)
+  foreach(eachFileName ${ARGN})
+    # 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}")
+    IF(EXISTS ${aTestFileName})
+      ADD_TEST(NAME ${aTestName}
+               COMMAND ${PYTHON_EXECUTABLE} ${aTestFileName})
+      # Debug output...
+      #MESSAGE(STATUS "Test added: ${aTestName} file: ${aTestFileName}")
+    ELSE(EXISTS ${aTestFileName})
+      MESSAGE(WARNING "Can not find the test file: ${aTestFileName}")
+    ENDIF(EXISTS ${aTestFileName})
+  endforeach(eachFileName ${ARGN})
+ENDMACRO(ADD_UNIT_TESTS)
+
index 3b497009507c16737aed907cec250a21ff06c12c..4f632cbc3f6591dfaec33af35c02571aa6a36920 100644 (file)
@@ -1,4 +1,5 @@
 INCLUDE(Common)
+INCLUDE(UnitTest)
 
 SET(PROJECT_HEADERS
     ConstructionPlugin.h
@@ -29,5 +30,5 @@ SET(XML_RESOURCES
 INSTALL(TARGETS ConstructionPlugin DESTINATION plugins)
 INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins)
 
-ENABLE_TESTING()
-ADD_SUBDIRECTORY(Test)
+ADD_UNIT_TESTS(TestPointName.py
+              )
diff --git a/src/ConstructionPlugin/Test/CMakeLists.txt b/src/ConstructionPlugin/Test/CMakeLists.txt
deleted file mode 100644 (file)
index 2fbb8fc..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-INCLUDE(Common)
-
-ENABLE_TESTING()
-ADD_TEST(ModelAPITest 
-         ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_point_name.py)
diff --git a/src/ConstructionPlugin/Test/TestPointName.py b/src/ConstructionPlugin/Test/TestPointName.py
new file mode 100644 (file)
index 0000000..06e70e6
--- /dev/null
@@ -0,0 +1,11 @@
+from ModelAPI import *
+p = ModelAPI_PluginManager.get()
+f = p.rootDocument().addFeature("Point")
+f_name = f.data().name()
+f.execute()
+
+doc = p.rootDocument()
+f1 = doc.object("Construction", 0)
+f1_name = f1.data().name()
+
+assert (f_name == f1_name)
diff --git a/src/ConstructionPlugin/Test/test_point_name.py b/src/ConstructionPlugin/Test/test_point_name.py
deleted file mode 100644 (file)
index 06e70e6..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-from ModelAPI import *
-p = ModelAPI_PluginManager.get()
-f = p.rootDocument().addFeature("Point")
-f_name = f.data().name()
-f.execute()
-
-doc = p.rootDocument()
-f1 = doc.object("Construction", 0)
-f1_name = f1.data().name()
-
-assert (f_name == f1_name)
index 883288049cd9b822c634b24ea0aa31e37c6606aa..8f02b77ab8e0f4e92e4b241e6adc9abed25153ca 100644 (file)
@@ -1,6 +1,7 @@
 FIND_PACKAGE(SWIG REQUIRED)
 INCLUDE(${SWIG_USE_FILE})
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+INCLUDE(UnitTest)
 
 SET(PROJECT_HEADERS
     ModelAPI.h
@@ -73,5 +74,5 @@ INSTALL(TARGETS _ModelAPI DESTINATION swig)
 INSTALL(TARGETS ModelAPI DESTINATION bin)
 INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION swig)
 
-ENABLE_TESTING()
-ADD_SUBDIRECTORY(Test)
+ADD_UNIT_TESTS(TestUndoRedo.py
+              )
diff --git a/src/ModelAPI/Test/CMakeLists.txt b/src/ModelAPI/Test/CMakeLists.txt
deleted file mode 100644 (file)
index bbab60e..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-INCLUDE(Common)
-
-ENABLE_TESTING()
-ADD_TEST(ModelAPITest 
-         ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_undo.py)
diff --git a/src/ModelAPI/Test/TestUndoRedo.py b/src/ModelAPI/Test/TestUndoRedo.py
new file mode 100644 (file)
index 0000000..74a1315
--- /dev/null
@@ -0,0 +1,26 @@
+from ModelAPI import *\r
+plugin_manager = ModelAPI_PluginManager.get()\r
+doc = plugin_manager.rootDocument()\r
+assert(not doc.canUndo())\r
+assert(not doc.canRedo()) \r
+\r
+doc.startOperation()\r
+feature = doc.addFeature("Point")\r
+feature_name = feature.data().name()\r
+assert(feature_name == "Point_1")\r
+\r
+feature.execute()\r
+doc.finishOperation();\r
+assert(doc.size("Construction") == 1)\r
+assert(doc.canUndo())\r
+assert(not doc.canRedo()) \r
+\r
+doc.undo()\r
+assert(doc.size("Construction") == 0)\r
+assert(not doc.canUndo())\r
+assert(doc.canRedo())\r
+\r
+doc.redo()\r
+assert(doc.size("Construction") == 1)\r
+assert(doc.canUndo())\r
+assert(not doc.canRedo())\r
diff --git a/src/ModelAPI/Test/test_undo.py b/src/ModelAPI/Test/test_undo.py
deleted file mode 100644 (file)
index 74a1315..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-from ModelAPI import *\r
-plugin_manager = ModelAPI_PluginManager.get()\r
-doc = plugin_manager.rootDocument()\r
-assert(not doc.canUndo())\r
-assert(not doc.canRedo()) \r
-\r
-doc.startOperation()\r
-feature = doc.addFeature("Point")\r
-feature_name = feature.data().name()\r
-assert(feature_name == "Point_1")\r
-\r
-feature.execute()\r
-doc.finishOperation();\r
-assert(doc.size("Construction") == 1)\r
-assert(doc.canUndo())\r
-assert(not doc.canRedo()) \r
-\r
-doc.undo()\r
-assert(doc.size("Construction") == 0)\r
-assert(not doc.canUndo())\r
-assert(doc.canRedo())\r
-\r
-doc.redo()\r
-assert(doc.size("Construction") == 1)\r
-assert(doc.canUndo())\r
-assert(not doc.canRedo())\r