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