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/text/XTextColumns.hpp>
13 #include <com/sun/star/text/XTextTablesSupplier.hpp>
14 #include <com/sun/star/text/XTextSectionsSupplier.hpp>
15 #include <com/sun/star/text/XTextField.hpp>
16 #include <com/sun/star/graphic/XGraphic.hpp>
18 #include <editeng/boxitem.hxx>
19 #include <editeng/lrspitem.hxx>
20 #include <editeng/ulspitem.hxx>
21 #include <sfx2/docfile.hxx>
22 #include <sfx2/docfilt.hxx>
27 #include <unotxdoc.hxx>
29 #include <IDocumentLayoutAccess.hxx>
31 // tests should only be added to ww8IMPORT *if* they fail round-tripping in ww8EXPORT
35 class Test
: public SwModelTestBase
38 Test() : SwModelTestBase(u
"/sw/qa/extras/ww8import/data/"_ustr
, u
"MS Word 97"_ustr
)
43 CPPUNIT_TEST_FIXTURE(Test
, testN816593
)
45 createSwDoc("n816593.doc");
46 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
47 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
48 // Make sure that even if we import the two tables as non-floating, we
49 // still consider them different, and not merge them.
50 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
53 CPPUNIT_TEST_FIXTURE(Test
, testBnc875715
)
55 createSwDoc("bnc875715.doc");
56 uno::Reference
<text::XTextSectionsSupplier
> xTextSectionsSupplier(mxComponent
, uno::UNO_QUERY
);
57 uno::Reference
<container::XIndexAccess
> xSections(xTextSectionsSupplier
->getTextSections(), uno::UNO_QUERY
);
58 // Was incorrectly set as -1270.
59 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty
<sal_Int32
>(xSections
->getByIndex(0), u
"SectionLeftMargin"_ustr
));
62 CPPUNIT_TEST_FIXTURE(Test
, testFloatingTableSectionColumns
)
64 createSwDoc("floating-table-section-columns.doc");
65 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
66 OUString tableWidth
= getXPath(pXmlDoc
, "/root/page[1]/body/section/column[2]/body/txt/anchored/fly/tab/infos/bounds", "width");
67 // table width was restricted by a column
68 CPPUNIT_ASSERT( tableWidth
.toInt32() > 10000 );
71 CPPUNIT_TEST_FIXTURE(Test
, testTdf124601
)
73 createSwDoc("tdf124601.doc");
74 // Without the accompanying fix in place, this test would have failed, as the importer lost the
75 // fLayoutInCell shape property for wrap-though shapes.
76 CPPUNIT_ASSERT(getProperty
<bool>(getShapeByName(u
"Grafik 18"), u
"IsFollowingTextFlow"_ustr
));
77 CPPUNIT_ASSERT(getProperty
<bool>(getShapeByName(u
"Grafik 19"), u
"IsFollowingTextFlow"_ustr
));
80 CPPUNIT_TEST_FIXTURE(Test
, testImageLazyRead
)
82 createSwDoc("image-lazy-read.doc");
83 auto xGraphic
= getProperty
<uno::Reference
<graphic::XGraphic
>>(getShape(1), u
"Graphic"_ustr
);
84 Graphic
aGraphic(xGraphic
);
85 // This failed, import loaded the graphic, it wasn't lazy-read.
86 CPPUNIT_ASSERT(!aGraphic
.isAvailable());
89 CPPUNIT_TEST_FIXTURE(Test
, testImageLazyRead0size
)
91 createSwDoc("image-lazy-read-0size.doc");
92 // Load a document with a single bitmap in it: it's declared as a WMF one, but actually a TGA
94 SwDoc
* pDoc
= getSwDoc();
95 SwNode
* pNode
= pDoc
->GetNodes()[SwNodeOffset(6)];
96 SwGrfNode
* pGrfNode
= pNode
->GetGrfNode();
97 CPPUNIT_ASSERT(pGrfNode
);
98 // Without the accompanying fix in place, this test would have failed with:
99 // - Expected: 7590x10440
101 // i.e. the size was 0, even if the actual bitmap had a non-0 size.
102 CPPUNIT_ASSERT_EQUAL(Size(7590, 10440), pGrfNode
->GetTwipSize());
105 CPPUNIT_TEST_FIXTURE(Test
, testTdf106799
)
107 createSwDoc("tdf106799.doc");
108 // Ensure that all text portions are calculated before testing.
109 SwViewShell
* pViewShell
110 = getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
111 CPPUNIT_ASSERT(pViewShell
);
112 pViewShell
->Reformat();
114 sal_Int32
const nCellWidths
[3][4] = { { 9528, 0, 0, 0 },{ 2382, 2382, 2382, 2382 },{ 2382, 2382, 2382, 2382 } };
115 sal_Int32
const nCellTxtLns
[3][4] = { { 1, 0, 0, 0 },{ 1, 0, 0, 0},{ 1, 1, 1, 1 } };
116 // Table was distorted because of missing sprmPFInnerTableCell at paragraph marks (0x0D) with sprmPFInnerTtp
117 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
118 for (sal_Int32 nRow
: { 0, 1, 2 })
119 for (sal_Int32 nCell
: { 0, 1, 2, 3 })
121 OString
cellXPath("/root/page/body/tab/row/cell/tab/row[" + OString::number(nRow
+1) + "]/cell[" + OString::number(nCell
+1) + "]/");
122 CPPUNIT_ASSERT_EQUAL_MESSAGE(cellXPath
.getStr(), nCellWidths
[nRow
][nCell
], getXPath(pXmlDoc
, cellXPath
+ "infos/bounds", "width").toInt32());
123 if (nCellTxtLns
[nRow
][nCell
] != 0)
124 CPPUNIT_ASSERT_EQUAL_MESSAGE(cellXPath
.getStr(), nCellTxtLns
[nRow
][nCell
], getXPath(pXmlDoc
, cellXPath
+ "txt/SwParaPortion/SwLineLayout", "length").toInt32());
128 CPPUNIT_TEST_FIXTURE(Test
, testTdf121734
)
130 createSwDoc("tdf121734.doc");
131 SwDoc
* pDoc
= getSwDoc();
132 SwPosFlyFrames aPosFlyFrames
= pDoc
->GetAllFlyFormats(nullptr, false);
133 // There is only one fly frame in the document: the one with the imported floating table
134 CPPUNIT_ASSERT_EQUAL(size_t(1), aPosFlyFrames
.size());
135 for (const SwPosFlyFrame
& rPosFlyFrame
: aPosFlyFrames
)
137 const SwFrameFormat
& rFormat
= rPosFlyFrame
.GetFormat();
138 const SfxPoolItem
* pItem
= nullptr;
140 // The LR and UL spacings and borders must all be set explicitly;
141 // spacings and border distances must be 0; borders must be absent.
143 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, rFormat
.GetItemState(RES_LR_SPACE
, false, &pItem
));
144 auto pLR
= static_cast<const SvxLRSpaceItem
*>(pItem
);
146 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pLR
->ResolveLeft({}));
147 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pLR
->ResolveRight({}));
149 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, rFormat
.GetItemState(RES_UL_SPACE
, false, &pItem
));
150 auto pUL
= static_cast<const SvxULSpaceItem
*>(pItem
);
152 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pUL
->GetUpper());
153 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pUL
->GetLower());
155 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, rFormat
.GetItemState(RES_BOX
, false, &pItem
));
156 auto pBox
= static_cast<const SvxBoxItem
*>(pItem
);
157 CPPUNIT_ASSERT(pBox
);
158 for (auto eLine
: { SvxBoxItemLine::TOP
, SvxBoxItemLine::BOTTOM
,
159 SvxBoxItemLine::LEFT
, SvxBoxItemLine::RIGHT
})
161 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), pBox
->GetDistance(eLine
));
162 CPPUNIT_ASSERT(!pBox
->GetLine(eLine
));
167 CPPUNIT_TEST_FIXTURE(Test
, testTdf125281
)
169 createSwDoc("tdf125281.doc");
171 // Windows fails with actual == 26171 for some reason; also lazy load isn't lazy in Windows
172 // debug builds, reason is not known at the moment.
174 // Load a .doc file which has an embedded .emf image.
175 SwDoc
* pDoc
= getSwDoc();
176 SwNode
* pNode
= pDoc
->GetNodes()[SwNodeOffset(6)];
177 CPPUNIT_ASSERT(pNode
->IsGrfNode());
178 SwGrfNode
* pGrfNode
= pNode
->GetGrfNode();
179 const Graphic
& rGraphic
= pGrfNode
->GetGrf();
181 // Without the accompanying fix in place, this test would have failed, as pref size was 0 till
182 // an actual Paint() was performed (and even then, it was wrong).
183 tools::Long nExpected
= 25664;
184 CPPUNIT_ASSERT_EQUAL(nExpected
, rGraphic
.GetPrefSize().getWidth());
186 // Without the accompanying fix in place, this test would have failed, as setting the pref size
187 // swapped the image in.
188 CPPUNIT_ASSERT(!rGraphic
.isAvailable());
192 CPPUNIT_TEST_FIXTURE(Test
, testTdf122425_1
)
194 createSwDoc("tdf122425_1.doc");
195 // This is for header text in case we use a hack for fixed-height headers
196 // (see SwWW8ImplReader::Read_HdFtTextAsHackedFrame)
197 SwDoc
* pDoc
= getSwDoc();
198 SwPosFlyFrames aPosFlyFrames
= pDoc
->GetAllFlyFormats(nullptr, false);
199 // There are two fly frames in the document: for first page's header, and for other pages'
200 CPPUNIT_ASSERT_EQUAL(size_t(2), aPosFlyFrames
.size());
201 for (const SwPosFlyFrame
& rPosFlyFrame
: aPosFlyFrames
)
203 const SwFrameFormat
& rFormat
= rPosFlyFrame
.GetFormat();
204 const SfxPoolItem
* pItem
= nullptr;
206 // The LR and UL spacings and borders must all be set explicitly;
207 // spacings and border distances must be 0; borders must be absent
209 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, rFormat
.GetItemState(RES_LR_SPACE
, false, &pItem
));
210 auto pLR
= static_cast<const SvxLRSpaceItem
*>(pItem
);
212 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pLR
->ResolveLeft({}));
213 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pLR
->ResolveRight({}));
215 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, rFormat
.GetItemState(RES_UL_SPACE
, false, &pItem
));
216 auto pUL
= static_cast<const SvxULSpaceItem
*>(pItem
);
218 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pUL
->GetUpper());
219 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pUL
->GetLower());
221 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, rFormat
.GetItemState(RES_BOX
, false, &pItem
));
222 auto pBox
= static_cast<const SvxBoxItem
*>(pItem
);
223 CPPUNIT_ASSERT(pBox
);
224 for (auto eLine
: { SvxBoxItemLine::TOP
, SvxBoxItemLine::BOTTOM
,
225 SvxBoxItemLine::LEFT
, SvxBoxItemLine::RIGHT
})
227 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), pBox
->GetDistance(eLine
));
228 CPPUNIT_ASSERT(!pBox
->GetLine(eLine
));
232 //tdf#139495: without the fix, a negative number was converted into a uInt16, overflowing to 115501
233 auto nDist
= getProperty
<sal_uInt32
>(getStyles(u
"PageStyles"_ustr
)->getByName(u
"Standard"_ustr
), u
"HeaderBodyDistance"_ustr
);
234 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), nDist
);
237 CPPUNIT_TEST_FIXTURE(Test
, testTdf110987
)
239 createSwDoc("tdf110987");
240 // The input document is an empty .doc, but without file name
241 // extension. Check that it was loaded as a normal .doc document,
242 // and not a template.
243 OUString sFilterName
= getSwDocShell()->GetMedium()->GetFilter()->GetFilterName();
244 CPPUNIT_ASSERT(sFilterName
!= "MS Word 97 Vorlage");
247 CPPUNIT_TEST_FIXTURE(Test
, testTdf120761_zOrder
)
249 createSwDoc("tdf120761_zOrder.dot");
250 //The blue shape was covering everything (highest zorder = 2) instead of the lowest(0)
251 uno::Reference
<drawing::XShape
> xShape(getShapeByName(u
"Picture 2"), uno::UNO_QUERY
);
252 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), getProperty
<sal_uInt32
>(xShape
, u
"ZOrder"_ustr
));
255 CPPUNIT_TEST_FIXTURE(Test
, testTdf142003
)
257 createSwDoc("changes-in-footnote.doc");
259 SwEditShell
* const pEditShell(getSwDoc()->GetEditShell());
260 CPPUNIT_ASSERT(pEditShell
);
261 pEditShell
->AcceptRedline(0);
263 //The changes were offset from where they should have been
264 uno::Reference
<text::XFootnotesSupplier
> xFootnotesSupplier(mxComponent
, uno::UNO_QUERY
);
265 uno::Reference
<container::XIndexAccess
> xFootnotes
= xFootnotesSupplier
->getFootnotes();
266 uno::Reference
<text::XTextRange
> xParagraph(xFootnotes
->getByIndex(0), uno::UNO_QUERY
);
267 //before change was incorrect, Loren ipsum , doconsectetur ...
268 CPPUNIT_ASSERT(xParagraph
->getString().startsWith("Lorem ipsum , consectetur adipiscing elit."));
271 CPPUNIT_TEST_FIXTURE(Test
, testTdf160301
)
273 // Without the fix in place, fields in the test doc are imported as DocInformation
274 // with the content set to the variable name
275 createSwDoc("tdf160301.doc");
276 uno::Reference
<text::XTextFieldsSupplier
> xTextFieldsSupplier(mxComponent
, uno::UNO_QUERY
);
277 uno::Reference
<container::XEnumerationAccess
> xFieldsAccess(xTextFieldsSupplier
->getTextFields());
278 uno::Reference
<container::XEnumeration
> xFields(xFieldsAccess
->createEnumeration());
279 uno::Reference
<text::XTextField
> xField(xFields
->nextElement(), uno::UNO_QUERY
);
280 // Without the fix in place this fails with
281 // Expected: Jeff Smith
283 CPPUNIT_ASSERT_EQUAL(u
"Jeff Smith"_ustr
, xField
->getPresentation(false));
284 // Without the fix in place this fails with
285 // Expected: User Field FullName = Jeff Smith
286 // Actual: DocInformation:FullName
287 CPPUNIT_ASSERT_EQUAL(u
"User Field FullName = Jeff Smith"_ustr
, xField
->getPresentation(true));
290 CPPUNIT_TEST_FIXTURE(Test
, testTdf127048
)
292 // Use loadComponentFromURL so MacrosTest::loadFromDesktop is not called.
293 // Otherwise it sets MacroExecutionMode to ALWAYS_EXECUTE_NO_WARN
294 mxComponent
= mxDesktop
->loadComponentFromURL(createFileURL(u
"tdf127048.doc"), u
"_default"_ustr
, 0, {});
295 CPPUNIT_ASSERT_EQUAL(false, getSwDocShell()->GetMacroCallsSeenWhileLoading());
298 CPPUNIT_TEST_FIXTURE(Test
, testTdf134902
)
300 createSwDoc("tdf134902.docx");
301 CPPUNIT_ASSERT_EQUAL(4, getShapes());
302 uno::Reference
<drawing::XShape
> xShape
;
303 uno::Reference
< beans::XPropertySet
> XPropSet
;
304 for (int i
= 3; i
<= getShapes(); i
++)
306 xShape
= getShape(i
);
307 XPropSet
.set( xShape
, uno::UNO_QUERY_THROW
);
310 bool isVisible
= true;
311 XPropSet
->getPropertyValue(u
"Visible"_ustr
) >>= isVisible
;
312 CPPUNIT_ASSERT(!isVisible
);
314 catch (beans::UnknownPropertyException
&)
320 // tests should only be added to ww8IMPORT *if* they fail round-tripping in ww8EXPORT
322 } // end of anonymous namespace
323 CPPUNIT_PLUGIN_IMPLEMENT();
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */