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