Line data Source code
1 : /*
2 : * This file is part of the LibreOffice project.
3 : *
4 : * This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this
6 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 : */
8 :
9 : #include <swmodeltestbase.hxx>
10 :
11 : #if !defined(MACOSX) && !defined(WNT)
12 :
13 : #include <com/sun/star/awt/FontWeight.hpp>
14 : #include <com/sun/star/style/PageStyleLayout.hpp>
15 : #include <com/sun/star/table/XCell.hpp>
16 : #include <com/sun/star/table/BorderLine.hpp>
17 : #include <com/sun/star/text/XTextTable.hpp>
18 :
19 : #include <wrtsh.hxx>
20 : #include <ndtxt.hxx>
21 : #include <swdtflvr.hxx>
22 : #include <view.hxx>
23 : #include <edtwin.hxx>
24 : #include <olmenu.hxx>
25 : #include <cmdid.h>
26 :
27 : typedef std::map<OUString, com::sun::star::uno::Sequence< com::sun::star::table::BorderLine> > AllBordersMap;
28 : typedef std::pair<OUString, com::sun::star::uno::Sequence< com::sun::star::table::BorderLine> > StringSequencePair;
29 :
30 18 : class Test : public SwModelTestBase
31 : {
32 : public:
33 18 : Test() : SwModelTestBase("/sw/qa/extras/odfimport/data/", "writer8") {}
34 : };
35 :
36 : #define DECLARE_ODFIMPORT_TEST(TestName, filename) DECLARE_SW_IMPORT_TEST(TestName, filename, Test)
37 :
38 9 : DECLARE_ODFIMPORT_TEST(testEmptySvgFamilyName, "empty-svg-family-name.odt")
39 : {
40 : // .odt import did crash on the empty font list (which I think is valid according SVG spec)
41 1 : }
42 :
43 9 : DECLARE_ODFIMPORT_TEST(testHideAllSections, "fdo53210.odt")
44 : {
45 : // This document has a section that is conditionally hidden, but has no empty paragraph after it.
46 1 : uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
47 2 : uno::Reference<container::XNameAccess> xMasters = xTextFieldsSupplier->getTextFieldMasters();
48 : // Set _CS_Allgemein to 0
49 2 : uno::Reference<beans::XPropertySet> xMaster(xMasters->getByName("com.sun.star.text.fieldmaster.User._CS_Allgemein"), uno::UNO_QUERY);
50 1 : xMaster->setPropertyValue("Content", uno::makeAny(OUString("0")));
51 : // This used to crash
52 2 : uno::Reference<util::XRefreshable>(xTextFieldsSupplier->getTextFields(), uno::UNO_QUERY)->refresh();
53 1 : }
54 :
55 9 : DECLARE_ODFIMPORT_TEST(testOdtBorders, "borders_ooo33.odt")
56 : {
57 1 : AllBordersMap map;
58 2 : uno::Sequence< table::BorderLine > tempSequence(4);
59 :
60 1 : tempSequence[0] = table::BorderLine(0, 2, 2, 35); // left
61 1 : tempSequence[1] = table::BorderLine(0, 2, 2, 35); // right
62 1 : tempSequence[2] = table::BorderLine(0, 2, 2, 35); // top
63 1 : tempSequence[3] = table::BorderLine(0, 2, 2, 35); // bottom
64 1 : map.insert(StringSequencePair(OUString("B2"), tempSequence));
65 1 : tempSequence[0] = table::BorderLine(0, 0, 2, 0);
66 1 : tempSequence[1] = table::BorderLine(0, 0, 2, 0);
67 1 : tempSequence[2] = table::BorderLine(0, 0, 2, 0);
68 1 : tempSequence[3] = table::BorderLine(0, 0, 2, 0);
69 1 : map.insert(StringSequencePair(OUString("D2"), tempSequence));
70 1 : tempSequence[0] = table::BorderLine(0, 2, 2, 88);
71 1 : tempSequence[1] = table::BorderLine(0, 2, 2, 88);
72 1 : tempSequence[2] = table::BorderLine(0, 2, 2, 88);
73 1 : tempSequence[3] = table::BorderLine(0, 2, 2, 88);
74 1 : map.insert(StringSequencePair(OUString("B4"), tempSequence));
75 1 : tempSequence[0] = table::BorderLine(0, 0, 18, 0);
76 1 : tempSequence[1] = table::BorderLine(0, 0, 18, 0);
77 1 : tempSequence[2] = table::BorderLine(0, 0, 18, 0);
78 1 : tempSequence[3] = table::BorderLine(0, 0, 18, 0);
79 1 : map.insert(StringSequencePair(OUString("D4"), tempSequence));
80 1 : tempSequence[0] = table::BorderLine(0, 35, 35, 35);
81 1 : tempSequence[1] = table::BorderLine(0, 35, 35, 35);
82 1 : tempSequence[2] = table::BorderLine(0, 35, 35, 35);
83 1 : tempSequence[3] = table::BorderLine(0, 35, 35, 35);
84 1 : map.insert(StringSequencePair(OUString("B6"), tempSequence));
85 1 : tempSequence[0] = table::BorderLine(0, 0, 35, 0);
86 1 : tempSequence[1] = table::BorderLine(0, 0, 35, 0);
87 1 : tempSequence[2] = table::BorderLine(0, 0, 35, 0);
88 1 : tempSequence[3] = table::BorderLine(0, 0, 35, 0);
89 1 : map.insert(StringSequencePair(OUString("D6"), tempSequence));
90 1 : tempSequence[0] = table::BorderLine(0, 88, 88, 88);
91 1 : tempSequence[1] = table::BorderLine(0, 88, 88, 88);
92 1 : tempSequence[2] = table::BorderLine(0, 88, 88, 88);
93 1 : tempSequence[3] = table::BorderLine(0, 88, 88, 88);
94 1 : map.insert(StringSequencePair(OUString("B8"), tempSequence));
95 1 : tempSequence[0] = table::BorderLine(0, 0, 88, 0);
96 1 : tempSequence[1] = table::BorderLine(0, 0, 88, 0);
97 1 : tempSequence[2] = table::BorderLine(0, 0, 88, 0);
98 1 : tempSequence[3] = table::BorderLine(0, 0, 88, 0);
99 1 : map.insert(StringSequencePair(OUString("D8"), tempSequence));
100 1 : tempSequence[0] = table::BorderLine(0, 2, 35, 88);
101 1 : tempSequence[1] = table::BorderLine(0, 2, 35, 88);
102 1 : tempSequence[2] = table::BorderLine(0, 2, 35, 88);
103 1 : tempSequence[3] = table::BorderLine(0, 2, 35, 88);
104 1 : map.insert(StringSequencePair(OUString("B10"), tempSequence));
105 1 : tempSequence[0] = table::BorderLine(0, 0, 141, 0);
106 1 : tempSequence[1] = table::BorderLine(0, 0, 141, 0);
107 1 : tempSequence[2] = table::BorderLine(0, 0, 141, 0);
108 1 : tempSequence[3] = table::BorderLine(0, 0, 141, 0);
109 1 : map.insert(StringSequencePair(OUString("D10"), tempSequence));
110 1 : tempSequence[0] = table::BorderLine(0, 2, 88, 88);
111 1 : tempSequence[1] = table::BorderLine(0, 2, 88, 88);
112 1 : tempSequence[2] = table::BorderLine(0, 2, 88, 88);
113 1 : tempSequence[3] = table::BorderLine(0, 2, 88, 88);
114 1 : map.insert(StringSequencePair(OUString("B12"), tempSequence));
115 1 : tempSequence[0] = table::BorderLine(0, 0, 176, 0);
116 1 : tempSequence[1] = table::BorderLine(0, 0, 176, 0);
117 1 : tempSequence[2] = table::BorderLine(0, 0, 176, 0);
118 1 : tempSequence[3] = table::BorderLine(0, 0, 176, 0);
119 1 : map.insert(StringSequencePair(OUString("D12"), tempSequence));
120 1 : tempSequence[0] = table::BorderLine(0, 2, 141, 88);
121 1 : tempSequence[1] = table::BorderLine(0, 2, 141, 88);
122 1 : tempSequence[2] = table::BorderLine(0, 2, 141, 88);
123 1 : tempSequence[3] = table::BorderLine(0, 2, 141, 88);
124 1 : map.insert(StringSequencePair(OUString("B14"), tempSequence));
125 1 : tempSequence[0] = table::BorderLine(0, 35, 88, 88);
126 1 : tempSequence[1] = table::BorderLine(0, 35, 88, 88);
127 1 : tempSequence[2] = table::BorderLine(0, 35, 88, 88);
128 1 : tempSequence[3] = table::BorderLine(0, 35, 88, 88);
129 1 : map.insert(StringSequencePair(OUString("B16"), tempSequence));
130 1 : tempSequence[0] = table::BorderLine(0, 88, 35, 35);
131 1 : tempSequence[1] = table::BorderLine(0, 88, 35, 35);
132 1 : tempSequence[2] = table::BorderLine(0, 88, 35, 35);
133 1 : tempSequence[3] = table::BorderLine(0, 88, 35, 35);
134 1 : map.insert(StringSequencePair(OUString("B18"), tempSequence));
135 1 : tempSequence[0] = table::BorderLine(0, 88, 141, 88);
136 1 : tempSequence[1] = table::BorderLine(0, 88, 141, 88);
137 1 : tempSequence[2] = table::BorderLine(0, 88, 141, 88);
138 1 : tempSequence[3] = table::BorderLine(0, 88, 141, 88);
139 1 : map.insert(StringSequencePair(OUString("B20"), tempSequence));
140 1 : tempSequence[0] = table::BorderLine(0, 141, 88, 88);
141 1 : tempSequence[1] = table::BorderLine(0, 141, 88, 88);
142 1 : tempSequence[2] = table::BorderLine(0, 141, 88, 88);
143 1 : tempSequence[3] = table::BorderLine(0, 141, 88, 88);
144 1 : map.insert(StringSequencePair(OUString("B22"), tempSequence));
145 :
146 2 : uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
147 2 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(textDocument->getText(), uno::UNO_QUERY);
148 : // list of paragraphs
149 2 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
150 2 : do
151 : {
152 2 : uno::Reference<lang::XServiceInfo> xServiceInfo;
153 2 : if (xParaEnum->nextElement() >>= xServiceInfo)
154 : {
155 2 : if (xServiceInfo->supportsService("com.sun.star.text.TextTable"))
156 : {
157 1 : uno::Reference<text::XTextTable> const xTextTable(xServiceInfo, uno::UNO_QUERY_THROW);
158 2 : uno::Sequence<OUString> const cells = xTextTable->getCellNames();
159 1 : sal_Int32 nLength = cells.getLength();
160 :
161 1 : AllBordersMap::iterator it;
162 1 : it = map.begin();
163 :
164 116 : for (sal_Int32 i = 0; i < nLength; ++i)
165 : {
166 115 : if(i%10==6 || (i%10==8 && i<60)) // only B and D cells have borders, every 2 rows
167 : {
168 17 : uno::Reference<table::XCell> xCell = xTextTable->getCellByName(cells[i]);
169 34 : uno::Reference< beans::XPropertySet > xPropSet(xCell, uno::UNO_QUERY_THROW);
170 17 : it = map.find(cells[i]);
171 :
172 34 : uno::Any aLeftBorder = xPropSet->getPropertyValue("LeftBorder");
173 17 : table::BorderLine aLeftBorderLine;
174 17 : if (aLeftBorder >>= aLeftBorderLine)
175 : {
176 17 : sal_Int32 innerLineWidth = aLeftBorderLine.InnerLineWidth;
177 17 : sal_Int32 outerLineWidth = aLeftBorderLine.OuterLineWidth;
178 17 : sal_Int32 lineDistance = aLeftBorderLine.LineDistance;
179 :
180 17 : sal_Int32 perfectInner = it->second[0].InnerLineWidth;
181 17 : sal_Int32 perfectOuter = it->second[0].OuterLineWidth;
182 17 : sal_Int32 perfectDistance = it->second[0].LineDistance;
183 17 : CPPUNIT_ASSERT_EQUAL(perfectInner, innerLineWidth);
184 17 : CPPUNIT_ASSERT_EQUAL(perfectOuter, outerLineWidth);
185 17 : CPPUNIT_ASSERT_EQUAL(perfectDistance, lineDistance);
186 : }
187 :
188 34 : uno::Any aRightBorder = xPropSet->getPropertyValue("RightBorder");
189 17 : table::BorderLine aRightBorderLine;
190 17 : if (aRightBorder >>= aRightBorderLine)
191 : {
192 17 : sal_Int32 innerLineWidth = aRightBorderLine.InnerLineWidth;
193 17 : sal_Int32 outerLineWidth = aRightBorderLine.OuterLineWidth;
194 17 : sal_Int32 lineDistance = aRightBorderLine.LineDistance;
195 :
196 17 : sal_Int32 perfectInner = it->second[1].InnerLineWidth;
197 17 : sal_Int32 perfectOuter = it->second[1].OuterLineWidth;
198 17 : sal_Int32 perfectDistance = it->second[1].LineDistance;
199 17 : CPPUNIT_ASSERT_EQUAL(perfectInner, innerLineWidth);
200 17 : CPPUNIT_ASSERT_EQUAL(perfectOuter, outerLineWidth);
201 17 : CPPUNIT_ASSERT_EQUAL(perfectDistance, lineDistance);
202 : }
203 :
204 34 : uno::Any aTopBorder = xPropSet->getPropertyValue("TopBorder");
205 17 : table::BorderLine aTopBorderLine;
206 17 : if (aTopBorder >>= aTopBorderLine)
207 : {
208 17 : sal_Int32 innerLineWidth = aTopBorderLine.InnerLineWidth;
209 17 : sal_Int32 outerLineWidth = aTopBorderLine.OuterLineWidth;
210 17 : sal_Int32 lineDistance = aTopBorderLine.LineDistance;
211 :
212 17 : sal_Int32 perfectInner = it->second[2].InnerLineWidth;
213 17 : sal_Int32 perfectOuter = it->second[2].OuterLineWidth;
214 17 : sal_Int32 perfectDistance = it->second[2].LineDistance;
215 17 : CPPUNIT_ASSERT_EQUAL(perfectInner, innerLineWidth);
216 17 : CPPUNIT_ASSERT_EQUAL(perfectOuter, outerLineWidth);
217 17 : CPPUNIT_ASSERT_EQUAL(perfectDistance, lineDistance);
218 : }
219 :
220 34 : uno::Any aBottomBorder = xPropSet->getPropertyValue("BottomBorder");
221 17 : table::BorderLine aBottomBorderLine;
222 17 : if (aBottomBorder >>= aBottomBorderLine)
223 : {
224 17 : sal_Int32 innerLineWidth = aBottomBorderLine.InnerLineWidth;
225 17 : sal_Int32 outerLineWidth = aBottomBorderLine.OuterLineWidth;
226 17 : sal_Int32 lineDistance = aBottomBorderLine.LineDistance;
227 :
228 17 : sal_Int32 perfectInner = it->second[3].InnerLineWidth;
229 17 : sal_Int32 perfectOuter = it->second[3].OuterLineWidth;
230 17 : sal_Int32 perfectDistance = it->second[3].LineDistance;
231 17 : CPPUNIT_ASSERT_EQUAL(perfectInner, innerLineWidth);
232 17 : CPPUNIT_ASSERT_EQUAL(perfectOuter, outerLineWidth);
233 17 : CPPUNIT_ASSERT_EQUAL(perfectDistance, lineDistance);
234 17 : }
235 : }
236 1 : } //end of the 'for' loop
237 : }
238 2 : }
239 3 : } while(xParaEnum->hasMoreElements());
240 1 : }
241 :
242 9 : DECLARE_ODFIMPORT_TEST(testPageStyleLayoutDefault, "hello.odt")
243 : {
244 1 : uno::Reference<beans::XPropertySet> xPropertySet(getStyles("PageStyles")->getByName("Default Style"), uno::UNO_QUERY);
245 : // This was style::PageStyleLayout_MIRRORED.
246 1 : CPPUNIT_ASSERT_EQUAL(style::PageStyleLayout_ALL, getProperty<style::PageStyleLayout>(xPropertySet, "PageStyleLayout"));
247 1 : }
248 :
249 9 : DECLARE_ODFIMPORT_TEST(testPageStyleLayoutRight, "hello.odt")
250 : {
251 1 : uno::Reference<beans::XPropertySet> xPropertySet(getStyles("PageStyles")->getByName("Default Style"), uno::UNO_QUERY);
252 : // This caused a crash.
253 1 : xPropertySet->setPropertyValue("PageStyleLayout", uno::makeAny(style::PageStyleLayout_RIGHT));
254 1 : }
255 :
256 9 : DECLARE_ODFIMPORT_TEST(testFdo61952, "hello.odt")
257 : {
258 1 : uno::Reference<beans::XPropertySet> xPara(getParagraph(0), uno::UNO_QUERY);
259 1 : xPara->setPropertyValue("PageDescName", uno::makeAny(OUString("Left Page")));
260 1 : xPara->setPropertyValue("PageDescName", uno::makeAny(OUString("Right Page")));
261 1 : xPara->setPropertyValue("PageDescName", uno::makeAny(OUString("Left Page")));
262 1 : xPara->setPropertyValue("PageDescName", uno::makeAny(OUString("Right Page")));
263 1 : }
264 :
265 9 : DECLARE_ODFIMPORT_TEST(testFdo60842, "fdo60842.odt")
266 : {
267 1 : uno::Reference<text::XTextContent> const xTable(getParagraphOrTable(0));
268 1 : getCell(xTable, "A1", "");
269 1 : getCell(xTable, "B1", "18/02/2012");
270 1 : getCell(xTable, "C1", "USD"); // this is the cell with office:string-value
271 1 : getCell(xTable, "D1", "");
272 1 : getCell(xTable, "E1", "01/04/2012");
273 1 : }
274 :
275 9 : DECLARE_ODFIMPORT_TEST(testFdo56272, "fdo56272.odt")
276 : {
277 1 : uno::Reference<drawing::XShape> xShape = getShape(1);
278 : // Vertical position was incorrect.
279 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(422), xShape->getPosition().Y); // Was -2371
280 1 : }
281 :
282 9 : DECLARE_ODFIMPORT_TEST(testFdo75872_ooo33, "fdo75872_ooo33.odt")
283 : {
284 : // graphics default style: line color and fill color changed
285 1 : uno::Reference<drawing::XShape> xShape = getShape(1);
286 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(COL_BLACK),
287 1 : getProperty<sal_Int32>(xShape, "LineColor"));
288 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(RGB_COLORDATA(153, 204, 255)),
289 2 : getProperty<sal_Int32>(xShape, "FillColor"));
290 1 : }
291 :
292 9 : DECLARE_ODFIMPORT_TEST(testFdo75872_aoo40, "fdo75872_aoo40.odt")
293 : {
294 : // graphics default style: line color and fill color changed
295 1 : uno::Reference<drawing::XShape> xShape = getShape(1);
296 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(RGB_COLORDATA(128, 128, 128)),
297 1 : getProperty<sal_Int32>(xShape, "LineColor"));
298 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(RGB_COLORDATA(0xCF, 0xE7, 0xF5)),
299 2 : getProperty<sal_Int32>(xShape, "FillColor"));
300 1 : }
301 :
302 9 : DECLARE_ODFIMPORT_TEST(testFdo55814, "fdo55814.odt")
303 : {
304 1 : uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
305 2 : uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
306 2 : uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
307 2 : uno::Reference<beans::XPropertySet> xField(xFields->nextElement(), uno::UNO_QUERY);
308 1 : xField->setPropertyValue("Content", uno::makeAny(OUString("Yes")));
309 1 : uno::Reference<util::XRefreshable>(xTextFieldsSupplier->getTextFields(), uno::UNO_QUERY)->refresh();
310 2 : uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY);
311 2 : uno::Reference<container::XIndexAccess> xSections(xTextSectionsSupplier->getTextSections(), uno::UNO_QUERY);
312 : // This was "0".
313 2 : CPPUNIT_ASSERT_EQUAL(OUString("Hide==\"Yes\""), getProperty<OUString>(xSections->getByIndex(0), "Condition"));
314 1 : }
315 :
316 4 : void lcl_CheckShape(
317 : uno::Reference<drawing::XShape> const& xShape, OUString const& rExpected)
318 : {
319 4 : uno::Reference<container::XNamed> const xNamed(xShape, uno::UNO_QUERY);
320 4 : CPPUNIT_ASSERT(xNamed.is());
321 4 : CPPUNIT_ASSERT_EQUAL(rExpected, xNamed->getName());
322 4 : }
323 :
324 9 : DECLARE_ODFIMPORT_TEST(testFdo68839, "fdo68839.odt")
325 : {
326 : // check names
327 1 : lcl_CheckShape(getShape(1), "FrameXXX");
328 1 : lcl_CheckShape(getShape(2), "ObjectXXX");
329 1 : lcl_CheckShape(getShape(3), "FrameY");
330 1 : lcl_CheckShape(getShape(4), "graphicsXXX");
331 : try {
332 1 : uno::Reference<drawing::XShape> xShape = getShape(5);
333 0 : CPPUNIT_FAIL("IndexOutOfBoundsException expected");
334 1 : } catch (lang::IndexOutOfBoundsException const&) { }
335 : // check prev/next chain
336 1 : uno::Reference<beans::XPropertySet> xFrame1(getShape(1), uno::UNO_QUERY);
337 2 : uno::Reference<beans::XPropertySet> xFrame2(getShape(3), uno::UNO_QUERY);
338 2 : CPPUNIT_ASSERT_EQUAL(OUString(),
339 1 : getProperty<OUString>(xFrame1, "ChainPrevName"));
340 2 : CPPUNIT_ASSERT_EQUAL(OUString("FrameY"),
341 1 : getProperty<OUString>(xFrame1, "ChainNextName"));
342 2 : CPPUNIT_ASSERT_EQUAL(OUString("FrameXXX"),
343 1 : getProperty<OUString>(xFrame2, "ChainPrevName"));
344 2 : CPPUNIT_ASSERT_EQUAL(OUString(),
345 2 : getProperty<OUString>(xFrame2, "ChainNextName"));
346 1 : }
347 :
348 9 : DECLARE_ODFIMPORT_TEST(testFdo37606, "fdo37606.odt")
349 : {
350 1 : SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
351 1 : CPPUNIT_ASSERT(pTxtDoc);
352 1 : SwWrtShell* pWrtShell = pTxtDoc->GetDocShell()->GetWrtShell();
353 1 : SwShellCrsr* pShellCrsr = pWrtShell->getShellCrsr(false);
354 :
355 : {
356 1 : pWrtShell->SelAll();
357 1 : SwTxtNode& rStart = dynamic_cast<SwTxtNode&>(pShellCrsr->Start()->nNode.GetNode());
358 1 : CPPUNIT_ASSERT_EQUAL(OUString("A1"), rStart.GetTxt());
359 :
360 1 : SwTxtNode& rEnd = dynamic_cast<SwTxtNode&>(pShellCrsr->End()->nNode.GetNode());
361 : // This was "A1", i.e. Ctrl-A only selected the A1 cell of the table, not the whole document.
362 1 : CPPUNIT_ASSERT_EQUAL(OUString("Hello."), rEnd.GetTxt());
363 : }
364 :
365 : {
366 1 : pWrtShell->SttEndDoc(false); // Go to the end of the doc.
367 1 : pWrtShell->SelAll(); // And now that we're outside of the table, try Ctrl-A again.
368 1 : SwTxtNode& rStart = dynamic_cast<SwTxtNode&>(pShellCrsr->Start()->nNode.GetNode());
369 : // This was "Hello", i.e. Ctrl-A did not select the starting table.
370 1 : CPPUNIT_ASSERT_EQUAL(OUString("A1"), rStart.GetTxt());
371 :
372 1 : SwTxtNode& rEnd = dynamic_cast<SwTxtNode&>(pShellCrsr->End()->nNode.GetNode());
373 1 : CPPUNIT_ASSERT_EQUAL(OUString("Hello."), rEnd.GetTxt());
374 : }
375 :
376 : {
377 1 : pWrtShell->Delete(); // Delete the selection
378 : // And make sure the table got deleted as well.
379 1 : SwNodes& rNodes = pWrtShell->GetDoc()->GetNodes();
380 1 : SwNodeIndex nNode(rNodes.GetEndOfExtras());
381 1 : SwCntntNode* pCntntNode = rNodes.GoNext(&nNode);
382 : // First content node was in a table -> table wasn't deleted.
383 1 : CPPUNIT_ASSERT(!pCntntNode->FindTableNode());
384 : }
385 1 : }
386 :
387 9 : DECLARE_ODFIMPORT_TEST(testFdo37606Copy, "fdo37606.odt")
388 : {
389 1 : SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
390 1 : CPPUNIT_ASSERT(pTxtDoc);
391 1 : SwWrtShell* pWrtShell = pTxtDoc->GetDocShell()->GetWrtShell();
392 : // Ctrl-A
393 1 : pWrtShell->SelAll();
394 :
395 : // Ctrl-C
396 1 : SwTransferable* pTransferable = new SwTransferable(*pWrtShell);
397 1 : uno::Reference<datatransfer::XTransferable> xTransferable(pTransferable);
398 1 : pTransferable->Copy();
399 :
400 1 : pWrtShell->SttEndDoc(false); // Go to the end of the doc.
401 :
402 : // Ctrl-V
403 2 : TransferableDataHelper aDataHelper(TransferableDataHelper::CreateFromSystemClipboard(&pWrtShell->GetView().GetEditWin()));
404 1 : SwTransferable::Paste( *pWrtShell, aDataHelper );
405 :
406 : // Previously copy&paste failed to copy the table in case it was the document-starting one.
407 2 : uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
408 2 : uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY);
409 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTables->getCount());
410 1 : }
411 :
412 9 : DECLARE_ODFIMPORT_TEST(testFdo69862, "fdo69862.odt")
413 : {
414 : // The test doc is special in that it starts with a table and it also has a footnote.
415 1 : SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
416 1 : CPPUNIT_ASSERT(pTxtDoc);
417 1 : SwWrtShell* pWrtShell = pTxtDoc->GetDocShell()->GetWrtShell();
418 1 : SwShellCrsr* pShellCrsr = pWrtShell->getShellCrsr(false);
419 :
420 1 : pWrtShell->SelAll();
421 1 : SwTxtNode& rStart = dynamic_cast<SwTxtNode&>(pShellCrsr->Start()->nNode.GetNode());
422 : // This was "Footnote.", as Ctrl-A also selected footnotes, but it should not.
423 1 : CPPUNIT_ASSERT_EQUAL(OUString("A1"), rStart.GetTxt());
424 :
425 1 : SwTxtNode& rEnd = dynamic_cast<SwTxtNode&>(pShellCrsr->End()->nNode.GetNode());
426 1 : CPPUNIT_ASSERT_EQUAL(OUString("H" "\x01" "ello."), rEnd.GetTxt());
427 1 : }
428 :
429 9 : DECLARE_ODFIMPORT_TEST(testFdo69979, "fdo69979.odt")
430 : {
431 : // The test doc is special in that it starts with a table and it also has a header.
432 1 : SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
433 1 : CPPUNIT_ASSERT(pTxtDoc);
434 1 : SwWrtShell* pWrtShell = pTxtDoc->GetDocShell()->GetWrtShell();
435 1 : SwShellCrsr* pShellCrsr = pWrtShell->getShellCrsr(false);
436 :
437 1 : pWrtShell->SelAll();
438 1 : SwTxtNode& rStart = dynamic_cast<SwTxtNode&>(pShellCrsr->Start()->nNode.GetNode());
439 : // This was "", as Ctrl-A also selected headers, but it should not.
440 1 : CPPUNIT_ASSERT_EQUAL(OUString("A1"), rStart.GetTxt());
441 :
442 1 : SwTxtNode& rEnd = dynamic_cast<SwTxtNode&>(pShellCrsr->End()->nNode.GetNode());
443 1 : CPPUNIT_ASSERT_EQUAL(OUString("Hello."), rEnd.GetTxt());
444 1 : }
445 :
446 9 : DECLARE_ODFIMPORT_TEST(testSpellmenuRedline, "spellmenu-redline.odt")
447 : {
448 1 : SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
449 1 : CPPUNIT_ASSERT(pTxtDoc);
450 1 : SwWrtShell* pWrtShell = pTxtDoc->GetDocShell()->GetWrtShell();
451 1 : OUString aParaText;
452 2 : uno::Reference<linguistic2::XSpellAlternatives> xAlt;
453 2 : SwSpellPopup aPopup(pWrtShell, xAlt, aParaText);
454 : // Make sure that if we show the spellcheck popup menu (for the current
455 : // document, which contains redlines), then the last two entries will be
456 : // always 'go to next/previous change'.
457 1 : CPPUNIT_ASSERT_EQUAL(sal_uInt16(FN_REDLINE_NEXT_CHANGE), aPopup.GetItemId(aPopup.GetItemCount() - 2));
458 2 : CPPUNIT_ASSERT_EQUAL(sal_uInt16(FN_REDLINE_PREV_CHANGE), aPopup.GetItemId(aPopup.GetItemCount() - 1));
459 1 : }
460 :
461 9 : DECLARE_ODFIMPORT_TEST(testAnnotationFormatting, "annotation-formatting.odt")
462 : {
463 1 : uno::Reference<beans::XPropertySet> xTextField = getProperty< uno::Reference<beans::XPropertySet> >(getRun(getParagraph(1), 1), "TextField");
464 2 : uno::Reference<text::XText> xText = getProperty< uno::Reference<text::XText> >(xTextField, "TextRange");
465 : // Make sure we test the right annotation.
466 2 : uno::Reference<text::XTextRange> xParagraph = getParagraphOfText(1, xText, "Looses: bold");
467 : // Formatting was lost: the second text portion was NORMAL, not BOLD.
468 2 : CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, getProperty<float>(getRun(xParagraph, 2), "CharWeight"));
469 1 : }
470 :
471 : #endif
472 :
473 4 : CPPUNIT_PLUGIN_IMPLEMENT();
474 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|