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 <com/sun/star/style/PageStyleLayout.hpp>
10 : #include <com/sun/star/table/XCell.hpp>
11 : #include <com/sun/star/table/BorderLine.hpp>
12 : #include <com/sun/star/text/XTextTable.hpp>
13 : #include <swmodeltestbase.hxx>
14 :
15 : typedef std::map<OUString, com::sun::star::uno::Sequence< com::sun::star::table::BorderLine> > AllBordersMap;
16 : typedef std::pair<OUString, com::sun::star::uno::Sequence< com::sun::star::table::BorderLine> > StringSequencePair;
17 :
18 3 : class Test : public SwModelTestBase
19 : {
20 : public:
21 : void testEmptySvgFamilyName();
22 : void testHideAllSections();
23 : void testOdtBorders();
24 : void testPageStyleLayoutDefault();
25 : void testPageStyleLayoutRight();
26 : void testFdo61952();
27 : void testFdo60842();
28 : void testFdo56272();
29 : void testFdo55814();
30 :
31 2 : CPPUNIT_TEST_SUITE(Test);
32 : #if !defined(MACOSX) && !defined(WNT)
33 1 : CPPUNIT_TEST(run);
34 : #endif
35 2 : CPPUNIT_TEST_SUITE_END();
36 :
37 : private:
38 : void run();
39 : };
40 :
41 1 : void Test::run()
42 : {
43 : MethodEntry<Test> aMethods[] = {
44 : {"empty-svg-family-name.odt", &Test::testEmptySvgFamilyName},
45 : {"fdo53210.odt", &Test::testHideAllSections},
46 : {"borders_ooo33.odt", &Test::testOdtBorders},
47 : {"hello.odt", &Test::testPageStyleLayoutDefault},
48 : {"hello.odt", &Test::testPageStyleLayoutRight},
49 : {"hello.odt", &Test::testFdo61952},
50 : {"fdo60842.odt", &Test::testFdo60842},
51 : {"fdo56272.odt", &Test::testFdo56272},
52 : {"fdo55814.odt", &Test::testFdo55814},
53 1 : };
54 1 : header();
55 10 : for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
56 : {
57 9 : MethodEntry<Test>& rEntry = aMethods[i];
58 9 : load("/sw/qa/extras/odfimport/data/", rEntry.pName);
59 9 : (this->*rEntry.pMethod)();
60 9 : finish();
61 : }
62 1 : }
63 :
64 1 : void Test::testEmptySvgFamilyName()
65 : {
66 : // .odt import did crash on the empty font list (which I think is valid according SVG spec)
67 1 : }
68 :
69 1 : void Test::testHideAllSections()
70 : {
71 : // This document has a section that is conditionally hidden, but has no empty paragraph after it.
72 1 : uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
73 2 : uno::Reference<container::XNameAccess> xMasters = xTextFieldsSupplier->getTextFieldMasters();
74 : // Set _CS_Allgemein to 0
75 2 : uno::Reference<beans::XPropertySet> xMaster(xMasters->getByName("com.sun.star.text.fieldmaster.User._CS_Allgemein"), uno::UNO_QUERY);
76 1 : xMaster->setPropertyValue("Content", uno::makeAny(OUString("0")));
77 : // This used to crash
78 2 : uno::Reference<util::XRefreshable>(xTextFieldsSupplier->getTextFields(), uno::UNO_QUERY)->refresh();
79 1 : }
80 :
81 1 : void Test::testOdtBorders()
82 : {
83 1 : AllBordersMap map;
84 2 : uno::Sequence< table::BorderLine > tempSequence(4);
85 :
86 1 : tempSequence[0] = table::BorderLine(0, 2, 2, 35); // left
87 1 : tempSequence[1] = table::BorderLine(0, 2, 2, 35); // right
88 1 : tempSequence[2] = table::BorderLine(0, 2, 2, 35); // top
89 1 : tempSequence[3] = table::BorderLine(0, 2, 2, 35); // bottom
90 1 : map.insert(StringSequencePair(OUString("B2"), tempSequence));
91 1 : tempSequence[0] = table::BorderLine(0, 0, 2, 0);
92 1 : tempSequence[1] = table::BorderLine(0, 0, 2, 0);
93 1 : tempSequence[2] = table::BorderLine(0, 0, 2, 0);
94 1 : tempSequence[3] = table::BorderLine(0, 0, 2, 0);
95 1 : map.insert(StringSequencePair(OUString("D2"), tempSequence));
96 1 : tempSequence[0] = table::BorderLine(0, 2, 2, 88);
97 1 : tempSequence[1] = table::BorderLine(0, 2, 2, 88);
98 1 : tempSequence[2] = table::BorderLine(0, 2, 2, 88);
99 1 : tempSequence[3] = table::BorderLine(0, 2, 2, 88);
100 1 : map.insert(StringSequencePair(OUString("B4"), tempSequence));
101 1 : tempSequence[0] = table::BorderLine(0, 0, 18, 0);
102 1 : tempSequence[1] = table::BorderLine(0, 0, 18, 0);
103 1 : tempSequence[2] = table::BorderLine(0, 0, 18, 0);
104 1 : tempSequence[3] = table::BorderLine(0, 0, 18, 0);
105 1 : map.insert(StringSequencePair(OUString("D4"), tempSequence));
106 1 : tempSequence[0] = table::BorderLine(0, 35, 35, 35);
107 1 : tempSequence[1] = table::BorderLine(0, 35, 35, 35);
108 1 : tempSequence[2] = table::BorderLine(0, 35, 35, 35);
109 1 : tempSequence[3] = table::BorderLine(0, 35, 35, 35);
110 1 : map.insert(StringSequencePair(OUString("B6"), tempSequence));
111 1 : tempSequence[0] = table::BorderLine(0, 0, 35, 0);
112 1 : tempSequence[1] = table::BorderLine(0, 0, 35, 0);
113 1 : tempSequence[2] = table::BorderLine(0, 0, 35, 0);
114 1 : tempSequence[3] = table::BorderLine(0, 0, 35, 0);
115 1 : map.insert(StringSequencePair(OUString("D6"), tempSequence));
116 1 : tempSequence[0] = table::BorderLine(0, 88, 88, 88);
117 1 : tempSequence[1] = table::BorderLine(0, 88, 88, 88);
118 1 : tempSequence[2] = table::BorderLine(0, 88, 88, 88);
119 1 : tempSequence[3] = table::BorderLine(0, 88, 88, 88);
120 1 : map.insert(StringSequencePair(OUString("B8"), tempSequence));
121 1 : tempSequence[0] = table::BorderLine(0, 0, 88, 0);
122 1 : tempSequence[1] = table::BorderLine(0, 0, 88, 0);
123 1 : tempSequence[2] = table::BorderLine(0, 0, 88, 0);
124 1 : tempSequence[3] = table::BorderLine(0, 0, 88, 0);
125 1 : map.insert(StringSequencePair(OUString("D8"), tempSequence));
126 1 : tempSequence[0] = table::BorderLine(0, 2, 35, 88);
127 1 : tempSequence[1] = table::BorderLine(0, 2, 35, 88);
128 1 : tempSequence[2] = table::BorderLine(0, 2, 35, 88);
129 1 : tempSequence[3] = table::BorderLine(0, 2, 35, 88);
130 1 : map.insert(StringSequencePair(OUString("B10"), tempSequence));
131 1 : tempSequence[0] = table::BorderLine(0, 0, 141, 0);
132 1 : tempSequence[1] = table::BorderLine(0, 0, 141, 0);
133 1 : tempSequence[2] = table::BorderLine(0, 0, 141, 0);
134 1 : tempSequence[3] = table::BorderLine(0, 0, 141, 0);
135 1 : map.insert(StringSequencePair(OUString("D10"), tempSequence));
136 1 : tempSequence[0] = table::BorderLine(0, 2, 88, 88);
137 1 : tempSequence[1] = table::BorderLine(0, 2, 88, 88);
138 1 : tempSequence[2] = table::BorderLine(0, 2, 88, 88);
139 1 : tempSequence[3] = table::BorderLine(0, 2, 88, 88);
140 1 : map.insert(StringSequencePair(OUString("B12"), tempSequence));
141 1 : tempSequence[0] = table::BorderLine(0, 0, 176, 0);
142 1 : tempSequence[1] = table::BorderLine(0, 0, 176, 0);
143 1 : tempSequence[2] = table::BorderLine(0, 0, 176, 0);
144 1 : tempSequence[3] = table::BorderLine(0, 0, 176, 0);
145 1 : map.insert(StringSequencePair(OUString("D12"), tempSequence));
146 1 : tempSequence[0] = table::BorderLine(0, 2, 141, 88);
147 1 : tempSequence[1] = table::BorderLine(0, 2, 141, 88);
148 1 : tempSequence[2] = table::BorderLine(0, 2, 141, 88);
149 1 : tempSequence[3] = table::BorderLine(0, 2, 141, 88);
150 1 : map.insert(StringSequencePair(OUString("B14"), tempSequence));
151 1 : tempSequence[0] = table::BorderLine(0, 35, 88, 88);
152 1 : tempSequence[1] = table::BorderLine(0, 35, 88, 88);
153 1 : tempSequence[2] = table::BorderLine(0, 35, 88, 88);
154 1 : tempSequence[3] = table::BorderLine(0, 35, 88, 88);
155 1 : map.insert(StringSequencePair(OUString("B16"), tempSequence));
156 1 : tempSequence[0] = table::BorderLine(0, 88, 35, 35);
157 1 : tempSequence[1] = table::BorderLine(0, 88, 35, 35);
158 1 : tempSequence[2] = table::BorderLine(0, 88, 35, 35);
159 1 : tempSequence[3] = table::BorderLine(0, 88, 35, 35);
160 1 : map.insert(StringSequencePair(OUString("B18"), tempSequence));
161 1 : tempSequence[0] = table::BorderLine(0, 88, 141, 88);
162 1 : tempSequence[1] = table::BorderLine(0, 88, 141, 88);
163 1 : tempSequence[2] = table::BorderLine(0, 88, 141, 88);
164 1 : tempSequence[3] = table::BorderLine(0, 88, 141, 88);
165 1 : map.insert(StringSequencePair(OUString("B20"), tempSequence));
166 1 : tempSequence[0] = table::BorderLine(0, 141, 88, 88);
167 1 : tempSequence[1] = table::BorderLine(0, 141, 88, 88);
168 1 : tempSequence[2] = table::BorderLine(0, 141, 88, 88);
169 1 : tempSequence[3] = table::BorderLine(0, 141, 88, 88);
170 1 : map.insert(StringSequencePair(OUString("B22"), tempSequence));
171 :
172 2 : uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
173 2 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(textDocument->getText(), uno::UNO_QUERY);
174 : // list of paragraphs
175 2 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
176 2 : do
177 : {
178 2 : uno::Reference<lang::XServiceInfo> xServiceInfo;
179 2 : if (xParaEnum->nextElement() >>= xServiceInfo)
180 : {
181 2 : if (xServiceInfo->supportsService("com.sun.star.text.TextTable"))
182 : {
183 1 : uno::Reference<text::XTextTable> const xTextTable(xServiceInfo, uno::UNO_QUERY_THROW);
184 2 : uno::Sequence<OUString> const cells = xTextTable->getCellNames();
185 2 : uno::Sequence< uno::Sequence< sal_Int32 > > borderWidthSequence;
186 1 : sal_Int32 nLength = cells.getLength();
187 :
188 1 : AllBordersMap::iterator it;
189 1 : it = map.begin();
190 :
191 116 : for (sal_Int32 i = 0; i < nLength; ++i)
192 : {
193 115 : if(i%10==6 || (i%10==8 && i<60)) // only B and D cells have borders, every 2 rows
194 : {
195 17 : uno::Reference<table::XCell> xCell = xTextTable->getCellByName(cells[i]);
196 34 : uno::Reference< beans::XPropertySet > xPropSet(xCell, uno::UNO_QUERY_THROW);
197 17 : it = map.find(cells[i]);
198 :
199 34 : uno::Any aLeftBorder = xPropSet->getPropertyValue("LeftBorder");
200 17 : table::BorderLine aLeftBorderLine;
201 17 : if (aLeftBorder >>= aLeftBorderLine)
202 : {
203 17 : sal_Int32 innerLineWidth = aLeftBorderLine.InnerLineWidth;
204 17 : sal_Int32 outerLineWidth = aLeftBorderLine.OuterLineWidth;
205 17 : sal_Int32 lineDistance = aLeftBorderLine.LineDistance;
206 :
207 17 : sal_Int32 perfectInner = it->second[0].InnerLineWidth;
208 17 : sal_Int32 perfectOuter = it->second[0].OuterLineWidth;
209 17 : sal_Int32 perfectDistance = it->second[0].LineDistance;
210 17 : CPPUNIT_ASSERT_EQUAL(perfectInner, innerLineWidth);
211 17 : CPPUNIT_ASSERT_EQUAL(perfectOuter, outerLineWidth);
212 17 : CPPUNIT_ASSERT_EQUAL(perfectDistance, lineDistance);
213 : }
214 :
215 34 : uno::Any aRightBorder = xPropSet->getPropertyValue("RightBorder");
216 17 : table::BorderLine aRightBorderLine;
217 17 : if (aRightBorder >>= aRightBorderLine)
218 : {
219 17 : sal_Int32 innerLineWidth = aRightBorderLine.InnerLineWidth;
220 17 : sal_Int32 outerLineWidth = aRightBorderLine.OuterLineWidth;
221 17 : sal_Int32 lineDistance = aRightBorderLine.LineDistance;
222 :
223 17 : sal_Int32 perfectInner = it->second[1].InnerLineWidth;
224 17 : sal_Int32 perfectOuter = it->second[1].OuterLineWidth;
225 17 : sal_Int32 perfectDistance = it->second[1].LineDistance;
226 17 : CPPUNIT_ASSERT_EQUAL(perfectInner, innerLineWidth);
227 17 : CPPUNIT_ASSERT_EQUAL(perfectOuter, outerLineWidth);
228 17 : CPPUNIT_ASSERT_EQUAL(perfectDistance, lineDistance);
229 : }
230 :
231 34 : uno::Any aTopBorder = xPropSet->getPropertyValue("TopBorder");
232 17 : table::BorderLine aTopBorderLine;
233 17 : if (aTopBorder >>= aTopBorderLine)
234 : {
235 17 : sal_Int32 innerLineWidth = aTopBorderLine.InnerLineWidth;
236 17 : sal_Int32 outerLineWidth = aTopBorderLine.OuterLineWidth;
237 17 : sal_Int32 lineDistance = aTopBorderLine.LineDistance;
238 :
239 17 : sal_Int32 perfectInner = it->second[2].InnerLineWidth;
240 17 : sal_Int32 perfectOuter = it->second[2].OuterLineWidth;
241 17 : sal_Int32 perfectDistance = it->second[2].LineDistance;
242 17 : CPPUNIT_ASSERT_EQUAL(perfectInner, innerLineWidth);
243 17 : CPPUNIT_ASSERT_EQUAL(perfectOuter, outerLineWidth);
244 17 : CPPUNIT_ASSERT_EQUAL(perfectDistance, lineDistance);
245 : }
246 :
247 34 : uno::Any aBottomBorder = xPropSet->getPropertyValue("BottomBorder");
248 17 : table::BorderLine aBottomBorderLine;
249 17 : if (aBottomBorder >>= aBottomBorderLine)
250 : {
251 17 : sal_Int32 innerLineWidth = aBottomBorderLine.InnerLineWidth;
252 17 : sal_Int32 outerLineWidth = aBottomBorderLine.OuterLineWidth;
253 17 : sal_Int32 lineDistance = aBottomBorderLine.LineDistance;
254 :
255 17 : sal_Int32 perfectInner = it->second[3].InnerLineWidth;
256 17 : sal_Int32 perfectOuter = it->second[3].OuterLineWidth;
257 17 : sal_Int32 perfectDistance = it->second[3].LineDistance;
258 17 : CPPUNIT_ASSERT_EQUAL(perfectInner, innerLineWidth);
259 17 : CPPUNIT_ASSERT_EQUAL(perfectOuter, outerLineWidth);
260 17 : CPPUNIT_ASSERT_EQUAL(perfectDistance, lineDistance);
261 17 : }
262 : }
263 1 : } //end of the 'for' loop
264 : }
265 2 : }
266 3 : } while(xParaEnum->hasMoreElements());
267 1 : }
268 :
269 1 : void Test::testPageStyleLayoutDefault()
270 : {
271 1 : uno::Reference<beans::XPropertySet> xPropertySet(getStyles("PageStyles")->getByName("Default Style"), uno::UNO_QUERY);
272 : // This was style::PageStyleLayout_MIRRORED.
273 1 : CPPUNIT_ASSERT_EQUAL(style::PageStyleLayout_ALL, getProperty<style::PageStyleLayout>(xPropertySet, "PageStyleLayout"));
274 1 : }
275 :
276 1 : void Test::testPageStyleLayoutRight()
277 : {
278 1 : uno::Reference<beans::XPropertySet> xPropertySet(getStyles("PageStyles")->getByName("Default Style"), uno::UNO_QUERY);
279 : // This caused a crash.
280 1 : xPropertySet->setPropertyValue("PageStyleLayout", uno::makeAny(style::PageStyleLayout_RIGHT));
281 1 : }
282 :
283 1 : void Test::testFdo61952()
284 : {
285 1 : uno::Reference<beans::XPropertySet> xPara(getParagraph(0), uno::UNO_QUERY);
286 1 : xPara->setPropertyValue("PageDescName", uno::makeAny(OUString("Left Page")));
287 1 : xPara->setPropertyValue("PageDescName", uno::makeAny(OUString("Right Page")));
288 1 : xPara->setPropertyValue("PageDescName", uno::makeAny(OUString("Left Page")));
289 1 : xPara->setPropertyValue("PageDescName", uno::makeAny(OUString("Right Page")));
290 1 : }
291 :
292 1 : void Test::testFdo60842()
293 : {
294 1 : uno::Reference<text::XTextContent> const xTable(getParagraphOrTable(0));
295 1 : getCell(xTable, "A1", "");
296 1 : getCell(xTable, "B1", "18/02/2012");
297 1 : getCell(xTable, "C1", "USD"); // this is the cell with office:string-value
298 1 : getCell(xTable, "D1", "");
299 1 : getCell(xTable, "E1", "01/04/2012");
300 1 : }
301 :
302 1 : void Test::testFdo56272()
303 : {
304 1 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
305 2 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
306 2 : uno::Reference<drawing::XShape> xShape(xDraws->getByIndex(0), uno::UNO_QUERY);
307 : // Vertical position was incorrect.
308 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(422), xShape->getPosition().Y); // Was -2371
309 1 : }
310 :
311 1 : void Test::testFdo55814()
312 : {
313 1 : uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
314 2 : uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
315 2 : uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
316 2 : uno::Reference<beans::XPropertySet> xField(xFields->nextElement(), uno::UNO_QUERY);
317 1 : xField->setPropertyValue("Content", uno::makeAny(OUString("Yes")));
318 1 : uno::Reference<util::XRefreshable>(xTextFieldsSupplier->getTextFields(), uno::UNO_QUERY)->refresh();
319 2 : uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY);
320 2 : uno::Reference<container::XIndexAccess> xSections(xTextSectionsSupplier->getTextSections(), uno::UNO_QUERY);
321 : // This was "0".
322 2 : CPPUNIT_ASSERT_EQUAL(OUString("Hide==\"Yes\""), getProperty<OUString>(xSections->getByIndex(0), "Condition"));
323 1 : }
324 :
325 1 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
326 :
327 4 : CPPUNIT_PLUGIN_IMPLEMENT();
328 :
329 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|