]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Test addPoint
authorspo <sergey.pokhodenko@opencascade.com>
Wed, 25 May 2016 05:30:10 +0000 (08:30 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Fri, 17 Jun 2016 11:41:00 +0000 (14:41 +0300)
src/ConstructionAPI/ConstructionAPI_Point.cpp
src/ConstructionAPI/ConstructionAPI_Point.h
src/ConstructionAPI/Test/MockModelAPI_Document.h [new file with mode: 0644]
src/ConstructionAPI/Test/TestPoint.cpp
src/ModelHighAPI/Test/TestDouble.py

index e6e6922ae94178d0d93fdf86d35873fa9f474031..d7e9867a19af75d4d79ec005de15c49a76fef357 100644 (file)
@@ -8,6 +8,7 @@
 #include "ConstructionAPI_Point.h"
 //--------------------------------------------------------------------------------------
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Document.h>
 #include <ModelAPI_Feature.h>
 
 #include <ModelHighAPI_Double.h>
@@ -84,3 +85,24 @@ std::shared_ptr<ModelAPI_AttributeDouble> ConstructionAPI_Point::z() const
 {
   return myZ;
 }
+
+//--------------------------------------------------------------------------------------
+// TODO(spo): make add* as static functions of the class
+PointPtr addPoint(
+    std::shared_ptr<ModelAPI_Document> thePart)
+{
+  // TODO(spo): check that thePart is not empty
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature("Point");
+  return PointPtr(new ConstructionAPI_Point(aFeature));
+}
+
+PointPtr addPoint(
+    std::shared_ptr<ModelAPI_Document> thePart,
+    const ModelHighAPI_Double& theX,
+    const ModelHighAPI_Double& theY,
+    const ModelHighAPI_Double& theZ)
+{
+  // TODO(spo): check that thePart is not empty
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature("Point");
+  return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
+}
index b7217a62ccfd7aa679a787d095f722a6e7521a37..88d97e4a9d5067b2e5ef36dec3b5a276f6086fd2 100644 (file)
@@ -13,6 +13,7 @@
 #include <ModelHighAPI_Interface.h>
 //--------------------------------------------------------------------------------------
 class ModelAPI_AttributeDouble;
+class ModelAPI_Document;
 class ModelHighAPI_Double;
 //--------------------------------------------------------------------------------------
 /*
@@ -42,6 +43,15 @@ protected:
   bool initialize();
 };
 
+//! Pointer on point object
+typedef std::shared_ptr<ConstructionAPI_Point> PointPtr;
+
+PointPtr addPoint(std::shared_ptr<ModelAPI_Document> thePart);
+PointPtr addPoint(std::shared_ptr<ModelAPI_Document> thePart,
+                  const ModelHighAPI_Double & theX,
+                  const ModelHighAPI_Double & theY,
+                  const ModelHighAPI_Double & theZ);
+
 //--------------------------------------------------------------------------------------
 //--------------------------------------------------------------------------------------
 #endif /* SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_POINT_H_ */ 
diff --git a/src/ConstructionAPI/Test/MockModelAPI_Document.h b/src/ConstructionAPI/Test/MockModelAPI_Document.h
new file mode 100644 (file)
index 0000000..cceea81
--- /dev/null
@@ -0,0 +1,84 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#ifndef MockModelAPI_Document_H_
+#define MockModelAPI_Document_H_
+
+#include <gmock/gmock.h>
+
+#include <ModelAPI_Document.h>
+
+class MockModelAPI_Document : public ModelAPI_Document {
+ public:
+  MOCK_CONST_METHOD0(kind,
+      const std::string&());
+  MOCK_METHOD1(close,
+      void(bool));
+  MOCK_METHOD2(addFeature,
+      std::shared_ptr<ModelAPI_Feature>(std::string, bool));
+  MOCK_METHOD3(refsToFeature,
+      void(std::shared_ptr<ModelAPI_Feature> theFeature,
+           std::set<std::shared_ptr<ModelAPI_Feature> >& theRefs,
+           const bool isSendError));
+  MOCK_METHOD1(removeFeature,
+      void(std::shared_ptr<ModelAPI_Feature> theFeature));
+  MOCK_METHOD2(moveFeature,
+      void(std::shared_ptr<ModelAPI_Feature> theMoved, std::shared_ptr<ModelAPI_Feature> theAfterThis));
+  MOCK_CONST_METHOD0(id,
+      const int());
+  MOCK_METHOD2(object,
+      std::shared_ptr<ModelAPI_Object>(const std::string& theGroupID, const int theIndex));
+  MOCK_METHOD2(objectByName,
+      std::shared_ptr<ModelAPI_Object>(const std::string& theGroupID, const std::string& theName));
+  MOCK_METHOD1(index,
+      const int(std::shared_ptr<ModelAPI_Object> theObject));
+  MOCK_METHOD1(size,
+      int(const std::string& theGroupID));
+  MOCK_METHOD1(currentFeature,
+      std::shared_ptr<ModelAPI_Feature>(const bool theVisible));
+  MOCK_METHOD2(setCurrentFeature,
+      void(std::shared_ptr<ModelAPI_Feature> theCurrent, const bool theVisible));
+  MOCK_METHOD0(setCurrentFeatureUp,
+      void());
+  MOCK_METHOD0(numInternalFeatures,
+      int());
+  MOCK_METHOD1(internalFeature,
+      std::shared_ptr<ModelAPI_Feature>(const int theIndex));
+  MOCK_METHOD0(synchronizeTransactions,
+      void());
+  MOCK_METHOD1(featureById,
+      std::shared_ptr<ModelAPI_Feature>(const int theId));
+  MOCK_METHOD2(createConstruction,
+      std::shared_ptr<ModelAPI_ResultConstruction>(const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex));
+  MOCK_METHOD2(createBody,
+      std::shared_ptr<ModelAPI_ResultBody>(const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex));
+  MOCK_METHOD2(createPart,
+      std::shared_ptr<ModelAPI_ResultPart>(const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex));
+  MOCK_METHOD3(copyPart,
+      std::shared_ptr<ModelAPI_ResultPart>(const std::shared_ptr<ModelAPI_ResultPart>& theOrigin,
+                                           const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex));
+  MOCK_METHOD2(createGroup,
+      std::shared_ptr<ModelAPI_ResultGroup>(const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex));
+  MOCK_METHOD2(createParameter,
+      std::shared_ptr<ModelAPI_ResultParameter>(const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex));
+  MOCK_METHOD1(feature,
+      std::shared_ptr<ModelAPI_Feature>(const std::shared_ptr<ModelAPI_Result>& theResult));
+  MOCK_METHOD0(allFeatures,
+      std::list<std::shared_ptr<ModelAPI_Feature> >());
+  MOCK_METHOD1(setActive,
+      void(const bool theFlag));
+  MOCK_CONST_METHOD0(isActive,
+      bool());
+  MOCK_METHOD0(isOpened,
+      bool());
+  MOCK_METHOD2(producedByFeature,
+      std::shared_ptr<ModelAPI_Feature>(std::shared_ptr<ModelAPI_Result> theResult, const std::shared_ptr<GeomAPI_Shape>& theShape));
+  MOCK_CONST_METHOD2(isLater,
+      bool(std::shared_ptr<ModelAPI_Feature> theLater, std::shared_ptr<ModelAPI_Feature> theCurrent));
+  MOCK_METHOD1(updateHistory,
+      void(const std::shared_ptr<ModelAPI_Object> theObject));
+  MOCK_METHOD1(updateHistory,
+      void(const std::string theGroup));
+};
+
+#endif // MockMockModelAPI_Document_H_
+
index bada269f80de8b8d9bc890d305aa11c5b54f5620..cb17fc964b83d76059268441879894ba1fc8aa3f 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "MockModelAPI_AttributeDouble.h"
 #include "MockModelAPI_Data.h"
+#include "MockModelAPI_Document.h"
 #include "MockModelAPI_Feature.h"
 
 using ::testing::_;
@@ -17,6 +18,7 @@ using ::testing::Return;
 using ::testing::ReturnRefOfCopy;
 using ::testing::Test;
 
+// TODO(spo): should be common function
 void null_deleter(void *) {}
 
 class MockEvents_Listener : public Events_Listener {
@@ -31,8 +33,12 @@ public:
   MockModelAPI_AttributeDouble aMockAttributeDouble;
   MockModelAPI_Data aMockData;
   MockModelAPI_Feature aMockFeature;
+  MockModelAPI_Document aMockDocument;
 
   ConstructionAPI_Point_Constructor_Test() {
+    ON_CALL(aMockDocument, addFeature(_, _))
+      .WillByDefault(Return(std::shared_ptr<ModelAPI_Feature>(&aMockFeature, &null_deleter)));
+
     ON_CALL(aMockFeature, getKind())
       .WillByDefault(ReturnRefOfCopy(std::string("Point")));
 
@@ -49,7 +55,7 @@ public:
     Events_Loop::loop()->removeListener(&aErrorListener);
   }
 
-  void testUsingAttributes() {
+  void testInitializeFeature() {
     EXPECT_CALL(aMockFeature, getKind());
 
     EXPECT_CALL(aMockFeature, data())
@@ -60,6 +66,13 @@ public:
     EXPECT_CALL(aMockData, real("z"));
   }
 
+  void testSetAttributes() {
+    EXPECT_CALL(aMockAttributeDouble, setValue(10));
+    EXPECT_CALL(aMockAttributeDouble, setText("20"));
+    EXPECT_CALL(aMockAttributeDouble, setText("x + 30"));
+
+    EXPECT_CALL(aMockFeature, execute());
+  }
 };
 
 TEST_F(ConstructionAPI_Point_Constructor_Test, GetEmptyFeature_SendException) {
@@ -94,7 +107,7 @@ TEST_F(ConstructionAPI_Point_Constructor_Test, GetWrongFeature_SendException) {
 TEST_F(ConstructionAPI_Point_Constructor_Test, GetFeature) {
   FeaturePtr aFeature(&aMockFeature, &null_deleter);
 
-  testUsingAttributes();
+  testInitializeFeature();
 
   ConstructionAPI_Point aPoint(aFeature);
 }
@@ -102,13 +115,29 @@ TEST_F(ConstructionAPI_Point_Constructor_Test, GetFeature) {
 TEST_F(ConstructionAPI_Point_Constructor_Test, GetFeatureAndValues) {
   FeaturePtr aFeature(&aMockFeature, &null_deleter);
 
-  testUsingAttributes();
+  testInitializeFeature();
+  testSetAttributes();
 
-  EXPECT_CALL(aMockAttributeDouble, setValue(10));
-  EXPECT_CALL(aMockAttributeDouble, setText("20"));
-  EXPECT_CALL(aMockAttributeDouble, setText("x + 30"));
+  ConstructionAPI_Point aPoint(aFeature, 10, "20", std::string("x + 30"));
+}
 
-  EXPECT_CALL(aMockFeature, execute());
+TEST_F(ConstructionAPI_Point_Constructor_Test, addPoint) {
+  DocumentPtr aDocument(&aMockDocument, &null_deleter);
 
-  ConstructionAPI_Point aPoint(aFeature, 10, "20", std::string("x + 30"));
+  EXPECT_CALL(aMockDocument, addFeature("Point", true));
+
+  testInitializeFeature();
+
+  PointPtr aPoint = addPoint(aDocument);
+}
+
+TEST_F(ConstructionAPI_Point_Constructor_Test, addPointWithValues) {
+  DocumentPtr aDocument(&aMockDocument, &null_deleter);
+
+  EXPECT_CALL(aMockDocument, addFeature("Point", true));
+
+  testInitializeFeature();
+  testSetAttributes();
+
+  PointPtr aPoint = addPoint(aDocument, 10, "20", std::string("x + 30"));
 }
index 6009e720a6c32138af41ecbac78514628154d7ba..d34c8d420be008d9f9b7653a0ddf8f265f4449d4 100644 (file)
@@ -9,11 +9,11 @@ class DoubleTestCase(unittest.TestCase):
 
     def test_create_from_double(self):
         from_double = ModelHighAPI.ModelHighAPI_Double(100.)
-        self.assertEqual(100., from_double.value())
+        self.assertEqual(100., from_double.value())
 
     def test_create_from_text(self):
         from_string = ModelHighAPI.ModelHighAPI_Double("200 + x")
-        self.assertEqual("200 + x", from_string.text())
+        self.assertEqual("200 + x", from_string.text())
     
 
 if __name__ == "__main__":