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 #ifndef INCLUDED_SW_QA_INC_BORDERTEST_HXX 10 #define INCLUDED_SW_QA_INC_BORDERTEST_HXX 11 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> 19 20 #include <map> 21 22 namespace com::sun::star::table { class XCell; } 23 24 typedef std::map<OUString, css::table::BorderLine> BorderLineMap; 25 typedef std::pair<OUString, css::table::BorderLine> StringBorderPair; 26 27 using namespace com::sun::star; 28 29 class BorderTest 30 { 31 public: BorderTest()32 BorderTest() 33 { 34 35 } testTheBorders(uno::Reference<lang::XComponent> const & mxComponent,bool isBinaryDoc)36 static void testTheBorders(uno::Reference<lang::XComponent> const & mxComponent, bool isBinaryDoc) 37 { 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(); 42 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(OUString("A1"), table::BorderLine(0, 53, 26, 26))); 47 map0.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 79, 26, 26))); 48 map0.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 106, 26, 26))); 49 map0.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 159, 26, 26))); 50 map0.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 212, 26, 26))); 51 BorderLineMap map1; 52 map1.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 9, 9, 9))); 53 map1.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 18, 18, 18))); 54 map1.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 26, 26))); 55 map1.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 53))); 56 map1.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 79))); 57 map1.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 106))); 58 BorderLineMap map2; 59 map2.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 9, 5, 5))); 60 map2.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 18, 9, 9))); 61 map2.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 14, 14))); 62 map2.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 35, 18, 18))); 63 map2.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 26))); 64 map2.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 79, 41, 41))); 65 map2.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 106, 53, 53))); 66 map2.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 159, 79, 79))); 67 map2.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 212, 106, 106))); 68 BorderLineMap map3; 69 map3.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 53, 26, 9))); 70 map3.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 53, 26, 18))); 71 map3.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 53, 26, 26))); 72 map3.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 26, 35))); 73 map3.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 53))); 74 map3.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 53, 26, 79))); 75 map3.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 53, 26, 106))); 76 map3.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 53, 26, 159))); 77 map3.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 53, 26, 212))); 78 map3.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 53, 26, 9))); 79 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) 84 { 85 map4.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 53, 26, 18))); 86 map4.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 53, 26, 26))); 87 map4.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 26, 35))); 88 map4.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 35))); 89 map4.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 53, 26, 79))); 90 map4.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 53, 26, 106))); 91 map4.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 53, 26, 159))); 92 map4.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 53, 26, 212))); 93 } 94 else 95 { 96 map4.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 0, 26, 4))); 97 map4.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 5, 26, 5))); 98 map4.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 14, 26, 14))); 99 map4.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 23, 26, 23))); 100 map4.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 41, 26, 41))); 101 map4.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 67, 26, 67))); 102 map4.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 93, 26, 93))); 103 map4.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 146, 26, 146))); 104 map4.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 199, 26, 199))); 105 } 106 BorderLineMap map5; 107 if (isBinaryDoc) 108 { 109 map5.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 26, 53, 9))); 110 map5.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 53, 18))); 111 map5.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 53, 26))); 112 map5.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 26, 53, 35))); 113 map5.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 26, 53, 53))); 114 map5.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 26, 53, 79))); 115 map5.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 26, 53, 106))); 116 map5.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 26, 53, 159))); 117 map5.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 26, 53, 212))); 118 } 119 else 120 { 121 map5.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 26, 2, 4))); 122 map5.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 5, 5))); 123 map5.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 14, 14))); 124 map5.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 26, 23, 23))); 125 map5.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 26, 41, 41))); 126 map5.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 26, 67, 67))); 127 map5.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 26, 93, 93))); 128 map5.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 26, 146, 146))); 129 map5.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 26, 199, 199))); 130 } 131 BorderLineMap map6; 132 map6.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 14, 14, 26))); 133 map6.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 26, 53))); 134 map6.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 41, 41, 79))); 135 map6.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 106))); 136 map6.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 159))); 137 map6.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 212))); 138 BorderLineMap map7; 139 map7.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 14, 14, 26))); 140 map7.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 26, 53))); 141 map7.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 41, 41, 79))); 142 map7.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 106))); 143 map7.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 159))); 144 map7.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 212))); 145 146 sal_Int32 currentTable = 0; //to know which map should we check with the current table 147 BorderLineMap* tempMap; 148 tempMap = &map0; 149 do 150 { 151 uno::Reference<lang::XServiceInfo> xServiceInfo; 152 if (xParaEnum->nextElement() >>= xServiceInfo) 153 { 154 if (xServiceInfo->supportsService("com.sun.star.text.TextTable")) 155 { 156 uno::Reference<text::XTextTable> const xTextTable(xServiceInfo, uno::UNO_QUERY_THROW); 157 uno::Sequence<OUString> const cells = xTextTable->getCellNames(); 158 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; 173 174 BorderLineMap::iterator it = tempMap->begin(); 175 176 for (const auto& rCell : cells) 177 { 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("TopBorder"); 181 table::BorderLine aBorderLine; 182 it = tempMap->find(rCell); 183 if ((aAny >>= aBorderLine) && (it!=tempMap->end())) 184 { 185 sal_Int32 innerLineWidth = aBorderLine.InnerLineWidth; 186 sal_Int32 outerLineWidth = aBorderLine.OuterLineWidth; 187 sal_Int32 lineDistance = aBorderLine.LineDistance; 188 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); 195 } 196 } 197 ++currentTable; 198 } 199 } 200 } while(xParaEnum->hasMoreElements()); 201 } 202 203 }; 204 #endif 205 206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 207