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 : #ifndef bordertest_hxx
34 : #define bordertest_hxx
35 :
36 : typedef std::map<OUString, com::sun::star::table::BorderLine> BorderLineMap;
37 : typedef std::pair<OUString, com::sun::star::table::BorderLine> StringBorderPair;
38 :
39 : using namespace com::sun::star;
40 :
41 : class BorderTest
42 : {
43 : public:
44 6 : BorderTest()
45 : {
46 :
47 6 : }
48 6 : void testTheBorders(uno::Reference<lang::XComponent> mxComponent)
49 : {
50 6 : uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
51 6 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(textDocument->getText(), uno::UNO_QUERY);
52 : // list of paragraphs
53 6 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
54 :
55 : // maps containing TopBorder widths for every cell
56 : // one map for each tables - there are 8 of them, counting from 0
57 6 : BorderLineMap map0;
58 6 : map0.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 53, 26, 26)));
59 6 : map0.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 79, 26, 26)));
60 6 : map0.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 106, 26, 26)));
61 6 : map0.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 159, 26, 26)));
62 6 : map0.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 212, 26, 26)));
63 6 : BorderLineMap map1;
64 6 : map1.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 9, 9, 9)));
65 6 : map1.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 18, 18, 18)));
66 6 : map1.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 26, 26)));
67 6 : map1.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 53)));
68 6 : map1.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 79)));
69 6 : map1.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 106)));
70 6 : BorderLineMap map2;
71 6 : map2.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 9, 5, 5)));
72 6 : map2.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 18, 9, 9)));
73 6 : map2.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 14, 14)));
74 6 : map2.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 35, 18, 18)));
75 6 : map2.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 26)));
76 6 : map2.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 79, 41, 41)));
77 6 : map2.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 106, 53, 53)));
78 6 : map2.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 159, 79, 79)));
79 6 : map2.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 212, 106, 106)));
80 6 : BorderLineMap map3;
81 6 : map3.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 53, 26, 9)));
82 6 : map3.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 53, 26, 18)));
83 6 : map3.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 53, 26, 26)));
84 6 : map3.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 26, 35)));
85 6 : map3.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 53)));
86 6 : map3.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 53, 26, 79)));
87 6 : map3.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 53, 26, 106)));
88 6 : map3.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 53, 26, 159)));
89 6 : map3.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 53, 26, 212)));
90 6 : map3.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 53, 26, 9)));
91 6 : BorderLineMap map4;
92 6 : map4.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 53, 26, 18)));
93 6 : map4.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 53, 26, 26)));
94 6 : map4.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 26, 35)));
95 6 : map4.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 35)));
96 6 : map4.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 53, 26, 79)));
97 6 : map4.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 53, 26, 106)));
98 6 : map4.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 53, 26, 159)));
99 6 : map4.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 53, 26, 212)));
100 6 : BorderLineMap map5;
101 6 : map5.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 26, 53, 9)));
102 6 : map5.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 53, 18)));
103 6 : map5.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 53, 26)));
104 6 : map5.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 26, 53, 35)));
105 6 : map5.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 26, 53, 53)));
106 6 : map5.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 26, 53, 79)));
107 6 : map5.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 26, 53, 106)));
108 6 : map5.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 26, 53, 159)));
109 6 : map5.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 26, 53, 212)));
110 6 : BorderLineMap map6;
111 6 : map6.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 14, 14, 26)));
112 6 : map6.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 26, 53)));
113 6 : map6.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 41, 41, 79)));
114 6 : map6.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 106)));
115 6 : map6.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 159)));
116 6 : map6.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 212)));
117 6 : BorderLineMap map7;
118 6 : map7.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 14, 14, 26)));
119 6 : map7.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 26, 53)));
120 6 : map7.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 41, 41, 79)));
121 6 : map7.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 106)));
122 6 : map7.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 159)));
123 6 : map7.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 212)));
124 :
125 6 : sal_Int32 currentTable = 0; //to know which map should we check with the current table
126 : BorderLineMap* tempMap;
127 6 : tempMap = &map0;
128 114 : do
129 : {
130 114 : uno::Reference<lang::XServiceInfo> xServiceInfo;
131 114 : if (xParaEnum->nextElement() >>= xServiceInfo)
132 : {
133 114 : if (xServiceInfo->supportsService("com.sun.star.text.TextTable"))
134 : {
135 48 : uno::Reference<text::XTextTable> const xTextTable(xServiceInfo, uno::UNO_QUERY_THROW);
136 48 : uno::Sequence<OUString> const cells = xTextTable->getCellNames();
137 48 : uno::Sequence< uno::Sequence< sal_Int32 > > borderWidthSequence;
138 48 : sal_Int32 nLength = cells.getLength();
139 :
140 48 : if(currentTable == sal_Int32(1))
141 6 : tempMap = &map1;
142 48 : if(currentTable == sal_Int32(2))
143 6 : tempMap = &map2;
144 48 : if(currentTable == sal_Int32(3))
145 6 : tempMap = &map3;
146 48 : if(currentTable == sal_Int32(4))
147 6 : tempMap = &map4;
148 48 : if(currentTable == sal_Int32(5))
149 6 : tempMap = &map5;
150 48 : if(currentTable == sal_Int32(6))
151 6 : tempMap = &map6;
152 48 : if(currentTable == sal_Int32(7))
153 6 : tempMap = &map7;
154 :
155 48 : BorderLineMap::iterator it;
156 48 : it = tempMap->begin();
157 :
158 402 : for (sal_Int32 i = 0; i < nLength; ++i)
159 : {
160 354 : uno::Reference<table::XCell> xCell = xTextTable->getCellByName(cells[i]);
161 354 : uno::Reference< beans::XPropertySet > xPropSet(xCell, uno::UNO_QUERY_THROW);
162 354 : uno::Any aAny = xPropSet->getPropertyValue("TopBorder");
163 354 : table::BorderLine aBorderLine;
164 354 : it = tempMap->find(cells[i]);
165 354 : if ((aAny >>= aBorderLine) && (it!=tempMap->end()))
166 : {
167 348 : sal_Int32 innerLineWidth = aBorderLine.InnerLineWidth;
168 348 : sal_Int32 outerLineWidth = aBorderLine.OuterLineWidth;
169 348 : sal_Int32 lineDistance = aBorderLine.LineDistance;
170 :
171 348 : sal_Int32 perfectInner = it->second.InnerLineWidth;
172 348 : sal_Int32 perfectOuter = it->second.OuterLineWidth;
173 348 : sal_Int32 perfectDistance = it->second.LineDistance;
174 348 : CPPUNIT_ASSERT_EQUAL(perfectInner, innerLineWidth);
175 348 : CPPUNIT_ASSERT_EQUAL(perfectOuter, outerLineWidth);
176 348 : CPPUNIT_ASSERT_EQUAL(perfectDistance, lineDistance);
177 : }
178 354 : }
179 48 : ++currentTable;
180 : }
181 114 : }
182 120 : } while(xParaEnum->hasMoreElements());
183 6 : }
184 :
185 : };
186 : #endif
|