summaryrefslogtreecommitdiff
path: root/sw/qa/extras/inc/bordertest.hxx
blob: 52776c38e012359cbbe31c822835822d8dd2e435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
#ifndef INCLUDED_SW_QA_EXTRAS_INC_BORDERTEST_HXX
#define INCLUDED_SW_QA_EXTRAS_INC_BORDERTEST_HXX

#include <cppunit/TestAssert.h>
#include <com/sun/star/table/BorderLine.hpp>
#include <com/sun/star/text/XTextTable.hpp>
#include <com/sun/star/text/XTextDocument.hpp>
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>

#include <map>

namespace com::sun::star::table { class XCell; }

typedef std::map<OUString, css::table::BorderLine> BorderLineMap;
typedef std::pair<OUString, css::table::BorderLine> StringBorderPair;

using namespace com::sun::star;

class BorderTest
{
public:
    BorderTest()
    {

    }
    static void testTheBorders(uno::Reference<lang::XComponent> const & mxComponent, bool isBinaryDoc)
    {
    uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
    uno::Reference<container::XEnumerationAccess> xParaEnumAccess(textDocument->getText(), uno::UNO_QUERY);
    // list of paragraphs
    uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();

    // maps containing TopBorder widths for every cell
    // one map for each tables - there are 8 of them, counting from 0
    BorderLineMap map0;
    map0.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 53, 26, 26)));
    map0.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 79, 26, 26)));
    map0.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 106, 26, 26)));
    map0.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 159, 26, 26)));
    map0.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 212, 26, 26)));
    BorderLineMap map1;
    map1.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 9, 9, 9)));
    map1.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 18, 18, 18)));
    map1.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 26, 26)));
    map1.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 53)));
    map1.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 79)));
    map1.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 106)));
    BorderLineMap map2;
    map2.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 9, 5, 5)));
    map2.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 18, 9, 9)));
    map2.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 14, 14)));
    map2.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 35, 18, 18)));
    map2.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 26)));
    map2.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 79, 41, 41)));
    map2.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 106, 53, 53)));
    map2.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 159, 79, 79)));
    map2.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 212, 106, 106)));
    BorderLineMap map3;
    map3.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 53, 26, 9)));
    map3.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 53, 26, 18)));
    map3.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 53, 26, 26)));
    map3.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 26, 35)));
    map3.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 53)));
    map3.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 53, 26, 79)));
    map3.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 53, 26, 106)));
    map3.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 53, 26, 159)));
    map3.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 53, 26, 212)));
    map3.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 53, 26, 9)));

    // Binary-DOC importer changes 'inset' and 'outset' border styles to other styles
    // during import, so for now - leaving binary-doc results as they were.
    BorderLineMap map4;
    if (isBinaryDoc)
    {
        map4.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 53, 26, 18)));
        map4.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 53, 26, 26)));
        map4.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 26, 35)));
        map4.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 53, 26, 35)));
        map4.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 53, 26, 79)));
        map4.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 53, 26, 106)));
        map4.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 53, 26, 159)));
        map4.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 53, 26, 212)));
    }
    else
    {
        map4.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 0, 26, 4)));
        map4.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 5, 26, 5)));
        map4.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 14, 26, 14)));
        map4.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 23, 26, 23)));
        map4.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 41, 26, 41)));
        map4.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 67, 26, 67)));
        map4.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 93, 26, 93)));
        map4.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 146, 26, 146)));
        map4.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 199, 26, 199)));
    }
    BorderLineMap map5;
    if (isBinaryDoc)
    {
        map5.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 26, 53, 9)));
        map5.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 53, 18)));
        map5.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 53, 26)));
        map5.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 26, 53, 35)));
        map5.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 26, 53, 53)));
        map5.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 26, 53, 79)));
        map5.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 26, 53, 106)));
        map5.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 26, 53, 159)));
        map5.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 26, 53, 212)));
    }
    else
    {
        map5.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 26, 2, 4)));
        map5.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 5, 5)));
        map5.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 26, 14, 14)));
        map5.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 26, 23, 23)));
        map5.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 26, 41, 41)));
        map5.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 26, 67, 67)));
        map5.insert(StringBorderPair(OUString("G1"), table::BorderLine(0, 26, 93, 93)));
        map5.insert(StringBorderPair(OUString("H1"), table::BorderLine(0, 26, 146, 146)));
        map5.insert(StringBorderPair(OUString("I1"), table::BorderLine(0, 26, 199, 199)));
    }
    BorderLineMap map6;
    map6.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 14, 14, 26)));
    map6.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 26, 53)));
    map6.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 41, 41, 79)));
    map6.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 106)));
    map6.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 159)));
    map6.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 212)));
    BorderLineMap map7;
    map7.insert(StringBorderPair(OUString("A1"), table::BorderLine(0, 14, 14, 26)));
    map7.insert(StringBorderPair(OUString("B1"), table::BorderLine(0, 26, 26, 53)));
    map7.insert(StringBorderPair(OUString("C1"), table::BorderLine(0, 41, 41, 79)));
    map7.insert(StringBorderPair(OUString("D1"), table::BorderLine(0, 53, 53, 106)));
    map7.insert(StringBorderPair(OUString("E1"), table::BorderLine(0, 79, 79, 159)));
    map7.insert(StringBorderPair(OUString("F1"), table::BorderLine(0, 106, 106, 212)));

    sal_Int32 currentTable = 0; //to know which map should we check with the current table
    BorderLineMap* tempMap;
    tempMap = &map0;
    do
    {
        uno::Reference<lang::XServiceInfo> xServiceInfo;
        if (xParaEnum->nextElement() >>= xServiceInfo)
        {
            if (xServiceInfo->supportsService("com.sun.star.text.TextTable"))
            {
                uno::Reference<text::XTextTable> const xTextTable(xServiceInfo, uno::UNO_QUERY_THROW);
                uno::Sequence<OUString> const cells = xTextTable->getCellNames();

                if(currentTable == sal_Int32(1))
                    tempMap = &map1;
                if(currentTable == sal_Int32(2))
                    tempMap = &map2;
                if(currentTable == sal_Int32(3))
                    tempMap = &map3;
                if(currentTable == sal_Int32(4))
                    tempMap = &map4;
                if(currentTable == sal_Int32(5))
                    tempMap = &map5;
                if(currentTable == sal_Int32(6))
                    tempMap = &map6;
                if(currentTable == sal_Int32(7))
                    tempMap = &map7;

                BorderLineMap::iterator it = tempMap->begin();

                for (const auto& rCell : cells)
                {
                    uno::Reference<table::XCell> xCell = xTextTable->getCellByName(rCell);
                    uno::Reference< beans::XPropertySet > xPropSet(xCell, uno::UNO_QUERY_THROW);
                    uno::Any aAny = xPropSet->getPropertyValue("TopBorder");
                    table::BorderLine aBorderLine;
                    it = tempMap->find(rCell);
                    if ((aAny >>= aBorderLine) && (it!=tempMap->end()))
                    {
                        sal_Int32 innerLineWidth = aBorderLine.InnerLineWidth;
                        sal_Int32 outerLineWidth = aBorderLine.OuterLineWidth;
                        sal_Int32 lineDistance = aBorderLine.LineDistance;

                        sal_Int32 perfectInner = it->second.InnerLineWidth;
                        sal_Int32 perfectOuter = it->second.OuterLineWidth;
                        sal_Int32 perfectDistance = it->second.LineDistance;
                        CPPUNIT_ASSERT_EQUAL(perfectInner, innerLineWidth);
                        CPPUNIT_ASSERT_EQUAL(perfectOuter, outerLineWidth);
                        CPPUNIT_ASSERT_EQUAL(perfectDistance, lineDistance);
                    }
                }
                ++currentTable;
            }
        }
    } while(xParaEnum->hasMoreElements());
    }

};
#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */