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 <MockEvents_Listener.h>
13 #include <MockModelAPI_AttributeDouble.h>
14 #include <MockModelAPI_Data.h>
15 #include <MockModelAPI_Document.h>
16 #include <MockModelAPI_Feature.h>
19 using ::testing::Return;
20 using ::testing::ReturnRefOfCopy;
21 using ::testing::Test;
23 // TODO(spo): should be common function
24 void null_deleter(void *) {}
26 class ConstructionAPI_Point_Constructor_Test : public Test {
28 MockEvents_Listener aErrorListener;
29 MockModelAPI_AttributeDouble aMockAttributeDouble;
30 MockModelAPI_Data aMockData;
31 MockModelAPI_Feature aMockFeature;
32 MockModelAPI_Document aMockDocument;
34 ConstructionAPI_Point_Constructor_Test() {
35 ON_CALL(aMockDocument, addFeature(_, _))
36 .WillByDefault(Return(std::shared_ptr<ModelAPI_Feature>(&aMockFeature, &null_deleter)));
38 ON_CALL(aMockFeature, getKind())
39 .WillByDefault(ReturnRefOfCopy(std::string("Point")));
41 ON_CALL(aMockFeature, data())
42 .WillByDefault(Return(std::shared_ptr<ModelAPI_Data>(&aMockData, &null_deleter)));
44 ON_CALL(aMockData, real(_))
45 .WillByDefault(Return(std::shared_ptr<ModelAPI_AttributeDouble>(&aMockAttributeDouble, &null_deleter)));
47 Events_Loop::loop()->registerListener(&aErrorListener, Events_Error::errorID());
50 ~ConstructionAPI_Point_Constructor_Test() {
51 Events_Loop::loop()->removeListener(&aErrorListener);
54 void testInitializeFeature() {
55 EXPECT_CALL(aMockFeature, getKind());
57 EXPECT_CALL(aMockFeature, data())
60 EXPECT_CALL(aMockData, real("x"));
61 EXPECT_CALL(aMockData, real("y"));
62 EXPECT_CALL(aMockData, real("z"));
65 void testSetAttributes() {
66 EXPECT_CALL(aMockAttributeDouble, setValue(10));
67 EXPECT_CALL(aMockAttributeDouble, setText("20"));
68 EXPECT_CALL(aMockAttributeDouble, setText("x + 30"));
70 EXPECT_CALL(aMockFeature, execute());
74 TEST_F(ConstructionAPI_Point_Constructor_Test, GetEmptyFeature_SendException) {
77 EXPECT_CALL(aErrorListener, processEvent(_));
79 ConstructionAPI_Point aPoint(aFeature);
82 TEST_F(ConstructionAPI_Point_Constructor_Test, GetEmptyFeatureAndValues_SendException) {
85 EXPECT_CALL(aErrorListener, processEvent(_));
87 ConstructionAPI_Point aPoint(aFeature, 10, "20", std::string("x + 30"));
90 TEST_F(ConstructionAPI_Point_Constructor_Test, GetWrongFeature_SendException) {
91 FeaturePtr aFeature(&aMockFeature, &null_deleter);
93 ON_CALL(aMockFeature, getKind())
94 .WillByDefault(ReturnRefOfCopy(std::string("WrongKind")));
96 EXPECT_CALL(aMockFeature, getKind());
97 EXPECT_CALL(aErrorListener, processEvent(_));
99 ConstructionAPI_Point aPoint(aFeature);
103 TEST_F(ConstructionAPI_Point_Constructor_Test, GetFeature) {
104 FeaturePtr aFeature(&aMockFeature, &null_deleter);
106 testInitializeFeature();
108 ConstructionAPI_Point aPoint(aFeature);
111 TEST_F(ConstructionAPI_Point_Constructor_Test, GetFeatureAndValues) {
112 FeaturePtr aFeature(&aMockFeature, &null_deleter);
114 testInitializeFeature();
117 ConstructionAPI_Point aPoint(aFeature, 10, "20", std::string("x + 30"));
121 TEST_F(ConstructionAPI_Point_Constructor_Test, addPoint) {
122 DocumentPtr aDocument(&aMockDocument, &null_deleter);
124 EXPECT_CALL(aMockDocument, addFeature("Point", true));
126 testInitializeFeature();
129 PointPtr aPoint = addPoint(aDocument, 10, "20", std::string("x + 30"));