File size: 6,276 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// SPDX-License-Identifier: LGPL-2.1-or-later

#include <gtest/gtest.h>

#include "Mod/Part/App/FeatureRevolution.h"
#include <src/App/InitApplication.h>

#include "Base/Interpreter.h"

#include "BRepBuilderAPI_MakeEdge.hxx"

#include "TopoDS_Iterator.hxx"

#include "PartTestHelpers.h"

class FeatureRevolutionTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass
{
protected:
    static void SetUpTestSuite()
    {
        tests::initApplication();
    }


    void SetUp() override
    {
        createTestDoc();
        _revolution = _doc->addObject<Part::Revolution>();
        PartTestHelpers::rectangle(len, wid, "Rect1");
        _revolution->Source.setValue(_doc->getObjects().back());
        _revolution->Axis.setValue(0, 1, 0);
    }

    void TearDown() override
    {}

    // NOLINTBEGIN(cppcoreguidelines-non-private-member-variables-in-classes)
    Part::Revolution* _revolution = nullptr;
    // Arbtitrary constants for testing.  Named here for clarity.
    const double len = 3;
    const double wid = 4;
    const double ext1 = 10;
    // NOLINTEND(cppcoreguidelines-non-private-member-variables-in-classes)
};

TEST_F(FeatureRevolutionTest, testExecute)
{
    // Arrange
    double puckVolume = len * len * std::numbers::pi * wid;  // Area is PIr2; apply height
    // Act
    _revolution->execute();
    Part::TopoShape ts = _revolution->Shape.getValue();
    double volume = PartTestHelpers::getVolume(ts.getShape());
    Base::BoundBox3d bb = ts.getBoundBox();
    // Assert
    EXPECT_FLOAT_EQ(volume, puckVolume);
    EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(-len, 0, -len, len, wid, len)));
}

TEST_F(FeatureRevolutionTest, testExecuteBase)
{
    // Arrange
    double rad = len + 1.0;
    double rad2 = 1.0;
    double outerPuckVolume = rad * rad * std::numbers::pi * wid;    // Area is PIr2; apply height
    double innerPuckVolume = rad2 * rad2 * std::numbers::pi * wid;  // Area is PIr2; apply height
    _revolution->Base.setValue(Base::Vector3d(len + 1, 0, 0));
    // Act
    _revolution->execute();
    Part::TopoShape ts = _revolution->Shape.getValue();
    double volume = PartTestHelpers::getVolume(ts.getShape());
    Base::BoundBox3d bb = ts.getBoundBox();
    // Assert
    EXPECT_FLOAT_EQ(volume, outerPuckVolume - innerPuckVolume);
    EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, -wid, wid * 2, wid, wid)));
}


TEST_F(FeatureRevolutionTest, testAxis)
{
    // Arrange
    double puckVolume = wid * wid * std::numbers::pi * len;  // Area is PIr2 times height
    _revolution->Axis.setValue(Base::Vector3d(1, 0, 0));
    // Act
    _revolution->execute();
    Part::TopoShape ts = _revolution->Shape.getValue();
    double volume = PartTestHelpers::getVolume(ts.getShape());
    Base::BoundBox3d bb = ts.getBoundBox();
    // Assert
    EXPECT_FLOAT_EQ(volume, puckVolume);
    EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, -wid, -wid, len, wid, wid)));
}

TEST_F(FeatureRevolutionTest, testAxisLink)
{
    // Arrange
    BRepBuilderAPI_MakeEdge e1(gp_Pnt(0, 0, 0), gp_Pnt(0, 0, ext1));
    auto edge = _doc->addObject<Part::Feature>("Edge");
    edge->Shape.setValue(e1);
    _revolution->AxisLink.setValue(edge);
    // double puckVolume = wid * wid * std::numbers::pi * len;  // Area is PIr2; apply height
    // Act
    _revolution->execute();
    Part::TopoShape ts = _revolution->Shape.getValue();
    double volume = PartTestHelpers::getVolume(ts.getShape());
    Base::BoundBox3d bb = ts.getBoundBox();
    // Assert
    double puckVolume = 0;  // Someday make this test use a more interesting edge angle
    EXPECT_FLOAT_EQ(volume, puckVolume);
    EXPECT_TRUE(
        PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(-ext1 / 2, -ext1 / 2, 0, ext1 / 2, ext1 / 2, 0))
    );
}

TEST_F(FeatureRevolutionTest, testSymmetric)
{
    // Arrange
    double puckVolume = len * len * std::numbers::pi * wid;  // Area is PIr2 times height
    _revolution->Symmetric.setValue(true);
    // Act
    _revolution->execute();
    Part::TopoShape ts = _revolution->Shape.getValue();
    double volume = PartTestHelpers::getVolume(ts.getShape());
    Base::BoundBox3d bb = ts.getBoundBox();
    // Assert
    EXPECT_FLOAT_EQ(volume, puckVolume);
    EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(-len, 0, -len, len, wid, len)));
}

TEST_F(FeatureRevolutionTest, testAngle)
{
    // Arrange
    double puckVolume = len * len * std::numbers::pi * wid;  // Area is PIr2 times height
    _revolution->Angle.setValue(90);                         // NOLINT magic number
    // Act
    _revolution->execute();
    Part::TopoShape ts = _revolution->Shape.getValue();
    double volume = PartTestHelpers::getVolume(ts.getShape());
    Base::BoundBox3d bb = ts.getBoundBox();
    // Assert
    EXPECT_FLOAT_EQ(volume, puckVolume / 4);
    EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, -len, len, wid, 0)));
}

TEST_F(FeatureRevolutionTest, testMustExecute)
{
    // Assert
    EXPECT_TRUE(_revolution->mustExecute());
    // Act
    _doc->recompute();
    // Assert
    EXPECT_FALSE(_revolution->mustExecute());
    // Act
    _revolution->Base.setValue(_revolution->Base.getValue());
    // Assert
    EXPECT_TRUE(_revolution->mustExecute());
    // Act
    _doc->recompute();
    // Assert
    EXPECT_FALSE(_revolution->mustExecute());
    // Act
    _revolution->Solid.setValue(Standard_True);
    // Assert
    EXPECT_TRUE(_revolution->mustExecute());
    // Act
    _doc->recompute();
    // Assert
    EXPECT_FALSE(_revolution->mustExecute());
}

// TEST_F(FeatureRevolutionTest, testOnChanged)
// {
//     // void onChanged(const App::Property* prop) override;
// }

TEST_F(FeatureRevolutionTest, testGetProviderName)
{
    // Act
    _revolution->execute();
    const char* name = _revolution->getViewProviderName();
    // Assert
    EXPECT_STREQ(name, "PartGui::ViewProviderRevolution");
}

// Tested by execute above
// TEST_F(FeatureRevolutionTest, testFetchAxisLink)
// {
//     // static bool fetchAxisLink(const App::PropertyLinkSub& axisLink,
//     //                           Base::Vector3d &center,
//     //                           Base::Vector3d &dir,
//     //                           double &angle);
// }