| | |
| |
|
| | #include <gtest/gtest.h> |
| |
|
| | #include <array> |
| | #include <boost/core/ignore_unused.hpp> |
| |
|
| | #include <App/Application.h> |
| | #include <App/ComplexGeoData.h> |
| | #include <Base/BoundBox.h> |
| | #include <Base/Writer.h> |
| | #include <src/App/InitApplication.h> |
| |
|
| |
|
| | class ConcreteComplexGeoDataForTesting: public Data::ComplexGeoData |
| | { |
| | public: |
| | std::vector<const char*> getElementTypes() const override |
| | { |
| | return {"EDGE"}; |
| | } |
| |
|
| | unsigned long countSubElements(const char* Type) const override |
| | { |
| | (void)Type; |
| | return 0; |
| | } |
| |
|
| | Data::Segment* getSubElement(const char* Type, unsigned long number) const override |
| | { |
| | (void)number; |
| | (void)Type; |
| | return nullptr; |
| | } |
| |
|
| | void setTransform(const Base::Matrix4D& rclTrf) override |
| | { |
| | (void)rclTrf; |
| | } |
| |
|
| | Base::Matrix4D getTransform() const override |
| | { |
| | return {}; |
| | } |
| |
|
| | void transformGeometry(const Base::Matrix4D& rclMat) override |
| | { |
| | (void)rclMat; |
| | } |
| |
|
| | Base::BoundBox3d getBoundBox() const override |
| | { |
| | return Base::BoundBox3d(); |
| | } |
| | }; |
| |
|
| | class ComplexGeoDataTest: public ::testing::Test |
| | { |
| | protected: |
| | static void SetUpTestSuite() |
| | { |
| | tests::initApplication(); |
| | } |
| |
|
| | void SetUp() override |
| | { |
| | _docName = App::GetApplication().getUniqueDocumentName("test"); |
| | App::GetApplication().newDocument(_docName.c_str(), "testUser"); |
| | } |
| |
|
| | void TearDown() override |
| | { |
| | App::GetApplication().closeDocument(_docName.c_str()); |
| | } |
| |
|
| | ConcreteComplexGeoDataForTesting& cgd() |
| | { |
| | return _complexGeoData; |
| | } |
| |
|
| | std::tuple<Data::IndexedName, Data::MappedName> createMappedName(const std::string& name) |
| | { |
| | auto elementMap = std::make_shared<Data::ElementMap>(); |
| | cgd().resetElementMap(elementMap); |
| | auto mappedName = Data::MappedName(name.c_str()); |
| | auto indexedName = Data::IndexedName(_complexGeoData.getElementTypes().front(), 1); |
| | elementMap->setElementName(indexedName, mappedName, 0); |
| | return std::make_tuple(indexedName, mappedName); |
| | } |
| |
|
| | private: |
| | ConcreteComplexGeoDataForTesting _complexGeoData; |
| | std::string _docName; |
| | }; |
| |
|
| | |
| |
|
| | TEST_F(ComplexGeoDataTest, getIndexedNameNoName) |
| | { |
| | |
| | auto result = cgd().getIndexedName(Data::MappedName()); |
| |
|
| | |
| | EXPECT_FALSE(result); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, getIndexedNameNoElementMap) |
| | { |
| | |
| | auto result = cgd().getIndexedName(Data::MappedName("TestName")); |
| |
|
| | |
| | EXPECT_TRUE(result); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, getMappedNameNoElement) |
| | { |
| | |
| | auto result = cgd().getMappedName(Data::IndexedName {}); |
| |
|
| | |
| | EXPECT_FALSE(result); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, getMappedNameDisallowUnmappedNoMap) |
| | { |
| | |
| | auto result = cgd().getMappedName(Data::IndexedName {"TestName"}, false); |
| |
|
| | |
| | EXPECT_FALSE(result); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, getMappedNameDisallowUnmappedWithMap) |
| | { |
| | |
| | auto elementMap = std::make_shared<Data::ElementMap>(); |
| | cgd().resetElementMap(elementMap); |
| | auto mappedName = Data::MappedName("TestMappedName"); |
| | auto indexedName = Data::IndexedName("EDGE", 1); |
| | elementMap->setElementName(indexedName, mappedName, 0); |
| |
|
| | |
| | auto result = cgd().getMappedName(indexedName, false); |
| |
|
| | |
| | EXPECT_TRUE(result); |
| | EXPECT_EQ(mappedName, result); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, getMappedNameDisallowUnmappedMissingFromMap) |
| | { |
| | |
| | auto mappedName = Data::MappedName("NotTheTestName"); |
| | cgd().getIndexedName(mappedName); |
| |
|
| | |
| | auto result = cgd().getMappedName(Data::IndexedName {"TestName"}, false); |
| |
|
| | |
| | EXPECT_FALSE(result); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, getMappedNameAllowUnmapped) |
| | { |
| | |
| | auto result = cgd().getMappedName(Data::IndexedName {"TestName"}, true); |
| |
|
| | |
| | EXPECT_TRUE(result); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, getElementNameGivenIndexedName) |
| | { |
| | |
| | const char* name {"EDGE123"}; |
| | auto indexedName = cgd().getIndexedName(Data::MappedName(name)); |
| |
|
| | |
| | auto result = cgd().getElementName(name); |
| |
|
| | |
| | EXPECT_EQ(result.index, indexedName); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, getElementNameGivenMappedName) |
| | { |
| | |
| | const char* name {"EDGE123"}; |
| | auto mappedName = cgd().getMappedName(Data::IndexedName(name)); |
| |
|
| | |
| | auto result = cgd().getElementName(name); |
| |
|
| | |
| | EXPECT_EQ(result.name, mappedName); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, getElementMappedNamesNoMapNoUnmapped) |
| | { |
| | |
| | |
| | auto indexedName = Data::IndexedName("EDGE1"); |
| |
|
| | |
| | auto result = cgd().getElementMappedNames(indexedName, false); |
| |
|
| | |
| | EXPECT_TRUE(result.empty()); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, getElementMappedNamesWithMapNoUnmapped) |
| | { |
| | |
| | auto elementMap = std::make_shared<Data::ElementMap>(); |
| | cgd().resetElementMap(elementMap); |
| | auto mappedName = Data::MappedName("TestMappedName"); |
| | auto indexedName = Data::IndexedName("EDGE", 1); |
| | elementMap->setElementName(indexedName, mappedName, 0); |
| |
|
| | |
| | auto result = cgd().getElementMappedNames(indexedName, false); |
| |
|
| | |
| | EXPECT_FALSE(result.empty()); |
| | EXPECT_EQ(result[0].first, mappedName); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, getElementMappedNamesNoMapWithUnmapped) |
| | { |
| | |
| | auto indexedName = Data::IndexedName("EDGE1"); |
| |
|
| | |
| | auto result = cgd().getElementMappedNames(indexedName, true); |
| |
|
| | |
| | EXPECT_FALSE(result.empty()); |
| | } |
| |
|
| |
|
| | TEST_F(ComplexGeoDataTest, getElementMappedNamesWithMapWithUnmapped) |
| | { |
| | |
| | Data::MappedName mappedName; |
| | Data::IndexedName indexedName; |
| | std::tie(indexedName, mappedName) = createMappedName("TestMappedName"); |
| | auto unmappedName = Data::IndexedName("EDGE", 2); |
| |
|
| | |
| | auto result = cgd().getElementMappedNames(unmappedName, true); |
| |
|
| | |
| | EXPECT_FALSE(result.empty()); |
| | EXPECT_NE(result[0].first, mappedName); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, elementTypeValidIndexName) |
| | { |
| | |
| | auto indexedName = Data::IndexedName("EDGE", 1); |
| |
|
| | |
| | char elementType = cgd().elementType(indexedName); |
| |
|
| | |
| | EXPECT_EQ(elementType, 'E'); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, elementTypeInvalidIndexedName) |
| | { |
| | |
| | auto indexedName = Data::IndexedName("INVALID", 1); |
| |
|
| | |
| | char elementType = cgd().elementType(indexedName); |
| |
|
| | |
| | EXPECT_EQ(elementType, 0); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, elementTypeCharEmptyName) |
| | { |
| | |
| | char elementType = cgd().elementType(nullptr); |
| |
|
| | |
| | EXPECT_EQ(elementType, 0); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, elementTypeCharIndexedName) |
| | { |
| | |
| | char elementType = cgd().elementType("EDGE1"); |
| |
|
| | |
| | EXPECT_EQ(elementType, 'E'); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, elementTypeCharMappedNameNoPrefix) |
| | { |
| | |
| | int size {0}; |
| | Data::MappedName mappedName; |
| | Data::IndexedName indexedName; |
| | std::tie(indexedName, mappedName) = createMappedName("TestMappedName:;"); |
| |
|
| | |
| | char elementType = cgd().elementType(mappedName.toConstString(0, size)); |
| |
|
| | |
| | EXPECT_EQ(elementType, 'E'); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, elementTypeCharMappedNameWithPrefix) |
| | { |
| | |
| | int size {0}; |
| | Data::MappedName mappedName; |
| | Data::IndexedName indexedName; |
| | std::string name(Data::ELEMENT_MAP_PREFIX); |
| | name.append("TestMappedElement:;"); |
| | std::tie(indexedName, mappedName) = createMappedName(name); |
| |
|
| | |
| | char elementType = cgd().elementType(mappedName.toConstString(0, size)); |
| |
|
| | |
| | EXPECT_EQ(elementType, 'E'); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, resetElementMapNoArgument) |
| | { |
| | |
| | cgd().resetElementMap(); |
| |
|
| | |
| | EXPECT_EQ(cgd().getElementMapSize(), 0); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, resetElementMapWithArgument) |
| | { |
| | |
| | auto elementMap = std::make_shared<Data::ElementMap>(); |
| | auto mappedName = Data::MappedName("TestMappedName"); |
| | auto indexedName = Data::IndexedName("EDGE", 1); |
| | elementMap->setElementName(indexedName, mappedName, 0); |
| |
|
| | |
| | cgd().resetElementMap(elementMap); |
| |
|
| | |
| | EXPECT_EQ(cgd().getElementMapSize(), 1); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, setAndGetElementMap) |
| | { |
| | |
| | auto elementMap = std::make_shared<Data::ElementMap>(); |
| | cgd().resetElementMap(elementMap); |
| | std::vector<Data::MappedElement> vecMappedElements; |
| | auto mappedNameA = Data::MappedName("TestMappedNameA"); |
| | auto indexedNameA = Data::IndexedName("EDGE", 1); |
| | vecMappedElements.emplace_back(indexedNameA, mappedNameA); |
| | auto mappedNameB = Data::MappedName("TestMappedNameB"); |
| | auto indexedNameB = Data::IndexedName("EDGE", 2); |
| | vecMappedElements.emplace_back(indexedNameB, mappedNameB); |
| |
|
| | |
| | auto emptyElementMap = cgd().getElementMap(); |
| | cgd().setElementMap(vecMappedElements); |
| | auto resultingElementMap = cgd().getElementMap(); |
| |
|
| | |
| | EXPECT_TRUE(emptyElementMap.empty()); |
| | EXPECT_EQ(resultingElementMap.size(), vecMappedElements.size()); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, getElementMapSize) |
| | { |
| | |
| | auto elementMap = std::make_shared<Data::ElementMap>(); |
| | auto mappedName = Data::MappedName("TestMappedName"); |
| | auto indexedName = Data::IndexedName("EDGE", 1); |
| | elementMap->setElementName(indexedName, mappedName, 0); |
| | cgd().resetElementMap(elementMap); |
| |
|
| | |
| | auto result = cgd().getElementMapSize(); |
| |
|
| | |
| | EXPECT_EQ(result, 1); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, flushElementMap) |
| | { |
| | |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, saveWithNoElementMap) |
| | { |
| | |
| | Base::StringWriter writer; |
| | cgd().resetElementMap(); |
| |
|
| | |
| | cgd().Save(writer); |
| |
|
| | |
| | EXPECT_TRUE(writer.getString().find("<ElementMap/>") != std::string::npos); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, saveWithElementMap) |
| | { |
| | |
| | Base::StringWriter writer; |
| | auto map = createMappedName("SomeElement"); |
| |
|
| | |
| | cgd().Save(writer); |
| |
|
| | |
| | EXPECT_TRUE(writer.getString().find("<ElementMap ") != std::string::npos); |
| | EXPECT_TRUE(writer.getString().find("<ElementMap2 ") != std::string::npos); |
| | EXPECT_TRUE(writer.getString().find(" file=") == std::string::npos); |
| | |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, saveWithPersistenceFilename) |
| | { |
| | |
| | Base::StringWriter writer; |
| | auto map = createMappedName("SomeElement"); |
| | cgd().setPersistenceFileName("some_file_name.txt"); |
| |
|
| | |
| | cgd().Save(writer); |
| |
|
| | |
| | EXPECT_TRUE(writer.getString().find(" file=") != std::string::npos); |
| | EXPECT_TRUE(writer.getString().find("some_file_name.txt") != std::string::npos); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, saveDocFileWithNoElementMap) |
| | { |
| | |
| | Base::StringWriter writer; |
| | cgd().resetElementMap(nullptr); |
| |
|
| | |
| | cgd().SaveDocFile(writer); |
| |
|
| | |
| | EXPECT_TRUE(writer.getString().find("BeginElementMap") == std::string::npos); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, saveDocFileWithElementMap) |
| | { |
| | |
| | Base::StringWriter writer; |
| | auto map = createMappedName("SomeElement"); |
| |
|
| | |
| | cgd().SaveDocFile(writer); |
| |
|
| | |
| | EXPECT_TRUE(writer.getString().find("BeginElementMap v1") != std::string::npos); |
| | } |
| |
|
| | TEST_F(ComplexGeoDataTest, restoreStream) |
| | {} |
| |
|
| | TEST_F(ComplexGeoDataTest, traceElement) |
| | { |
| | Data::MappedName mappedName; |
| | Data::IndexedName indexedName; |
| | std::string name(Data::ELEMENT_MAP_PREFIX); |
| | name.append("TestMappedElement:;"); |
| | std::tie(indexedName, mappedName) = createMappedName(name); |
| |
|
| | |
| | Data::TraceCallback cb = |
| | [name](const Data::MappedName& elementname, int offset, long encodedTag, long tag) { |
| | boost::ignore_unused(offset); |
| | boost::ignore_unused(encodedTag); |
| | boost::ignore_unused(tag); |
| | EXPECT_STREQ(elementname.toString().c_str(), name.substr(1).c_str()); |
| | return false; |
| | }; |
| | |
| | cgd().traceElement(mappedName, cb); |
| | } |
| |
|
| | |
| |
|