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_Feature.h"
16 using ::testing::Return;
17 using ::testing::ReturnRefOfCopy;
18 using ::testing::Test;
20 void null_deleter(void *) {}
22 class MockEvents_Listener : public Events_Listener {
24 MOCK_METHOD1(processEvent,
25 void(const std::shared_ptr<Events_Message>& theMessage));
28 class ConstructionAPI_Point_Constructor_Test : public Test {
30 MockEvents_Listener aErrorListener;
31 MockModelAPI_AttributeDouble aMockAttributeDouble;
32 MockModelAPI_Data aMockData;
33 MockModelAPI_Feature aMockFeature;
35 ConstructionAPI_Point_Constructor_Test() {
36 ON_CALL(aMockFeature, getKind())
37 .WillByDefault(ReturnRefOfCopy(std::string("Point")));
39 ON_CALL(aMockFeature, data())
40 .WillByDefault(Return(std::shared_ptr<ModelAPI_Data>(&aMockData, &null_deleter)));
42 ON_CALL(aMockData, real(_))
43 .WillByDefault(Return(std::shared_ptr<ModelAPI_AttributeDouble>(&aMockAttributeDouble, &null_deleter)));
45 Events_Loop::loop()->registerListener(&aErrorListener, Events_Error::errorID());
48 ~ConstructionAPI_Point_Constructor_Test() {
49 Events_Loop::loop()->removeListener(&aErrorListener);
52 void testUsingAttributes() {
53 EXPECT_CALL(aMockFeature, getKind());
55 EXPECT_CALL(aMockFeature, data())
58 EXPECT_CALL(aMockData, real("x"));
59 EXPECT_CALL(aMockData, real("y"));
60 EXPECT_CALL(aMockData, real("z"));
65 TEST_F(ConstructionAPI_Point_Constructor_Test, GetEmptyFeature_SendException) {
68 EXPECT_CALL(aErrorListener, processEvent(_));
70 ConstructionAPI_Point aPoint(aFeature);
73 TEST_F(ConstructionAPI_Point_Constructor_Test, GetEmptyFeatureAndValues_SendException) {
76 EXPECT_CALL(aErrorListener, processEvent(_));
78 ConstructionAPI_Point aPoint(aFeature, 10, "20", std::string("x + 30"));
81 TEST_F(ConstructionAPI_Point_Constructor_Test, GetWrongFeature_SendException) {
82 FeaturePtr aFeature(&aMockFeature, &null_deleter);
84 ON_CALL(aMockFeature, getKind())
85 .WillByDefault(ReturnRefOfCopy(std::string("WrongKind")));
87 EXPECT_CALL(aMockFeature, getKind());
88 EXPECT_CALL(aErrorListener, processEvent(_));
90 ConstructionAPI_Point aPoint(aFeature);
94 TEST_F(ConstructionAPI_Point_Constructor_Test, GetFeature) {
95 FeaturePtr aFeature(&aMockFeature, &null_deleter);
97 testUsingAttributes();
99 ConstructionAPI_Point aPoint(aFeature);
102 TEST_F(ConstructionAPI_Point_Constructor_Test, GetFeatureAndValues) {
103 FeaturePtr aFeature(&aMockFeature, &null_deleter);
105 testUsingAttributes();
107 EXPECT_CALL(aMockAttributeDouble, setValue(10));
108 EXPECT_CALL(aMockAttributeDouble, setText("20"));
109 EXPECT_CALL(aMockAttributeDouble, setText("x + 30"));
111 EXPECT_CALL(aMockFeature, execute());
113 ConstructionAPI_Point aPoint(aFeature, 10, "20", std::string("x + 30"));