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