1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <swmodeltestbase.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
#include <com/sun/star/style/ParagraphAdjust.hpp>
#include <com/sun/star/text/TextContentAnchorType.hpp>
#include <com/sun/star/text/XTextDocument.hpp>
#include <com/sun/star/text/XTextTable.hpp>
#include <comphelper/sequenceashashmap.hxx>
#include <o3tl/string_view.hxx>
#include <docsh.hxx>
#include <IDocumentMarkAccess.hxx>
#include <IDocumentSettingAccess.hxx>
#include <unotxdoc.hxx>
#include <ndtxt.hxx>
#include <editeng/lrspitem.hxx>
#include <wrtsh.hxx>
#include <itabenum.hxx>
#include <frmmgr.hxx>
#include <formatflysplit.hxx>
#include <fmtwrapinfluenceonobjpos.hxx>
class Test : public SwModelTestBase
{
public:
Test()
: SwModelTestBase("/sw/qa/extras/ww8export/data/", "MS Word 97")
{
}
};
CPPUNIT_TEST_FIXTURE(Test, testTdf77964)
{
loadAndReload("tdf77964.doc");
// both images were loading as AT_PARA instead of AS_CHAR. Image2 visually had text wrapping.
CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AS_CHARACTER, getProperty<text::TextContentAnchorType>(getShapeByName(u"Image2"), "AnchorType"));
}
DECLARE_WW8EXPORT_TEST(testTdf150197_anlv2ListFormat, "tdf150197_anlv2ListFormat.doc")
{
CPPUNIT_ASSERT_EQUAL(OUString("1."), getProperty<OUString>(getParagraph(2), "ListLabelString"));
CPPUNIT_ASSERT_EQUAL(OUString("2."), getProperty<OUString>(getParagraph(3), "ListLabelString"));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Did you fix me? I should be 2.1", OUString("4.1"),
getProperty<OUString>(getParagraph(4), "ListLabelString"));
}
DECLARE_WW8EXPORT_TEST(testTdf117994_CRnumformatting, "tdf117994_CRnumformatting.doc")
{
CPPUNIT_ASSERT_EQUAL(OUString("1."), parseDump("//body/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::Number']"_ostr, "expand"_ostr));
//Without this fix in place, it would become 200 (and non-bold).
CPPUNIT_ASSERT_EQUAL(OUString("160"), parseDump("//body/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::Number']/SwFont"_ostr, "height"_ostr));
}
DECLARE_WW8EXPORT_TEST(testTdf151548_formFieldMacros, "tdf151548_formFieldMacros.doc")
{
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
for(auto aIter = pMarkAccess->getFieldmarksBegin(); aIter != pMarkAccess->getFieldmarksEnd(); ++aIter)
{
const OUString sName = (*aIter)->GetName();
CPPUNIT_ASSERT(sName == "Check1" || sName == "Check2" || sName == "Text1" || sName == "Dropdown1");
}
}
DECLARE_WW8EXPORT_TEST(testTdf141649_conditionalText, "tdf141649_conditionalText.doc")
{
// In MS Word, the IF field is editable and requires manual update, so the most correct
// result is "manual refresh with F9" inside a text field,
// but for our purposes, a single instance of "trueResult" is appropriate.
getParagraph(1, "trueResult");
}
DECLARE_WW8EXPORT_TEST(testTdf90408, "tdf90408.doc")
{
uno::Reference<beans::XPropertySet> xRun(getRun(getParagraph(1), 1), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL_MESSAGE("checkbox is 16pt", 16.f, getProperty<float>(xRun, "CharHeight"));
xRun.set(getRun(getParagraph(1), 2, "unchecked"), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL_MESSAGE("text is 12pt", 12.f, getProperty<float>(xRun, "CharHeight"));
}
DECLARE_WW8EXPORT_TEST(testTdf90408B, "tdf90408B.doc")
{
uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xCell->getText(), uno::UNO_QUERY);
uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
uno::Reference<text::XTextRange> xPara(xParaEnum->nextElement(), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xRun(getRun(xPara, 1), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL_MESSAGE("checkbox is 28pt", 28.f, getProperty<float>(xRun, "CharHeight"));
xRun.set(getRun(xPara, 2, u" Κατάψυξη, "_ustr), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL_MESSAGE("text is 10pt", 10.f, getProperty<float>(xRun, "CharHeight"));
}
DECLARE_WW8EXPORT_TEST(testTdf155465_paraAdjustDistribute, "tdf155465_paraAdjustDistribute.doc")
{
// Without the accompanying fix in place, this test would have failed with
// 'Expected: 2; Actual : 0', i.e. the first paragraph's ParaAdjust was left, not block.
const style::ParagraphAdjust eBlock = style::ParagraphAdjust_BLOCK;
auto nAdjust = getProperty<sal_Int16>(getParagraph(1), "ParaAdjust");
CPPUNIT_ASSERT_EQUAL(eBlock, static_cast<style::ParagraphAdjust>(nAdjust));
nAdjust = getProperty<sal_Int16>(getParagraph(1), "ParaLastLineAdjust");
CPPUNIT_ASSERT_EQUAL(eBlock, static_cast<style::ParagraphAdjust>(nAdjust));
nAdjust = getProperty<sal_Int16>(getParagraph(2), "ParaAdjust");
CPPUNIT_ASSERT_EQUAL(eBlock, static_cast<style::ParagraphAdjust>(nAdjust));
nAdjust = getProperty<sal_Int16>(getParagraph(2), "ParaLastLineAdjust");
CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_LEFT, static_cast<style::ParagraphAdjust>(nAdjust));
}
CPPUNIT_TEST_FIXTURE(Test, testDontBreakWrappedTables)
{
// Given a document with the DO_NOT_BREAK_WRAPPED_TABLES compat mode enabled:
createSwDoc();
{
SwDoc* pDoc = getSwDoc();
IDocumentSettingAccess& rIDSA = pDoc->getIDocumentSettingAccess();
rIDSA.set(DocumentSettingId::DO_NOT_BREAK_WRAPPED_TABLES, true);
}
// When saving to doc:
saveAndReload("MS Word 97");
// Then make sure the compat flag is serialized:
SwDoc* pDoc = getSwDoc();
IDocumentSettingAccess& rIDSA = pDoc->getIDocumentSettingAccess();
bool bDontBreakWrappedTables = rIDSA.get(DocumentSettingId::DO_NOT_BREAK_WRAPPED_TABLES);
// Without the accompanying fix in place, this test would have failed, the compat flag was not
// set.
CPPUNIT_ASSERT(bDontBreakWrappedTables);
}
CPPUNIT_TEST_FIXTURE(Test, testFloattableOverlapNeverDOCExport)
{
// Given a document with a floating table, overlap is not allowed:
{
createSwDoc();
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
pWrtShell->Insert2("before table");
// Insert a table:
SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 0);
pWrtShell->InsertTable(aTableOptions, /*nRows=*/1, /*nCols=*/1);
pWrtShell->MoveTable(GotoPrevTable, fnTableStart);
// Select table:
pWrtShell->SelAll();
// Wrap the table in a text frame:
SwFlyFrameAttrMgr aMgr(true, pWrtShell, Frmmgr_Type::TEXT, nullptr);
pWrtShell->StartAllAction();
aMgr.InsertFlyFrame(RndStdIds::FLY_AT_PARA, aMgr.GetPos(), aMgr.GetSize());
pWrtShell->EndAllAction();
// Allow the text frame to split:
pWrtShell->StartAllAction();
sw::FrameFormats<sw::SpzFrameFormat*>* pFlys = pDoc->GetSpzFrameFormats();
sw::SpzFrameFormat* pFly = (*pFlys)[0];
SwAttrSet aSet(pFly->GetAttrSet());
aSet.Put(SwFormatFlySplit(true));
// Don't allow overlap:
SwFormatWrapInfluenceOnObjPos aInfluence;
aInfluence.SetAllowOverlap(false);
aSet.Put(aInfluence);
pDoc->SetAttr(aSet, *pFly);
pWrtShell->EndAllAction();
}
// When saving to DOC:
saveAndReload("MS Word 97");
// Then make sure that the overlap=never markup is written:
SwDoc* pDoc = getSwDoc();
sw::FrameFormats<sw::SpzFrameFormat*>* pFlys = pDoc->GetSpzFrameFormats();
sw::SpzFrameFormat* pFly = (*pFlys)[0];
// Without the accompanying fix in place, this test would have failed, i.e. TFNoAllowOverlap was
// not written.
CPPUNIT_ASSERT(!pFly->GetAttrSet().GetWrapInfluenceOnObjPos().GetAllowOverlap());
}
static bool IsFirstLine(const SwTextNode* pTextNode)
{
const SfxPoolItem* pItem = pTextNode->GetNoCondAttr(RES_MARGIN_FIRSTLINE, false);
return !!pItem;
}
DECLARE_WW8EXPORT_TEST(testInlinePageBreakFirstLine, "inlinePageBreakFirstLine.doc")
{
SwDoc* pDoc = getSwDoc();
const SwNodes& rNodes = pDoc->GetNodes();
std::vector<SwTextNode*> aTextNodes;
for (SwNodeOffset nNode(0); nNode < rNodes.Count(); ++nNode)
{
SwNode* pNode = pDoc->GetNodes()[nNode];
SwTextNode* pTextNode = pNode->GetTextNode();
if (!pTextNode)
continue;
aTextNodes.push_back(pTextNode);
}
CPPUNIT_ASSERT_EQUAL(size_t(3), aTextNodes.size());
CPPUNIT_ASSERT_EQUAL(OUString("First line"), aTextNodes[0]->GetText());
CPPUNIT_ASSERT(IsFirstLine(aTextNodes[0]));
// Here exists an inline pagebreak (a pagebreak without a paragraph before it)
// This text node is not indented because it is not the first line of the paragraph
CPPUNIT_ASSERT_EQUAL(OUString("Should not be indented"), aTextNodes[1]->GetText());
CPPUNIT_ASSERT(!IsFirstLine(aTextNodes[1]));
// Here is the actual second paragraph
CPPUNIT_ASSERT_EQUAL(OUString("Should be indented"), aTextNodes[2]->GetText());
CPPUNIT_ASSERT(IsFirstLine(aTextNodes[2]));
}
DECLARE_WW8EXPORT_TEST(testNonInlinePageBreakFirstLine, "nonInlinePageBreakFirstLine.doc")
{
SwDoc* pDoc = getSwDoc();
const SwNodes& rNodes = pDoc->GetNodes();
std::vector<SwTextNode*> aTextNodes;
for (SwNodeOffset nNode(0); nNode < rNodes.Count(); ++nNode)
{
SwNode* pNode = pDoc->GetNodes()[nNode];
SwTextNode* pTextNode = pNode->GetTextNode();
if (!pTextNode)
continue;
aTextNodes.push_back(pTextNode);
}
CPPUNIT_ASSERT_EQUAL(size_t(2), aTextNodes.size());
CPPUNIT_ASSERT_EQUAL(OUString("First line"), aTextNodes[0]->GetText());
CPPUNIT_ASSERT(IsFirstLine(aTextNodes[0]));
// Here exists a pagebreak after a paragraph
// This text node is indented because it is the first line of a paragraph
CPPUNIT_ASSERT_EQUAL(OUString("Should be indented"), aTextNodes[1]->GetText());
CPPUNIT_ASSERT(IsFirstLine(aTextNodes[1]));
}
DECLARE_WW8EXPORT_TEST(testTdf104704_mangledFooter, "tdf104704_mangledFooter.odt")
{
CPPUNIT_ASSERT_EQUAL(2, getPages());
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|