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/document/XDocumentPropertiesSupplier.hpp>
15 #include <com/sun/star/graphic/XGraphic.hpp>
16 #include <com/sun/star/style/ParagraphAdjust.hpp>
17 #include <com/sun/star/text/TextContentAnchorType.hpp>
18 #include <com/sun/star/text/XTextDocument.hpp>
19 #include <com/sun/star/text/XTextTable.hpp>
21 #include <comphelper/sequenceashashmap.hxx>
22 #include <o3tl/string_view.hxx>
25 #include <IDocumentMarkAccess.hxx>
26 #include <IDocumentSettingAccess.hxx>
27 #include <unotxdoc.hxx>
29 #include <itabenum.hxx>
31 #include <formatflysplit.hxx>
32 #include <fmtwrapinfluenceonobjpos.hxx>
34 class Test
: public SwModelTestBase
38 : SwModelTestBase("/sw/qa/extras/ww8export/data/", "MS Word 97")
43 CPPUNIT_TEST_FIXTURE(Test
, testTdf77964
)
45 loadAndReload("tdf77964.doc");
46 // both images were loading as AT_PARA instead of AS_CHAR. Image2 visually had text wrapping.
47 CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AS_CHARACTER
, getProperty
<text::TextContentAnchorType
>(getShapeByName(u
"Image2"), "AnchorType"));
50 DECLARE_WW8EXPORT_TEST(testTdf150197_anlv2ListFormat
, "tdf150197_anlv2ListFormat.doc")
52 CPPUNIT_ASSERT_EQUAL(OUString("1."), getProperty
<OUString
>(getParagraph(2), "ListLabelString"));
53 CPPUNIT_ASSERT_EQUAL(OUString("2."), getProperty
<OUString
>(getParagraph(3), "ListLabelString"));
54 CPPUNIT_ASSERT_EQUAL_MESSAGE("Did you fix me? I should be 2.1", OUString("4.1"),
55 getProperty
<OUString
>(getParagraph(4), "ListLabelString"));
58 DECLARE_WW8EXPORT_TEST(testTdf117994_CRnumformatting
, "tdf117994_CRnumformatting.doc")
60 CPPUNIT_ASSERT_EQUAL(OUString("1."), parseDump("//body/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::Number']", "expand"));
61 //Without this fix in place, it would become 200 (and non-bold).
62 CPPUNIT_ASSERT_EQUAL(OUString("160"), parseDump("//body/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::Number']/SwFont", "height"));
65 DECLARE_WW8EXPORT_TEST(testTdf151548_formFieldMacros
, "tdf151548_formFieldMacros.doc")
67 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
68 SwDoc
* pDoc
= pTextDoc
->GetDocShell()->GetDoc();
69 IDocumentMarkAccess
* pMarkAccess
= pDoc
->getIDocumentMarkAccess();
70 for(auto aIter
= pMarkAccess
->getFieldmarksBegin(); aIter
!= pMarkAccess
->getFieldmarksEnd(); ++aIter
)
72 const OUString sName
= (*aIter
)->GetName();
73 CPPUNIT_ASSERT(sName
== "Check1" || sName
== "Check2" || sName
== "Text1" || sName
== "Dropdown1");
77 DECLARE_WW8EXPORT_TEST(testTdf141649_conditionalText
, "tdf141649_conditionalText.doc")
79 // In MS Word, the IF field is editable and requires manual update, so the most correct
80 // result is "manual refresh with F9" inside a text field,
81 // but for our purposes, a single instance of "trueResult" is appropriate.
82 getParagraph(1, "trueResult");
85 DECLARE_WW8EXPORT_TEST(testTdf90408
, "tdf90408.doc")
87 uno::Reference
<beans::XPropertySet
> xRun(getRun(getParagraph(1), 1), uno::UNO_QUERY_THROW
);
88 CPPUNIT_ASSERT_EQUAL_MESSAGE("checkbox is 16pt", 16.f
, getProperty
<float>(xRun
, "CharHeight"));
89 xRun
.set(getRun(getParagraph(1), 2, "unchecked"), uno::UNO_QUERY_THROW
);
90 CPPUNIT_ASSERT_EQUAL_MESSAGE("text is 12pt", 12.f
, getProperty
<float>(xRun
, "CharHeight"));
93 DECLARE_WW8EXPORT_TEST(testTdf90408B
, "tdf90408B.doc")
95 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
96 uno::Reference
<container::XIndexAccess
> xTables(xTextTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
97 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
98 uno::Reference
<text::XTextRange
> xCell(xTable
->getCellByName("A1"), uno::UNO_QUERY
);
100 uno::Reference
<container::XEnumerationAccess
> xParaEnumAccess(xCell
->getText(), uno::UNO_QUERY
);
101 uno::Reference
<container::XEnumeration
> xParaEnum
= xParaEnumAccess
->createEnumeration();
102 uno::Reference
<text::XTextRange
> xPara(xParaEnum
->nextElement(), uno::UNO_QUERY
);
104 uno::Reference
<beans::XPropertySet
> xRun(getRun(xPara
, 1), uno::UNO_QUERY_THROW
);
105 CPPUNIT_ASSERT_EQUAL_MESSAGE("checkbox is 28pt", 28.f
, getProperty
<float>(xRun
, "CharHeight"));
106 xRun
.set(getRun(xPara
, 2, u
" Κατάψυξη, "), uno::UNO_QUERY_THROW
);
107 CPPUNIT_ASSERT_EQUAL_MESSAGE("text is 10pt", 10.f
, getProperty
<float>(xRun
, "CharHeight"));
110 DECLARE_WW8EXPORT_TEST(testTdf155465_paraAdjustDistribute
, "tdf155465_paraAdjustDistribute.doc")
112 // Without the accompanying fix in place, this test would have failed with
113 // 'Expected: 2; Actual : 0', i.e. the first paragraph's ParaAdjust was left, not block.
114 const style::ParagraphAdjust eBlock
= style::ParagraphAdjust_BLOCK
;
115 auto nAdjust
= getProperty
<sal_Int16
>(getParagraph(1), "ParaAdjust");
116 CPPUNIT_ASSERT_EQUAL(eBlock
, static_cast<style::ParagraphAdjust
>(nAdjust
));
118 nAdjust
= getProperty
<sal_Int16
>(getParagraph(1), "ParaLastLineAdjust");
119 CPPUNIT_ASSERT_EQUAL(eBlock
, static_cast<style::ParagraphAdjust
>(nAdjust
));
121 nAdjust
= getProperty
<sal_Int16
>(getParagraph(2), "ParaAdjust");
122 CPPUNIT_ASSERT_EQUAL(eBlock
, static_cast<style::ParagraphAdjust
>(nAdjust
));
124 nAdjust
= getProperty
<sal_Int16
>(getParagraph(2), "ParaLastLineAdjust");
125 CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_LEFT
, static_cast<style::ParagraphAdjust
>(nAdjust
));
128 CPPUNIT_TEST_FIXTURE(Test
, testDontBreakWrappedTables
)
130 // Given a document with the DO_NOT_BREAK_WRAPPED_TABLES compat mode enabled:
133 SwDoc
* pDoc
= getSwDoc();
134 IDocumentSettingAccess
& rIDSA
= pDoc
->getIDocumentSettingAccess();
135 rIDSA
.set(DocumentSettingId::DO_NOT_BREAK_WRAPPED_TABLES
, true);
138 // When saving to doc:
139 saveAndReload("MS Word 97");
141 // Then make sure the compat flag is serialized:
142 SwDoc
* pDoc
= getSwDoc();
143 IDocumentSettingAccess
& rIDSA
= pDoc
->getIDocumentSettingAccess();
144 bool bDontBreakWrappedTables
= rIDSA
.get(DocumentSettingId::DO_NOT_BREAK_WRAPPED_TABLES
);
145 // Without the accompanying fix in place, this test would have failed, the compat flag was not
147 CPPUNIT_ASSERT(bDontBreakWrappedTables
);
150 CPPUNIT_TEST_FIXTURE(Test
, testFloattableOverlapNeverDOCExport
)
152 // Given a document with a floating table, overlap is not allowed:
155 SwDoc
* pDoc
= getSwDoc();
156 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
157 pWrtShell
->Insert2("before table");
159 SwInsertTableOptions
aTableOptions(SwInsertTableFlags::DefaultBorder
, 0);
160 pWrtShell
->InsertTable(aTableOptions
, /*nRows=*/1, /*nCols=*/1);
161 pWrtShell
->MoveTable(GotoPrevTable
, fnTableStart
);
164 // Wrap the table in a text frame:
165 SwFlyFrameAttrMgr
aMgr(true, pWrtShell
, Frmmgr_Type::TEXT
, nullptr);
166 pWrtShell
->StartAllAction();
167 aMgr
.InsertFlyFrame(RndStdIds::FLY_AT_PARA
, aMgr
.GetPos(), aMgr
.GetSize());
168 pWrtShell
->EndAllAction();
169 // Allow the text frame to split:
170 pWrtShell
->StartAllAction();
171 sw::FrameFormats
<sw::SpzFrameFormat
*>* pFlys
= pDoc
->GetSpzFrameFormats();
172 sw::SpzFrameFormat
* pFly
= (*pFlys
)[0];
173 SwAttrSet
aSet(pFly
->GetAttrSet());
174 aSet
.Put(SwFormatFlySplit(true));
175 // Don't allow overlap:
176 SwFormatWrapInfluenceOnObjPos aInfluence
;
177 aInfluence
.SetAllowOverlap(false);
178 aSet
.Put(aInfluence
);
179 pDoc
->SetAttr(aSet
, *pFly
);
180 pWrtShell
->EndAllAction();
183 // When saving to DOC:
184 saveAndReload("MS Word 97");
186 // Then make sure that the overlap=never markup is written:
187 SwDoc
* pDoc
= getSwDoc();
188 sw::FrameFormats
<sw::SpzFrameFormat
*>* pFlys
= pDoc
->GetSpzFrameFormats();
189 sw::SpzFrameFormat
* pFly
= (*pFlys
)[0];
190 // Without the accompanying fix in place, this test would have failed, i.e. TFNoAllowOverlap was
192 CPPUNIT_ASSERT(!pFly
->GetAttrSet().GetWrapInfluenceOnObjPos().GetAllowOverlap());
195 DECLARE_WW8EXPORT_TEST(testTdf104704_mangledFooter
, "tdf104704_mangledFooter.odt")
197 CPPUNIT_ASSERT_EQUAL(2, getPages());
200 CPPUNIT_PLUGIN_IMPLEMENT();
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */