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