]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add test for HighModelAPI_Double
authorspo <sergey.pokhodenko@opencascade.com>
Thu, 26 May 2016 14:38:01 +0000 (17:38 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Fri, 17 Jun 2016 11:41:02 +0000 (14:41 +0300)
src/ConstructionAPI/Test/TestPoint.cpp
src/ModelHighAPI/CMakeLists.txt
src/ModelHighAPI/Mock/MockEvents_Listener.h [new file with mode: 0644]
src/ModelHighAPI/ModelHighAPI_Double.cpp
src/ModelHighAPI/ModelHighAPI_Double.h
src/ModelHighAPI/Test/CMakeLists.txt [new file with mode: 0644]
src/ModelHighAPI/Test/TestDouble.cpp [new file with mode: 0644]

index aeb6657d25974b89c07ee11c129fcb9be607d1aa..b136b03675f83e3f963f8afa04c0d5e421d86be1 100644 (file)
@@ -8,10 +8,12 @@
 #include <ModelHighAPI_Double.h>
 #include <ConstructionAPI_Point.h>
 
-#include "MockModelAPI_AttributeDouble.h"
-#include "MockModelAPI_Data.h"
-#include "MockModelAPI_Document.h"
-#include "MockModelAPI_Feature.h"
+#include <MockEvents_Listener.h>
+
+#include <MockModelAPI_AttributeDouble.h>
+#include <MockModelAPI_Data.h>
+#include <MockModelAPI_Document.h>
+#include <MockModelAPI_Feature.h>
 
 using ::testing::_;
 using ::testing::Return;
@@ -21,12 +23,6 @@ using ::testing::Test;
 // TODO(spo): should be common function
 void null_deleter(void *) {}
 
-class MockEvents_Listener : public Events_Listener {
-public:
-  MOCK_METHOD1(processEvent,
-    void(const std::shared_ptr<Events_Message>& theMessage));
-};
-
 class ConstructionAPI_Point_Constructor_Test : public Test {
 public:
   MockEvents_Listener aErrorListener;
index 404e8f8a2d72b43b59c4819a05b7b8d65e79d45f..9ae3be6efb72b120e6422e59477f01393cabfde1 100644 (file)
@@ -16,6 +16,7 @@ SET(PROJECT_SOURCES
 SET(PROJECT_LIBRARIES
   Config
   Events
+  ModelAPI
 )
 
 ADD_DEFINITIONS(-DMODELHIGHAPI_EXPORTS)
@@ -59,3 +60,5 @@ INCLUDE(UnitTest)
 ADD_UNIT_TESTS(
   TestDouble.py
 )
+
+ADD_SUBDIRECTORY (Test)
diff --git a/src/ModelHighAPI/Mock/MockEvents_Listener.h b/src/ModelHighAPI/Mock/MockEvents_Listener.h
new file mode 100644 (file)
index 0000000..cf5c1ab
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#ifndef MockEvents_Listener_H_
+#define MockEvents_Listener_H_
+
+#include <gmock/gmock.h>
+
+#include <Events_Listener.h>
+
+class MockEvents_Listener : public Events_Listener {
+public:
+  MOCK_METHOD1(processEvent,
+    void(const std::shared_ptr<Events_Message>& theMessage));
+};
+
+#endif // MockEvents_Listener_H_
index ca1f661a9ca44f518c4361263d252302b77df48b..b40b89e0cd99c4c5ff1449c1b77f26b0beeec874 100644 (file)
 //--------------------------------------------------------------------------------------
 
 //--------------------------------------------------------------------------------------
-ModelHighAPI_Double::ModelHighAPI_Double()
-{
-}
-
 ModelHighAPI_Double::ModelHighAPI_Double(double theValue)
 : myValue(theValue)
 {
index f39e50445a0fa6ac484062e1cfd1839e29a33ec3..3f84a72f8c6de40a9aa91be9588c7f8999d3c36a 100644 (file)
@@ -22,10 +22,8 @@ class ModelAPI_AttributeDouble;
 class ModelHighAPI_Double
 {
 public:
-  /// Default constructor
-  ModelHighAPI_Double();
   /// Constructor for double
-  ModelHighAPI_Double(double theValue);
+  ModelHighAPI_Double(double theValue = 0.);
   /// Constructor for std::string
   ModelHighAPI_Double(const std::string & theValue);
   /// Constructor for char *
diff --git a/src/ModelHighAPI/Test/CMakeLists.txt b/src/ModelHighAPI/Test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..2af368b
--- /dev/null
@@ -0,0 +1,24 @@
+## Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+include(GTest)
+
+set(PROJECT_SOURCES
+  TestDouble.cpp
+)
+
+include_directories(
+  ${PROJECT_SOURCE_DIR}/src/ModelHighAPI
+  ${PROJECT_SOURCE_DIR}/src/ModelHighAPI/Mock
+)
+
+set(PROJECT_LIBRARIES
+  ModelHighAPI
+)
+
+set(PACKAGE_NAME "ModelHighAPI")
+set(TARGET_NAME "Test${PACKAGE_NAME}")
+
+add_executable(${TARGET_NAME} ${PROJECT_SOURCES})
+target_link_libraries(${TARGET_NAME} ${PROJECT_LIBRARIES} ${GTEST_LIBRARY})
+
+GTEST_ADD_TESTS(${CMAKE_BINARY_DIR}/bin/${TARGET_NAME} "" ${PROJECT_SOURCES})
diff --git a/src/ModelHighAPI/Test/TestDouble.cpp b/src/ModelHighAPI/Test/TestDouble.cpp
new file mode 100644 (file)
index 0000000..23c47a5
--- /dev/null
@@ -0,0 +1,59 @@
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include <ModelHighAPI_Double.h>
+
+#include <MockModelAPI_AttributeDouble.h>
+
+using ::testing::_;
+using ::testing::Return;
+using ::testing::ReturnRefOfCopy;
+using ::testing::Test;
+
+// TODO(spo): should be common function
+void null_deleter(void *) {}
+
+class HighModelAPI_Double_Test : public Test {
+public:
+  MockModelAPI_AttributeDouble aMockAttributeDouble;
+  std::shared_ptr<ModelAPI_AttributeDouble> anAttributeDouble;
+
+  HighModelAPI_Double_Test() {
+    anAttributeDouble = std::shared_ptr<ModelAPI_AttributeDouble>(&aMockAttributeDouble, &null_deleter);
+  }
+
+  ~HighModelAPI_Double_Test() {
+  }
+};
+
+TEST_F(HighModelAPI_Double_Test, Default) {
+  ModelHighAPI_Double aValue;
+
+  EXPECT_CALL(aMockAttributeDouble, setValue(0.));
+
+  aValue.fillAttribute(anAttributeDouble);
+}
+
+TEST_F(HighModelAPI_Double_Test, Double) {
+  ModelHighAPI_Double aValue(100);
+
+  EXPECT_CALL(aMockAttributeDouble, setValue(100.));
+
+  aValue.fillAttribute(anAttributeDouble);
+}
+
+TEST_F(HighModelAPI_Double_Test, Char) {
+  ModelHighAPI_Double aValue("20");
+
+  EXPECT_CALL(aMockAttributeDouble, setText("20"));
+
+  aValue.fillAttribute(anAttributeDouble);
+}
+
+TEST_F(HighModelAPI_Double_Test, String) {
+  ModelHighAPI_Double aValue(std::string("x + 30"));
+
+  EXPECT_CALL(aMockAttributeDouble, setText("x + 30"));
+
+  aValue.fillAttribute(anAttributeDouble);
+}