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