Skip to content

Commit 6cc4718

Browse files
authored
fix document path (#450)
1 parent 8f6ce6f commit 6cc4718

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

src/odr/document_element.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,8 @@ template <typename T> class TypedElement : public Element {
235235
: Element(document, element), m_element{element} {}
236236
TypedElement(const internal::abstract::Document *document,
237237
internal::abstract::Element *element)
238-
: Element(document, element), m_element{dynamic_cast<T *>(element)} {}
239-
240-
bool operator==(const TypedElement &rhs) const {
241-
return m_element == rhs.m_element;
242-
}
243-
bool operator!=(const TypedElement &rhs) const {
244-
return m_element != rhs.m_element;
245-
}
238+
: Element(document, dynamic_cast<T *>(element)),
239+
m_element{dynamic_cast<T *>(element)} {}
246240

247241
protected:
248242
T *m_element;

test/src/document_test.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,30 @@ TEST(Document, odt) {
3333
EXPECT_EQ(Measure("0.7874in"), page_layout.margin.top);
3434
}
3535

36+
TEST(Document, odt_element_path) {
37+
const auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
38+
39+
const DocumentFile document_file(
40+
TestData::test_file_path("odr-public/odt/about.odt"), *logger);
41+
42+
EXPECT_EQ(document_file.file_type(), FileType::opendocument_text);
43+
44+
const Document document = document_file.document();
45+
46+
EXPECT_EQ(document.document_type(), DocumentType::text);
47+
48+
const auto root = document.root_element();
49+
const auto p1 = root.first_child();
50+
EXPECT_EQ(p1.type(), ElementType::paragraph);
51+
const auto t1 = p1.first_child();
52+
EXPECT_EQ(t1.type(), ElementType::text);
53+
54+
const DocumentPath t1_path = DocumentPath::extract(t1, root);
55+
EXPECT_EQ(t1_path.to_string(), "/child:0/child:0");
56+
const Element t1_via_path = DocumentPath::find(root, t1_path);
57+
EXPECT_EQ(t1_via_path, t1);
58+
}
59+
3660
TEST(Document, odg) {
3761
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
3862

0 commit comments

Comments
 (0)