Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : */
9 :
10 : #include <com/sun/star/table/XCell.hpp>
11 : #include <com/sun/star/table/BorderLine.hpp>
12 : #include <com/sun/star/text/XTextTable.hpp>
13 :
14 : #ifndef INCLUDED_SW_QA_EXTRAS_INC_BORDERTEST_HXX
15 : #define INCLUDED_SW_QA_EXTRAS_INC_BORDERTEST_HXX
16 :
17 : typedef std::map<OUString, com::sun::star::table::BorderLine> BorderLineMap;
18 : typedef std::pair<OUString, com::sun::star::table::BorderLine> StringBorderPair;
19 :
20 : using namespace com::sun::star;
21 :
22 : class BorderTest
23 : {
24 : public:
25 3 : BorderTest()
26 : {
27 :
28 3 : }
29 3 : static void testTheBorders(uno::Reference<lang::XComponent> mxComponent, bool isBinaryDoc)
30 : {
31 3 : uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
32 6 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(textDocument->getText(), uno::UNO_QUERY);
33 : // list of paragraphs
34 6 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
35 :
36 : // maps containing TopBorder widths for every cell
37 : // one map for each tables - there are 8 of them, counting from 0
38 6 : BorderLineMap map0;
39 3 : map0.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 53, 26, 26)));
40 3 : map0.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 79, 26, 26)));
41 3 : map0.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 106, 26, 26)));
42 3 : map0.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 159, 26, 26)));
43 3 : map0.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 212, 26, 26)));
44 6 : BorderLineMap map1;
45 3 : map1.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 9, 9, 9)));
46 3 : map1.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 18, 18, 18)));
47 3 : map1.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 26, 26)));
48 3 : map1.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 53)));
49 3 : map1.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 79)));
50 3 : map1.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 106)));
51 6 : BorderLineMap map2;
52 3 : map2.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 9, 5, 5)));
53 3 : map2.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 18, 9, 9)));
54 3 : map2.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 14, 14)));
55 3 : map2.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 35, 18, 18)));
56 3 : map2.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 26)));
57 3 : map2.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 79, 41, 41)));
58 3 : map2.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 106, 53, 53)));
59 3 : map2.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 159, 79, 79)));
60 3 : map2.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 212, 106, 106)));
61 6 : BorderLineMap map3;
62 3 : map3.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 53, 26, 9)));
63 3 : map3.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 53, 26, 18)));
64 3 : map3.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 53, 26, 26)));
65 3 : map3.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 26, 35)));
66 3 : map3.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 53)));
67 3 : map3.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 53, 26, 79)));
68 3 : map3.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 53, 26, 106)));
69 3 : map3.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 53, 26, 159)));
70 3 : map3.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 53, 26, 212)));
71 3 : map3.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 53, 26, 9)));
72 :
73 : // Binary-DOC importer changes 'inset' and 'outset' border styles to other styles
74 : // during import, so for now - leaving binary-doc results as they were.
75 6 : BorderLineMap map4;
76 3 : if (isBinaryDoc)
77 : {
78 1 : map4.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 53, 26, 18)));
79 1 : map4.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 53, 26, 26)));
80 1 : map4.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 26, 35)));
81 1 : map4.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 35)));
82 1 : map4.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 53, 26, 79)));
83 1 : map4.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 53, 26, 106)));
84 1 : map4.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 53, 26, 159)));
85 1 : map4.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 53, 26, 212)));
86 : }
87 : else
88 : {
89 2 : map4.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 0, 26, 4)));
90 2 : map4.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 5, 26, 5)));
91 2 : map4.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 14, 26, 14)));
92 2 : map4.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 23, 26, 23)));
93 2 : map4.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 41, 26, 41)));
94 2 : map4.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 67, 26, 67)));
95 2 : map4.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 93, 26, 93)));
96 2 : map4.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 146, 26, 146)));
97 2 : map4.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 199, 26, 199)));
98 : }
99 6 : BorderLineMap map5;
100 3 : if (isBinaryDoc)
101 : {
102 1 : map5.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 26, 53, 9)));
103 1 : map5.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 53, 18)));
104 1 : map5.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 53, 26)));
105 1 : map5.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 26, 53, 35)));
106 1 : map5.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 26, 53, 53)));
107 1 : map5.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 26, 53, 79)));
108 1 : map5.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 26, 53, 106)));
109 1 : map5.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 26, 53, 159)));
110 1 : map5.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 26, 53, 212)));
111 : }
112 : else
113 : {
114 2 : map5.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 26, 2, 4)));
115 2 : map5.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 5, 5)));
116 2 : map5.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 14, 14)));
117 2 : map5.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 26, 23, 23)));
118 2 : map5.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 26, 41, 41)));
119 2 : map5.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 26, 67, 67)));
120 2 : map5.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 26, 93, 93)));
121 2 : map5.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 26, 146, 146)));
122 2 : map5.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 26, 199, 199)));
123 : }
124 6 : BorderLineMap map6;
125 3 : map6.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 14, 14, 26)));
126 3 : map6.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 26, 53)));
127 3 : map6.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 41, 41, 79)));
128 3 : map6.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 106)));
129 3 : map6.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 159)));
130 3 : map6.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 212)));
131 6 : BorderLineMap map7;
132 3 : map7.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 14, 14, 26)));
133 3 : map7.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 26, 53)));
134 3 : map7.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 41, 41, 79)));
135 3 : map7.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 106)));
136 3 : map7.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 159)));
137 3 : map7.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 212)));
138 :
139 3 : sal_Int32 currentTable = 0; //to know which map should we check with the current table
140 : BorderLineMap* tempMap;
141 3 : tempMap = &map0;
142 57 : do
143 : {
144 57 : uno::Reference<lang::XServiceInfo> xServiceInfo;
145 57 : if (xParaEnum->nextElement() >>= xServiceInfo)
146 : {
147 57 : if (xServiceInfo->supportsService("com.sun.star.text.TextTable"))
148 : {
149 24 : uno::Reference<text::XTextTable> const xTextTable(xServiceInfo, uno::UNO_QUERY_THROW);
150 48 : uno::Sequence<OUString> const cells = xTextTable->getCellNames();
151 24 : sal_Int32 nLength = cells.getLength();
152 :
153 24 : if(currentTable == sal_Int32(1))
154 3 : tempMap = &map1;
155 24 : if(currentTable == sal_Int32(2))
156 3 : tempMap = &map2;
157 24 : if(currentTable == sal_Int32(3))
158 3 : tempMap = &map3;
159 24 : if(currentTable == sal_Int32(4))
160 3 : tempMap = &map4;
161 24 : if(currentTable == sal_Int32(5))
162 3 : tempMap = &map5;
163 24 : if(currentTable == sal_Int32(6))
164 3 : tempMap = &map6;
165 24 : if(currentTable == sal_Int32(7))
166 3 : tempMap = &map7;
167 :
168 24 : BorderLineMap::iterator it;
169 24 : it = tempMap->begin();
170 :
171 201 : for (sal_Int32 i = 0; i < nLength; ++i)
172 : {
173 177 : uno::Reference<table::XCell> xCell = xTextTable->getCellByName(cells[i]);
174 354 : uno::Reference< beans::XPropertySet > xPropSet(xCell, uno::UNO_QUERY_THROW);
175 354 : uno::Any aAny = xPropSet->getPropertyValue("TopBorder");
176 177 : table::BorderLine aBorderLine;
177 177 : it = tempMap->find(cells[i]);
178 177 : if ((aAny >>= aBorderLine) && (it!=tempMap->end()))
179 : {
180 176 : sal_Int32 innerLineWidth = aBorderLine.InnerLineWidth;
181 176 : sal_Int32 outerLineWidth = aBorderLine.OuterLineWidth;
182 176 : sal_Int32 lineDistance = aBorderLine.LineDistance;
183 :
184 176 : sal_Int32 perfectInner = it->second.InnerLineWidth;
185 176 : sal_Int32 perfectOuter = it->second.OuterLineWidth;
186 176 : sal_Int32 perfectDistance = it->second.LineDistance;
187 176 : CPPUNIT_ASSERT_EQUAL(perfectInner, innerLineWidth);
188 176 : CPPUNIT_ASSERT_EQUAL(perfectOuter, outerLineWidth);
189 176 : CPPUNIT_ASSERT_EQUAL(perfectDistance, lineDistance);
190 : }
191 177 : }
192 48 : ++currentTable;
193 : }
194 57 : }
195 60 : } while(xParaEnum->hasMoreElements());
196 3 : }
197 :
198 : };
199 : #endif
200 :
201 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|