1 #include <gtest/gtest.h>
2 #include <gmock/gmock.h>
4 #include <Events_Loop.h>
5 #include <Events_Error.h>
7 #include <ModelAPI_Feature.h>
8 #include <ModelHighAPI_Double.h>
9 #include <ConstructionAPI_Point.h>
11 #include "MockModelAPI_AttributeDouble.h"
12 #include "MockModelAPI_Data.h"
13 #include "MockModelAPI_Document.h"
14 #include "MockModelAPI_Feature.h"
17 using ::testing::Return;
18 using ::testing::ReturnRefOfCopy;
19 using ::testing::Test;
21 // TODO(spo): should be common function
22 void null_deleter(void *) {}
24 class MockEvents_Listener : public Events_Listener {
26 MOCK_METHOD1(processEvent,
27 void(const std::shared_ptr<Events_Message>& theMessage));
30 class ConstructionAPI_Point_Constructor_Test : public Test {
32 MockEvents_Listener aErrorListener;
33 MockModelAPI_AttributeDouble aMockAttributeDouble;
34 MockModelAPI_Data aMockData;
35 MockModelAPI_Feature aMockFeature;
36 MockModelAPI_Document aMockDocument;
38 ConstructionAPI_Point_Constructor_Test() {
39 ON_CALL(aMockDocument, addFeature(_, _))
40 .WillByDefault(Return(std::shared_ptr<ModelAPI_Feature>(&aMockFeature, &null_deleter)));
42 ON_CALL(aMockFeature, getKind())
43 .WillByDefault(ReturnRefOfCopy(std::string("Point")));
45 ON_CALL(aMockFeature, data())
46 .WillByDefault(Return(std::shared_ptr<ModelAPI_Data>(&aMockData, &null_deleter)));
48 ON_CALL(aMockData, real(_))
49 .WillByDefault(Return(std::shared_ptr<ModelAPI_AttributeDouble>(&aMockAttributeDouble, &null_deleter)));
51 Events_Loop::loop()->registerListener(&aErrorListener, Events_Error::errorID());
54 ~ConstructionAPI_Point_Constructor_Test() {
55 Events_Loop::loop()->removeListener(&aErrorListener);
58 void testInitializeFeature() {
59 EXPECT_CALL(aMockFeature, getKind());
61 EXPECT_CALL(aMockFeature, data())
64 EXPECT_CALL(aMockData, real("x"));
65 EXPECT_CALL(aMockData, real("y"));
66 EXPECT_CALL(aMockData, real("z"));
69 void testSetAttributes() {
70 EXPECT_CALL(aMockAttributeDouble, setValue(10));
71 EXPECT_CALL(aMockAttributeDouble, setText("20"));
72 EXPECT_CALL(aMockAttributeDouble, setText("x + 30"));
74 EXPECT_CALL(aMockFeature, execute());
78 TEST_F(ConstructionAPI_Point_Constructor_Test, GetEmptyFeature_SendException) {
81 EXPECT_CALL(aErrorListener, processEvent(_));
83 ConstructionAPI_Point aPoint(aFeature);
86 TEST_F(ConstructionAPI_Point_Constructor_Test, GetEmptyFeatureAndValues_SendException) {
89 EXPECT_CALL(aErrorListener, processEvent(_));
91 ConstructionAPI_Point aPoint(aFeature, 10, "20", std::string("x + 30"));
94 TEST_F(ConstructionAPI_Point_Constructor_Test, GetWrongFeature_SendException) {
95 FeaturePtr aFeature(&aMockFeature, &null_deleter);
97 ON_CALL(aMockFeature, getKind())
98 .WillByDefault(ReturnRefOfCopy(std::string("WrongKind")));
100 EXPECT_CALL(aMockFeature, getKind());
101 EXPECT_CALL(aErrorListener, processEvent(_));
103 ConstructionAPI_Point aPoint(aFeature);
107 TEST_F(ConstructionAPI_Point_Constructor_Test, GetFeature) {
108 FeaturePtr aFeature(&aMockFeature, &null_deleter);
110 testInitializeFeature();
112 ConstructionAPI_Point aPoint(aFeature);
115 TEST_F(ConstructionAPI_Point_Constructor_Test, GetFeatureAndValues) {
116 FeaturePtr aFeature(&aMockFeature, &null_deleter);
118 testInitializeFeature();
121 ConstructionAPI_Point aPoint(aFeature, 10, "20", std::string("x + 30"));
124 TEST_F(ConstructionAPI_Point_Constructor_Test, addPoint) {
125 DocumentPtr aDocument(&aMockDocument, &null_deleter);
127 EXPECT_CALL(aMockDocument, addFeature("Point", true));
129 testInitializeFeature();
131 PointPtr aPoint = addPoint(aDocument);
134 TEST_F(ConstructionAPI_Point_Constructor_Test, addPointWithValues) {
135 DocumentPtr aDocument(&aMockDocument, &null_deleter);
137 EXPECT_CALL(aMockDocument, addFeature("Point", true));
139 testInitializeFeature();
142 PointPtr aPoint = addPoint(aDocument, 10, "20", std::string("x + 30"));