android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / qa / extras / ww8import / ww8import.cxx
blob82b4c74253ddd73228f19abcc3de183c8c29ca1e
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 <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/graphic/XGraphic.hpp>
17 #include <editeng/boxitem.hxx>
18 #include <editeng/lrspitem.hxx>
19 #include <editeng/ulspitem.hxx>
20 #include <sfx2/docfile.hxx>
21 #include <sfx2/docfilt.hxx>
23 #include <editsh.hxx>
24 #include <ndgrf.hxx>
25 #include <docsh.hxx>
26 #include <unotxdoc.hxx>
27 #include <viewsh.hxx>
28 #include <IDocumentLayoutAccess.hxx>
30 // tests should only be added to ww8IMPORT *if* they fail round-tripping in ww8EXPORT
32 class Test : public SwModelTestBase
34 public:
35 Test() : SwModelTestBase("/sw/qa/extras/ww8import/data/", "MS Word 97")
40 CPPUNIT_TEST_FIXTURE(Test, testFloatingTableSectionMargins)
42 createSwDoc("floating-table-section-margins.doc");
43 sal_Int32 pageLeft = parseDump("/root/page[2]/infos/bounds", "left").toInt32();
44 sal_Int32 pageWidth = parseDump("/root/page[2]/infos/bounds", "width").toInt32();
45 sal_Int32 tableLeft = parseDump("//tab/infos/bounds", "left").toInt32();
46 sal_Int32 tableWidth = parseDump("//tab/infos/bounds", "width").toInt32();
47 CPPUNIT_ASSERT( pageWidth > 0 );
48 CPPUNIT_ASSERT( tableWidth > 0 );
49 // The table's resulting position should be roughly centered.
50 CPPUNIT_ASSERT( abs(( pageLeft + pageWidth / 2 ) - ( tableLeft + tableWidth / 2 )) < 20 );
52 uno::Reference<beans::XPropertySet> xTextSection = getProperty< uno::Reference<beans::XPropertySet> >(getParagraph(2), "TextSection");
53 CPPUNIT_ASSERT(xTextSection.is());
54 uno::Reference<text::XTextColumns> xTextColumns = getProperty< uno::Reference<text::XTextColumns> >(xTextSection, "TextColumns");
55 OUString pageStyleName = getProperty<OUString>(getParagraph(2), "PageStyleName");
56 uno::Reference<beans::XPropertySet> xPageStyle(getStyles("PageStyles")->getByName(pageStyleName), uno::UNO_QUERY);
57 uno::Reference<text::XTextColumns> xPageColumns = getProperty< uno::Reference<text::XTextColumns> >(xPageStyle, "TextColumns");
59 //either one or the other should get the column's, not both.
60 CPPUNIT_ASSERT( xTextColumns->getColumnCount() != xPageColumns->getColumnCount());
63 CPPUNIT_TEST_FIXTURE(Test, testN816593)
65 createSwDoc("n816593.doc");
66 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
67 uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
68 // Make sure that even if we import the two tables as non-floating, we
69 // still consider them different, and not merge them.
70 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount());
73 CPPUNIT_TEST_FIXTURE(Test, testBnc875715)
75 createSwDoc("bnc875715.doc");
76 uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY);
77 uno::Reference<container::XIndexAccess> xSections(xTextSectionsSupplier->getTextSections(), uno::UNO_QUERY);
78 // Was incorrectly set as -1270.
79 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xSections->getByIndex(0), "SectionLeftMargin"));
82 CPPUNIT_TEST_FIXTURE(Test, testFloatingTableSectionColumns)
84 createSwDoc("floating-table-section-columns.doc");
85 OUString tableWidth = parseDump("/root/page[1]/body/section/column[2]/body/txt/anchored/fly/tab/infos/bounds", "width");
86 // table width was restricted by a column
87 CPPUNIT_ASSERT( tableWidth.toInt32() > 10000 );
90 CPPUNIT_TEST_FIXTURE(Test, testTdf124601)
92 createSwDoc("tdf124601.doc");
93 // Without the accompanying fix in place, this test would have failed, as the importer lost the
94 // fLayoutInCell shape property for wrap-though shapes.
95 CPPUNIT_ASSERT(getProperty<bool>(getShapeByName(u"Grafik 18"), "IsFollowingTextFlow"));
96 CPPUNIT_ASSERT(getProperty<bool>(getShapeByName(u"Grafik 19"), "IsFollowingTextFlow"));
99 CPPUNIT_TEST_FIXTURE(Test, testImageLazyRead)
101 createSwDoc("image-lazy-read.doc");
102 auto xGraphic = getProperty<uno::Reference<graphic::XGraphic>>(getShape(1), "Graphic");
103 Graphic aGraphic(xGraphic);
104 // This failed, import loaded the graphic, it wasn't lazy-read.
105 CPPUNIT_ASSERT(!aGraphic.isAvailable());
108 CPPUNIT_TEST_FIXTURE(Test, testImageLazyRead0size)
110 createSwDoc("image-lazy-read-0size.doc");
111 // Load a document with a single bitmap in it: it's declared as a WMF one, but actually a TGA
112 // bitmap.
113 SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
114 SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
115 SwNode* pNode = pDoc->GetNodes()[SwNodeOffset(6)];
116 SwGrfNode* pGrfNode = pNode->GetGrfNode();
117 CPPUNIT_ASSERT(pGrfNode);
118 // Without the accompanying fix in place, this test would have failed with:
119 // - Expected: 7590x10440
120 // - Actual : 0x0
121 // i.e. the size was 0, even if the actual bitmap had a non-0 size.
122 CPPUNIT_ASSERT_EQUAL(Size(7590, 10440), pGrfNode->GetTwipSize());
125 CPPUNIT_TEST_FIXTURE(Test, testTdf106799)
127 createSwDoc("tdf106799.doc");
128 // Ensure that all text portions are calculated before testing.
129 SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
130 CPPUNIT_ASSERT(pTextDoc);
131 SwViewShell* pViewShell
132 = pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
133 CPPUNIT_ASSERT(pViewShell);
134 pViewShell->Reformat();
136 sal_Int32 const nCellWidths[3][4] = { { 9528, 0, 0, 0 },{ 2382, 2382, 2382, 2382 },{ 2382, 2382, 2382, 2382 } };
137 sal_Int32 const nCellTxtLns[3][4] = { { 1, 0, 0, 0 },{ 1, 0, 0, 0},{ 1, 1, 1, 1 } };
138 // Table was distorted because of missing sprmPFInnerTableCell at paragraph marks (0x0D) with sprmPFInnerTtp
139 for (sal_Int32 nRow : { 0, 1, 2 })
140 for (sal_Int32 nCell : { 0, 1, 2, 3 })
142 OString cellXPath("/root/page/body/tab/row/cell/tab/row[" + OString::number(nRow+1) + "]/cell[" + OString::number(nCell+1) + "]/");
143 CPPUNIT_ASSERT_EQUAL_MESSAGE(cellXPath.getStr(), nCellWidths[nRow][nCell], parseDump(cellXPath + "infos/bounds", "width").toInt32());
144 if (nCellTxtLns[nRow][nCell] != 0)
145 CPPUNIT_ASSERT_EQUAL_MESSAGE(cellXPath.getStr(), nCellTxtLns[nRow][nCell], parseDump(cellXPath + "txt/SwParaPortion/SwLineLayout", "length").toInt32());
149 CPPUNIT_TEST_FIXTURE(Test, testTdf121734)
151 createSwDoc("tdf121734.doc");
152 SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
153 CPPUNIT_ASSERT(pTextDoc);
154 SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
155 SwPosFlyFrames aPosFlyFrames = pDoc->GetAllFlyFormats(nullptr, false);
156 // There is only one fly frame in the document: the one with the imported floating table
157 CPPUNIT_ASSERT_EQUAL(size_t(1), aPosFlyFrames.size());
158 for (const SwPosFlyFrame& rPosFlyFrame : aPosFlyFrames)
160 const SwFrameFormat& rFormat = rPosFlyFrame.GetFormat();
161 const SfxPoolItem* pItem = nullptr;
163 // The LR and UL spacings and borders must all be set explicitly;
164 // spacings and border distances must be 0; borders must be absent.
166 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, rFormat.GetItemState(RES_LR_SPACE, false, &pItem));
167 auto pLR = static_cast<const SvxLRSpaceItem*>(pItem);
168 CPPUNIT_ASSERT(pLR);
169 CPPUNIT_ASSERT_EQUAL(tools::Long(0), pLR->GetLeft());
170 CPPUNIT_ASSERT_EQUAL(tools::Long(0), pLR->GetRight());
172 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, rFormat.GetItemState(RES_UL_SPACE, false, &pItem));
173 auto pUL = static_cast<const SvxULSpaceItem*>(pItem);
174 CPPUNIT_ASSERT(pUL);
175 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pUL->GetUpper());
176 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pUL->GetLower());
178 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, rFormat.GetItemState(RES_BOX, false, &pItem));
179 auto pBox = static_cast<const SvxBoxItem*>(pItem);
180 CPPUNIT_ASSERT(pBox);
181 for (auto eLine : { SvxBoxItemLine::TOP, SvxBoxItemLine::BOTTOM,
182 SvxBoxItemLine::LEFT, SvxBoxItemLine::RIGHT })
184 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), pBox->GetDistance(eLine));
185 CPPUNIT_ASSERT(!pBox->GetLine(eLine));
190 CPPUNIT_TEST_FIXTURE(Test, testTdf125281)
192 createSwDoc("tdf125281.doc");
193 #if !defined(_WIN32)
194 // Windows fails with actual == 26171 for some reason; also lazy load isn't lazy in Windows
195 // debug builds, reason is not known at the moment.
197 // Load a .doc file which has an embedded .emf image.
198 SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
199 SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
200 SwNode* pNode = pDoc->GetNodes()[SwNodeOffset(6)];
201 CPPUNIT_ASSERT(pNode->IsGrfNode());
202 SwGrfNode* pGrfNode = pNode->GetGrfNode();
203 const Graphic& rGraphic = pGrfNode->GetGrf();
205 // Without the accompanying fix in place, this test would have failed, as pref size was 0 till
206 // an actual Paint() was performed (and even then, it was wrong).
207 tools::Long nExpected = 25664;
208 CPPUNIT_ASSERT_EQUAL(nExpected, rGraphic.GetPrefSize().getWidth());
210 // Without the accompanying fix in place, this test would have failed, as setting the pref size
211 // swapped the image in.
212 CPPUNIT_ASSERT(!rGraphic.isAvailable());
213 #endif
216 CPPUNIT_TEST_FIXTURE(Test, testTdf122425_1)
218 createSwDoc("tdf122425_1.doc");
219 // This is for header text in case we use a hack for fixed-height headers
220 // (see SwWW8ImplReader::Read_HdFtTextAsHackedFrame)
221 SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
222 CPPUNIT_ASSERT(pTextDoc);
223 SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
224 SwPosFlyFrames aPosFlyFrames = pDoc->GetAllFlyFormats(nullptr, false);
225 // There are two fly frames in the document: for first page's header, and for other pages'
226 CPPUNIT_ASSERT_EQUAL(size_t(2), aPosFlyFrames.size());
227 for (const SwPosFlyFrame& rPosFlyFrame : aPosFlyFrames)
229 const SwFrameFormat& rFormat = rPosFlyFrame.GetFormat();
230 const SfxPoolItem* pItem = nullptr;
232 // The LR and UL spacings and borders must all be set explicitly;
233 // spacings and border distances must be 0; borders must be absent
235 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, rFormat.GetItemState(RES_LR_SPACE, false, &pItem));
236 auto pLR = static_cast<const SvxLRSpaceItem*>(pItem);
237 CPPUNIT_ASSERT(pLR);
238 CPPUNIT_ASSERT_EQUAL(tools::Long(0), pLR->GetLeft());
239 CPPUNIT_ASSERT_EQUAL(tools::Long(0), pLR->GetRight());
241 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, rFormat.GetItemState(RES_UL_SPACE, false, &pItem));
242 auto pUL = static_cast<const SvxULSpaceItem*>(pItem);
243 CPPUNIT_ASSERT(pUL);
244 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pUL->GetUpper());
245 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pUL->GetLower());
247 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, rFormat.GetItemState(RES_BOX, false, &pItem));
248 auto pBox = static_cast<const SvxBoxItem*>(pItem);
249 CPPUNIT_ASSERT(pBox);
250 for (auto eLine : { SvxBoxItemLine::TOP, SvxBoxItemLine::BOTTOM,
251 SvxBoxItemLine::LEFT, SvxBoxItemLine::RIGHT })
253 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), pBox->GetDistance(eLine));
254 CPPUNIT_ASSERT(!pBox->GetLine(eLine));
258 //tdf#139495: without the fix, a negative number was converted into a uInt16, overflowing to 115501
259 auto nDist = getProperty<sal_uInt32>(getStyles("PageStyles")->getByName("Standard"), "HeaderBodyDistance");
260 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), nDist);
263 CPPUNIT_TEST_FIXTURE(Test, testTdf110987)
265 createSwDoc("tdf110987");
266 // The input document is an empty .doc, but without file name
267 // extension. Check that it was loaded as a normal .doc document,
268 // and not a template.
269 SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
270 CPPUNIT_ASSERT(pTextDoc);
271 OUString sFilterName = pTextDoc->GetDocShell()->GetMedium()->GetFilter()->GetFilterName();
272 CPPUNIT_ASSERT(sFilterName != "MS Word 97 Vorlage");
275 CPPUNIT_TEST_FIXTURE(Test, testTdf120761_zOrder)
277 createSwDoc("tdf120761_zOrder.dot");
278 //The blue shape was covering everything (highest zorder = 2) instead of the lowest(0)
279 uno::Reference<drawing::XShape> xShape(getShapeByName(u"Picture 2"), uno::UNO_QUERY);
280 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), getProperty<sal_uInt32>(xShape, "ZOrder"));
283 CPPUNIT_TEST_FIXTURE(Test, testTdf142003)
285 createSwDoc("changes-in-footnote.doc");
287 SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
288 CPPUNIT_ASSERT(pTextDoc);
290 SwEditShell* const pEditShell(pTextDoc->GetDocShell()->GetDoc()->GetEditShell());
291 pEditShell->AcceptRedline(0);
293 //The changes were offset from where they should have been
294 uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY);
295 uno::Reference<container::XIndexAccess> xFootnotes = xFootnotesSupplier->getFootnotes();
296 uno::Reference<text::XTextRange> xParagraph(xFootnotes->getByIndex(0), uno::UNO_QUERY);
297 //before change was incorrect, Loren ipsum , doconsectetur ...
298 CPPUNIT_ASSERT(xParagraph->getString().startsWith("Lorem ipsum , consectetur adipiscing elit."));
301 // tests should only be added to ww8IMPORT *if* they fail round-tripping in ww8EXPORT
303 CPPUNIT_PLUGIN_IMPLEMENT();
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */