android: Update app-specific/MIME type icons
[LibreOffice.git] / writerfilter / qa / cppunittests / dmapper / DomainMapperTableHandler.cxx
blob6d732ec5edc14a5ade0849edfc87f40e3868643d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <test/unoapi_test.hxx>
12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/table/BorderLine2.hpp>
14 #include <com/sun/star/text/XTextTable.hpp>
15 #include <com/sun/star/text/XTextTablesSupplier.hpp>
16 #include <com/sun/star/text/XTextFramesSupplier.hpp>
17 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
18 #include <com/sun/star/text/XTextDocument.hpp>
19 #include <com/sun/star/style/BreakType.hpp>
20 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
21 #include <com/sun/star/text/XPageCursor.hpp>
23 using namespace ::com::sun::star;
25 namespace
27 /// Tests for writerfilter/source/dmapper/DomainMapperTableHandler.cxx.
28 class Test : public UnoApiTest
30 public:
31 Test()
32 : UnoApiTest("/writerfilter/qa/cppunittests/dmapper/data/")
37 CPPUNIT_TEST_FIXTURE(Test, test1cellInsidevRightborder)
39 loadFromURL(u"1cell-insidev-rightborder.docx");
40 uno::Reference<text::XTextTablesSupplier> xTextDocument(mxComponent, uno::UNO_QUERY);
41 uno::Reference<container::XIndexAccess> xTables(xTextDocument->getTextTables(), uno::UNO_QUERY);
42 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
43 uno::Reference<beans::XPropertySet> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
44 table::BorderLine2 aBorder;
45 xCell->getPropertyValue("RightBorder") >>= aBorder;
46 // Without the accompanying fix in place, this test would have failed with:
47 // - Expected: 0
48 // - Actual : 18
49 // i.e. the request to have no table-level right border was lost on import.
50 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0), aBorder.LineWidth);
53 CPPUNIT_TEST_FIXTURE(Test, testNestedFloatingTable)
55 loadFromURL(u"nested-floating-table.docx");
56 // Normal outer table, floating inner tables.
57 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
58 uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(),
59 uno::UNO_QUERY);
60 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xIndexAccess->getCount());
63 CPPUNIT_TEST_FIXTURE(Test, testFloatingTableBreakBefore)
65 // Given a 3 pages document: page break, then a multi-page floating table on pages 2 and 3:
66 // When laying out that document:
67 loadFromURL(u"floattable-break-before.docx");
69 // Then make sure the page break property is on the anchor of the floating table, otherwise it
70 // has no effect:
71 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
72 uno::Reference<container::XEnumerationAccess> xText(xTextDocument->getText(), uno::UNO_QUERY);
73 uno::Reference<container::XEnumeration> xParagraphs = xText->createEnumeration();
74 xParagraphs->nextElement();
75 xParagraphs->nextElement();
76 uno::Reference<beans::XPropertySet> xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY);
77 style::BreakType eBreakType{};
78 xParagraph->getPropertyValue("BreakType") >>= eBreakType;
79 // Without the accompanying fix in place, this test would have failed with:
80 // - Expected: 4 (style::BreakType_PAGE_BEFORE)
81 // - Actual : 0 (style::BreakType_NONE)
82 // i.e. the page break was lost.
83 CPPUNIT_ASSERT_EQUAL(style::BreakType_PAGE_BEFORE, eBreakType);
86 CPPUNIT_TEST_FIXTURE(Test, test3NestedFloatingTables)
88 // Given a document with nested tables: outer and inner one is normal, middle one is floating:
89 // When laying out that document:
90 loadFromURL(u"floattable-nested-3tables.docx");
92 // Then make sure we don't crash and create the 3 tables:
93 // Without the accompanying fix in place, this would have crashed, layout can't handle nested
94 // floating tables currently.
95 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
96 uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(),
97 uno::UNO_QUERY);
98 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xIndexAccess->getCount());
101 CPPUNIT_TEST_FIXTURE(Test, testFloatingTablesOuterNonsplitInner)
103 // Given a document with a normal table, 3 outer floating tables and an inner floating table in
104 // the last floating table:
105 loadFromURL(u"floattable-outer-nonsplit-inner.docx");
107 // When counting the floating tables in the document:
108 uno::Reference<text::XTextFramesSupplier> xFramesSupplier(mxComponent, uno::UNO_QUERY);
109 uno::Reference<container::XIndexAccess> xFrames(xFramesSupplier->getTextFrames(),
110 uno::UNO_QUERY);
112 // Then make sure no floating tables are missing:
113 // Without the accompanying fix in place, this test would have failed with:
114 // - Expected: 4
115 // - Actual : 3
116 // i.e. the inner floating table was not floating.
117 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), xFrames->getCount());
120 CPPUNIT_TEST_FIXTURE(Test, testDOCXFloatingTableHiddenAnchor)
122 // Given a document with a floating table, anchored in a paragraph that is hidden:
123 loadFromURL(u"floattable-hidden-anchor.docx");
125 // When checking the visibility of the the anchor paragraph:
126 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
127 uno::Reference<container::XEnumerationAccess> xText(xTextDocument->getText(), uno::UNO_QUERY);
128 uno::Reference<container::XEnumeration> xParagraphs = xText->createEnumeration();
129 uno::Reference<beans::XPropertySet> xAnchor(xParagraphs->nextElement(), uno::UNO_QUERY);
131 // Then make sure the anchor (and thus the table) is visible:
132 bool bCharHidden{};
133 CPPUNIT_ASSERT(xAnchor->getPropertyValue("CharHidden") >>= bCharHidden);
134 // Without the accompanying fix in place, this test would have failed, the paragraph + table was
135 // hidden.
136 CPPUNIT_ASSERT(!bCharHidden);
139 CPPUNIT_TEST_FIXTURE(Test, testDOCXFloatingTableNested)
141 // Given a document with nested, multi-page floating tables:
142 // When loading that document:
143 loadFromURL(u"floattable-nested.docx");
145 // Then make sure that both floating tables are allowed to split:
146 uno::Reference<text::XTextFramesSupplier> xFramesSupplier(mxComponent, uno::UNO_QUERY);
147 uno::Reference<container::XIndexAccess> xFrames(xFramesSupplier->getTextFrames(),
148 uno::UNO_QUERY);
149 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xFrames->getCount());
150 // Outer frame:
151 uno::Reference<beans::XPropertySet> xFrame1;
152 xFrames->getByIndex(0) >>= xFrame1;
153 bool bIsSplitAllowed = false;
154 xFrame1->getPropertyValue("IsSplitAllowed") >>= bIsSplitAllowed;
155 CPPUNIT_ASSERT(bIsSplitAllowed);
156 // Inner frame:
157 uno::Reference<beans::XPropertySet> xFrame2;
158 xFrames->getByIndex(1) >>= xFrame2;
159 bIsSplitAllowed = false;
160 xFrame2->getPropertyValue("IsSplitAllowed") >>= bIsSplitAllowed;
161 // Without the accompanying fix in place, this test would have failed, the inner frame could not
162 // split.
163 CPPUNIT_ASSERT(bIsSplitAllowed);
166 CPPUNIT_TEST_FIXTURE(Test, testDOCXFloatingTableHeader)
168 // Given a document with a header that has a floating table and some large images in the body
169 // text:
170 loadFromURL(u"floattable-header.docx");
172 // When breaking that document into pages:
173 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
174 uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(
175 xModel->getCurrentController(), uno::UNO_QUERY);
176 uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(),
177 uno::UNO_QUERY);
178 xCursor->jumpToLastPage();
180 // Then make sure we get 2 pages:
181 sal_Int32 nLastPage = xCursor->getPage();
182 // Without the accompanying fix in place, this test would have failed, the page count went to
183 // 2233 pages and then there was a layout loop.
184 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), nLastPage);
188 CPPUNIT_PLUGIN_IMPLEMENT();
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */