Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License or as specified alternatively below. You may obtain a copy of
8 : : * the License at http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * Major Contributor(s):
16 : : * Copyright (C) 2012 Artur Dorda <artur.dorda+libo@gmail.com> (initial developer)
17 : : *
18 : : * All Rights Reserved.
19 : : *
20 : : * For minor contributions see the git repository.
21 : : *
22 : : * Alternatively, the contents of this file may be used under the terms of
23 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : : * instead of those above.
27 : : */
28 : :
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 : : using rtl::OUString;
34 : :
35 : : #ifndef bordertest_hxx
36 : : #define bordertest_hxx
37 : :
38 : : typedef std::map<rtl::OUString, com::sun::star::table::BorderLine> BorderLineMap;
39 : : typedef std::pair<rtl::OUString, com::sun::star::table::BorderLine> StringBorderPair;
40 : :
41 : : using namespace com::sun::star;
42 : :
43 : : class BorderTest
44 : : {
45 : : public:
46 : 9 : BorderTest()
47 : : {
48 : :
49 : 9 : }
50 : 9 : void testTheBorders(uno::Reference<lang::XComponent> mxComponent)
51 : : {
52 [ + - ]: 9 : uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
53 [ + - ][ + - ]: 9 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(textDocument->getText(), uno::UNO_QUERY);
[ + - ]
54 : : // list of paragraphs
55 [ + - ][ + - ]: 9 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
56 : :
57 : : // maps containing TopBorder widths for every cell
58 : : // one map for each tables - there are 8 of them, counting from 0
59 [ + - ]: 9 : BorderLineMap map0;
60 [ + - ]: 9 : map0.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 53, 26, 26)));
61 [ + - ]: 9 : map0.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 79, 26, 26)));
62 [ + - ]: 9 : map0.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 106, 26, 26)));
63 [ + - ]: 9 : map0.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 159, 26, 26)));
64 [ + - ]: 9 : map0.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 212, 26, 26)));
65 [ + - ]: 9 : BorderLineMap map1;
66 [ + - ]: 9 : map1.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 9, 9, 9)));
67 [ + - ]: 9 : map1.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 18, 18, 18)));
68 [ + - ]: 9 : map1.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 26, 26)));
69 [ + - ]: 9 : map1.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 53)));
70 [ + - ]: 9 : map1.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 79)));
71 [ + - ]: 9 : map1.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 106)));
72 [ + - ]: 9 : BorderLineMap map2;
73 [ + - ]: 9 : map2.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 9, 5, 5)));
74 [ + - ]: 9 : map2.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 18, 9, 9)));
75 [ + - ]: 9 : map2.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 14, 14)));
76 [ + - ]: 9 : map2.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 35, 18, 18)));
77 [ + - ]: 9 : map2.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 26)));
78 [ + - ]: 9 : map2.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 79, 41, 41)));
79 [ + - ]: 9 : map2.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 106, 53, 53)));
80 [ + - ]: 9 : map2.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 159, 79, 79)));
81 [ + - ]: 9 : map2.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 212, 106, 106)));
82 [ + - ]: 9 : BorderLineMap map3;
83 [ + - ]: 9 : map3.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 53, 26, 9)));
84 [ + - ]: 9 : map3.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 53, 26, 18)));
85 [ + - ]: 9 : map3.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 53, 26, 26)));
86 [ + - ]: 9 : map3.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 26, 35)));
87 [ + - ]: 9 : map3.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 53)));
88 [ + - ]: 9 : map3.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 53, 26, 79)));
89 [ + - ]: 9 : map3.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 53, 26, 106)));
90 [ + - ]: 9 : map3.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 53, 26, 159)));
91 [ + - ]: 9 : map3.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 53, 26, 212)));
92 [ + - ]: 9 : map3.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 53, 26, 9)));
93 [ + - ]: 9 : BorderLineMap map4;
94 [ + - ]: 9 : map4.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 53, 26, 18)));
95 [ + - ]: 9 : map4.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 53, 26, 26)));
96 [ + - ]: 9 : map4.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 26, 35)));
97 [ + - ]: 9 : map4.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 35)));
98 [ + - ]: 9 : map4.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 53, 26, 79)));
99 [ + - ]: 9 : map4.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 53, 26, 106)));
100 [ + - ]: 9 : map4.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 53, 26, 159)));
101 [ + - ]: 9 : map4.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 53, 26, 212)));
102 [ + - ]: 9 : BorderLineMap map5;
103 [ + - ]: 9 : map5.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 26, 53, 9)));
104 [ + - ]: 9 : map5.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 53, 18)));
105 [ + - ]: 9 : map5.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 53, 26)));
106 [ + - ]: 9 : map5.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 26, 53, 35)));
107 [ + - ]: 9 : map5.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 26, 53, 53)));
108 [ + - ]: 9 : map5.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 26, 53, 79)));
109 [ + - ]: 9 : map5.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 26, 53, 106)));
110 [ + - ]: 9 : map5.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 26, 53, 159)));
111 [ + - ]: 9 : map5.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 26, 53, 212)));
112 [ + - ]: 9 : BorderLineMap map6;
113 [ + - ]: 9 : map6.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 14, 14, 26)));
114 [ + - ]: 9 : map6.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 26, 53)));
115 [ + - ]: 9 : map6.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 41, 41, 79)));
116 [ + - ]: 9 : map6.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 106)));
117 [ + - ]: 9 : map6.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 159)));
118 [ + - ]: 9 : map6.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 212)));
119 [ + - ]: 9 : BorderLineMap map7;
120 [ + - ]: 9 : map7.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 14, 14, 26)));
121 [ + - ]: 9 : map7.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 26, 53)));
122 [ + - ]: 9 : map7.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 41, 41, 79)));
123 [ + - ]: 9 : map7.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 106)));
124 [ + - ]: 9 : map7.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 159)));
125 [ + - ]: 9 : map7.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 212)));
126 : :
127 : 9 : sal_Int32 currentTable = 0; //to know which map should we check with the current table
128 : : BorderLineMap* tempMap;
129 : 9 : tempMap = &map0;
130 [ + + ]: 171 : do
131 : : {
132 : 171 : uno::Reference<lang::XServiceInfo> xServiceInfo;
133 [ + - ][ + - ]: 171 : if (xParaEnum->nextElement() >>= xServiceInfo)
[ + - ][ + - ]
134 : : {
135 [ + - ][ + - ]: 171 : if (xServiceInfo->supportsService("com.sun.star.text.TextTable"))
[ + + ]
136 : : {
137 [ + - ]: 72 : uno::Reference<text::XTextTable> const xTextTable(xServiceInfo, uno::UNO_QUERY_THROW);
138 [ + - ][ + - ]: 72 : uno::Sequence<rtl::OUString> const cells = xTextTable->getCellNames();
139 [ + - ]: 72 : uno::Sequence< uno::Sequence< sal_Int32 > > borderWidthSequence;
140 : 72 : sal_Int32 nLength = cells.getLength();
141 : :
142 [ + + ]: 72 : if(currentTable == sal_Int32(1))
143 : 9 : tempMap = &map1;
144 [ + + ]: 72 : if(currentTable == sal_Int32(2))
145 : 9 : tempMap = &map2;
146 [ + + ]: 72 : if(currentTable == sal_Int32(3))
147 : 9 : tempMap = &map3;
148 [ + + ]: 72 : if(currentTable == sal_Int32(4))
149 : 9 : tempMap = &map4;
150 [ + + ]: 72 : if(currentTable == sal_Int32(5))
151 : 9 : tempMap = &map5;
152 [ + + ]: 72 : if(currentTable == sal_Int32(6))
153 : 9 : tempMap = &map6;
154 [ + + ]: 72 : if(currentTable == sal_Int32(7))
155 : 9 : tempMap = &map7;
156 : :
157 : 72 : BorderLineMap::iterator it;
158 : 72 : it = tempMap->begin();
159 : :
160 [ + + ]: 603 : for (sal_Int32 i = 0; i < nLength; ++i)
161 : : {
162 [ + - ][ + - ]: 531 : uno::Reference<table::XCell> xCell = xTextTable->getCellByName(cells[i]);
163 [ + - ]: 531 : uno::Reference< beans::XPropertySet > xPropSet(xCell, uno::UNO_QUERY_THROW);
164 [ + - ][ + - ]: 531 : uno::Any aAny = xPropSet->getPropertyValue("TopBorder");
165 : 531 : table::BorderLine aBorderLine;
166 [ + - ]: 531 : it = tempMap->find(cells[i]);
167 [ + - ][ + - ]: 531 : if ((aAny >>= aBorderLine) && (it!=tempMap->end()))
[ + + ][ + - ]
[ + + # # ]
168 : : {
169 : 522 : sal_Int32 innerLineWidth = aBorderLine.InnerLineWidth;
170 : 522 : sal_Int32 outerLineWidth = aBorderLine.OuterLineWidth;
171 : 522 : sal_Int32 lineDistance = aBorderLine.LineDistance;
172 : :
173 : 522 : sal_Int32 perfectInner = it->second.InnerLineWidth;
174 : 522 : sal_Int32 perfectOuter = it->second.OuterLineWidth;
175 : 522 : sal_Int32 perfectDistance = it->second.LineDistance;
176 [ + - ][ + - ]: 522 : CPPUNIT_ASSERT_EQUAL(perfectInner, innerLineWidth);
[ + - ][ + - ]
[ + - ]
177 [ + - ][ + - ]: 522 : CPPUNIT_ASSERT_EQUAL(perfectOuter, outerLineWidth);
[ + - ][ + - ]
[ + - ]
178 [ + - ][ + - ]: 522 : CPPUNIT_ASSERT_EQUAL(perfectDistance, lineDistance);
[ + - ][ + - ]
[ + - ]
179 : : }
180 : 531 : }
181 [ + - ][ + - ]: 72 : ++currentTable;
182 : : }
183 : 171 : }
184 [ + - ][ + - ]: 180 : } while(xParaEnum->hasMoreElements());
185 : 9 : }
186 : :
187 : : };
188 : : #endif
|