]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #20641: Tests for implemented features
authorazv <artem.zhidkov@opencascade.com>
Thu, 20 May 2021 09:43:14 +0000 (12:43 +0300)
committerazv <artem.zhidkov@opencascade.com>
Thu, 20 May 2021 09:43:14 +0000 (12:43 +0300)
19 files changed:
src/CollectionPlugin/Test/TestCreateShapesFromGroups.py [new file with mode: 0755]
src/CollectionPlugin/tests.set [changed mode: 0644->0755]
src/ConnectorAPI/Test/CMakeLists.txt [changed mode: 0644->0755]
src/ConnectorAPI/Test/TestImportSTL.py [new file with mode: 0755]
src/ConnectorAPI/Test/data/cube_ascii.stl [new file with mode: 0755]
src/ConnectorAPI/Test/data/cube_binary.stl [new file with mode: 0755]
src/ConnectorAPI/Test/tests.set [changed mode: 0644->0755]
src/ExchangePlugin/CMakeLists.txt [changed mode: 0644->0755]
src/ExchangePlugin/CTestTestfileInstall.cmake [deleted file]
src/ExchangePlugin/Test/CMakeLists.txt [new file with mode: 0755]
src/ExchangePlugin/Test/CTestTestfileInstall.cmake [new file with mode: 0755]
src/ExchangePlugin/Test/TestImportImage_1.py [new file with mode: 0755]
src/ExchangePlugin/Test/TestImportImage_2.py [new file with mode: 0755]
src/ExchangePlugin/Test/data/1.jpg [new file with mode: 0755]
src/ExchangePlugin/Test/data/2.png [new file with mode: 0755]
src/ExchangePlugin/Test/testme.py [new file with mode: 0755]
src/ExchangePlugin/Test/tests.set [new file with mode: 0755]
src/ExchangePlugin/Test/tests_gui.set [new file with mode: 0755]
src/ExchangePlugin/tests.set [deleted file]

diff --git a/src/CollectionPlugin/Test/TestCreateShapesFromGroups.py b/src/CollectionPlugin/Test/TestCreateShapesFromGroups.py
new file mode 100755 (executable)
index 0000000..b68df37
--- /dev/null
@@ -0,0 +1,114 @@
+# Copyright (C) 2021  CEA/DEN, EDF R&D
+#
+# 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
+#
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+
+### Create Part
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+
+### Create Box
+Box_1 = model.addBox(Part_1_doc, 10, 10, 1)
+
+### Create RevolutionFuse
+RevolutionFuse_1 = model.addRevolutionFuse(Part_1_doc, [], model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Top]"), 80, 0, [model.selection("SOLID", "Box_1_1")])
+
+### Create Sketch
+Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Top"))
+
+### Create SketchArc
+SketchArc_1 = Sketch_1.addArc(4.7, 4.9, 1.8, 3.2, 7.6, 3.2, True)
+
+### Create SketchArc
+SketchArc_2 = Sketch_1.addArc(4.7, 4.9, 1.4, 3.2, 8.1, 3.2, True)
+
+### Create SketchLine
+SketchLine_1 = Sketch_1.addLine(1.4, 3.2, 1.8, 3.2)
+Sketch_1.setCoincident(SketchArc_2.startPoint(), SketchLine_1.startPoint())
+Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_1.endPoint())
+
+### Create SketchLine
+SketchLine_2 = Sketch_1.addLine(7.6, 3.2, 8.1, 3.2)
+Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_2.startPoint())
+Sketch_1.setCoincident(SketchArc_2.endPoint(), SketchLine_2.endPoint())
+Sketch_1.setCoincident(SketchArc_1.center(), SketchArc_2.center())
+Sketch_1.setHorizontal(SketchLine_1.result())
+Sketch_1.setCollinear(SketchLine_1.result(), SketchLine_2.result())
+Sketch_1.setRadius(SketchArc_1.results()[1], 3.5)
+Sketch_1.setRadius(SketchArc_2.results()[1], 4)
+RevolutionFuse_1.setNestedSketch(Sketch_1)
+
+### Create Group
+Group_1_objects = [model.selection("FACE", "RevolutionFuse_1_1/Modified_Face&Box_1_1/Top"),
+                   model.selection("FACE", "RevolutionFuse_1_1/Generated_Face&Sketch_1/SketchArc_1_2"),
+                   model.selection("FACE", "RevolutionFuse_1_1/Generated_Face&Sketch_1/SketchArc_2_2"),
+                   model.selection("FACE", "RevolutionFuse_1_1/To_Face")]
+Group_1 = model.addGroup(Part_1_doc, "Faces", Group_1_objects)
+Group_1.setName("Group_faces")
+Group_1.result().setName("Group_faces")
+
+### Create GroupShape
+GroupShape_1 = model.addGroupShape(Part_1_doc, [model.selection("COMPOUND", "Group_faces")])
+GroupShape_1.result().setName("GroupShape_1")
+
+### Create Shell
+Shell_1 = model.addShell(Part_1_doc, [model.selection("COMPOUND", "GroupShape_1")])
+Shell_1.result().setName("Shell_1_1")
+
+### Create Group
+Group_2_objects = [model.selection("EDGE", "[RevolutionFuse_1_1/To_Face][GroupShape_1_1_3/GroupShape_1_1_3]"),
+                   model.selection("EDGE", "[GroupShape_1_1_3/GroupShape_1_1_3][new_weak_name_1]"),
+                   model.selection("EDGE", "[GroupShape_1_1_3/GroupShape_1_1_3][new_weak_name_4]")]
+Group_2 = model.addGroup(Part_1_doc, "Edges", Group_2_objects)
+Group_2.setName("Group_edges")
+Group_2.result().setName("Group_edges")
+
+### Create GroupShape
+GroupShape_2 = model.addGroupShape(Part_1_doc, [model.selection("COMPOUND", "Group_edges")])
+GroupShape_2.result().setName("GroupShape_2")
+
+### Create Wire
+Wire_1_objects = [model.selection("EDGE", "GroupShape_2_1_2"),
+                  model.selection("EDGE", "GroupShape_2_1_3"),
+                  model.selection("EDGE", "GroupShape_2_1_1")]
+Wire_1 = model.addWire(Part_1_doc, Wire_1_objects, False)
+Wire_1.result().setName("Wire_1_1")
+
+model.end()
+
+#=============================================================================
+# Tests :
+#=============================================================================
+# Group of edges :
+model.checkResult(Wire_1, model, 1, [0], [0], [0], [3], [6])
+r=Wire_1.defaultResult()
+s=r.shape()
+dim=s.computeSize()
+dim=dim[1:]
+dx=abs(dim[3]-dim[0])
+dy=abs(dim[4]-dim[1])
+dz=abs(dim[5]-dim[2])
+print(dx,dy,dz)
+tol=1e-06
+assert(abs(dx-7.0000002) <= tol)
+assert(abs(dy-2.6261643) <= tol)
+assert(abs(dz-8.46802318) <= tol)
old mode 100644 (file)
new mode 100755 (executable)
index 387c5af..fe648a0
@@ -69,4 +69,5 @@ SET(TEST_NAMES
                TestGroupMoveAndSplit4.py
                Test3114.py
                Test18739.py
+               TestCreateShapesFromGroups.py
 )
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index 563bb20..d931acb
@@ -44,3 +44,4 @@ INSTALL(FILES CTestTestfileInstall.cmake
   RENAME CTestTestfile.cmake)
 
 INSTALL(FILES tests.set DESTINATION ${TEST_INSTALL_DIRECTORY})
+INSTALL(DIRECTORY data DESTINATION ${TEST_INSTALL_DIRECTORY})
diff --git a/src/ConnectorAPI/Test/TestImportSTL.py b/src/ConnectorAPI/Test/TestImportSTL.py
new file mode 100755 (executable)
index 0000000..b55211e
--- /dev/null
@@ -0,0 +1,84 @@
+# Copyright (C) 2021  CEA/DEN, EDF R&D
+#
+# 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
+#
+
+import os
+from salome.shaper import model
+
+import salome
+salome.salome_init(1)
+
+data_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data")
+
+def testImportSTL():
+    model.begin()
+    partSet = model.moduleDocument()
+
+    ### Create Part
+    Part_1 = model.addPart(partSet)
+    Part_1_doc = Part_1.document()
+
+    ### Create Import
+    Import_1 = model.addImport(Part_1_doc, os.path.join(data_dir, "cube_ascii.stl"))
+    model.do()
+    Import_1.setName("cube_ascii")
+    Import_1.result().setName("cube_ascii")
+    BoundingBox_1 = model.getBoundingBox(Part_1_doc, model.selection("SOLID", "cube_ascii"))
+
+    Import_2 = model.addImport(Part_1_doc, os.path.join(data_dir, "cube_binary.stl"))
+    model.do()
+    Import_2.setName("cube_binary")
+    Import_2.result().setName("cube_binary")
+
+    model.end()
+
+    #=============================================================================
+    # Tests :
+    #=============================================================================
+    # ASCII STL file :
+    model.checkResult(Import_1, model, 1, [0], [1], [12], [36], [72])
+    r=Import_1.defaultResult()
+    s=r.shape()
+    dim=s.computeSize()
+    dim=dim[1:]
+    dx=abs(dim[3]-dim[0])
+    dy=abs(dim[4]-dim[1])
+    dz=abs(dim[5]-dim[2])
+    tol=1e-06
+    assert(abs(dx-14) <= tol)
+    assert(abs(dy-8) <= tol)
+    assert(abs(dz-5) <= tol)
+    model.testResultsVolumes(Import_1, [560.0000222], theNbSignificantDigits = 7)
+
+    # Binary STL file :
+    model.checkResult(Import_2, model, 1, [0], [1], [12], [36], [72])
+    r=Import_2.defaultResult()
+    s=r.shape()
+    dim=s.computeSize()
+    dim=dim[1:]
+    dx=abs(dim[3]-dim[0])
+    dy=abs(dim[4]-dim[1])
+    dz=abs(dim[5]-dim[2])
+    assert(abs(dx-10) <= tol)
+    assert(abs(dy-10) <= tol)
+    assert(abs(dz-10) <= tol)
+    model.testResultsVolumes(Import_2, [1000], theNbSignificantDigits = 7)
+
+
+if __name__ == '__main__':
+    testImportSTL()
diff --git a/src/ConnectorAPI/Test/data/cube_ascii.stl b/src/ConnectorAPI/Test/data/cube_ascii.stl
new file mode 100755 (executable)
index 0000000..125cfe1
--- /dev/null
@@ -0,0 +1,86 @@
+solid 
+ facet normal -1.000000e+00  0.000000e+00  0.000000e+00
+   outer loop
+     vertex  0.000000e+00  0.000000e+00  0.000000e+00
+     vertex  0.000000e+00  8.000000e+00  5.000000e+00
+     vertex  0.000000e+00  8.000000e+00  0.000000e+00
+   endloop
+ endfacet
+ facet normal -1.000000e+00  0.000000e+00  0.000000e+00
+   outer loop
+     vertex  0.000000e+00  0.000000e+00  5.000000e+00
+     vertex  0.000000e+00  8.000000e+00  5.000000e+00
+     vertex  0.000000e+00  0.000000e+00  0.000000e+00
+   endloop
+ endfacet
+ facet normal  1.000000e+00  0.000000e+00  0.000000e+00
+   outer loop
+     vertex  1.400000e+01  0.000000e+00  0.000000e+00
+     vertex  1.400000e+01  8.000000e+00  0.000000e+00
+     vertex  1.400000e+01  8.000000e+00  5.000000e+00
+   endloop
+ endfacet
+ facet normal  1.000000e+00 -0.000000e+00  0.000000e+00
+   outer loop
+     vertex  1.400000e+01  0.000000e+00  5.000000e+00
+     vertex  1.400000e+01  0.000000e+00  0.000000e+00
+     vertex  1.400000e+01  8.000000e+00  5.000000e+00
+   endloop
+ endfacet
+ facet normal  0.000000e+00 -1.000000e+00 -0.000000e+00
+   outer loop
+     vertex  1.400000e+01  0.000000e+00  5.000000e+00
+     vertex  0.000000e+00  0.000000e+00  0.000000e+00
+     vertex  1.400000e+01  0.000000e+00  0.000000e+00
+   endloop
+ endfacet
+ facet normal -0.000000e+00 -1.000000e+00  0.000000e+00
+   outer loop
+     vertex  1.400000e+01  0.000000e+00  5.000000e+00
+     vertex  0.000000e+00  0.000000e+00  5.000000e+00
+     vertex  0.000000e+00  0.000000e+00  0.000000e+00
+   endloop
+ endfacet
+ facet normal  0.000000e+00  1.000000e+00  0.000000e+00
+   outer loop
+     vertex  1.400000e+01  8.000000e+00  5.000000e+00
+     vertex  1.400000e+01  8.000000e+00  0.000000e+00
+     vertex  0.000000e+00  8.000000e+00  0.000000e+00
+   endloop
+ endfacet
+ facet normal  0.000000e+00  1.000000e+00  0.000000e+00
+   outer loop
+     vertex  1.400000e+01  8.000000e+00  5.000000e+00
+     vertex  0.000000e+00  8.000000e+00  0.000000e+00
+     vertex  0.000000e+00  8.000000e+00  5.000000e+00
+   endloop
+ endfacet
+ facet normal -0.000000e+00  0.000000e+00 -1.000000e+00
+   outer loop
+     vertex  1.400000e+01  8.000000e+00  0.000000e+00
+     vertex  0.000000e+00  0.000000e+00  0.000000e+00
+     vertex  0.000000e+00  8.000000e+00  0.000000e+00
+   endloop
+ endfacet
+ facet normal  0.000000e+00 -0.000000e+00 -1.000000e+00
+   outer loop
+     vertex  1.400000e+01  8.000000e+00  0.000000e+00
+     vertex  1.400000e+01  0.000000e+00  0.000000e+00
+     vertex  0.000000e+00  0.000000e+00  0.000000e+00
+   endloop
+ endfacet
+ facet normal  0.000000e+00  0.000000e+00  1.000000e+00
+   outer loop
+     vertex  1.400000e+01  8.000000e+00  5.000000e+00
+     vertex  0.000000e+00  8.000000e+00  5.000000e+00
+     vertex  0.000000e+00  0.000000e+00  5.000000e+00
+   endloop
+ endfacet
+ facet normal  0.000000e+00  0.000000e+00  1.000000e+00
+   outer loop
+     vertex  1.400000e+01  8.000000e+00  5.000000e+00
+     vertex  0.000000e+00  0.000000e+00  5.000000e+00
+     vertex  1.400000e+01  0.000000e+00  5.000000e+00
+   endloop
+ endfacet
+endsolid
diff --git a/src/ConnectorAPI/Test/data/cube_binary.stl b/src/ConnectorAPI/Test/data/cube_binary.stl
new file mode 100755 (executable)
index 0000000..12ba5f1
Binary files /dev/null and b/src/ConnectorAPI/Test/data/cube_binary.stl differ
old mode 100644 (file)
new mode 100755 (executable)
index fa9195c..a566496
@@ -28,5 +28,6 @@ SET(TEST_NAMES
   Test18887
   Test3195
   TestExportSTL
+  TestImportSTL
   TestImportSTEP
 )
old mode 100644 (file)
new mode 100755 (executable)
index a155317..e8db9c5
@@ -108,23 +108,4 @@ INSTALL(FILES ${XML_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES})
 INSTALL(DIRECTORY icons/ DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/Exchange)
 INSTALL(FILES ${TEXT_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES})
 
-include(tests.set)
-
-ADD_UNIT_TESTS(${TEST_NAMES})
-
-if(${HAVE_SALOME})
-  enable_testing()
-  set(TEST_INSTALL_DIRECTORY "${SALOME_SHAPER_INSTALL_TESTS}/ExchangePlugin")
-  
-  install(FILES CTestTestfileInstall.cmake
-  DESTINATION ${TEST_INSTALL_DIRECTORY}
-  RENAME CTestTestfile.cmake)
-  install(FILES tests.set DESTINATION ${TEST_INSTALL_DIRECTORY})
-  
-  set(TMP_TESTS_NAMES)
-  foreach(tfile ${TEST_NAMES})
-    list(APPEND TMP_TESTS_NAMES "Test/${tfile}")
-  endforeach(tfile ${TEST_NAMES})
-  
-  install(FILES ${TMP_TESTS_NAMES} DESTINATION ${TEST_INSTALL_DIRECTORY})
-endif(${HAVE_SALOME})
+ADD_SUBDIRECTORY(Test)
diff --git a/src/ExchangePlugin/CTestTestfileInstall.cmake b/src/ExchangePlugin/CTestTestfileInstall.cmake
deleted file mode 100644 (file)
index ceaee95..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-# Copyright (C) 2021  CEA/DEN, EDF R&D
-#
-# 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
-#
-
-include(tests.set)
-
-foreach(tfile ${TEST_NAMES})
-  set(TEST_NAME ${COMPONENT_NAME}_${tfile})
-  add_test(${TEST_NAME} python ${tfile})
-  set_tests_properties(${TEST_NAME} PROPERTIES LABELS "${SALOME_TEST_LABEL_ADV}")
-endforeach()
diff --git a/src/ExchangePlugin/Test/CMakeLists.txt b/src/ExchangePlugin/Test/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..6d267d4
--- /dev/null
@@ -0,0 +1,65 @@
+# Copyright (C) 2021  CEA/DEN, EDF R&D
+#
+# 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
+#
+
+include(tests.set)
+
+ADD_UNIT_TESTS(${TEST_NAMES})
+
+if(${HAVE_SALOME})
+  enable_testing()
+  set(TEST_INSTALL_DIRECTORY "${SALOME_SHAPER_INSTALL_TESTS}/ExchangePlugin")
+  
+  install(FILES CTestTestfileInstall.cmake
+          DESTINATION ${TEST_INSTALL_DIRECTORY}
+          RENAME CTestTestfile.cmake)
+  install(FILES tests.set DESTINATION ${TEST_INSTALL_DIRECTORY})
+  
+  set(TMP_TESTS_NAMES)
+  foreach(tfile ${TEST_NAMES})
+    list(APPEND TMP_TESTS_NAMES "${tfile}")
+  endforeach(tfile ${TEST_NAMES})
+  
+  # tests which require SALOME GUI
+  include(tests_gui.set)
+  SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
+  set(COMPONENT_NAME "ExchangePlugin")
+  foreach(tfile ${TEST_WITH_GUI_NAMES})
+    # Strip the ".py" suffix
+    get_filename_component(TEST_NAME ${tfile} NAME_WE)
+    # -B ${CMAKE_SOURCE_DIR}/doc/salome/examples/testme.py
+    set(TEST_NAME ${COMPONENT_NAME}_${TEST_NAME})
+    add_test(NAME ${TEST_NAME}
+             COMMAND ${PYTHON_EXECUTABLE} -B ${CMAKE_CURRENT_SOURCE_DIR}/testme.py ${CMAKE_CURRENT_SOURCE_DIR}/${tfile})
+    set_tests_properties(${TEST_NAME} PROPERTIES ENVIRONMENT "${tests_env};SHAPER_UNIT_TEST_IN_PROGRESS=1")
+    set_tests_properties(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}")
+
+    # salome test
+    list(APPEND TMP_TESTS_NAMES "${tfile}")
+  endforeach()
+
+  install(FILES ${TMP_TESTS_NAMES} DESTINATION ${TEST_INSTALL_DIRECTORY})
+
+  install(FILES testme.py DESTINATION ${TEST_INSTALL_DIRECTORY}
+                          PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+                                      GROUP_READ GROUP_EXECUTE
+                                      WORLD_READ WORLD_EXECUTE)
+
+  install(FILES tests_gui.set DESTINATION ${TEST_INSTALL_DIRECTORY})
+  install(DIRECTORY data DESTINATION ${TEST_INSTALL_DIRECTORY})
+endif(${HAVE_SALOME})
diff --git a/src/ExchangePlugin/Test/CTestTestfileInstall.cmake b/src/ExchangePlugin/Test/CTestTestfileInstall.cmake
new file mode 100755 (executable)
index 0000000..cb194fb
--- /dev/null
@@ -0,0 +1,29 @@
+# Copyright (C) 2021  CEA/DEN, EDF R&D
+#
+# 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
+#
+
+include(tests.set)
+include(tests_gui.set)
+
+set(TEST_NAMES ${TEST_NAMES} ${TEST_WITH_GUI_NAMES})
+
+foreach(tfile ${TEST_NAMES})
+  set(TEST_NAME ${COMPONENT_NAME}_${tfile})
+  add_test(${TEST_NAME} python ${tfile})
+  set_tests_properties(${TEST_NAME} PROPERTIES LABELS "${SALOME_TEST_LABEL_ADV}")
+endforeach()
diff --git a/src/ExchangePlugin/Test/TestImportImage_1.py b/src/ExchangePlugin/Test/TestImportImage_1.py
new file mode 100755 (executable)
index 0000000..2c974d6
--- /dev/null
@@ -0,0 +1,99 @@
+# Copyright (C) 2021  CEA/DEN, EDF R&D
+#
+# 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
+#
+
+import os
+from salome.shaper import model
+
+import salome
+salome.salome_init(1)
+
+data_dir = os.path.join(os.path.dirname(sys.argv[0]), "data")
+
+model.begin()
+partSet = model.moduleDocument()
+
+### Create Part
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+
+### Create ImportImage
+ImportImage_1 = model.addImportImage(Part_1_doc, os.path.join(data_dir, "1.jpg"))
+model.do()
+ImportImage_1.setName("drawing")
+ImportImage_1.result().setName("drawing")
+
+### Create Translation
+Translation_1 = model.addTranslation(Part_1_doc, [model.selection("FACE", "drawing")], startPoint = model.selection("VERTEX", "[drawing/Shape_1]e[drawing/Shape_4]e"), endPoint = model.selection("VERTEX", "PartSet/Origin"), keepSubResults = True)
+
+### Create Scale
+Scale_1 = model.addScale(Part_1_doc, [model.selection("FACE", "drawing")] , model.selection("VERTEX", "PartSet/Origin"), 0.5, keepSubResults = True)
+
+model.end()
+
+#=============================================================================
+# Tests :
+#=============================================================================
+model.checkResult(Scale_1, model, 1, [0], [0], [1], [4], [8])
+r=Scale_1.defaultResult()
+s=r.shape()
+dim=s.computeSize()
+dim=dim[1:]
+dx=abs(dim[3]-dim[0])
+dy=abs(dim[4]-dim[1])
+dz=abs(dim[5]-dim[2])
+tol=1e-06
+assert(abs(dx-400) <= tol)
+assert(abs(dy-258.5) <= tol)
+assert(abs(dz-0) <= tol)
+
+#=============================================================================
+# Change the image :
+#=============================================================================
+model.begin()
+ImportImage_1.setFilePath(os.path.join(data_dir, "2.png"))
+ImportImage_1.execute()
+ImportImage_1.result().setName("drawing")
+Scale_1.setScaleFactor(0.7)
+Scale_1.execute()
+model.do()
+model.end()
+salome.sg.UpdateView()
+
+#=============================================================================
+# Tests :
+#=============================================================================
+model.checkResult(Scale_1, model, 1, [0], [0], [1], [4], [8])
+r=Scale_1.defaultResult()
+s=r.shape()
+dim=s.computeSize()
+dim=dim[1:]
+dx=abs(dim[3]-dim[0])
+dy=abs(dim[4]-dim[1])
+dz=abs(dim[5]-dim[2])
+tol=1e-06
+assert(abs(dx-448) <= tol)
+assert(abs(dy-296.8) <= tol)
+assert(abs(dz-0) <= tol)
+
+
+# Close SALOME GUI
+import salome_utils
+import subprocess
+port = salome_utils.getPortNumber()
+proc = subprocess.Popen(["killSalomeWithPort.py", "{}".format(port)])
diff --git a/src/ExchangePlugin/Test/TestImportImage_2.py b/src/ExchangePlugin/Test/TestImportImage_2.py
new file mode 100755 (executable)
index 0000000..025bd92
--- /dev/null
@@ -0,0 +1,105 @@
+# Copyright (C) 2021  CEA/DEN, EDF R&D
+#
+# 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
+#
+
+import os
+from salome.shaper import model
+
+import salome
+salome.salome_init(1)
+
+data_dir = os.path.join(os.path.dirname(sys.argv[0]), "data")
+
+from tempfile import TemporaryDirectory
+tmp_dir = TemporaryDirectory()
+img_file = os.path.join(tmp_dir.name, "1.jpg")
+
+from shutil import copyfile
+copyfile(os.path.join(data_dir, "1.jpg"), img_file)
+
+
+model.begin()
+partSet = model.moduleDocument()
+
+### Create Part
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+
+### Create ImportImage
+ImportImage_1 = model.addImportImage(Part_1_doc, img_file)
+model.do()
+ImportImage_1.setName("drawing")
+ImportImage_1.result().setName("drawing")
+
+### Create Translation
+Translation_1 = model.addTranslation(Part_1_doc, [model.selection("FACE", "drawing")], startPoint = model.selection("VERTEX", "[drawing/Shape_1]e[drawing/Shape_4]e"), endPoint = model.selection("VERTEX", "PartSet/Origin"), keepSubResults = True)
+
+### Create Scale
+Scale_1 = model.addScale(Part_1_doc, [model.selection("FACE", "drawing")] , model.selection("VERTEX", "PartSet/Origin"), 0.5, keepSubResults = True)
+
+model.end()
+
+#=============================================================================
+# Tests :
+#=============================================================================
+model.checkResult(Scale_1, model, 1, [0], [0], [1], [4], [8])
+r=Scale_1.defaultResult()
+s=r.shape()
+dim=s.computeSize()
+dim=dim[1:]
+dx=abs(dim[3]-dim[0])
+dy=abs(dim[4]-dim[1])
+dz=abs(dim[5]-dim[2])
+tol=1e-06
+assert(abs(dx-400) <= tol)
+assert(abs(dy-258.5) <= tol)
+assert(abs(dz-0) <= tol)
+
+#=============================================================================
+# Change the image :
+#=============================================================================
+os.rename(img_file, os.path.join(tmp_dir.name, "1_new.jpg"))
+
+model.begin()
+Scale_1.setScaleFactor(0.7)
+Scale_1.execute()
+model.do()
+model.end()
+
+#=============================================================================
+# Tests :
+#=============================================================================
+model.checkResult(Scale_1, model, 1, [0], [0], [1], [4], [8])
+r=Scale_1.defaultResult()
+s=r.shape()
+dim=s.computeSize()
+dim=dim[1:]
+dx=abs(dim[3]-dim[0])
+dy=abs(dim[4]-dim[1])
+dz=abs(dim[5]-dim[2])
+tol=1e-06
+assert(abs(dx-560) <= tol)
+assert(abs(dy-361.9) <= tol)
+assert(abs(dz-0) <= tol)
+
+
+# Close SALOME GUI
+import salome_utils
+import subprocess
+port = salome_utils.getPortNumber()
+proc = subprocess.Popen(["killSalomeWithPort.py", "{}".format(port)])
diff --git a/src/ExchangePlugin/Test/data/1.jpg b/src/ExchangePlugin/Test/data/1.jpg
new file mode 100755 (executable)
index 0000000..546569c
Binary files /dev/null and b/src/ExchangePlugin/Test/data/1.jpg differ
diff --git a/src/ExchangePlugin/Test/data/2.png b/src/ExchangePlugin/Test/data/2.png
new file mode 100755 (executable)
index 0000000..ea55f7f
Binary files /dev/null and b/src/ExchangePlugin/Test/data/2.png differ
diff --git a/src/ExchangePlugin/Test/testme.py b/src/ExchangePlugin/Test/testme.py
new file mode 100755 (executable)
index 0000000..94e8622
--- /dev/null
@@ -0,0 +1,74 @@
+# Copyright (C) 2007-2021  CEA/DEN, EDF R&D
+#
+# 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
+#
+
+#!/usr/bin/env python3
+
+import unittest, sys, os
+import subprocess
+
+testTimeout = 600
+
+class SalomeSession(object):
+    def __init__(self, script):
+        isOk = True
+        proc = subprocess.Popen(["runSalome.py", "--modules", "SHAPER,GEOM,SHAPERSTUDY", "--gui", "--splash", "0", script], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+        try:
+            out, err = proc.communicate(timeout = testTimeout)
+        except TimeoutExpired:
+            isOk = False
+            proc.kill()
+            out, err = proc.communicate()
+            error = "Killed by CPU limit."
+            pass
+        print(err)
+
+        assert isOk, "Test failed. {}".format(error)
+
+        # # import runSalome
+        # # run_script = "runSalome.py"
+        # # if sys.platform == 'win32':
+            # # module_dir = os.getenv("KERNEL_ROOT_DIR")
+            # # if module_dir: run_script = os.path.join(module_dir, "bin", "salome", run_script)
+            # # pass
+        # # sys.argv  = [run_script]
+        # # sys.argv += ["--gui"]
+        # # sys.argv += ["--splash=0"]
+        # # sys.argv += ["--modules=SHAPER,GEOM,SHAPERSTUDY,SMESH"]
+        # # sys.argv += ["%s" % script]
+        # # if sys.platform == 'win32':
+            # # main_module_path = sys.modules['__main__'].__file__
+            # # sys.modules['__main__'].__file__ = ''
+        # # clt, d = runSalome.main()
+        # # if sys.platform == 'win32':
+            # # sys.modules['__main__'].__file__ = main_module_path
+        return
+
+    def __del__(self):
+        port = os.getenv('NSPORT')
+        import killSalomeWithPort
+        killSalomeWithPort.killMyPort(port)
+        return
+    pass
+
+class MyTest(unittest.TestCase):
+    def testFunction(self):
+        SalomeSession(sys.argv[1])
+    pass
+
+unittest.main(argv=sys.argv[:1])
diff --git a/src/ExchangePlugin/Test/tests.set b/src/ExchangePlugin/Test/tests.set
new file mode 100755 (executable)
index 0000000..5fb4781
--- /dev/null
@@ -0,0 +1,59 @@
+# Copyright (C) 2021  CEA/DEN, EDF R&D
+#
+# 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
+#
+
+SET(TEST_NAMES
+  TestImport.py
+  TestExport.py
+  Test2290.py
+  Test2459.py
+  Test18710.py
+  TestExportToXAOWithFields.py
+  TestExportToXAOWithGroupNotUpdated.py
+  TestExport_FiniteValidator.py
+  TestExportPart_Failure_1.py
+  TestExportPart_Failure_2.py
+  TestExportPart_Failure_3.py
+  TestExportPart_FullPartSet.py
+  TestExportPart_FullPart_1.py
+  TestExportPart_FullPart_2.py
+  TestExportPart_PartSet.py
+  TestExportPart_Results_1.py
+  TestExportPart_Results_2.py
+  TestExportPart_Results_3.py
+  TestExportPart_Results_4.py
+  TestExportPart_Results_5.py
+  TestExportPart_Results_6.py
+  TestExportPart_Results_7.py
+  TestExportPart_Results_8.py
+  TestImportPart_AfterCurrent_1.py
+  TestImportPart_AfterCurrent_2.py
+  TestImportPart_AfterLast_1.py
+  TestImportPart_AfterLast_2.py
+  TestImportPart_AfterLast_3.py
+  TestImportPart_AfterLast_4.py
+  TestImportPart_AfterLast_5.py
+  TestImportPart_AfterLast_6.py
+  TestImportPart_Construction_1.py
+  TestImportPart_Construction_2.py
+  TestImportPart_Construction_3.py
+  TestImportPart_Construction_4.py
+  TestImportPart_Multiple.py
+  TestImportPart_ToEmptyPart.py
+  TestImportPart_ToEmptyPartSet.py
+)
\ No newline at end of file
diff --git a/src/ExchangePlugin/Test/tests_gui.set b/src/ExchangePlugin/Test/tests_gui.set
new file mode 100755 (executable)
index 0000000..0464ada
--- /dev/null
@@ -0,0 +1,23 @@
+# Copyright (C) 2021  CEA/DEN, EDF R&D
+#
+# 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
+#
+
+SET(TEST_WITH_GUI_NAMES
+  TestImportImage_1.py
+  TestImportImage_2.py
+)
\ No newline at end of file
diff --git a/src/ExchangePlugin/tests.set b/src/ExchangePlugin/tests.set
deleted file mode 100644 (file)
index 5fb4781..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-# Copyright (C) 2021  CEA/DEN, EDF R&D
-#
-# 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
-#
-
-SET(TEST_NAMES
-  TestImport.py
-  TestExport.py
-  Test2290.py
-  Test2459.py
-  Test18710.py
-  TestExportToXAOWithFields.py
-  TestExportToXAOWithGroupNotUpdated.py
-  TestExport_FiniteValidator.py
-  TestExportPart_Failure_1.py
-  TestExportPart_Failure_2.py
-  TestExportPart_Failure_3.py
-  TestExportPart_FullPartSet.py
-  TestExportPart_FullPart_1.py
-  TestExportPart_FullPart_2.py
-  TestExportPart_PartSet.py
-  TestExportPart_Results_1.py
-  TestExportPart_Results_2.py
-  TestExportPart_Results_3.py
-  TestExportPart_Results_4.py
-  TestExportPart_Results_5.py
-  TestExportPart_Results_6.py
-  TestExportPart_Results_7.py
-  TestExportPart_Results_8.py
-  TestImportPart_AfterCurrent_1.py
-  TestImportPart_AfterCurrent_2.py
-  TestImportPart_AfterLast_1.py
-  TestImportPart_AfterLast_2.py
-  TestImportPart_AfterLast_3.py
-  TestImportPart_AfterLast_4.py
-  TestImportPart_AfterLast_5.py
-  TestImportPart_AfterLast_6.py
-  TestImportPart_Construction_1.py
-  TestImportPart_Construction_2.py
-  TestImportPart_Construction_3.py
-  TestImportPart_Construction_4.py
-  TestImportPart_Multiple.py
-  TestImportPart_ToEmptyPart.py
-  TestImportPart_ToEmptyPartSet.py
-)
\ No newline at end of file