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