Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : #include <swmodeltestbase.hxx>
11 :
12 : #if !defined(WNT)
13 :
14 : #include <com/sun/star/awt/FontWeight.hpp>
15 : #include <com/sun/star/drawing/FillStyle.hpp>
16 : #include <com/sun/star/drawing/BitmapMode.hpp>
17 : #include <com/sun/star/style/PageStyleLayout.hpp>
18 : #include <com/sun/star/table/XCell.hpp>
19 : #include <com/sun/star/table/BorderLine.hpp>
20 : #include <com/sun/star/text/XTextSection.hpp>
21 : #include <com/sun/star/text/XTextTable.hpp>
22 :
23 : #include <wrtsh.hxx>
24 : #include <ndtxt.hxx>
25 : #include <swdtflvr.hxx>
26 : #include <view.hxx>
27 : #include <edtwin.hxx>
28 : #include <olmenu.hxx>
29 : #include <cmdid.h>
30 :
31 : typedef std::map<OUString, com::sun::star::uno::Sequence< com::sun::star::table::BorderLine> > AllBordersMap;
32 : typedef std::pair<OUString, com::sun::star::uno::Sequence< com::sun::star::table::BorderLine> > StringSequencePair;
33 :
34 29 : class Test : public SwModelTestBase
35 : {
36 : public:
37 29 : Test() : SwModelTestBase("/sw/qa/extras/odfimport/data/", "writer8") {}
38 : };
39 :
40 12 : DECLARE_ODFIMPORT_TEST(testEmptySvgFamilyName, "empty-svg-family-name.odt")
41 : {
42 : // .odt import did crash on the empty font list (which I think is valid according SVG spec)
43 1 : }
44 :
45 12 : DECLARE_ODFIMPORT_TEST(testHideAllSections, "fdo53210.odt")
46 : {
47 : // This document has a section that is conditionally hidden, but has no empty paragraph after it.
48 1 : uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
49 2 : uno::Reference<container::XNameAccess> xMasters = xTextFieldsSupplier->getTextFieldMasters();
50 : // Set _CS_Allgemein to 0
51 2 : uno::Reference<beans::XPropertySet> xMaster(xMasters->getByName("com.sun.star.text.fieldmaster.User._CS_Allgemein"), uno::UNO_QUERY);
52 1 : xMaster->setPropertyValue("Content", uno::makeAny(OUString("0")));
53 : // This used to crash
54 2 : uno::Reference<util::XRefreshable>(xTextFieldsSupplier->getTextFields(), uno::UNO_QUERY)->refresh();
55 1 : }
56 :
57 12 : DECLARE_ODFIMPORT_TEST(testOdtBorders, "borders_ooo33.odt")
58 : {
59 1 : AllBordersMap map;
60 2 : uno::Sequence< table::BorderLine > tempSequence(4);
61 :
62 1 : tempSequence[0] = table::BorderLine(0, 2, 2, 35); // left
63 1 : tempSequence[1] = table::BorderLine(0, 2, 2, 35); // right
64 1 : tempSequence[2] = table::BorderLine(0, 2, 2, 35); // top
65 1 : tempSequence[3] = table::BorderLine(0, 2, 2, 35); // bottom
66 1 : map.insert(StringSequencePair(OUString("B2"), tempSequence));
67 1 : tempSequence[0] = table::BorderLine(0, 0, 2, 0);
68 1 : tempSequence[1] = table::BorderLine(0, 0, 2, 0);
69 1 : tempSequence[2] = table::BorderLine(0, 0, 2, 0);
70 1 : tempSequence[3] = table::BorderLine(0, 0, 2, 0);
71 1 : map.insert(StringSequencePair(OUString("D2"), tempSequence));
72 1 : tempSequence[0] = table::BorderLine(0, 2, 2, 88);
73 1 : tempSequence[1] = table::BorderLine(0, 2, 2, 88);
74 1 : tempSequence[2] = table::BorderLine(0, 2, 2, 88);
75 1 : tempSequence[3] = table::BorderLine(0, 2, 2, 88);
76 1 : map.insert(StringSequencePair(OUString("B4"), tempSequence));
77 1 : tempSequence[0] = table::BorderLine(0, 0, 18, 0);
78 1 : tempSequence[1] = table::BorderLine(0, 0, 18, 0);
79 1 : tempSequence[2] = table::BorderLine(0, 0, 18, 0);
80 1 : tempSequence[3] = table::BorderLine(0, 0, 18, 0);
81 1 : map.insert(StringSequencePair(OUString("D4"), tempSequence));
82 1 : tempSequence[0] = table::BorderLine(0, 35, 35, 35);
83 1 : tempSequence[1] = table::BorderLine(0, 35, 35, 35);
84 1 : tempSequence[2] = table::BorderLine(0, 35, 35, 35);
85 1 : tempSequence[3] = table::BorderLine(0, 35, 35, 35);
86 1 : map.insert(StringSequencePair(OUString("B6"), tempSequence));
87 1 : tempSequence[0] = table::BorderLine(0, 0, 35, 0);
88 1 : tempSequence[1] = table::BorderLine(0, 0, 35, 0);
89 1 : tempSequence[2] = table::BorderLine(0, 0, 35, 0);
90 1 : tempSequence[3] = table::BorderLine(0, 0, 35, 0);
91 1 : map.insert(StringSequencePair(OUString("D6"), tempSequence));
92 1 : tempSequence[0] = table::BorderLine(0, 88, 88, 88);
93 1 : tempSequence[1] = table::BorderLine(0, 88, 88, 88);
94 1 : tempSequence[2] = table::BorderLine(0, 88, 88, 88);
95 1 : tempSequence[3] = table::BorderLine(0, 88, 88, 88);
96 1 : map.insert(StringSequencePair(OUString("B8"), tempSequence));
97 1 : tempSequence[0] = table::BorderLine(0, 0, 88, 0);
98 1 : tempSequence[1] = table::BorderLine(0, 0, 88, 0);
99 1 : tempSequence[2] = table::BorderLine(0, 0, 88, 0);
100 1 : tempSequence[3] = table::BorderLine(0, 0, 88, 0);
101 1 : map.insert(StringSequencePair(OUString("D8"), tempSequence));
102 1 : tempSequence[0] = table::BorderLine(0, 2, 35, 88);
103 1 : tempSequence[1] = table::BorderLine(0, 2, 35, 88);
104 1 : tempSequence[2] = table::BorderLine(0, 2, 35, 88);
105 1 : tempSequence[3] = table::BorderLine(0, 2, 35, 88);
106 1 : map.insert(StringSequencePair(OUString("B10"), tempSequence));
107 1 : tempSequence[0] = table::BorderLine(0, 0, 141, 0);
108 1 : tempSequence[1] = table::BorderLine(0, 0, 141, 0);
109 1 : tempSequence[2] = table::BorderLine(0, 0, 141, 0);
110 1 : tempSequence[3] = table::BorderLine(0, 0, 141, 0);
111 1 : map.insert(StringSequencePair(OUString("D10"), tempSequence));
112 1 : tempSequence[0] = table::BorderLine(0, 2, 88, 88);
113 1 : tempSequence[1] = table::BorderLine(0, 2, 88, 88);
114 1 : tempSequence[2] = table::BorderLine(0, 2, 88, 88);
115 1 : tempSequence[3] = table::BorderLine(0, 2, 88, 88);
116 1 : map.insert(StringSequencePair(OUString("B12"), tempSequence));
117 1 : tempSequence[0] = table::BorderLine(0, 0, 176, 0);
118 1 : tempSequence[1] = table::BorderLine(0, 0, 176, 0);
119 1 : tempSequence[2] = table::BorderLine(0, 0, 176, 0);
120 1 : tempSequence[3] = table::BorderLine(0, 0, 176, 0);
121 1 : map.insert(StringSequencePair(OUString("D12"), tempSequence));
122 1 : tempSequence[0] = table::BorderLine(0, 2, 141, 88);
123 1 : tempSequence[1] = table::BorderLine(0, 2, 141, 88);
124 1 : tempSequence[2] = table::BorderLine(0, 2, 141, 88);
125 1 : tempSequence[3] = table::BorderLine(0, 2, 141, 88);
126 1 : map.insert(StringSequencePair(OUString("B14"), tempSequence));
127 1 : tempSequence[0] = table::BorderLine(0, 35, 88, 88);
128 1 : tempSequence[1] = table::BorderLine(0, 35, 88, 88);
129 1 : tempSequence[2] = table::BorderLine(0, 35, 88, 88);
130 1 : tempSequence[3] = table::BorderLine(0, 35, 88, 88);
131 1 : map.insert(StringSequencePair(OUString("B16"), tempSequence));
132 1 : tempSequence[0] = table::BorderLine(0, 88, 35, 35);
133 1 : tempSequence[1] = table::BorderLine(0, 88, 35, 35);
134 1 : tempSequence[2] = table::BorderLine(0, 88, 35, 35);
135 1 : tempSequence[3] = table::BorderLine(0, 88, 35, 35);
136 1 : map.insert(StringSequencePair(OUString("B18"), tempSequence));
137 1 : tempSequence[0] = table::BorderLine(0, 88, 141, 88);
138 1 : tempSequence[1] = table::BorderLine(0, 88, 141, 88);
139 1 : tempSequence[2] = table::BorderLine(0, 88, 141, 88);
140 1 : tempSequence[3] = table::BorderLine(0, 88, 141, 88);
141 1 : map.insert(StringSequencePair(OUString("B20"), tempSequence));
142 1 : tempSequence[0] = table::BorderLine(0, 141, 88, 88);
143 1 : tempSequence[1] = table::BorderLine(0, 141, 88, 88);
144 1 : tempSequence[2] = table::BorderLine(0, 141, 88, 88);
145 1 : tempSequence[3] = table::BorderLine(0, 141, 88, 88);
146 1 : map.insert(StringSequencePair(OUString("B22"), tempSequence));
147 :
148 2 : uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
149 2 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(textDocument->getText(), uno::UNO_QUERY);
150 : // list of paragraphs
151 2 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
152 2 : do
153 : {
154 2 : uno::Reference<lang::XServiceInfo> xServiceInfo;
155 2 : if (xParaEnum->nextElement() >>= xServiceInfo)
156 : {
157 2 : if (xServiceInfo->supportsService("com.sun.star.text.TextTable"))
158 : {
159 1 : uno::Reference<text::XTextTable> const xTextTable(xServiceInfo, uno::UNO_QUERY_THROW);
160 2 : uno::Sequence<OUString> const cells = xTextTable->getCellNames();
161 1 : sal_Int32 nLength = cells.getLength();
162 :
163 1 : AllBordersMap::iterator it;
164 1 : it = map.begin();
165 :
166 116 : for (sal_Int32 i = 0; i < nLength; ++i)
167 : {
168 115 : if(i%10==6 || (i%10==8 && i<60)) // only B and D cells have borders, every 2 rows
169 : {
170 17 : uno::Reference<table::XCell> xCell = xTextTable->getCellByName(cells[i]);
171 34 : uno::Reference< beans::XPropertySet > xPropSet(xCell, uno::UNO_QUERY_THROW);
172 17 : it = map.find(cells[i]);
173 :
174 34 : uno::Any aLeftBorder = xPropSet->getPropertyValue("LeftBorder");
175 17 : table::BorderLine aLeftBorderLine;
176 17 : if (aLeftBorder >>= aLeftBorderLine)
177 : {
178 17 : sal_Int32 innerLineWidth = aLeftBorderLine.InnerLineWidth;
179 17 : sal_Int32 outerLineWidth = aLeftBorderLine.OuterLineWidth;
180 17 : sal_Int32 lineDistance = aLeftBorderLine.LineDistance;
181 :
182 17 : sal_Int32 perfectInner = it->second[0].InnerLineWidth;
183 17 : sal_Int32 perfectOuter = it->second[0].OuterLineWidth;
184 17 : sal_Int32 perfectDistance = it->second[0].LineDistance;
185 17 : CPPUNIT_ASSERT_EQUAL(perfectInner, innerLineWidth);
186 17 : CPPUNIT_ASSERT_EQUAL(perfectOuter, outerLineWidth);
187 17 : CPPUNIT_ASSERT_EQUAL(perfectDistance, lineDistance);
188 : }
189 :
190 34 : uno::Any aRightBorder = xPropSet->getPropertyValue("RightBorder");
191 17 : table::BorderLine aRightBorderLine;
192 17 : if (aRightBorder >>= aRightBorderLine)
193 : {
194 17 : sal_Int32 innerLineWidth = aRightBorderLine.InnerLineWidth;
195 17 : sal_Int32 outerLineWidth = aRightBorderLine.OuterLineWidth;
196 17 : sal_Int32 lineDistance = aRightBorderLine.LineDistance;
197 :
198 17 : sal_Int32 perfectInner = it->second[1].InnerLineWidth;
199 17 : sal_Int32 perfectOuter = it->second[1].OuterLineWidth;
200 17 : sal_Int32 perfectDistance = it->second[1].LineDistance;
201 17 : CPPUNIT_ASSERT_EQUAL(perfectInner, innerLineWidth);
202 17 : CPPUNIT_ASSERT_EQUAL(perfectOuter, outerLineWidth);
203 17 : CPPUNIT_ASSERT_EQUAL(perfectDistance, lineDistance);
204 : }
205 :
206 34 : uno::Any aTopBorder = xPropSet->getPropertyValue("TopBorder");
207 17 : table::BorderLine aTopBorderLine;
208 17 : if (aTopBorder >>= aTopBorderLine)
209 : {
210 17 : sal_Int32 innerLineWidth = aTopBorderLine.InnerLineWidth;
211 17 : sal_Int32 outerLineWidth = aTopBorderLine.OuterLineWidth;
212 17 : sal_Int32 lineDistance = aTopBorderLine.LineDistance;
213 :
214 17 : sal_Int32 perfectInner = it->second[2].InnerLineWidth;
215 17 : sal_Int32 perfectOuter = it->second[2].OuterLineWidth;
216 17 : sal_Int32 perfectDistance = it->second[2].LineDistance;
217 17 : CPPUNIT_ASSERT_EQUAL(perfectInner, innerLineWidth);
218 17 : CPPUNIT_ASSERT_EQUAL(perfectOuter, outerLineWidth);
219 17 : CPPUNIT_ASSERT_EQUAL(perfectDistance, lineDistance);
220 : }
221 :
222 34 : uno::Any aBottomBorder = xPropSet->getPropertyValue("BottomBorder");
223 17 : table::BorderLine aBottomBorderLine;
224 17 : if (aBottomBorder >>= aBottomBorderLine)
225 : {
226 17 : sal_Int32 innerLineWidth = aBottomBorderLine.InnerLineWidth;
227 17 : sal_Int32 outerLineWidth = aBottomBorderLine.OuterLineWidth;
228 17 : sal_Int32 lineDistance = aBottomBorderLine.LineDistance;
229 :
230 17 : sal_Int32 perfectInner = it->second[3].InnerLineWidth;
231 17 : sal_Int32 perfectOuter = it->second[3].OuterLineWidth;
232 17 : sal_Int32 perfectDistance = it->second[3].LineDistance;
233 17 : CPPUNIT_ASSERT_EQUAL(perfectInner, innerLineWidth);
234 17 : CPPUNIT_ASSERT_EQUAL(perfectOuter, outerLineWidth);
235 17 : CPPUNIT_ASSERT_EQUAL(perfectDistance, lineDistance);
236 17 : }
237 : }
238 1 : } //end of the 'for' loop
239 : }
240 2 : }
241 3 : } while(xParaEnum->hasMoreElements());
242 1 : }
243 :
244 12 : DECLARE_ODFIMPORT_TEST(testPageStyleLayoutDefault, "hello.odt")
245 : {
246 1 : uno::Reference<beans::XPropertySet> xPropertySet(getStyles("PageStyles")->getByName("Default Style"), uno::UNO_QUERY);
247 : // This was style::PageStyleLayout_MIRRORED.
248 1 : CPPUNIT_ASSERT_EQUAL(style::PageStyleLayout_ALL, getProperty<style::PageStyleLayout>(xPropertySet, "PageStyleLayout"));
249 1 : }
250 :
251 12 : DECLARE_ODFIMPORT_TEST(testPageStyleLayoutRight, "hello.odt")
252 : {
253 1 : uno::Reference<beans::XPropertySet> xPropertySet(getStyles("PageStyles")->getByName("Default Style"), uno::UNO_QUERY);
254 : // This caused a crash.
255 1 : xPropertySet->setPropertyValue("PageStyleLayout", uno::makeAny(style::PageStyleLayout_RIGHT));
256 1 : }
257 :
258 12 : DECLARE_ODFIMPORT_TEST(testFdo61952, "hello.odt")
259 : {
260 1 : uno::Reference<beans::XPropertySet> xPara(getParagraph(0), uno::UNO_QUERY);
261 1 : xPara->setPropertyValue("PageDescName", uno::makeAny(OUString("Left Page")));
262 1 : xPara->setPropertyValue("PageDescName", uno::makeAny(OUString("Right Page")));
263 1 : xPara->setPropertyValue("PageDescName", uno::makeAny(OUString("Left Page")));
264 1 : xPara->setPropertyValue("PageDescName", uno::makeAny(OUString("Right Page")));
265 1 : }
266 :
267 12 : DECLARE_ODFIMPORT_TEST(testFdo60842, "fdo60842.odt")
268 : {
269 1 : uno::Reference<text::XTextContent> const xTable(getParagraphOrTable(0));
270 1 : getCell(xTable, "A1", "");
271 1 : getCell(xTable, "B1", "18/02/2012");
272 1 : getCell(xTable, "C1", "USD"); // this is the cell with office:string-value
273 1 : getCell(xTable, "D1", "");
274 1 : getCell(xTable, "E1", "01/04/2012");
275 1 : }
276 :
277 12 : DECLARE_ODFIMPORT_TEST(testFdo79269, "fdo79269.odt")
278 : {
279 1 : uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
280 2 : uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(xModel->getCurrentController(), uno::UNO_QUERY);
281 2 : uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY);
282 1 : xCursor->jumpToLastPage();
283 1 : CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xCursor->getPage());
284 :
285 : // The problem was that the first-footer was shared.
286 2 : uno::Reference<beans::XPropertySet> xPropSet(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY);
287 1 : CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xPropSet, "FirstIsShared"));
288 :
289 2 : uno::Reference<text::XTextRange> xFooter1 = getProperty< uno::Reference<text::XTextRange> >(xPropSet, "FooterTextFirst");
290 1 : CPPUNIT_ASSERT_EQUAL(OUString("forst"), xFooter1->getString());
291 2 : uno::Reference<text::XTextRange> xFooter = getProperty< uno::Reference<text::XTextRange> >(xPropSet, "FooterText");
292 2 : CPPUNIT_ASSERT_EQUAL(OUString("second"), xFooter->getString());
293 1 : }
294 :
295 12 : DECLARE_ODFIMPORT_TEST(testFdo79269_header, "fdo79269_header.odt")
296 : {
297 1 : uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
298 2 : uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(xModel->getCurrentController(), uno::UNO_QUERY);
299 2 : uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY);
300 1 : xCursor->jumpToLastPage();
301 1 : CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xCursor->getPage());
302 :
303 2 : uno::Reference<beans::XPropertySet> xPropSet(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY);
304 1 : CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xPropSet, "FirstIsShared"));
305 :
306 2 : uno::Reference<text::XTextRange> xFooter1 = getProperty< uno::Reference<text::XTextRange> >(xPropSet, "HeaderTextFirst");
307 1 : CPPUNIT_ASSERT_EQUAL(OUString("forst"), xFooter1->getString());
308 2 : uno::Reference<text::XTextRange> xFooter = getProperty< uno::Reference<text::XTextRange> >(xPropSet, "HeaderText");
309 2 : CPPUNIT_ASSERT_EQUAL(OUString("second"), xFooter->getString());
310 1 : }
311 :
312 12 : DECLARE_ODFIMPORT_TEST(testPageBackground, "PageBackground.odt")
313 : {
314 1 : uno::Reference<beans::XPropertySet> xPropertySet(getStyles("PageStyles")->getByName("Default Style"), uno::UNO_QUERY);
315 : // The background image was lost
316 1 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_BITMAP, getProperty<drawing::FillStyle>(xPropertySet, "FillStyle"));
317 1 : CPPUNIT_ASSERT_EQUAL(OUString("Sky"), getProperty<OUString>(xPropertySet, "FillBitmapName"));
318 1 : CPPUNIT_ASSERT_EQUAL(drawing::BitmapMode_REPEAT, getProperty<drawing::BitmapMode>(xPropertySet, "FillBitmapMode"));
319 :
320 2 : uno::Reference<beans::XPropertySet> xPropertySetOld(getStyles("PageStyles")->getByName("OldStandard"), uno::UNO_QUERY);
321 : // The background image was overridden by color
322 1 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_BITMAP, getProperty<drawing::FillStyle>(xPropertySetOld, "FillStyle"));
323 1 : CPPUNIT_ASSERT_EQUAL(OUString("Sky"), getProperty<OUString>(xPropertySetOld, "FillBitmapName"));
324 2 : CPPUNIT_ASSERT_EQUAL(drawing::BitmapMode_REPEAT, getProperty<drawing::BitmapMode>(xPropertySetOld, "FillBitmapMode"));
325 1 : }
326 :
327 12 : DECLARE_ODFIMPORT_TEST(testFdo56272, "fdo56272.odt")
328 : {
329 1 : uno::Reference<drawing::XShape> xShape = getShape(1);
330 : // Vertical position was incorrect.
331 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(422), xShape->getPosition().Y); // Was -2371
332 1 : }
333 :
334 12 : DECLARE_ODFIMPORT_TEST(testCalcFootnoteContent, "ooo32780-1.odt")
335 : {
336 : //this was a CalcFootnoteContent crash
337 1 : }
338 :
339 12 : DECLARE_ODFIMPORT_TEST(testMoveSubTree, "ooo77837-1.odt")
340 : {
341 : //this was a MoveSubTree crash
342 1 : }
343 :
344 12 : DECLARE_ODFIMPORT_TEST(testFdo75872_ooo33, "fdo75872_ooo33.odt")
345 : {
346 : // graphics default style: line color and fill color changed
347 1 : uno::Reference<drawing::XShape> xShape = getShape(1);
348 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(COL_BLACK),
349 1 : getProperty<sal_Int32>(xShape, "LineColor"));
350 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(RGB_COLORDATA(153, 204, 255)),
351 2 : getProperty<sal_Int32>(xShape, "FillColor"));
352 1 : }
353 :
354 12 : DECLARE_ODFIMPORT_TEST(testFdo75872_aoo40, "fdo75872_aoo40.odt")
355 : {
356 : // graphics default style: line color and fill color changed
357 1 : uno::Reference<drawing::XShape> xShape = getShape(1);
358 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(RGB_COLORDATA(128, 128, 128)),
359 1 : getProperty<sal_Int32>(xShape, "LineColor"));
360 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(RGB_COLORDATA(0xCF, 0xE7, 0xF5)),
361 2 : getProperty<sal_Int32>(xShape, "FillColor"));
362 1 : }
363 :
364 12 : DECLARE_ODFIMPORT_TEST(testFdo55814, "fdo55814.odt")
365 : {
366 1 : uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
367 2 : uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
368 2 : uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
369 2 : uno::Reference<beans::XPropertySet> xField(xFields->nextElement(), uno::UNO_QUERY);
370 1 : xField->setPropertyValue("Content", uno::makeAny(OUString("Yes")));
371 1 : uno::Reference<util::XRefreshable>(xTextFieldsSupplier->getTextFields(), uno::UNO_QUERY)->refresh();
372 2 : uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY);
373 2 : uno::Reference<container::XIndexAccess> xSections(xTextSectionsSupplier->getTextSections(), uno::UNO_QUERY);
374 : // This was "0".
375 2 : CPPUNIT_ASSERT_EQUAL(OUString("Hide==\"Yes\""), getProperty<OUString>(xSections->getByIndex(0), "Condition"));
376 1 : }
377 :
378 5 : void lcl_CheckShape(
379 : uno::Reference<drawing::XShape> const& xShape, OUString const& rExpected)
380 : {
381 5 : uno::Reference<container::XNamed> const xNamed(xShape, uno::UNO_QUERY);
382 5 : CPPUNIT_ASSERT(xNamed.is());
383 5 : CPPUNIT_ASSERT_EQUAL(rExpected, xNamed->getName());
384 5 : }
385 :
386 12 : DECLARE_ODFIMPORT_TEST(testFdo68839, "fdo68839.odt")
387 : {
388 : // check names
389 1 : lcl_CheckShape(getShape(1), "FrameXXX");
390 1 : lcl_CheckShape(getShape(2), "ObjectXXX");
391 1 : lcl_CheckShape(getShape(3), "FrameY");
392 1 : lcl_CheckShape(getShape(4), "graphicsXXX");
393 : try {
394 1 : uno::Reference<drawing::XShape> xShape = getShape(5);
395 0 : CPPUNIT_FAIL("IndexOutOfBoundsException expected");
396 1 : } catch (lang::IndexOutOfBoundsException const&) { }
397 : // check prev/next chain
398 1 : uno::Reference<beans::XPropertySet> xFrame1(getShape(1), uno::UNO_QUERY);
399 2 : uno::Reference<beans::XPropertySet> xFrame2(getShape(3), uno::UNO_QUERY);
400 2 : CPPUNIT_ASSERT_EQUAL(OUString(),
401 1 : getProperty<OUString>(xFrame1, "ChainPrevName"));
402 2 : CPPUNIT_ASSERT_EQUAL(OUString("FrameY"),
403 1 : getProperty<OUString>(xFrame1, "ChainNextName"));
404 2 : CPPUNIT_ASSERT_EQUAL(OUString("FrameXXX"),
405 1 : getProperty<OUString>(xFrame2, "ChainPrevName"));
406 2 : CPPUNIT_ASSERT_EQUAL(OUString(),
407 2 : getProperty<OUString>(xFrame2, "ChainNextName"));
408 1 : }
409 :
410 12 : DECLARE_ODFIMPORT_TEST(testFdo82165, "fdo82165.odt")
411 : {
412 : // there was a duplicate shape in the left header
413 1 : lcl_CheckShape(getShape(1), "Picture 9");
414 : try {
415 1 : uno::Reference<drawing::XShape> xShape = getShape(2);
416 0 : CPPUNIT_FAIL("IndexOutOfBoundsException expected");
417 1 : } catch (lang::IndexOutOfBoundsException const&) { }
418 1 : }
419 :
420 12 : DECLARE_ODFIMPORT_TEST(testTdf89802, "tdf89802.fodt")
421 : {
422 : // the text frame was dropped during import
423 1 : uno::Reference<text::XTextFramesSupplier> const xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
424 2 : uno::Reference<container::XIndexAccess> const xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
425 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
426 2 : uno::Reference<beans::XPropertySet> const xFrame(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
427 1 : sal_Int32 nValue(0);
428 1 : xFrame->getPropertyValue("BackColor") >>= nValue;
429 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0x3f004586), nValue);
430 1 : }
431 :
432 12 : DECLARE_ODFIMPORT_TEST(testFdo37606, "fdo37606.odt")
433 : {
434 1 : SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
435 1 : CPPUNIT_ASSERT(pTextDoc);
436 1 : SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
437 1 : SwShellCrsr* pShellCrsr = pWrtShell->getShellCrsr(false);
438 :
439 : {
440 1 : pWrtShell->SelAll(); // Selects A1.
441 1 : SwTextNode& rCellEnd = dynamic_cast<SwTextNode&>(pShellCrsr->End()->nNode.GetNode());
442 : // fdo#72486 This was "Hello.", i.e. a single select-all selected the whole document, not just the cell only.
443 1 : CPPUNIT_ASSERT_EQUAL(OUString("A1"), rCellEnd.GetText());
444 :
445 1 : pWrtShell->SelAll(); // Selects the whole table.
446 1 : pWrtShell->SelAll(); // Selects the whole document.
447 1 : SwTextNode& rStart = dynamic_cast<SwTextNode&>(pShellCrsr->Start()->nNode.GetNode());
448 1 : CPPUNIT_ASSERT_EQUAL(OUString("A1"), rStart.GetText());
449 :
450 1 : SwTextNode& rEnd = dynamic_cast<SwTextNode&>(pShellCrsr->End()->nNode.GetNode());
451 : // This was "A1", i.e. Ctrl-A only selected the A1 cell of the table, not the whole document.
452 1 : CPPUNIT_ASSERT_EQUAL(OUString("Hello."), rEnd.GetText());
453 : }
454 :
455 : {
456 1 : pWrtShell->SttEndDoc(false); // Go to the end of the doc.
457 1 : pWrtShell->SelAll(); // And now that we're outside of the table, try Ctrl-A again.
458 1 : SwTextNode& rStart = dynamic_cast<SwTextNode&>(pShellCrsr->Start()->nNode.GetNode());
459 : // This was "Hello", i.e. Ctrl-A did not select the starting table.
460 1 : CPPUNIT_ASSERT_EQUAL(OUString("A1"), rStart.GetText());
461 :
462 1 : SwTextNode& rEnd = dynamic_cast<SwTextNode&>(pShellCrsr->End()->nNode.GetNode());
463 1 : CPPUNIT_ASSERT_EQUAL(OUString("Hello."), rEnd.GetText());
464 : }
465 :
466 : {
467 1 : pWrtShell->Delete(); // Delete the selection
468 : // And make sure the table got deleted as well.
469 1 : SwNodes& rNodes = pWrtShell->GetDoc()->GetNodes();
470 1 : SwNodeIndex nNode(rNodes.GetEndOfExtras());
471 1 : SwContentNode* pContentNode = rNodes.GoNext(&nNode);
472 : // First content node was in a table -> table wasn't deleted.
473 1 : CPPUNIT_ASSERT(!pContentNode->FindTableNode());
474 : }
475 1 : }
476 :
477 12 : DECLARE_ODFIMPORT_TEST(testFdo37606Copy, "fdo37606.odt")
478 : {
479 1 : SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
480 1 : CPPUNIT_ASSERT(pTextDoc);
481 1 : SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
482 : // Ctrl-A
483 1 : pWrtShell->SelAll(); // Selects A1.
484 1 : pWrtShell->SelAll(); // Selects the whole table.
485 1 : pWrtShell->SelAll(); // Selects the whole document.
486 :
487 : // Ctrl-C
488 1 : SwTransferable* pTransferable = new SwTransferable(*pWrtShell);
489 1 : uno::Reference<datatransfer::XTransferable> xTransferable(pTransferable);
490 1 : pTransferable->Copy();
491 :
492 1 : pWrtShell->SttEndDoc(false); // Go to the end of the doc.
493 :
494 : // Ctrl-V
495 2 : TransferableDataHelper aDataHelper(TransferableDataHelper::CreateFromSystemClipboard(&pWrtShell->GetView().GetEditWin()));
496 1 : SwTransferable::Paste( *pWrtShell, aDataHelper );
497 :
498 : // Previously copy&paste failed to copy the table in case it was the document-starting one.
499 2 : uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
500 2 : uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY);
501 : #if !defined(MACOSX) && !defined(LIBO_HEADLESS) // FIXME
502 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTables->getCount());
503 : #endif
504 1 : }
505 :
506 12 : DECLARE_ODFIMPORT_TEST(testFdo69862, "fdo69862.odt")
507 : {
508 : // The test doc is special in that it starts with a table and it also has a footnote.
509 1 : SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
510 1 : CPPUNIT_ASSERT(pTextDoc);
511 1 : SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
512 1 : SwShellCrsr* pShellCrsr = pWrtShell->getShellCrsr(false);
513 :
514 1 : pWrtShell->SelAll(); // Selects A1.
515 1 : pWrtShell->SelAll(); // Selects the whole table.
516 1 : pWrtShell->SelAll(); // Selects the whole document.
517 1 : SwTextNode& rStart = dynamic_cast<SwTextNode&>(pShellCrsr->Start()->nNode.GetNode());
518 : // This was "Footnote.", as Ctrl-A also selected footnotes, but it should not.
519 1 : CPPUNIT_ASSERT_EQUAL(OUString("A1"), rStart.GetText());
520 :
521 1 : SwTextNode& rEnd = dynamic_cast<SwTextNode&>(pShellCrsr->End()->nNode.GetNode());
522 1 : CPPUNIT_ASSERT_EQUAL(OUString("H" "\x01" "ello."), rEnd.GetText());
523 1 : }
524 :
525 12 : DECLARE_ODFIMPORT_TEST(testFdo69979, "fdo69979.odt")
526 : {
527 : // The test doc is special in that it starts with a table and it also has a header.
528 1 : SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
529 1 : CPPUNIT_ASSERT(pTextDoc);
530 1 : SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
531 1 : SwShellCrsr* pShellCrsr = pWrtShell->getShellCrsr(false);
532 :
533 1 : pWrtShell->SelAll(); // Selects A1.
534 1 : pWrtShell->SelAll(); // Selects the whole table.
535 1 : pWrtShell->SelAll(); // Selects the whole document.
536 1 : SwTextNode& rStart = dynamic_cast<SwTextNode&>(pShellCrsr->Start()->nNode.GetNode());
537 : // This was "", as Ctrl-A also selected headers, but it should not.
538 1 : CPPUNIT_ASSERT_EQUAL(OUString("A1"), rStart.GetText());
539 :
540 1 : SwTextNode& rEnd = dynamic_cast<SwTextNode&>(pShellCrsr->End()->nNode.GetNode());
541 1 : CPPUNIT_ASSERT_EQUAL(OUString("Hello."), rEnd.GetText());
542 1 : }
543 :
544 12 : DECLARE_ODFIMPORT_TEST(testSpellmenuRedline, "spellmenu-redline.odt")
545 : {
546 1 : SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
547 1 : CPPUNIT_ASSERT(pTextDoc);
548 1 : SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
549 1 : OUString aParaText;
550 2 : uno::Reference<linguistic2::XSpellAlternatives> xAlt;
551 2 : SwSpellPopup aPopup(pWrtShell, xAlt, aParaText);
552 : // Make sure that if we show the spellcheck popup menu (for the current
553 : // document, which contains redlines), then the last two entries will be
554 : // always 'go to next/previous change'.
555 1 : CPPUNIT_ASSERT_EQUAL(sal_uInt16(FN_REDLINE_NEXT_CHANGE), aPopup.GetItemId(aPopup.GetItemCount() - 2));
556 2 : CPPUNIT_ASSERT_EQUAL(sal_uInt16(FN_REDLINE_PREV_CHANGE), aPopup.GetItemId(aPopup.GetItemCount() - 1));
557 1 : }
558 :
559 12 : DECLARE_ODFIMPORT_TEST(testAnnotationFormatting, "annotation-formatting.odt")
560 : {
561 1 : uno::Reference<beans::XPropertySet> xTextField = getProperty< uno::Reference<beans::XPropertySet> >(getRun(getParagraph(1), 1), "TextField");
562 2 : uno::Reference<text::XText> xText = getProperty< uno::Reference<text::XText> >(xTextField, "TextRange");
563 : // Make sure we test the right annotation.
564 2 : uno::Reference<text::XTextRange> xParagraph = getParagraphOfText(1, xText, "Looses: bold");
565 : // Formatting was lost: the second text portion was NORMAL, not BOLD.
566 2 : CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, getProperty<float>(getRun(xParagraph, 2), "CharWeight"));
567 1 : }
568 :
569 12 : DECLARE_ODFIMPORT_TEST(fdo81223, "fdo81223.odt")
570 : {
571 1 : uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
572 2 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
573 2 : uno::Reference<beans::XPropertySet> xFrame(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
574 1 : sal_Int32 nValue(0);
575 1 : xFrame->getPropertyValue("BackColor") >>= nValue;
576 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0xffffffff), nValue);
577 1 : }
578 :
579 12 : DECLARE_ODFIMPORT_TEST(fdo90130_1, "fdo90130-1.odt")
580 : {
581 1 : uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
582 2 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
583 2 : uno::Reference<beans::XPropertySet> xFrame(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
584 1 : sal_Int32 nValue(0);
585 1 : xFrame->getPropertyValue("BackColor") >>= nValue;
586 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0x00ff3333), nValue);
587 1 : }
588 :
589 12 : DECLARE_ODFIMPORT_TEST(fdo90130_2, "fdo90130-2.odt")
590 : {
591 1 : uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
592 2 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
593 2 : uno::Reference<beans::XPropertySet> xFrame(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
594 1 : sal_Int32 nValue(0);
595 1 : xFrame->getPropertyValue("BackColorTransparency") >>= nValue;
596 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(50), nValue);
597 1 : }
598 :
599 12 : DECLARE_ODFIMPORT_TEST(testBnc800714, "bnc800714.fodt")
600 : {
601 : // Document's second paragraph wants to be together with the third one, but:
602 : // - it's in a section with multiple columns
603 : // - contains a single as-char anchored frame
604 : // This was a layout loop.
605 1 : CPPUNIT_ASSERT(getProperty< uno::Reference<text::XTextSection> >(getParagraph(2), "TextSection").is());
606 1 : CPPUNIT_ASSERT(getProperty<bool>(getParagraph(2), "ParaKeepTogether"));
607 1 : }
608 :
609 : #endif
610 :
611 4 : CPPUNIT_PLUGIN_IMPLEMENT();
612 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|