File size: 4,487 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 | // SPDX-License-Identifier: LGPL-2.1-or-later
#include <gtest/gtest.h>
#include "PartTestHelpers.h"
#include <Mod/Part/App/TopoShape.h>
#include "src/App/InitApplication.h"
class TopoShapeTest: public ::testing::Test
{
protected:
static void SetUpTestSuite()
{
tests::initApplication();
}
void SetUp() override
{
Base::Interpreter().runString("import Part");
_docName = App::GetApplication().getUniqueDocumentName("test");
App::GetApplication().newDocument(_docName.c_str(), "testUser");
_hasher = Base::Reference<App::StringHasher>(new App::StringHasher);
ASSERT_EQ(_hasher.getRefCount(), 1);
}
void TearDown() override
{
App::GetApplication().closeDocument(_docName.c_str());
}
private:
std::string _docName;
Data::ElementIDRefs _sid;
App::StringHasherRef _hasher;
};
// clang-format off
TEST_F(TopoShapeTest, TestElementTypeFace1)
{
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex("Face1"),
std::make_pair(std::string("Face"), 1UL));
}
TEST_F(TopoShapeTest, TestElementTypeEdge12)
{
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex("Edge12"),
std::make_pair(std::string("Edge"), 12UL));
}
TEST_F(TopoShapeTest, TestElementTypeVertex3)
{
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex("Vertex3"),
std::make_pair(std::string("Vertex"), 3UL));
}
TEST_F(TopoShapeTest, TestElementTypeFacer)
{
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex("Facer"),
std::make_pair(std::string(), 0UL));
}
TEST_F(TopoShapeTest, TestElementTypeVertex)
{
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex("Vertex"),
std::make_pair(std::string(), 0UL));
}
TEST_F(TopoShapeTest, TestElementTypeEmpty)
{
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex(""),
std::make_pair(std::string(), 0UL));
}
TEST_F(TopoShapeTest, TestElementTypeNull)
{
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex(nullptr),
std::make_pair(std::string(), 0UL));
}
TEST_F(TopoShapeTest, TestElementTypeWithHash)
{
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex(";#7:1;:G0;XTR;:H11a6:8,F.Face3"),
std::make_pair(std::string("Face"), 3UL));
}
TEST_F(TopoShapeTest, TestElementTypeWithSubelements)
{
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex("Part.Body.Pad.Face3"),
std::make_pair(std::string(), 0UL));
}
TEST_F(TopoShapeTest, TestElementTypeNonMatching)
{
for (std::array elements = {"Face0", "Face01", "XFace3", "Face3extra"};
const auto& element : elements) {
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex(element),
std::make_pair(std::string(), 0UL));
}
}
TEST_F(TopoShapeTest, TestTypeFace1)
{
EXPECT_EQ(Part::TopoShape::getTypeAndIndex("Face1"),
std::make_pair(std::string("Face"), 1UL));
}
TEST_F(TopoShapeTest, TestTypeEdge12)
{
EXPECT_EQ(Part::TopoShape::getTypeAndIndex("Edge12"),
std::make_pair(std::string("Edge"), 12UL));
}
TEST_F(TopoShapeTest, TestTypeVertex3)
{
EXPECT_EQ(Part::TopoShape::getTypeAndIndex("Vertex3"),
std::make_pair(std::string("Vertex"), 3UL));
}
TEST_F(TopoShapeTest, TestTypeFacer)
{
EXPECT_EQ(Part::TopoShape::getTypeAndIndex("Facer"),
std::make_pair(std::string("Facer"), 0UL));
}
TEST_F(TopoShapeTest, TestTypeVertex)
{
EXPECT_EQ(Part::TopoShape::getTypeAndIndex("Vertex"),
std::make_pair(std::string("Vertex"), 0UL));
}
TEST_F(TopoShapeTest, TestTypeEmpty)
{
EXPECT_EQ(Part::TopoShape::getTypeAndIndex(""),
std::make_pair(std::string(), 0UL));
}
TEST_F(TopoShapeTest, TestTypeNull)
{
EXPECT_EQ(Part::TopoShape::getTypeAndIndex(nullptr),
std::make_pair(std::string(), 0UL));
}
TEST_F(TopoShapeTest, TestGetSubshape)
{
// Arrange
auto [cube1, cube2] = PartTestHelpers::CreateTwoTopoShapeCubes();
// Act
auto face = cube1.getSubShape("Face2");
auto vertex = cube2.getSubShape(TopAbs_VERTEX,2);
auto silentFail = cube1.getSubShape("NotThere", true);
// Assert
EXPECT_EQ(face.ShapeType(), TopAbs_FACE);
EXPECT_EQ(vertex.ShapeType(), TopAbs_VERTEX);
EXPECT_TRUE(silentFail.IsNull());
EXPECT_THROW(cube1.getSubShape("Face7"), Base::IndexError); // Out of range
EXPECT_THROW(cube1.getSubShape("WOOHOO", false), Base::ValueError); // Invalid
}
// clang-format on
|