1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License or as specified alternatively below. You may obtain a copy of
8 * the License at http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * Major Contributor(s):
16 * Copyright (C) 2012 Artur Dorda <artur.dorda+libo@gmail.com> (initial developer)
18 * All Rights Reserved.
20 * For minor contributions see the git repository.
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 * instead of those above.
29 #include <com/sun/star/table/XCell.hpp>
30 #include <com/sun/star/table/BorderLine.hpp>
31 #include <com/sun/star/text/XTextTable.hpp>
33 #ifndef bordertest_hxx
34 #define bordertest_hxx
36 typedef std::map
<OUString
, com::sun::star::table::BorderLine
> BorderLineMap
;
37 typedef std::pair
<OUString
, com::sun::star::table::BorderLine
> StringBorderPair
;
39 using namespace com::sun::star
;
48 void testTheBorders(uno::Reference
<lang::XComponent
> mxComponent
)
50 uno::Reference
<text::XTextDocument
> textDocument(mxComponent
, uno::UNO_QUERY
);
51 uno::Reference
<container::XEnumerationAccess
> xParaEnumAccess(textDocument
->getText(), uno::UNO_QUERY
);
53 uno::Reference
<container::XEnumeration
> xParaEnum
= xParaEnumAccess
->createEnumeration();
55 // maps containing TopBorder widths for every cell
56 // one map for each tables - there are 8 of them, counting from 0
58 map0
.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 53, 26, 26)));
59 map0
.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 79, 26, 26)));
60 map0
.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 106, 26, 26)));
61 map0
.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 159, 26, 26)));
62 map0
.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 212, 26, 26)));
64 map1
.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 9, 9, 9)));
65 map1
.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 18, 18, 18)));
66 map1
.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 26, 26)));
67 map1
.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 53)));
68 map1
.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 79)));
69 map1
.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 106)));
71 map2
.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 9, 5, 5)));
72 map2
.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 18, 9, 9)));
73 map2
.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 14, 14)));
74 map2
.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 35, 18, 18)));
75 map2
.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 26)));
76 map2
.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 79, 41, 41)));
77 map2
.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 106, 53, 53)));
78 map2
.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 159, 79, 79)));
79 map2
.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 212, 106, 106)));
81 map3
.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 53, 26, 9)));
82 map3
.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 53, 26, 18)));
83 map3
.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 53, 26, 26)));
84 map3
.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 26, 35)));
85 map3
.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 53)));
86 map3
.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 53, 26, 79)));
87 map3
.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 53, 26, 106)));
88 map3
.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 53, 26, 159)));
89 map3
.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 53, 26, 212)));
90 map3
.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 53, 26, 9)));
92 map4
.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 53, 26, 18)));
93 map4
.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 53, 26, 26)));
94 map4
.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 26, 35)));
95 map4
.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 35)));
96 map4
.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 53, 26, 79)));
97 map4
.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 53, 26, 106)));
98 map4
.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 53, 26, 159)));
99 map4
.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 53, 26, 212)));
101 map5
.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 26, 53, 9)));
102 map5
.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 53, 18)));
103 map5
.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 53, 26)));
104 map5
.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 26, 53, 35)));
105 map5
.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 26, 53, 53)));
106 map5
.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 26, 53, 79)));
107 map5
.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 26, 53, 106)));
108 map5
.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 26, 53, 159)));
109 map5
.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 26, 53, 212)));
111 map6
.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 14, 14, 26)));
112 map6
.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 26, 53)));
113 map6
.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 41, 41, 79)));
114 map6
.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 106)));
115 map6
.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 159)));
116 map6
.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 212)));
118 map7
.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 14, 14, 26)));
119 map7
.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 26, 53)));
120 map7
.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 41, 41, 79)));
121 map7
.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 106)));
122 map7
.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 159)));
123 map7
.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 212)));
125 sal_Int32 currentTable
= 0; //to know which map should we check with the current table
126 BorderLineMap
* tempMap
;
130 uno::Reference
<lang::XServiceInfo
> xServiceInfo
;
131 if (xParaEnum
->nextElement() >>= xServiceInfo
)
133 if (xServiceInfo
->supportsService("com.sun.star.text.TextTable"))
135 uno::Reference
<text::XTextTable
> const xTextTable(xServiceInfo
, uno::UNO_QUERY_THROW
);
136 uno::Sequence
<OUString
> const cells
= xTextTable
->getCellNames();
137 uno::Sequence
< uno::Sequence
< sal_Int32
> > borderWidthSequence
;
138 sal_Int32 nLength
= cells
.getLength();
140 if(currentTable
== sal_Int32(1))
142 if(currentTable
== sal_Int32(2))
144 if(currentTable
== sal_Int32(3))
146 if(currentTable
== sal_Int32(4))
148 if(currentTable
== sal_Int32(5))
150 if(currentTable
== sal_Int32(6))
152 if(currentTable
== sal_Int32(7))
155 BorderLineMap::iterator it
;
156 it
= tempMap
->begin();
158 for (sal_Int32 i
= 0; i
< nLength
; ++i
)
160 uno::Reference
<table::XCell
> xCell
= xTextTable
->getCellByName(cells
[i
]);
161 uno::Reference
< beans::XPropertySet
> xPropSet(xCell
, uno::UNO_QUERY_THROW
);
162 uno::Any aAny
= xPropSet
->getPropertyValue("TopBorder");
163 table::BorderLine aBorderLine
;
164 it
= tempMap
->find(cells
[i
]);
165 if ((aAny
>>= aBorderLine
) && (it
!=tempMap
->end()))
167 sal_Int32 innerLineWidth
= aBorderLine
.InnerLineWidth
;
168 sal_Int32 outerLineWidth
= aBorderLine
.OuterLineWidth
;
169 sal_Int32 lineDistance
= aBorderLine
.LineDistance
;
171 sal_Int32 perfectInner
= it
->second
.InnerLineWidth
;
172 sal_Int32 perfectOuter
= it
->second
.OuterLineWidth
;
173 sal_Int32 perfectDistance
= it
->second
.LineDistance
;
174 CPPUNIT_ASSERT_EQUAL(perfectInner
, innerLineWidth
);
175 CPPUNIT_ASSERT_EQUAL(perfectOuter
, outerLineWidth
);
176 CPPUNIT_ASSERT_EQUAL(perfectDistance
, lineDistance
);
182 } while(xParaEnum
->hasMoreElements());