1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <swmodeltestbase.hxx>
12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/container/XIndexAccess.hpp>
14 #include <com/sun/star/style/ParagraphAdjust.hpp>
15 #include <com/sun/star/text/HoriOrientation.hpp>
16 #include <com/sun/star/text/WritingMode2.hpp>
17 #include <com/sun/star/text/XDependentTextField.hpp>
18 #include <com/sun/star/text/XTextTable.hpp>
19 #include <com/sun/star/text/XTextTablesSupplier.hpp>
20 #include <com/sun/star/text/XFootnote.hpp>
21 #include <com/sun/star/drawing/XControlShape.hpp>
22 #include <com/sun/star/text/VertOrientation.hpp>
23 #include <com/sun/star/text/WrapTextMode.hpp>
24 #include <com/sun/star/text/TextContentAnchorType.hpp>
25 #include <com/sun/star/text/XFootnotesSupplier.hpp>
26 #include <com/sun/star/text/XEndnotesSupplier.hpp>
28 #include <svx/svdpage.hxx>
29 #include <o3tl/string_view.hxx>
31 #include <ftninfo.hxx>
32 #include <drawdoc.hxx>
33 #include <IDocumentDrawModelAccess.hxx>
35 #include <unotxdoc.hxx>
36 #include <IDocumentLayoutAccess.hxx>
37 #include <rootfrm.hxx>
38 #include <pagefrm.hxx>
39 #include <sortedobjs.hxx>
41 #include <anchoredobject.hxx>
43 #include <flyfrms.hxx>
45 class Test
: public SwModelTestBase
48 Test() : SwModelTestBase(u
"/sw/qa/extras/ww8export/data/"_ustr
, u
"MS Word 97"_ustr
) {}
51 DECLARE_WW8EXPORT_TEST(testTdf99120
, "tdf99120.doc")
53 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
54 assertXPathContent(pXmlDoc
, "/root/page[1]/header/txt/text()", u
"Section 1, odd.");
55 assertXPathContent(pXmlDoc
, "/root/page[2]/header/txt/text()", u
"Section 1, even.");
56 // This failed: the header was empty on the 3rd page, as the first page header was shown.
57 assertXPathContent(pXmlDoc
, "/root/page[3]/header/txt/text()", u
"Section 2, odd.");
58 assertXPathContent(pXmlDoc
, "/root/page[4]/header/txt/text()", u
"Section 2, even.");
61 CPPUNIT_TEST_FIXTURE(Test
, testTdf41542_borderlessPadding
)
63 loadAndReload("tdf41542_borderlessPadding.odt");
64 // the page style's borderless padding should force this to 3 pages, not 1
65 CPPUNIT_ASSERT_EQUAL( 3, getPages() );
68 DECLARE_WW8EXPORT_TEST(testTdf60378_mergedBorders
, "tdf60378_mergedBorders.doc")
70 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
71 uno::Reference
<container::XIndexAccess
> xTables(xTextTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
72 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
74 // The border width was zero
75 table::BorderLine2 aBorder
= getProperty
<table::BorderLine2
>(xTable
->getCellByName(u
"B2"_ustr
), u
"RightBorder"_ustr
);
76 CPPUNIT_ASSERT(aBorder
.LineWidth
> 0);
79 DECLARE_WW8EXPORT_TEST(testTdf55528_relativeTableWidth
, "tdf55528_relativeTableWidth.doc")
82 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
83 uno::Reference
<container::XIndexAccess
> xTables(xTextTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
84 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
86 CPPUNIT_ASSERT_EQUAL_MESSAGE("Table relative width percent", sal_Int16(98), getProperty
<sal_Int16
>(xTable
, u
"RelativeWidth"_ustr
));
89 CPPUNIT_TEST_FIXTURE(Test
, testTdf128700_relativeTableWidth
)
91 auto verify
= [this]() {
92 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
93 uno::Reference
<container::XIndexAccess
> xTables(xTextTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
94 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
96 // Since the table has been converted into a floating frame, the relative width either needed to be transferred
97 // onto the frame, or else just thrown out. Otherwise it becomes relative to the size of the frame.
98 CPPUNIT_ASSERT_EQUAL_MESSAGE("Floated table can't use relative width", sal_Int16(0), getProperty
<sal_Int16
>(xTable
, u
"RelativeWidth"_ustr
));
100 // This also resulted in a layout loop when flys were allowed to split in footers.
101 createSwDoc("tdf128700_relativeTableWidth.doc");
103 saveAndReload(u
"MS Word 97"_ustr
);
107 CPPUNIT_TEST_FIXTURE(Test
, testTdf116436_tableBackground
)
109 loadAndReload("tdf116436_tableBackground.odt");
110 CPPUNIT_ASSERT_EQUAL(1, getPages());
111 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
112 uno::Reference
<container::XIndexAccess
> xTables(xTextTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
113 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
114 uno::Reference
<table::XCell
> xCell
= xTable
->getCellByName(u
"A1"_ustr
);
115 CPPUNIT_ASSERT_EQUAL(Color(0xF8DF7C), getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
116 xCell
.set(xTable
->getCellByName(u
"A6"_ustr
));
117 CPPUNIT_ASSERT_EQUAL(Color(0x81D41A), getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
118 xCell
.set(xTable
->getCellByName(u
"B6"_ustr
));
119 CPPUNIT_ASSERT_EQUAL(Color(0xFFFBCC), getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
122 DECLARE_WW8EXPORT_TEST(testTdf37153
, "tdf37153_considerWrapOnObjPos.doc")
124 CPPUNIT_ASSERT_EQUAL(text::WrapTextMode_THROUGH
, getProperty
<text::WrapTextMode
>(getShape(1), u
"Surround"_ustr
));
126 uno::Reference
<text::XTextTablesSupplier
> xTablesSupplier(mxComponent
, uno::UNO_QUERY
);
127 uno::Reference
<container::XIndexAccess
> xTables(xTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
128 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
129 CPPUNIT_ASSERT_EQUAL(text::VertOrientation::BOTTOM
, getProperty
<sal_Int16
>(xTable
->getCellByName(u
"A1"_ustr
), u
"VertOrient"_ustr
));
131 //For MSO compatibility, the image should be at the top of the cell, not at the bottom - despite VertOrientation::BOTTOM
132 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
133 sal_Int32 nFlyTop
= getXPath(pXmlDoc
, "/root/page/body/tab/row/cell[1]/txt/anchored/fly/infos/bounds", "top").toInt32();
134 CPPUNIT_ASSERT_MESSAGE("FlyTop should be 3820, not 6623", nFlyTop
< 4000);
135 sal_Int32 nTextTop
= getXPath(pXmlDoc
, "/root/page/body/tab/row/cell[2]/txt[1]/infos/bounds", "top").toInt32();
136 CPPUNIT_ASSERT_MESSAGE("TextTop should be 5388", nTextTop
> 4000);
139 DECLARE_WW8EXPORT_TEST(testTdf49102_mergedCellNumbering
, "tdf49102_mergedCellNumbering.doc")
141 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
142 assertXPath(pXmlDoc
, "/root/page/body/tab/row[4]/cell/txt/SwParaPortion/SwLineLayout/child::*[@type='PortionType::Number']", "expand", u
"2.");
145 CPPUNIT_TEST_FIXTURE(Test
, testTdf55427_footnote2endnote
)
147 auto verify
= [this](bool bIsExport
= false) {
148 uno::Reference
<beans::XPropertySet
> xPageStyle(getStyles(u
"ParagraphStyles"_ustr
)->getByName(u
"Footnote"_ustr
), uno::UNO_QUERY
);
149 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Footnote style is rose color", Color(0xFF007F), getProperty
< Color
>(xPageStyle
, u
"CharColor"_ustr
));
150 xPageStyle
.set(getStyles(u
"ParagraphStyles"_ustr
)->getByName(u
"Endnote"_ustr
), uno::UNO_QUERY
);
151 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Endnote style is cyan3 color", Color(0x2BD0D2), getProperty
< Color
>(xPageStyle
, u
"CharColor"_ustr
));
153 SwDoc
* pDoc
= getSwDoc();
154 // The footnote numbering type of ARABIC will not transfer over when those footnotes are converted to endnotes.
155 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Footnote numbering type", SVX_NUM_ARABIC
, pDoc
->GetFootnoteInfo().m_aFormat
.GetNumberingType() );
156 // The original document has a real endnote using ROMAN_LOWER numbering, so that setting MUST remain unchanged.
157 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Endnote numbering type", SVX_NUM_ROMAN_LOWER
, pDoc
->GetEndNoteInfo().m_aFormat
.GetNumberingType() );
159 uno::Reference
<text::XFootnotesSupplier
> xFootnotesSupplier(mxComponent
, uno::UNO_QUERY
);
160 uno::Reference
<container::XIndexAccess
> xFootnotes
= xFootnotesSupplier
->getFootnotes();
162 uno::Reference
<text::XEndnotesSupplier
> xEndnotesSupplier(mxComponent
, uno::UNO_QUERY
);
163 uno::Reference
<container::XIndexAccess
> xEndnotes
= xEndnotesSupplier
->getEndnotes();
164 uno::Reference
<text::XFootnote
> xEndnote
;
165 xEndnotes
->getByIndex(0) >>= xEndnote
;
166 uno::Reference
<text::XText
> xEndnoteText
;
167 xEndnotes
->getByIndex(0) >>= xEndnoteText
;
169 // ODT footnote-at-document-end's closest DOC match is an endnote, so the two imports will not exactly match by design.
172 CPPUNIT_ASSERT_EQUAL_MESSAGE( "original footnote count", sal_Int32(5), xFootnotes
->getCount() );
173 CPPUNIT_ASSERT_EQUAL_MESSAGE( "original endnote count", sal_Int32(1), xEndnotes
->getCount() );
175 uno::Reference
<text::XFootnote
> xFootnote
;
176 xFootnotes
->getByIndex(0) >>= xFootnote
;
177 CPPUNIT_ASSERT_EQUAL_MESSAGE( "original footnote's number", u
"1"_ustr
, xFootnote
->getAnchor()->getString() );
178 CPPUNIT_ASSERT_EQUAL_MESSAGE( "original endnote's number", u
"i"_ustr
, xEndnote
->getAnchor()->getString() );
180 uno::Reference
<text::XText
> xFootnoteText
;
181 xFootnotes
->getByIndex(0) >>= xFootnoteText
;
182 CPPUNIT_ASSERT_EQUAL_MESSAGE( "original footnote style", u
"Footnote"_ustr
, getProperty
<OUString
>(getParagraphOfText(1, xFootnoteText
), u
"ParaStyleName"_ustr
) );
183 CPPUNIT_ASSERT_EQUAL_MESSAGE( "original endnote style", u
"Endnote"_ustr
, getProperty
<OUString
>(getParagraphOfText(1, xEndnoteText
), u
"ParaStyleName"_ustr
) );
187 // These asserted items are major differences in the conversion from footnote to endnote, NOT necessary conditions for a proper functioning document.
188 CPPUNIT_ASSERT_EQUAL_MESSAGE( "At-Document-End footnotes were converted into endnotes", sal_Int32(0), xFootnotes
->getCount() );
189 CPPUNIT_ASSERT_EQUAL_MESSAGE( "At-Document-End footnotes became endnotes", sal_Int32(6), xEndnotes
->getCount() );
191 CPPUNIT_ASSERT_EQUAL_MESSAGE( "converted footnote's number", u
"i"_ustr
, xEndnote
->getAnchor()->getString() );
192 xEndnotes
->getByIndex(4) >>= xEndnote
;
193 CPPUNIT_ASSERT_EQUAL_MESSAGE( "original endnote's new number", u
"v"_ustr
, xEndnote
->getAnchor()->getString() );
195 CPPUNIT_ASSERT_EQUAL_MESSAGE( "retained footnote style", u
"Footnote"_ustr
, getProperty
<OUString
>(getParagraphOfText(1, xEndnoteText
), u
"ParaStyleName"_ustr
) );
196 xEndnotes
->getByIndex(4) >>= xEndnoteText
;
197 CPPUNIT_ASSERT_EQUAL_MESSAGE( "original endnote style", u
"Endnote"_ustr
, getProperty
<OUString
>(getParagraphOfText(1, xEndnoteText
), u
"ParaStyleName"_ustr
) );
202 createSwDoc("tdf55427_footnote2endnote.odt");
204 saveAndReload(mpFilter
);
205 verify(/*bIsExport*/ true);
208 DECLARE_WW8EXPORT_TEST(testTdf107931_KERN_DocEnabled_disabledDefStyle
, "testTdf107931_KERN_DocEnabled_disabledDefStyle.doc")
210 // Paragraph 3: the default style has kerning disabled
211 CPPUNIT_ASSERT(!getProperty
<bool>(getRun(getParagraph(3), 1), u
"CharAutoKerning"_ustr
));
212 // Paragraph 4: style with kerning disabled
213 CPPUNIT_ASSERT(!getProperty
<bool>(getRun(getParagraph(4), 1), u
"CharAutoKerning"_ustr
));
214 // Paragraph 5: style with kerning enabled
215 CPPUNIT_ASSERT(getProperty
<bool>(getRun(getParagraph(5), 1), u
"CharAutoKerning"_ustr
));
216 // Paragraph 6: directly applied character properties: kerning disabled
217 CPPUNIT_ASSERT(!getProperty
<bool>(getRun(getParagraph(6), 1), u
"CharAutoKerning"_ustr
));
218 // Paragraph 7: directly applied character properties: kerning enabled
219 CPPUNIT_ASSERT(getProperty
<bool>(getRun(getParagraph(7), 1), u
"CharAutoKerning"_ustr
));
222 DECLARE_WW8EXPORT_TEST(testTdf107931_KERN_enabledDefStyle
, "testTdf107931_KERN_enabledDefStyle.doc")
224 // Paragraph 3: the default style has kerning enabled
225 CPPUNIT_ASSERT(getProperty
<bool>(getRun(getParagraph(3), 1), u
"CharAutoKerning"_ustr
));
226 // Paragraph 4: style with kerning disabled
227 CPPUNIT_ASSERT(!getProperty
<bool>(getRun(getParagraph(4), 1), u
"CharAutoKerning"_ustr
));
228 // Paragraph 5: style with kerning enabled
229 CPPUNIT_ASSERT(getProperty
<bool>(getRun(getParagraph(5), 1), u
"CharAutoKerning"_ustr
));
230 // Paragraph 6: directly applied character properties: kerning disabled
231 CPPUNIT_ASSERT(!getProperty
<bool>(getRun(getParagraph(6), 1), u
"CharAutoKerning"_ustr
));
232 // Paragraph 7: directly applied character properties: kerning enabled
233 CPPUNIT_ASSERT(getProperty
<bool>(getRun(getParagraph(7), 1), u
"CharAutoKerning"_ustr
));
236 DECLARE_WW8EXPORT_TEST(testTdf89377
, "tdf89377_tableWithBreakBeforeParaStyle.doc")
238 // the paragraph style should set table's text-flow break-before-page
239 CPPUNIT_ASSERT_EQUAL( 2, getPages() );
242 DECLARE_WW8EXPORT_TEST(testTdf96277
, "tdf96277.doc")
244 // mismatch between anchoring at paragraph and ULSpacing to Page
245 CPPUNIT_ASSERT_EQUAL( 1, getPages() );
248 DECLARE_WW8EXPORT_TEST(testBnc863018b
, "bnc863018b.doc")
250 // The whitespace above the table should allow text to flow between the table anchor and the table.
251 // Since it doesn't, don't add the whitespace.
252 CPPUNIT_ASSERT_EQUAL( 1, getPages() );
255 DECLARE_WW8EXPORT_TEST(testTdf112517_maxSprms
, "tdf112517_maxSprms.doc")
257 uno::Reference
<text::XTextTablesSupplier
> xTablesSupplier(mxComponent
, uno::UNO_QUERY
);
258 uno::Reference
<container::XIndexAccess
> xTables(xTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
259 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
260 CPPUNIT_ASSERT_EQUAL( sal_Int32(28), xTable
->getRows()->getCount() );
263 CPPUNIT_TEST_FIXTURE(Test
, testTdf108448_endNote
)
265 loadAndReload("tdf108448_endNote.odt");
266 CPPUNIT_ASSERT_EQUAL(1, getPages());
267 uno::Reference
<text::XEndnotesSupplier
> xEndnotesSupplier(mxComponent
, uno::UNO_QUERY
);
268 uno::Reference
<container::XIndexAccess
> xEndnotes
= xEndnotesSupplier
->getEndnotes();
269 uno::Reference
<text::XText
> xEndnote
;
270 xEndnotes
->getByIndex(0) >>= xEndnote
;
272 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Number of paragraphs in Endnote i", 1, getParagraphs(xEndnote
) );
275 CPPUNIT_TEST_FIXTURE(Test
, testTdf106062_nonHangingFootnote
)
277 loadAndReload("tdf106062_nonHangingFootnote.odt");
278 CPPUNIT_ASSERT_EQUAL(1, getPages());
279 uno::Reference
<text::XFootnotesSupplier
> xFootnotesSupplier(mxComponent
, uno::UNO_QUERY
);
280 uno::Reference
<container::XIndexAccess
> xFootnotes
= xFootnotesSupplier
->getFootnotes();
281 uno::Reference
<text::XTextRange
> xTextRange(xFootnotes
->getByIndex(0), uno::UNO_QUERY
);
282 // This failed, tab between the footnote number and the footnote content was lost on import.
283 CPPUNIT_ASSERT_MESSAGE( "Footnote starts with a tab", xTextRange
->getString().startsWith("\t") );
286 CPPUNIT_TEST_FIXTURE(Test
, testTdf116570_exportFootnote
)
288 loadAndReload("tdf116570_exportFootnote.odt");
289 CPPUNIT_ASSERT_EQUAL(1, getPages());
290 uno::Reference
<text::XFootnotesSupplier
> xFootnotesSupplier(mxComponent
, uno::UNO_QUERY
);
291 uno::Reference
<container::XIndexAccess
> xFootnotes
= xFootnotesSupplier
->getFootnotes();
292 uno::Reference
<text::XText
> xFootnoteText
;
293 xFootnotes
->getByIndex(0) >>= xFootnoteText
;
295 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Number of paragraphs in first footnote", 2, getParagraphs(xFootnoteText
) );
298 CPPUNIT_TEST_FIXTURE(Test
, testTdf80635_pageRightRTL
)
300 auto verify
= [this]() {
301 // tdf#80635 - assert horizontal position of the table.
302 uno::Reference
<drawing::XShape
> xFly
= getShape(1);
303 CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME
, getProperty
<sal_Int16
>(xFly
, u
"HoriOrientRelation"_ustr
));
304 CPPUNIT_ASSERT_EQUAL_MESSAGE("Horizontal Orientation", text::HoriOrientation::RIGHT
, getProperty
<sal_Int16
>(xFly
, u
"HoriOrient"_ustr
));
305 CPPUNIT_ASSERT_EQUAL_MESSAGE("text probably does not wrap here", 1, getPages());
307 createSwDoc("tdf80635_pageRightRTL.doc");
309 saveAndReload(u
"MS Word 97"_ustr
);
313 CPPUNIT_TEST_FIXTURE(Test
, testTdf80635_marginRTL
)
315 auto verify
= [this]() {
316 // tdf#80635 - assert the horizontal orientation of the table.
317 uno::Reference
<drawing::XShape
> xFly
= getShape(1);
318 CPPUNIT_ASSERT_EQUAL_MESSAGE("Horizontal Orientation", text::HoriOrientation::RIGHT
, getProperty
<sal_Int16
>(xFly
, u
"HoriOrient"_ustr
));
320 createSwDoc("tdf80635_marginRightRTL.doc");
322 saveAndReload(u
"MS Word 97"_ustr
);
326 CPPUNIT_TEST_FIXTURE(Test
, testTdf80635_marginLeft
)
328 auto verify
= [this]() {
329 // tdf#80635 - assert horizontal position of the table.
330 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
331 uno::Reference
<container::XIndexAccess
> xTables(xTextTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
332 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
333 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Table Indent", tools::Long(0), getProperty
<tools::Long
>(xTable
, u
"LeftMargin"_ustr
), 100);
334 uno::Reference
<drawing::XShape
> xFly
= getShape(1);
335 CPPUNIT_ASSERT_EQUAL(sal_Int32(-2958), getProperty
<sal_Int32
>(xFly
, u
"HoriOrientPosition"_ustr
));
337 createSwDoc("tdf80635_marginLeft.doc");
339 saveAndReload(u
"MS Word 97"_ustr
);
343 CPPUNIT_TEST_FIXTURE(Test
, testTdf80635_pageLeft
)
345 auto verify
= [this]() {
346 // tdf#80635 - assert horizontal orient relation of the table.
347 uno::Reference
<drawing::XShape
> xFly
= getShape(1);
348 CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME
, getProperty
<sal_Int16
>(xFly
, u
"HoriOrientRelation"_ustr
));
349 CPPUNIT_ASSERT_EQUAL(text::HoriOrientation::NONE
, getProperty
<sal_Int16
>(xFly
, u
"HoriOrient"_ustr
));
350 CPPUNIT_ASSERT_EQUAL(sal_Int32(-189), getProperty
<sal_Int32
>(xFly
, u
"HoriOrientPosition"_ustr
));
352 createSwDoc("tdf80635_pageLeft.doc");
354 saveAndReload(u
"MS Word 97"_ustr
);
358 DECLARE_WW8EXPORT_TEST(testTdf99197_defaultLTR
, "tdf99197_defaultLTR.doc")
360 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Default Paragraph style, LTR",
361 text::WritingMode2::LR_TB
, getProperty
<sal_Int16
>(getParagraph(1), u
"WritingMode"_ustr
) );
363 CPPUNIT_ASSERT_EQUAL_MESSAGE( "myDefaultStyle - no base style, LTR",
364 text::WritingMode2::LR_TB
, getProperty
<sal_Int16
>(getParagraph(2), u
"WritingMode"_ustr
) );
367 CPPUNIT_TEST_FIXTURE(Test
, testTdf107773
)
369 auto verify
= [this]() {
370 // This failed, multi-page table was imported as a non-split frame.
371 SwDoc
* pDoc
= getSwDoc();
372 SwRootFrame
* pLayout
= pDoc
->getIDocumentLayoutAccess().GetCurrentLayout();
373 auto pPage1
= dynamic_cast<SwPageFrame
*>(pLayout
->Lower());
374 CPPUNIT_ASSERT(pPage1
);
375 // pPage1 has no sorted (floating) objections.
376 CPPUNIT_ASSERT(pPage1
->GetSortedObjs());
377 const SwSortedObjs
& rPage1Objs
= *pPage1
->GetSortedObjs();
378 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPage1Objs
.size());
379 auto pPage1Fly
= dynamic_cast<SwFlyAtContentFrame
*>(rPage1Objs
[0]);
380 CPPUNIT_ASSERT(pPage1Fly
);
381 auto pTab1
= dynamic_cast<SwTabFrame
*>(pPage1Fly
->GetLower());
382 CPPUNIT_ASSERT(pTab1
);
383 // This failed, the split fly containing a table was exported back to DOC as shape+table,
384 // which can't split.
385 CPPUNIT_ASSERT(pTab1
->HasFollow());
387 // tdf#80635 - assert the horizontal orientation.
388 const SwFormatHoriOrient
& rFormatHoriOrient
= pPage1Fly
->GetFormat()->GetHoriOrient();
389 CPPUNIT_ASSERT_EQUAL(css::text::HoriOrientation::CENTER
, rFormatHoriOrient
.GetHoriOrient());
391 createSwDoc("tdf107773.doc");
393 saveAndReload(u
"MS Word 97"_ustr
);
397 DECLARE_WW8EXPORT_TEST(testTdf112074_RTLtableJustification
, "tdf112074_RTLtableJustification.doc")
399 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
400 uno::Reference
<container::XIndexAccess
> xTables(xTextTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
401 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
403 CPPUNIT_ASSERT_EQUAL_MESSAGE("Right To Left writing mode", text::WritingMode2::RL_TB
, getProperty
<sal_Int16
>(xTable
, u
"WritingMode"_ustr
));
404 CPPUNIT_ASSERT_EQUAL_MESSAGE("Horizontal Orientation", text::HoriOrientation::LEFT_AND_WIDTH
, getProperty
<sal_Int16
>(xTable
, u
"HoriOrient"_ustr
));
405 CPPUNIT_ASSERT_MESSAGE("Table Indent", getProperty
<tools::Long
>(xTable
, u
"LeftMargin"_ustr
) > 3000);
406 CPPUNIT_ASSERT_MESSAGE("Table Indent is 3750", getProperty
<tools::Long
>(xTable
, u
"LeftMargin"_ustr
) < 4000 );
407 CPPUNIT_ASSERT_EQUAL( style::ParagraphAdjust_RIGHT
, static_cast<style::ParagraphAdjust
>(getProperty
<sal_Int16
>(getParagraphOrTable(2), u
"ParaAdjust"_ustr
)) );
410 DECLARE_WW8EXPORT_TEST(testTdf98620_rtlJustify
, "tdf98620_rtlJustify.doc")
412 CPPUNIT_ASSERT_EQUAL( style::ParagraphAdjust_RIGHT
, static_cast<style::ParagraphAdjust
>(getProperty
<sal_Int16
>(getParagraph(1), u
"ParaAdjust"_ustr
)) );
413 CPPUNIT_ASSERT_EQUAL_MESSAGE("Right To Left style", text::WritingMode2::RL_TB
, getProperty
<sal_Int16
>(getParagraph(1), u
"WritingMode"_ustr
));
416 DECLARE_WW8EXPORT_TEST(testTdf121110_absJustify
, "tdf121110_absJustify.doc")
418 CPPUNIT_ASSERT_EQUAL( style::ParagraphAdjust_RIGHT
, static_cast<style::ParagraphAdjust
>(getProperty
<sal_Int16
>(getParagraph(1), u
"ParaAdjust"_ustr
)) );
419 CPPUNIT_ASSERT_EQUAL( style::ParagraphAdjust_LEFT
, static_cast<style::ParagraphAdjust
>(getProperty
<sal_Int16
>(getParagraph(3), u
"ParaAdjust"_ustr
)) );
422 CPPUNIT_TEST_FIXTURE(Test
, testTdf106174_rtlParaAlign
)
424 loadAndReload("tdf106174_rtlParaAlign.docx");
425 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_CENTER
), getProperty
<sal_Int16
>(getParagraph(1), u
"ParaAdjust"_ustr
));
426 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_CENTER
), getProperty
<sal_Int16
>(getParagraph(2), u
"ParaAdjust"_ustr
));
427 uno::Reference
<beans::XPropertySet
> xPropertySet(getStyles(u
"ParagraphStyles"_ustr
)->getByName(u
"Another paragraph aligned to right"_ustr
), uno::UNO_QUERY
);
428 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int16
>(xPropertySet
, u
"ParaAdjust"_ustr
));
429 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int16
>(getParagraph(3), u
"ParaAdjust"_ustr
));
430 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int16
>(getParagraph(4), u
"ParaAdjust"_ustr
));
431 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int16
>(getParagraph(5), u
"ParaAdjust"_ustr
));
432 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT
), getProperty
<sal_Int16
>(getParagraph(6), u
"ParaAdjust"_ustr
));
433 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int16
>(getParagraph(7), u
"ParaAdjust"_ustr
));
434 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int16
>(getParagraph(8), u
"ParaAdjust"_ustr
));
435 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT
), getProperty
<sal_Int16
>(getParagraph(9), u
"ParaAdjust"_ustr
));
436 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT
), getProperty
<sal_Int16
>(getParagraph(10), u
"ParaAdjust"_ustr
));
437 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int16
>(getParagraph(11), u
"ParaAdjust"_ustr
));
438 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT
), getProperty
<sal_Int16
>(getParagraph(12), u
"ParaAdjust"_ustr
));
439 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT
), getProperty
<sal_Int16
>(getParagraph(13), u
"ParaAdjust"_ustr
));
440 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int16
>(getParagraph(14), u
"ParaAdjust"_ustr
));
443 DECLARE_WW8EXPORT_TEST(testTdf119232_startEvenPage
, "tdf119232_startEvenPage.doc")
445 CPPUNIT_ASSERT_EQUAL(sal_Int16(2), getProperty
<sal_Int16
>(getParagraph(1), u
"PageNumberOffset"_ustr
));
448 DECLARE_WW8EXPORT_TEST(testTdf104805
, "tdf104805.doc")
450 // Prefix was "." instead of empty, so the second paragraph was
451 // rendered as ".1" instead of "1.".
452 // Unittest modified due to Prefix/Suffix support obsolete
453 uno::Reference
<beans::XPropertySet
> xPara(getParagraph(2), uno::UNO_QUERY
);
454 CPPUNIT_ASSERT_EQUAL(u
"1."_ustr
, getProperty
<OUString
>(xPara
, u
"ListLabelString"_ustr
));
457 DECLARE_WW8EXPORT_TEST(testTdf104334
, "tdf104334.doc")
459 // This failed with a container::NoSuchElementException: STYLEREF was
460 // mapped to SwChapterField, and the field result was "This is a Heading 1"
461 // instead of just "1".
462 CPPUNIT_ASSERT_EQUAL(u
"1"_ustr
, getRun(getParagraph(2), 4)->getString());
465 DECLARE_WW8EXPORT_TEST(testTdf108072
, "tdf108072.doc")
467 // The property IsSplitAllowed was imported from an obsolete property, sprmTFCantSplit90
468 // instead of sprmTFCantSplit. sprmTFCantSplit90 is set to true for merged rows, so
469 // for merged rows incorrect settings were imported, which prevented them from breaking over pages.
470 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
471 uno::Reference
<container::XIndexAccess
> xTables(xTextTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
472 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
473 uno::Reference
<container::XIndexAccess
> xTableRows
= xTable
->getRows();
474 CPPUNIT_ASSERT_EQUAL(true, getProperty
<bool>(xTableRows
->getByIndex(0), u
"IsSplitAllowed"_ustr
));
477 DECLARE_WW8EXPORT_TEST(testTdf123321
, "shapes-line-ellipse.doc")
479 // These are the 3 lines in which 1st and 3rd one were disappearing before
480 uno::Reference
<drawing::XShape
> l1
= getShape(7);
481 uno::Reference
<drawing::XShape
> l2
= getShape(8);
482 uno::Reference
<drawing::XShape
> l3
= getShape(9);
484 // first line (smallest)
485 // Fails without the fix: Expected: 423, Actual: 2
486 CPPUNIT_ASSERT_EQUAL(sal_Int32(423), l1
->getSize().Height
);
487 // Fails without the fix: Expected: 0, Actual: 2
488 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), l1
->getSize().Width
);
489 CPPUNIT_ASSERT_EQUAL(sal_Int32(7908), l1
->getPosition().X
);
490 CPPUNIT_ASSERT_EQUAL(sal_Int32(37), l1
->getPosition().Y
);
492 // second line (larger)
493 CPPUNIT_ASSERT_EQUAL(sal_Int32(2542), l2
->getSize().Height
);
494 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), l2
->getSize().Width
);
495 CPPUNIT_ASSERT_EQUAL(sal_Int32(7916), l2
->getPosition().X
);
496 CPPUNIT_ASSERT_EQUAL(sal_Int32(289), l2
->getPosition().Y
);
498 // third line (largest)
499 // Fails without the fix: Expected: 7027, Actual: 2
500 CPPUNIT_ASSERT_EQUAL(sal_Int32(7027), l3
->getSize().Height
);
501 // Fails without the fix: Expected: 0, Actual: 2
502 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), l3
->getSize().Width
);
503 CPPUNIT_ASSERT_EQUAL(sal_Int32(7911), l3
->getPosition().X
);
504 CPPUNIT_ASSERT_EQUAL(sal_Int32(231), l3
->getPosition().Y
);
507 DECLARE_WW8EXPORT_TEST(testTdf91687
, "tdf91687.doc")
509 // Exported Watermarks were resized
510 uno::Reference
<drawing::XShape
> xWatermark
= getShape(1);
512 CPPUNIT_ASSERT_EQUAL(sal_Int32(5172), xWatermark
->getSize().Height
);
513 CPPUNIT_ASSERT_EQUAL(sal_Int32(18105), xWatermark
->getSize().Width
);
516 DECLARE_WW8EXPORT_TEST(testTdf114308
, "tdf114308.doc")
518 // Watermark with no additional padding
519 uno::Reference
<drawing::XShape
> xWatermark
= getShape(1);
521 CPPUNIT_ASSERT_EQUAL(sal_Int32(8729), xWatermark
->getSize().Height
);
524 DECLARE_WW8EXPORT_TEST(testTdf111480
, "tdf111480.doc")
526 // Circular text was imported horizontally
527 uno::Reference
<drawing::XShape
> xText
= getShape(1);
529 CPPUNIT_ASSERT(xText
->getSize().Height
> 11000);
530 CPPUNIT_ASSERT(xText
->getSize().Width
> 11000);
533 CPPUNIT_TEST_FIXTURE(Test
, testTdf70838
)
535 loadAndReload("tdf70838.odt");
536 CPPUNIT_ASSERT_EQUAL(1, getShapes());
537 CPPUNIT_ASSERT_EQUAL(1, getPages());
538 SwDoc
* pDoc
= getSwDoc();
539 SdrPage
* pPage
= pDoc
->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
540 tools::Rectangle aRect
= pPage
->GetObj(0)->GetSnapRect();
541 CPPUNIT_ASSERT(aRect
.GetHeight() > aRect
.GetWidth());
544 CPPUNIT_TEST_FIXTURE(Test
, testTdf70838b_verticalRotation
)
546 loadAndReload("tdf70838b_verticalRotation.odt");
547 CPPUNIT_ASSERT_EQUAL(3, getShapes());
548 CPPUNIT_ASSERT_EQUAL(1, getPages());
549 SwDoc
* pDoc
= getSwDoc();
550 SdrPage
* pPage
= pDoc
->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
551 tools::Rectangle aGroupShape
= pPage
->GetObj(0)->GetSnapRect();
552 tools::Rectangle aLine
= pPage
->GetObj(2)->GetSnapRect();
554 CPPUNIT_ASSERT_MESSAGE("Smiley faces are round", aGroupShape
.GetHeight() > aGroupShape
.GetWidth());
555 CPPUNIT_ASSERT_MESSAGE("Line is taller, not wider", aLine
.GetHeight() > aLine
.GetWidth());
558 CPPUNIT_TEST_FIXTURE(Test
, testTdf129247
)
560 loadAndReload("tdf129247.docx");
561 CPPUNIT_ASSERT_EQUAL(1, getPages());
562 // Without the fix in place, the checkbox wouldn't be exported
563 CPPUNIT_ASSERT_EQUAL(1, getShapes());
566 CPPUNIT_TEST_FIXTURE(Test
, testActiveXCheckbox
)
568 loadAndReload("checkbox_control.odt");
569 CPPUNIT_ASSERT_EQUAL(2, getShapes());
570 CPPUNIT_ASSERT_EQUAL(1, getPages());
571 // First check box anchored as a floating object
572 uno::Reference
<drawing::XControlShape
> xControlShape
;
573 xControlShape
.set(getShape(2), uno::UNO_QUERY
);
574 CPPUNIT_ASSERT(xControlShape
.is());
576 // Check whether we have the right control
577 uno::Reference
<beans::XPropertySet
> xPropertySet(xControlShape
->getControl(), uno::UNO_QUERY
);
578 uno::Reference
<lang::XServiceInfo
> xServiceInfo(xPropertySet
, uno::UNO_QUERY
);
579 CPPUNIT_ASSERT_EQUAL(true, bool(xServiceInfo
->supportsService( u
"com.sun.star.form.component.CheckBox"_ustr
)));
580 CPPUNIT_ASSERT_EQUAL(u
"Floating Checkbox"_ustr
, getProperty
<OUString
>(xPropertySet
, u
"Label"_ustr
));
583 uno::Reference
<beans::XPropertySet
> xPropertySet2(xControlShape
, uno::UNO_QUERY
);
584 CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER
,getProperty
<text::TextContentAnchorType
>(xPropertySet2
,u
"AnchorType"_ustr
));
586 // Second check box anchored inline / as character
587 xControlShape
.set(getShape(1), uno::UNO_QUERY
);
589 // Check whether we have the right control
590 xPropertySet
.set(xControlShape
->getControl(), uno::UNO_QUERY
);
591 xServiceInfo
.set(xPropertySet
, uno::UNO_QUERY
);
592 CPPUNIT_ASSERT_EQUAL(true, bool(xServiceInfo
->supportsService(u
"com.sun.star.form.component.CheckBox"_ustr
)));
593 CPPUNIT_ASSERT_EQUAL(u
"Inline Checkbox"_ustr
, getProperty
<OUString
>(xPropertySet
, u
"Label"_ustr
));
596 xPropertySet2
.set(xControlShape
, uno::UNO_QUERY
);
597 CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AS_CHARACTER
,getProperty
<text::TextContentAnchorType
>(xPropertySet2
,u
"AnchorType"_ustr
));
600 DECLARE_WW8EXPORT_TEST( testTdf115896_layoutInCell
, "tdf115896_layoutInCell.doc" )
602 // Check anchor type - was anchored to page because of unknown version of Word
603 uno::Reference
<beans::XPropertySet
> xPropertySet(getShape(1), uno::UNO_QUERY_THROW
);
604 CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER
,getProperty
<text::TextContentAnchorType
>(xPropertySet
,u
"AnchorType"_ustr
));
607 DECLARE_WW8EXPORT_TEST(testTdf67207_MERGEFIELD
, "mailmerge.doc")
609 uno::Reference
<beans::XPropertySet
> xTextField
= getProperty
< uno::Reference
<beans::XPropertySet
> >(getRun(getParagraph(1), 2), u
"TextField"_ustr
);
610 CPPUNIT_ASSERT(xTextField
.is());
611 uno::Reference
<lang::XServiceInfo
> xServiceInfo(xTextField
, uno::UNO_QUERY_THROW
);
612 uno::Reference
<text::XDependentTextField
> xDependent(xTextField
, uno::UNO_QUERY_THROW
);
614 CPPUNIT_ASSERT(xServiceInfo
->supportsService(u
"com.sun.star.text.TextField.Database"_ustr
));
616 xTextField
->getPropertyValue(u
"Content"_ustr
) >>= sValue
;
617 CPPUNIT_ASSERT_EQUAL(u
"«Name»"_ustr
, sValue
);
619 uno::Reference
<beans::XPropertySet
> xFiledMaster
= xDependent
->getTextFieldMaster();
620 uno::Reference
<lang::XServiceInfo
> xFiledMasterServiceInfo(xFiledMaster
, uno::UNO_QUERY_THROW
);
622 CPPUNIT_ASSERT(xFiledMasterServiceInfo
->supportsService(u
"com.sun.star.text.fieldmaster.Database"_ustr
));
624 // Defined properties: DataBaseName, Name, DataTableName, DataColumnName, DependentTextFields, DataCommandType, InstanceName, DataBaseURL
625 CPPUNIT_ASSERT(xFiledMaster
->getPropertyValue(u
"Name"_ustr
) >>= sValue
);
626 CPPUNIT_ASSERT_EQUAL(u
"Name"_ustr
, sValue
);
627 CPPUNIT_ASSERT(xFiledMaster
->getPropertyValue(u
"DataColumnName"_ustr
) >>= sValue
);
628 CPPUNIT_ASSERT_EQUAL(u
"Name"_ustr
, sValue
);
629 CPPUNIT_ASSERT(xFiledMaster
->getPropertyValue(u
"InstanceName"_ustr
) >>= sValue
);
630 CPPUNIT_ASSERT_EQUAL(u
"com.sun.star.text.fieldmaster.DataBase.Name"_ustr
, sValue
);
633 CPPUNIT_TEST_FIXTURE(Test
, testTableCrossReference
)
635 loadAndReload("table_cross_reference.odt");
636 CPPUNIT_ASSERT_EQUAL(1, getPages());
637 // tdf#42346: Cross references to tables were not saved
638 // MSO uses simple bookmarks for referencing table caption, so we do the same by export
640 // Check whether we have all the necessary bookmarks exported and imported back
641 uno::Reference
<text::XBookmarksSupplier
> xBookmarksSupplier(mxComponent
, uno::UNO_QUERY
);
642 uno::Reference
<container::XIndexAccess
> xBookmarksByIdx(xBookmarksSupplier
->getBookmarks(), uno::UNO_QUERY
);
643 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(4), xBookmarksByIdx
->getCount());
644 uno::Reference
<container::XNameAccess
> xBookmarksByName
= xBookmarksSupplier
->getBookmarks();
645 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table0_full"_ustr
));
646 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table0_label_and_number"_ustr
));
647 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table0_caption_only"_ustr
));
648 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table0_number_only"_ustr
));
650 // Check bookmark text ranges
652 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table0_full"_ustr
), uno::UNO_QUERY
);
653 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
654 CPPUNIT_ASSERT_EQUAL(u
"Table 1: Table caption"_ustr
, xRange
->getString());
657 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table0_label_and_number"_ustr
), uno::UNO_QUERY
);
658 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
659 CPPUNIT_ASSERT_EQUAL(u
"Table 1"_ustr
, xRange
->getString());
662 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table0_caption_only"_ustr
), uno::UNO_QUERY
);
663 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
664 CPPUNIT_ASSERT_EQUAL(u
"Table caption"_ustr
, xRange
->getString());
667 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table0_number_only"_ustr
), uno::UNO_QUERY
);
668 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
669 CPPUNIT_ASSERT_EQUAL(u
"1"_ustr
, xRange
->getString());
672 // Check reference fields
673 uno::Reference
<text::XTextFieldsSupplier
> xTextFieldsSupplier(mxComponent
, uno::UNO_QUERY
);
674 uno::Reference
<container::XEnumerationAccess
> xFieldsAccess(xTextFieldsSupplier
->getTextFields());
675 uno::Reference
<container::XEnumeration
> xFields(xFieldsAccess
->createEnumeration());
676 CPPUNIT_ASSERT(xFields
->hasMoreElements());
678 sal_uInt16 nIndex
= 0;
679 while (xFields
->hasMoreElements())
681 uno::Reference
<lang::XServiceInfo
> xServiceInfo(xFields
->nextElement(), uno::UNO_QUERY
);
682 uno::Reference
<beans::XPropertySet
> xPropertySet(xServiceInfo
, uno::UNO_QUERY
);
685 // Full reference to table caption
688 CPPUNIT_ASSERT(xServiceInfo
->supportsService(u
"com.sun.star.text.TextField.GetReference"_ustr
));
691 xPropertySet
->getPropertyValue(u
"CurrentPresentation"_ustr
) >>= sValue
;
692 CPPUNIT_ASSERT_EQUAL(u
"Table 1: Table caption"_ustr
, sValue
);
693 xPropertySet
->getPropertyValue(u
"SourceName"_ustr
) >>= sValue
;
694 CPPUNIT_ASSERT_EQUAL(u
"Ref_Table0_full"_ustr
, sValue
);
695 xPropertySet
->getPropertyValue(u
"SequenceNumber"_ustr
) >>= nValue
;
696 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue
);
699 // Reference to table number
702 CPPUNIT_ASSERT(xServiceInfo
->supportsService(u
"com.sun.star.text.TextField.GetReference"_ustr
));
705 xPropertySet
->getPropertyValue(u
"CurrentPresentation"_ustr
) >>= sValue
;
706 CPPUNIT_ASSERT_EQUAL(u
"1"_ustr
, sValue
);
707 xPropertySet
->getPropertyValue(u
"SourceName"_ustr
) >>= sValue
;
708 CPPUNIT_ASSERT_EQUAL(u
"Ref_Table0_number_only"_ustr
, sValue
);
709 xPropertySet
->getPropertyValue(u
"SequenceNumber"_ustr
) >>= nValue
;
710 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue
);
713 // Reference to caption only
716 CPPUNIT_ASSERT(xServiceInfo
->supportsService(u
"com.sun.star.text.TextField.GetReference"_ustr
));
719 xPropertySet
->getPropertyValue(u
"CurrentPresentation"_ustr
) >>= sValue
;
720 CPPUNIT_ASSERT_EQUAL(u
"Table caption"_ustr
, sValue
);
721 xPropertySet
->getPropertyValue(u
"SourceName"_ustr
) >>= sValue
;
722 CPPUNIT_ASSERT_EQUAL(u
"Ref_Table0_caption_only"_ustr
, sValue
);
723 xPropertySet
->getPropertyValue(u
"SequenceNumber"_ustr
) >>= nValue
;
724 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue
);
727 // Reference to category and number
730 CPPUNIT_ASSERT(xServiceInfo
->supportsService(u
"com.sun.star.text.TextField.GetReference"_ustr
));
733 xPropertySet
->getPropertyValue(u
"CurrentPresentation"_ustr
) >>= sValue
;
734 CPPUNIT_ASSERT_EQUAL(u
"Table 1"_ustr
, sValue
);
735 xPropertySet
->getPropertyValue(u
"SourceName"_ustr
) >>= sValue
;
736 CPPUNIT_ASSERT_EQUAL(u
"Ref_Table0_label_and_number"_ustr
, sValue
);
737 xPropertySet
->getPropertyValue(u
"SequenceNumber"_ustr
) >>= nValue
;
738 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue
);
741 // Reference to page of the table
744 CPPUNIT_ASSERT(xServiceInfo
->supportsService(u
"com.sun.star.text.TextField.GetReference"_ustr
));
747 xPropertySet
->getPropertyValue(u
"CurrentPresentation"_ustr
) >>= sValue
;
748 CPPUNIT_ASSERT_EQUAL(u
"1"_ustr
, sValue
);
749 xPropertySet
->getPropertyValue(u
"SourceName"_ustr
) >>= sValue
;
750 CPPUNIT_ASSERT_EQUAL(u
"Ref_Table0_full"_ustr
, sValue
);
751 xPropertySet
->getPropertyValue(u
"SequenceNumber"_ustr
) >>= nValue
;
752 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue
);
755 // Page style reference / exported as simple page reference
758 CPPUNIT_ASSERT(xServiceInfo
->supportsService(u
"com.sun.star.text.TextField.GetReference"_ustr
));
761 xPropertySet
->getPropertyValue(u
"CurrentPresentation"_ustr
) >>= sValue
;
762 CPPUNIT_ASSERT_EQUAL(u
"1"_ustr
, sValue
);
763 xPropertySet
->getPropertyValue(u
"SourceName"_ustr
) >>= sValue
;
764 CPPUNIT_ASSERT_EQUAL(u
"Ref_Table0_full"_ustr
, sValue
);
765 xPropertySet
->getPropertyValue(u
"SequenceNumber"_ustr
) >>= nValue
;
766 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue
);
769 // Above / below reference
772 CPPUNIT_ASSERT(xServiceInfo
->supportsService(u
"com.sun.star.text.TextField.GetReference"_ustr
));
775 xPropertySet
->getPropertyValue(u
"CurrentPresentation"_ustr
) >>= sValue
;
776 CPPUNIT_ASSERT_EQUAL(u
"above"_ustr
, sValue
);
777 xPropertySet
->getPropertyValue(u
"SourceName"_ustr
) >>= sValue
;
778 CPPUNIT_ASSERT_EQUAL(u
"Ref_Table0_full"_ustr
, sValue
);
779 xPropertySet
->getPropertyValue(u
"SequenceNumber"_ustr
) >>= nValue
;
780 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nValue
);
788 CPPUNIT_ASSERT_EQUAL(sal_uInt16(8), nIndex
);
791 CPPUNIT_TEST_FIXTURE(Test
, testTableCrossReferenceCustomFormat
)
793 loadAndReload("table_cross_reference_custom_format.odt");
794 CPPUNIT_ASSERT_EQUAL(1, getPages());
795 // tdf#42346: Cross references to tables were not saved
796 // Check also captions with custom formatting
798 // Check whether we have all the necessary bookmarks exported and imported back
799 uno::Reference
<text::XBookmarksSupplier
> xBookmarksSupplier(mxComponent
, uno::UNO_QUERY
);
800 uno::Reference
<container::XIndexAccess
> xBookmarksByIdx(xBookmarksSupplier
->getBookmarks(), uno::UNO_QUERY
);
801 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(16), xBookmarksByIdx
->getCount());
802 uno::Reference
<container::XNameAccess
> xBookmarksByName
= xBookmarksSupplier
->getBookmarks();
803 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table0_full"_ustr
));
804 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table0_label_and_number"_ustr
));
805 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table0_caption_only"_ustr
));
806 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table0_number_only"_ustr
));
807 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table1_full"_ustr
));
808 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table1_label_and_number"_ustr
));
809 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table1_caption_only"_ustr
));
810 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table1_number_only"_ustr
));
811 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table2_full"_ustr
));
812 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table2_label_and_number"_ustr
));
813 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table2_caption_only"_ustr
));
814 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table2_number_only"_ustr
));
815 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table3_full"_ustr
));
816 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table3_label_and_number"_ustr
));
817 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table3_caption_only"_ustr
));
818 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Table3_number_only"_ustr
));
820 // Check bookmark text ranges
821 // First table's caption
823 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table0_full"_ustr
), uno::UNO_QUERY
);
824 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
825 CPPUNIT_ASSERT_EQUAL(u
"1. Table: Table caption"_ustr
, xRange
->getString());
828 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table0_label_and_number"_ustr
), uno::UNO_QUERY
);
829 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
830 CPPUNIT_ASSERT_EQUAL(u
"1. Table"_ustr
, xRange
->getString());
833 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table0_caption_only"_ustr
), uno::UNO_QUERY
);
834 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
835 CPPUNIT_ASSERT_EQUAL(u
"Table caption"_ustr
, xRange
->getString());
838 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table0_number_only"_ustr
), uno::UNO_QUERY
);
839 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
840 CPPUNIT_ASSERT_EQUAL(u
"1"_ustr
, xRange
->getString());
842 // Second table's caption
844 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table1_full"_ustr
), uno::UNO_QUERY
);
845 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
846 CPPUNIT_ASSERT_EQUAL(u
"2. TableTable caption"_ustr
, xRange
->getString());
849 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table1_label_and_number"_ustr
), uno::UNO_QUERY
);
850 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
851 CPPUNIT_ASSERT_EQUAL(u
"2. Table"_ustr
, xRange
->getString());
854 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table1_caption_only"_ustr
), uno::UNO_QUERY
);
855 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
856 CPPUNIT_ASSERT_EQUAL(u
"Table caption"_ustr
, xRange
->getString());
859 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table1_number_only"_ustr
), uno::UNO_QUERY
);
860 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
861 CPPUNIT_ASSERT_EQUAL(u
"2"_ustr
, xRange
->getString());
863 // Third table's caption
865 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table2_full"_ustr
), uno::UNO_QUERY
);
866 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
867 CPPUNIT_ASSERT_EQUAL(u
"3) Table Table caption"_ustr
, xRange
->getString());
870 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table2_label_and_number"_ustr
), uno::UNO_QUERY
);
871 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
872 CPPUNIT_ASSERT_EQUAL(u
"3) Table"_ustr
, xRange
->getString());
875 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table2_caption_only"_ustr
), uno::UNO_QUERY
);
876 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
877 CPPUNIT_ASSERT_EQUAL(u
"Table caption"_ustr
, xRange
->getString());
880 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table2_number_only"_ustr
), uno::UNO_QUERY
);
881 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
882 CPPUNIT_ASSERT_EQUAL(u
"3"_ustr
, xRange
->getString());
884 // Fourth table's caption
886 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table3_full"_ustr
), uno::UNO_QUERY
);
887 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
888 CPPUNIT_ASSERT_EQUAL(u
"Table 4- Table caption"_ustr
, xRange
->getString());
891 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table3_label_and_number"_ustr
), uno::UNO_QUERY
);
892 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
893 CPPUNIT_ASSERT_EQUAL(u
"Table 4"_ustr
, xRange
->getString());
896 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table3_caption_only"_ustr
), uno::UNO_QUERY
);
897 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
898 CPPUNIT_ASSERT_EQUAL(u
"Table caption"_ustr
, xRange
->getString());
901 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Table3_number_only"_ustr
), uno::UNO_QUERY
);
902 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
903 CPPUNIT_ASSERT_EQUAL(u
"4"_ustr
, xRange
->getString());
907 CPPUNIT_TEST_FIXTURE(Test
, testObjectCrossReference
)
909 loadAndReload("object_cross_reference.odt");
910 CPPUNIT_ASSERT_EQUAL(2, getPages());
911 // tdf#42346: Cross references to objects were not saved
912 // MSO uses simple bookmarks for referencing table caption, so we do the same by export
914 // Check whether we have all the necessary bookmarks exported and imported back
915 uno::Reference
<text::XBookmarksSupplier
> xBookmarksSupplier(mxComponent
, uno::UNO_QUERY
);
916 uno::Reference
<container::XIndexAccess
> xBookmarksByIdx(xBookmarksSupplier
->getBookmarks(), uno::UNO_QUERY
);
917 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(15), xBookmarksByIdx
->getCount());
918 uno::Reference
<container::XNameAccess
> xBookmarksByName
= xBookmarksSupplier
->getBookmarks();
919 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Drawing0_full"_ustr
));
920 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Drawing0_label_and_number"_ustr
));
921 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Drawing0_caption_only"_ustr
));
922 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Drawing0_number_only"_ustr
));
923 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Drawing1_full"_ustr
));
925 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Illustration0_full"_ustr
));
926 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Illustration0_label_and_number"_ustr
));
927 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Illustration0_caption_only"_ustr
));
928 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Illustration0_number_only"_ustr
));
929 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Illustration1_caption_only"_ustr
));
931 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Text0_full"_ustr
));
932 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Text0_label_and_number"_ustr
));
933 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Text0_caption_only"_ustr
));
934 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Text0_number_only"_ustr
));
935 CPPUNIT_ASSERT(xBookmarksByName
->hasByName(u
"Ref_Text1_label_and_number"_ustr
));
937 // Check bookmark text ranges
938 // Cross references to shapes
940 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Drawing0_full"_ustr
), uno::UNO_QUERY
);
941 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
942 CPPUNIT_ASSERT_EQUAL(u
"Drawing 1: A rectangle"_ustr
, xRange
->getString());
945 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Drawing0_label_and_number"_ustr
), uno::UNO_QUERY
);
946 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
947 CPPUNIT_ASSERT_EQUAL(u
"Drawing 1"_ustr
, xRange
->getString());
950 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Drawing0_caption_only"_ustr
), uno::UNO_QUERY
);
951 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
952 CPPUNIT_ASSERT_EQUAL(u
"A rectangle"_ustr
, xRange
->getString());
955 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Drawing0_number_only"_ustr
), uno::UNO_QUERY
);
956 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
957 CPPUNIT_ASSERT_EQUAL(u
"1"_ustr
, xRange
->getString());
960 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Drawing1_full"_ustr
), uno::UNO_QUERY
);
961 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
962 CPPUNIT_ASSERT_EQUAL(u
"Drawing 2: a circle"_ustr
, xRange
->getString());
965 // Cross references to pictures
967 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Illustration0_full"_ustr
), uno::UNO_QUERY
);
968 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
969 CPPUNIT_ASSERT_EQUAL(u
"Illustration 1: A picture"_ustr
, xRange
->getString());
972 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Illustration0_label_and_number"_ustr
), uno::UNO_QUERY
);
973 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
974 CPPUNIT_ASSERT_EQUAL(u
"Illustration 1"_ustr
, xRange
->getString());
977 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Illustration0_caption_only"_ustr
), uno::UNO_QUERY
);
978 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
979 CPPUNIT_ASSERT_EQUAL(u
"A picture"_ustr
, xRange
->getString());
982 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Illustration0_number_only"_ustr
), uno::UNO_QUERY
);
983 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
984 CPPUNIT_ASSERT_EQUAL(u
"1"_ustr
, xRange
->getString());
987 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Illustration1_caption_only"_ustr
), uno::UNO_QUERY
);
988 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
989 CPPUNIT_ASSERT_EQUAL(u
"another image"_ustr
, xRange
->getString());
992 // Cross references to text frames
994 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Text0_full"_ustr
), uno::UNO_QUERY
);
995 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
996 CPPUNIT_ASSERT_EQUAL(u
"Text 1: A frame"_ustr
, xRange
->getString());
999 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Text0_label_and_number"_ustr
), uno::UNO_QUERY
);
1000 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
1001 CPPUNIT_ASSERT_EQUAL(u
"Text 1"_ustr
, xRange
->getString());
1004 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Text0_caption_only"_ustr
), uno::UNO_QUERY
);
1005 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
1006 CPPUNIT_ASSERT_EQUAL(u
"A frame"_ustr
, xRange
->getString());
1009 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Text0_number_only"_ustr
), uno::UNO_QUERY
);
1010 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
1011 CPPUNIT_ASSERT_EQUAL(u
"1"_ustr
, xRange
->getString());
1014 uno::Reference
<text::XTextContent
> xContent(xBookmarksByName
->getByName(u
"Ref_Text1_label_and_number"_ustr
), uno::UNO_QUERY
);
1015 uno::Reference
<text::XTextRange
> xRange
= xContent
->getAnchor();
1016 CPPUNIT_ASSERT_EQUAL(u
"Text 2"_ustr
, xRange
->getString());
1020 DECLARE_WW8EXPORT_TEST(testTdf112118_DOC
, "tdf112118.doc")
1022 static const struct {
1023 const char* styleName
;
1025 const char* sideName
;
1027 sal_Int32 nBorderDistance
;
1028 sal_Int32 nBorderWidth
;
1030 } styleParams
[] = { // Margin (MS-style), border distance, border width
1034 { "Top", 496, 847, 159 }, // 851 twip, 24 pt (from text), 4.5 pt
1035 { "Left", 2083, 706, 212 }, // 1701 twip, 20 pt (from text), 6.0 pt
1036 { "Bottom", 1401, 564, 35 }, // 1134 twip, 16 pt (from text), 1.0 pt
1037 { "Right", 3471, 423, 106 } // 2268 twip, 12 pt (from text), 3.0 pt
1043 { "Top", 847, 496, 159 }, // 851 twip, 24 pt (from edge), 4.5 pt
1044 { "Left", 706, 2083, 212 }, // 1701 twip, 20 pt (from edge), 6.0 pt
1045 { "Bottom", 564, 1401, 35 }, // 1134 twip, 16 pt (from edge), 1.0 pt
1046 { "Right", 423, 3471, 106 } // 2268 twip, 12 pt (from edge), 3.0 pt
1050 auto xStyles
= getStyles(u
"PageStyles"_ustr
);
1052 for (const auto& style
: styleParams
)
1054 const OUString sName
= OUString::createFromAscii(style
.styleName
);
1055 uno::Reference
<beans::XPropertySet
> xStyle(xStyles
->getByName(sName
), uno::UNO_QUERY_THROW
);
1056 for (const auto& side
: style
.sideParams
)
1058 const OUString sSide
= OUString::createFromAscii(side
.sideName
);
1059 const OString sStage
= style
.styleName
+ OString::Concat(" ") + side
.sideName
;
1061 sal_Int32 nMargin
= getProperty
<sal_Int32
>(xStyle
, sSide
+ "Margin");
1062 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage
+ " margin width").getStr(),
1063 side
.nMargin
, nMargin
);
1065 sal_Int32 nBorderDistance
= getProperty
<sal_Int32
>(xStyle
, sSide
+ "BorderDistance");
1066 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage
+ " border distance").getStr(),
1067 side
.nBorderDistance
, nBorderDistance
);
1069 table::BorderLine aBorder
= getProperty
<table::BorderLine
>(xStyle
, sSide
+ "Border");
1070 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage
+ " border width").getStr(),
1072 sal_Int32(aBorder
.OuterLineWidth
+ aBorder
.InnerLineWidth
+ aBorder
.LineDistance
));
1074 // Check that AUTO border color is imported as black
1075 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage
+ " border color").getStr(),
1076 sal_Int32(COL_BLACK
), aBorder
.Color
);
1081 CPPUNIT_TEST_FIXTURE(Test
, testTdf117503
)
1083 loadAndReload("tdf117503.docx");
1084 // This was 3, first page + standard page styles were not merged together
1086 CPPUNIT_ASSERT_EQUAL(2, getPages());
1089 DECLARE_WW8EXPORT_TEST(testTdf117885
, "tdf117885.doc")
1091 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
1093 /* Get the vertical position of the paragraph containing the text "Start" */
1094 sal_Int32 nParaA_Top
= getXPath(pXmlDoc
,
1095 "/root/page/body/column[1]/body/txt[text()='Start']/infos/bounds", "top"
1098 /* Get the vertical position of the paragraph containing the text "Top B" */
1099 sal_Int32 nParaB_Top
= getXPath(pXmlDoc
,
1100 "/root/page/body/column[2]/body/txt[text()='Top B']/infos/bounds", "top"
1103 /* These two paragraphs are supposed to be at the top of the left
1104 * and right columns respectively. Check that they actually line up: */
1105 CPPUNIT_ASSERT_EQUAL(nParaA_Top
, nParaB_Top
);
1108 CPPUNIT_TEST_FIXTURE(Test
, testTdf118133
)
1110 loadAndReload("tdf118133.docx");
1111 // This was 0, doc import + doc export resulted in lost image due to broken
1112 // lazy-loading of tiff images.
1113 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(15240), getShape(1)->getSize().Width
);
1116 DECLARE_WW8EXPORT_TEST(testTdf118412
, "tdf118412.doc")
1118 /* Check that the first page's bottom margin is 1.251cm (not 2.540cm) */
1119 OUString sPageStyleName
= getProperty
<OUString
>(getParagraph(1), u
"PageStyleName"_ustr
);
1120 uno::Reference
<style::XStyle
> xPageStyle(
1121 getStyles(u
"PageStyles"_ustr
)->getByName(sPageStyleName
), uno::UNO_QUERY
);
1122 sal_Int32 nBottomMargin
= getProperty
<sal_Int32
>(xPageStyle
, u
"BottomMargin"_ustr
);
1123 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(1251), nBottomMargin
);
1126 CPPUNIT_TEST_FIXTURE(Test
, testContentControlExport
)
1128 // Given a document with a (rich text) content control:
1130 uno::Reference
<lang::XMultiServiceFactory
> xMSF(mxComponent
, uno::UNO_QUERY
);
1131 uno::Reference
<text::XTextDocument
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
1132 uno::Reference
<text::XText
> xText
= xTextDocument
->getText();
1133 uno::Reference
<text::XTextCursor
> xCursor
= xText
->createTextCursor();
1134 xText
->insertString(xCursor
, u
"test"_ustr
, /*bAbsorb=*/false);
1135 xCursor
->gotoStart(/*bExpand=*/false);
1136 xCursor
->gotoEnd(/*bExpand=*/true);
1137 uno::Reference
<text::XTextContent
> xContentControl(
1138 xMSF
->createInstance(u
"com.sun.star.text.ContentControl"_ustr
), uno::UNO_QUERY
);
1139 xText
->insertTextContent(xCursor
, xContentControl
, /*bAbsorb=*/true);
1141 // When saving that document to DOC and loading it back:
1142 saveAndReload(u
"MS Word 97"_ustr
);
1144 // Then make sure the dummy character at the end is filtered out:
1145 OUString aBodyText
= getBodyText();
1146 // Without the accompanying fix in place, this test would have failed:
1148 // - Actual : test<space>
1149 // i.e. the CH_TXTATR_BREAKWORD at the end was written, then the import replaced that with a
1151 CPPUNIT_ASSERT_EQUAL(u
"test"_ustr
, aBodyText
);
1154 CPPUNIT_PLUGIN_IMPLEMENT();
1156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */