2 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Initial Developer of the Original Code is
15 * Miklos Vajna <vmiklos@suse.cz> (SUSE, Inc.)
16 * Portions created by the Initial Developer are Copyright (C) 2012 the
17 * Initial Developer. All Rights Reserved.
21 * Alternatively, the contents of this file may be used under the terms of
22 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
23 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
24 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
25 * instead of those above.
28 #include <com/sun/star/table/XCell.hpp>
29 #include <com/sun/star/table/BorderLine.hpp>
30 #include <com/sun/star/text/XTextTable.hpp>
31 #include <swmodeltestbase.hxx>
33 typedef std::map
<OUString
, com::sun::star::uno::Sequence
< com::sun::star::table::BorderLine
> > AllBordersMap
;
34 typedef std::pair
<OUString
, com::sun::star::uno::Sequence
< com::sun::star::table::BorderLine
> > StringSequencePair
;
36 class Test
: public SwModelTestBase
39 void testEmptySvgFamilyName();
40 void testHideAllSections();
41 void testOdtBorders();
44 CPPUNIT_TEST_SUITE(Test
);
45 #if !defined(MACOSX) && !defined(WNT)
48 CPPUNIT_TEST_SUITE_END();
56 MethodEntry
<Test
> aMethods
[] = {
57 {"empty-svg-family-name.odt", &Test::testEmptySvgFamilyName
},
58 {"fdo53210.odt", &Test::testHideAllSections
},
59 {"borders_ooo33.odt", &Test::testOdtBorders
},
60 {"fdo56272.odt", &Test::testFdo56272
},
62 for (unsigned int i
= 0; i
< SAL_N_ELEMENTS(aMethods
); ++i
)
64 MethodEntry
<Test
>& rEntry
= aMethods
[i
];
65 mxComponent
= loadFromDesktop(getURLFromSrc("/sw/qa/extras/odfimport/data/") + OUString::createFromAscii(rEntry
.pName
));
66 (this->*rEntry
.pMethod
)();
70 void Test::testEmptySvgFamilyName()
72 // .odt import did crash on the empty font list (which I think is valid according SVG spec)
75 void Test::testHideAllSections()
77 // This document has a section that is conditionally hidden, but has no empty paragraph after it.
78 uno::Reference
<text::XTextFieldsSupplier
> xTextFieldsSupplier(mxComponent
, uno::UNO_QUERY
);
79 uno::Reference
<container::XNameAccess
> xMasters
= xTextFieldsSupplier
->getTextFieldMasters();
80 // Set _CS_Allgemein to 0
81 uno::Reference
<beans::XPropertySet
> xMaster(xMasters
->getByName("com.sun.star.text.fieldmaster.User._CS_Allgemein"), uno::UNO_QUERY
);
82 xMaster
->setPropertyValue("Content", uno::makeAny(OUString("0")));
84 uno::Reference
<util::XRefreshable
>(xTextFieldsSupplier
->getTextFields(), uno::UNO_QUERY
)->refresh();
87 void Test::testOdtBorders()
90 uno::Sequence
< table::BorderLine
> tempSequence(4);
92 tempSequence
[0] = table::BorderLine(0, 2, 2, 35); // left
93 tempSequence
[1] = table::BorderLine(0, 2, 2, 35); // right
94 tempSequence
[2] = table::BorderLine(0, 2, 2, 35); // top
95 tempSequence
[3] = table::BorderLine(0, 2, 2, 35); // bottom
96 map
.insert(StringSequencePair(OUString("B2"), tempSequence
));
97 tempSequence
[0] = table::BorderLine(0, 0, 2, 0);
98 tempSequence
[1] = table::BorderLine(0, 0, 2, 0);
99 tempSequence
[2] = table::BorderLine(0, 0, 2, 0);
100 tempSequence
[3] = table::BorderLine(0, 0, 2, 0);
101 map
.insert(StringSequencePair(OUString("D2"), tempSequence
));
102 tempSequence
[0] = table::BorderLine(0, 2, 2, 88);
103 tempSequence
[1] = table::BorderLine(0, 2, 2, 88);
104 tempSequence
[2] = table::BorderLine(0, 2, 2, 88);
105 tempSequence
[3] = table::BorderLine(0, 2, 2, 88);
106 map
.insert(StringSequencePair(OUString("B4"), tempSequence
));
107 tempSequence
[0] = table::BorderLine(0, 0, 18, 0);
108 tempSequence
[1] = table::BorderLine(0, 0, 18, 0);
109 tempSequence
[2] = table::BorderLine(0, 0, 18, 0);
110 tempSequence
[3] = table::BorderLine(0, 0, 18, 0);
111 map
.insert(StringSequencePair(OUString("D4"), tempSequence
));
112 tempSequence
[0] = table::BorderLine(0, 35, 35, 35);
113 tempSequence
[1] = table::BorderLine(0, 35, 35, 35);
114 tempSequence
[2] = table::BorderLine(0, 35, 35, 35);
115 tempSequence
[3] = table::BorderLine(0, 35, 35, 35);
116 map
.insert(StringSequencePair(OUString("B6"), tempSequence
));
117 tempSequence
[0] = table::BorderLine(0, 0, 35, 0);
118 tempSequence
[1] = table::BorderLine(0, 0, 35, 0);
119 tempSequence
[2] = table::BorderLine(0, 0, 35, 0);
120 tempSequence
[3] = table::BorderLine(0, 0, 35, 0);
121 map
.insert(StringSequencePair(OUString("D6"), tempSequence
));
122 tempSequence
[0] = table::BorderLine(0, 88, 88, 88);
123 tempSequence
[1] = table::BorderLine(0, 88, 88, 88);
124 tempSequence
[2] = table::BorderLine(0, 88, 88, 88);
125 tempSequence
[3] = table::BorderLine(0, 88, 88, 88);
126 map
.insert(StringSequencePair(OUString("B8"), tempSequence
));
127 tempSequence
[0] = table::BorderLine(0, 0, 88, 0);
128 tempSequence
[1] = table::BorderLine(0, 0, 88, 0);
129 tempSequence
[2] = table::BorderLine(0, 0, 88, 0);
130 tempSequence
[3] = table::BorderLine(0, 0, 88, 0);
131 map
.insert(StringSequencePair(OUString("D8"), tempSequence
));
132 tempSequence
[0] = table::BorderLine(0, 2, 35, 88);
133 tempSequence
[1] = table::BorderLine(0, 2, 35, 88);
134 tempSequence
[2] = table::BorderLine(0, 2, 35, 88);
135 tempSequence
[3] = table::BorderLine(0, 2, 35, 88);
136 map
.insert(StringSequencePair(OUString("B10"), tempSequence
));
137 tempSequence
[0] = table::BorderLine(0, 0, 141, 0);
138 tempSequence
[1] = table::BorderLine(0, 0, 141, 0);
139 tempSequence
[2] = table::BorderLine(0, 0, 141, 0);
140 tempSequence
[3] = table::BorderLine(0, 0, 141, 0);
141 map
.insert(StringSequencePair(OUString("D10"), tempSequence
));
142 tempSequence
[0] = table::BorderLine(0, 2, 88, 88);
143 tempSequence
[1] = table::BorderLine(0, 2, 88, 88);
144 tempSequence
[2] = table::BorderLine(0, 2, 88, 88);
145 tempSequence
[3] = table::BorderLine(0, 2, 88, 88);
146 map
.insert(StringSequencePair(OUString("B12"), tempSequence
));
147 tempSequence
[0] = table::BorderLine(0, 0, 176, 0);
148 tempSequence
[1] = table::BorderLine(0, 0, 176, 0);
149 tempSequence
[2] = table::BorderLine(0, 0, 176, 0);
150 tempSequence
[3] = table::BorderLine(0, 0, 176, 0);
151 map
.insert(StringSequencePair(OUString("D12"), tempSequence
));
152 tempSequence
[0] = table::BorderLine(0, 2, 141, 88);
153 tempSequence
[1] = table::BorderLine(0, 2, 141, 88);
154 tempSequence
[2] = table::BorderLine(0, 2, 141, 88);
155 tempSequence
[3] = table::BorderLine(0, 2, 141, 88);
156 map
.insert(StringSequencePair(OUString("B14"), tempSequence
));
157 tempSequence
[0] = table::BorderLine(0, 35, 88, 88);
158 tempSequence
[1] = table::BorderLine(0, 35, 88, 88);
159 tempSequence
[2] = table::BorderLine(0, 35, 88, 88);
160 tempSequence
[3] = table::BorderLine(0, 35, 88, 88);
161 map
.insert(StringSequencePair(OUString("B16"), tempSequence
));
162 tempSequence
[0] = table::BorderLine(0, 88, 35, 35);
163 tempSequence
[1] = table::BorderLine(0, 88, 35, 35);
164 tempSequence
[2] = table::BorderLine(0, 88, 35, 35);
165 tempSequence
[3] = table::BorderLine(0, 88, 35, 35);
166 map
.insert(StringSequencePair(OUString("B18"), tempSequence
));
167 tempSequence
[0] = table::BorderLine(0, 88, 141, 88);
168 tempSequence
[1] = table::BorderLine(0, 88, 141, 88);
169 tempSequence
[2] = table::BorderLine(0, 88, 141, 88);
170 tempSequence
[3] = table::BorderLine(0, 88, 141, 88);
171 map
.insert(StringSequencePair(OUString("B20"), tempSequence
));
172 tempSequence
[0] = table::BorderLine(0, 141, 88, 88);
173 tempSequence
[1] = table::BorderLine(0, 141, 88, 88);
174 tempSequence
[2] = table::BorderLine(0, 141, 88, 88);
175 tempSequence
[3] = table::BorderLine(0, 141, 88, 88);
176 map
.insert(StringSequencePair(OUString("B22"), tempSequence
));
178 uno::Reference
<text::XTextDocument
> textDocument(mxComponent
, uno::UNO_QUERY
);
179 uno::Reference
<container::XEnumerationAccess
> xParaEnumAccess(textDocument
->getText(), uno::UNO_QUERY
);
180 // list of paragraphs
181 uno::Reference
<container::XEnumeration
> xParaEnum
= xParaEnumAccess
->createEnumeration();
184 uno::Reference
<lang::XServiceInfo
> xServiceInfo
;
185 if (xParaEnum
->nextElement() >>= xServiceInfo
)
187 if (xServiceInfo
->supportsService("com.sun.star.text.TextTable"))
189 uno::Reference
<text::XTextTable
> const xTextTable(xServiceInfo
, uno::UNO_QUERY_THROW
);
190 uno::Sequence
<OUString
> const cells
= xTextTable
->getCellNames();
191 uno::Sequence
< uno::Sequence
< sal_Int32
> > borderWidthSequence
;
192 sal_Int32 nLength
= cells
.getLength();
194 AllBordersMap::iterator it
;
197 for (sal_Int32 i
= 0; i
< nLength
; ++i
)
199 if(i
%10==6 || (i
%10==8 && i
<60)) // only B and D cells have borders, every 2 rows
201 uno::Reference
<table::XCell
> xCell
= xTextTable
->getCellByName(cells
[i
]);
202 uno::Reference
< beans::XPropertySet
> xPropSet(xCell
, uno::UNO_QUERY_THROW
);
203 it
= map
.find(cells
[i
]);
205 uno::Any aLeftBorder
= xPropSet
->getPropertyValue("LeftBorder");
206 table::BorderLine aLeftBorderLine
;
207 if (aLeftBorder
>>= aLeftBorderLine
)
209 sal_Int32 innerLineWidth
= aLeftBorderLine
.InnerLineWidth
;
210 sal_Int32 outerLineWidth
= aLeftBorderLine
.OuterLineWidth
;
211 sal_Int32 lineDistance
= aLeftBorderLine
.LineDistance
;
213 sal_Int32 perfectInner
= it
->second
[0].InnerLineWidth
;
214 sal_Int32 perfectOuter
= it
->second
[0].OuterLineWidth
;
215 sal_Int32 perfectDistance
= it
->second
[0].LineDistance
;
216 CPPUNIT_ASSERT_EQUAL(perfectInner
, innerLineWidth
);
217 CPPUNIT_ASSERT_EQUAL(perfectOuter
, outerLineWidth
);
218 CPPUNIT_ASSERT_EQUAL(perfectDistance
, lineDistance
);
221 uno::Any aRightBorder
= xPropSet
->getPropertyValue("RightBorder");
222 table::BorderLine aRightBorderLine
;
223 if (aRightBorder
>>= aRightBorderLine
)
225 sal_Int32 innerLineWidth
= aRightBorderLine
.InnerLineWidth
;
226 sal_Int32 outerLineWidth
= aRightBorderLine
.OuterLineWidth
;
227 sal_Int32 lineDistance
= aRightBorderLine
.LineDistance
;
229 sal_Int32 perfectInner
= it
->second
[1].InnerLineWidth
;
230 sal_Int32 perfectOuter
= it
->second
[1].OuterLineWidth
;
231 sal_Int32 perfectDistance
= it
->second
[1].LineDistance
;
232 CPPUNIT_ASSERT_EQUAL(perfectInner
, innerLineWidth
);
233 CPPUNIT_ASSERT_EQUAL(perfectOuter
, outerLineWidth
);
234 CPPUNIT_ASSERT_EQUAL(perfectDistance
, lineDistance
);
237 uno::Any aTopBorder
= xPropSet
->getPropertyValue("TopBorder");
238 table::BorderLine aTopBorderLine
;
239 if (aTopBorder
>>= aTopBorderLine
)
241 sal_Int32 innerLineWidth
= aTopBorderLine
.InnerLineWidth
;
242 sal_Int32 outerLineWidth
= aTopBorderLine
.OuterLineWidth
;
243 sal_Int32 lineDistance
= aTopBorderLine
.LineDistance
;
245 sal_Int32 perfectInner
= it
->second
[2].InnerLineWidth
;
246 sal_Int32 perfectOuter
= it
->second
[2].OuterLineWidth
;
247 sal_Int32 perfectDistance
= it
->second
[2].LineDistance
;
248 CPPUNIT_ASSERT_EQUAL(perfectInner
, innerLineWidth
);
249 CPPUNIT_ASSERT_EQUAL(perfectOuter
, outerLineWidth
);
250 CPPUNIT_ASSERT_EQUAL(perfectDistance
, lineDistance
);
253 uno::Any aBottomBorder
= xPropSet
->getPropertyValue("BottomBorder");
254 table::BorderLine aBottomBorderLine
;
255 if (aBottomBorder
>>= aBottomBorderLine
)
257 sal_Int32 innerLineWidth
= aBottomBorderLine
.InnerLineWidth
;
258 sal_Int32 outerLineWidth
= aBottomBorderLine
.OuterLineWidth
;
259 sal_Int32 lineDistance
= aBottomBorderLine
.LineDistance
;
261 sal_Int32 perfectInner
= it
->second
[3].InnerLineWidth
;
262 sal_Int32 perfectOuter
= it
->second
[3].OuterLineWidth
;
263 sal_Int32 perfectDistance
= it
->second
[3].LineDistance
;
264 CPPUNIT_ASSERT_EQUAL(perfectInner
, innerLineWidth
);
265 CPPUNIT_ASSERT_EQUAL(perfectOuter
, outerLineWidth
);
266 CPPUNIT_ASSERT_EQUAL(perfectDistance
, lineDistance
);
269 } //end of the 'for' loop
272 } while(xParaEnum
->hasMoreElements());
275 void Test::testFdo56272()
277 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(mxComponent
, uno::UNO_QUERY
);
278 uno::Reference
<container::XIndexAccess
> xDraws(xDrawPageSupplier
->getDrawPage(), uno::UNO_QUERY
);
279 uno::Reference
<drawing::XShape
> xShape(xDraws
->getByIndex(0), uno::UNO_QUERY
);
280 // Vertical position was incorrect.
281 CPPUNIT_ASSERT_EQUAL(sal_Int32(422), xShape
->getPosition().Y
); // Was -2371
284 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
286 CPPUNIT_PLUGIN_IMPLEMENT();
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */