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