]> SALOME platform Git repositories - modules/shaper.git/blob - src/ConstructionAPI/Test/TestPoint.cpp
Salome HOME
Add ModelHighAPI & ConstructionAPI pachages
[modules/shaper.git] / src / ConstructionAPI / Test / TestPoint.cpp
1 #include <gtest/gtest.h>
2 #include <gmock/gmock.h>
3
4 #include <Events_Loop.h>
5 #include <Events_Error.h>
6
7 #include <ModelAPI_Feature.h>
8 #include <ModelHighAPI_Double.h>
9 #include <ConstructionAPI_Point.h>
10
11 #include "MockModelAPI_AttributeDouble.h"
12 #include "MockModelAPI_Data.h"
13 #include "MockModelAPI_Feature.h"
14
15 using ::testing::_;
16 using ::testing::Return;
17 using ::testing::ReturnRefOfCopy;
18 using ::testing::Test;
19
20 void null_deleter(void *) {}
21
22 class MockEvents_Listener : public Events_Listener {
23 public:
24   MOCK_METHOD1(processEvent,
25     void(const std::shared_ptr<Events_Message>& theMessage));
26 };
27
28 class ConstructionAPI_Point_Constructor_Test : public Test {
29 public:
30   MockEvents_Listener aErrorListener;
31   MockModelAPI_AttributeDouble aMockAttributeDouble;
32   MockModelAPI_Data aMockData;
33   MockModelAPI_Feature aMockFeature;
34
35   ConstructionAPI_Point_Constructor_Test() {
36     ON_CALL(aMockFeature, getKind())
37       .WillByDefault(ReturnRefOfCopy(std::string("Point")));
38
39     ON_CALL(aMockFeature, data())
40       .WillByDefault(Return(std::shared_ptr<ModelAPI_Data>(&aMockData, &null_deleter)));
41
42     ON_CALL(aMockData, real(_))
43       .WillByDefault(Return(std::shared_ptr<ModelAPI_AttributeDouble>(&aMockAttributeDouble, &null_deleter)));
44
45     Events_Loop::loop()->registerListener(&aErrorListener, Events_Error::errorID());
46   }
47
48   ~ConstructionAPI_Point_Constructor_Test() {
49     Events_Loop::loop()->removeListener(&aErrorListener);
50   }
51
52   void testUsingAttributes() {
53     EXPECT_CALL(aMockFeature, getKind());
54
55     EXPECT_CALL(aMockFeature, data())
56       .Times(3);
57
58     EXPECT_CALL(aMockData, real("x"));
59     EXPECT_CALL(aMockData, real("y"));
60     EXPECT_CALL(aMockData, real("z"));
61   }
62
63 };
64
65 TEST_F(ConstructionAPI_Point_Constructor_Test, GetEmptyFeature_SendException) {
66   FeaturePtr aFeature;
67
68   EXPECT_CALL(aErrorListener, processEvent(_));
69
70   ConstructionAPI_Point aPoint(aFeature);
71 }
72
73 TEST_F(ConstructionAPI_Point_Constructor_Test, GetEmptyFeatureAndValues_SendException) {
74   FeaturePtr aFeature;
75
76   EXPECT_CALL(aErrorListener, processEvent(_));
77
78   ConstructionAPI_Point aPoint(aFeature, 10, "20", std::string("x + 30"));
79 }
80
81 TEST_F(ConstructionAPI_Point_Constructor_Test, GetWrongFeature_SendException) {
82   FeaturePtr aFeature(&aMockFeature, &null_deleter);
83
84   ON_CALL(aMockFeature, getKind())
85     .WillByDefault(ReturnRefOfCopy(std::string("WrongKind")));
86
87   EXPECT_CALL(aMockFeature, getKind());
88   EXPECT_CALL(aErrorListener, processEvent(_));
89
90   ConstructionAPI_Point aPoint(aFeature);
91 }
92
93
94 TEST_F(ConstructionAPI_Point_Constructor_Test, GetFeature) {
95   FeaturePtr aFeature(&aMockFeature, &null_deleter);
96
97   testUsingAttributes();
98
99   ConstructionAPI_Point aPoint(aFeature);
100 }
101
102 TEST_F(ConstructionAPI_Point_Constructor_Test, GetFeatureAndValues) {
103   FeaturePtr aFeature(&aMockFeature, &null_deleter);
104
105   testUsingAttributes();
106
107   EXPECT_CALL(aMockAttributeDouble, setValue(10));
108   EXPECT_CALL(aMockAttributeDouble, setText("20"));
109   EXPECT_CALL(aMockAttributeDouble, setText("x + 30"));
110
111   EXPECT_CALL(aMockFeature, execute());
112
113   ConstructionAPI_Point aPoint(aFeature, 10, "20", std::string("x + 30"));
114 }