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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
/* -*- 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/.
*/
#include <test/bootstrapfixture.hxx>
#include <unotest/macros_test.hxx>
#include <com/sun/star/awt/FontWeight.hpp>
#include <com/sun/star/awt/FontSlant.hpp>
#include <com/sun/star/awt/FontUnderline.hpp>
#include <com/sun/star/awt/FontStrikeout.hpp>
#include <com/sun/star/table/BorderLine2.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/style/ParagraphAdjust.hpp>
#include <com/sun/star/style/LineSpacing.hpp>
#include <com/sun/star/text/XTextDocument.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
using namespace ::com::sun::star;
class LotusWordProTest : public test::BootstrapFixture, public unotest::MacrosTest
{
public:
virtual void setUp() override;
virtual void tearDown() override;
uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
private:
uno::Reference<lang::XComponent> mxComponent;
};
void LotusWordProTest::setUp()
{
test::BootstrapFixture::setUp();
mxDesktop.set(frame::Desktop::create(mxComponentContext));
}
void LotusWordProTest::tearDown()
{
if (mxComponent.is())
mxComponent->dispose();
test::BootstrapFixture::tearDown();
}
constexpr OUStringLiteral DATA_DIRECTORY = u"/lotuswordpro/qa/cppunit/data/";
CPPUNIT_TEST_FIXTURE(LotusWordProTest, testtdf33787OrderedBullets)
{
// Test if ordered bullets are incrementing correclty:
// A. Lettered bullet uppercase 1 (A.)
// B. Lettered bullet uppercase 2 (B.)
// C. Lettered bullet uppercase 3 (C.)
// It is also make sure that nested and skipped bullets are working correctly:
// 1) Numbered bullet w/ bracket one (1))
// Skipped bullet
// 2) Numbered bullet w/ bracket two (2))
// a) Lettered bullet w/ bracket lowercase 1 (a))
// b) Lettered bullet w/ bracket lowercase 2 (b))
OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf33787-ordered-bullets.lwp";
getComponent() = loadFromDesktop(aURL);
uno::Reference<text::XTextDocument> textDocument(getComponent(), uno::UNO_QUERY);
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(textDocument->getText(),
uno::UNO_QUERY);
uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
uno::Reference<beans::XPropertySet> xPara(xParaEnum->nextElement(), uno::UNO_QUERY);
OUString aListLabelString;
xPara->getPropertyValue("ListLabelString") >>= aListLabelString;
// Make sure the list start from 1.
CPPUNIT_ASSERT_EQUAL(OUString("1."), aListLabelString);
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
xPara->getPropertyValue("ListLabelString") >>= aListLabelString;
// Without the accompanying fix in place, this test would have failed, the list label was "1.".
CPPUNIT_ASSERT_EQUAL(OUString("2."), aListLabelString);
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
xPara->getPropertyValue("ListLabelString") >>= aListLabelString;
// Without the accompanying fix in place, this test would have failed, the list label was "1.".
CPPUNIT_ASSERT_EQUAL(OUString("3."), aListLabelString);
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
xPara->getPropertyValue("ListLabelString") >>= aListLabelString;
// Make sure the list start from i.
CPPUNIT_ASSERT_EQUAL(OUString("i."), aListLabelString);
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
xPara->getPropertyValue("ListLabelString") >>= aListLabelString;
// Without the accompanying fix in place, this test would have failed, the list label was "i.".
CPPUNIT_ASSERT_EQUAL(OUString("ii."), aListLabelString);
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
xPara->getPropertyValue("ListLabelString") >>= aListLabelString;
// Without the accompanying fix in place, this test would have failed, the list label was "i.".
CPPUNIT_ASSERT_EQUAL(OUString("iii."), aListLabelString);
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
xPara->getPropertyValue("ListLabelString") >>= aListLabelString;
// Make sure the list start from I.
CPPUNIT_ASSERT_EQUAL(OUString("I."), aListLabelString);
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
xPara->getPropertyValue("ListLabelString") >>= aListLabelString;
// Without the accompanying fix in place, this test would have failed, the list label was "I.".
CPPUNIT_ASSERT_EQUAL(OUString("II."), aListLabelString);
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
xPara->getPropertyValue("ListLabelString") >>= aListLabelString;
// Without the accompanying fix in place, this test would have failed, the list label was "I.".
CPPUNIT_ASSERT_EQUAL(OUString("III."), aListLabelString);
for (int i = 0; i < 7; ++i)
xParaEnum->nextElement();
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
xPara->getPropertyValue("ListLabelString") >>= aListLabelString;
// Without the accompanying fix in place, this test would have failed, the list label was "A.".
CPPUNIT_ASSERT_EQUAL(OUString("C."), aListLabelString);
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
xPara->getPropertyValue("ListLabelString") >>= aListLabelString;
// Make sure the nested list (with indendation) starts from 1).
CPPUNIT_ASSERT_EQUAL(OUString("1)"), aListLabelString);
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
xPara->getPropertyValue("ListLabelString") >>= aListLabelString;
// Make sure skipped element has no prefix
CPPUNIT_ASSERT_EQUAL(OUString(""), aListLabelString);
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
xPara->getPropertyValue("ListLabelString") >>= aListLabelString;
// Make sure the value after Skip is incremented properly
// Without the accompanying fix in place, this test would have failed, the list label was "1)".
CPPUNIT_ASSERT_EQUAL(OUString("2)"), aListLabelString);
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
xPara->getPropertyValue("ListLabelString") >>= aListLabelString;
// Next nested list
CPPUNIT_ASSERT_EQUAL(OUString("a)"), aListLabelString);
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
xPara->getPropertyValue("ListLabelString") >>= aListLabelString;
// Without the accompanying fix in place, this test would have failed, the list label was "a)".
CPPUNIT_ASSERT_EQUAL(OUString("b)"), aListLabelString);
}
CPPUNIT_TEST_FIXTURE(LotusWordProTest, testTdf129993)
{
OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf129993.lwp";
getComponent() = loadFromDesktop(aURL);
uno::Reference<text::XTextDocument> textDocument(getComponent(), uno::UNO_QUERY);
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(textDocument->getText(),
uno::UNO_QUERY);
uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
for (int i = 0; i < 15; ++i)
xParaEnum->nextElement();
uno::Reference<lang::XServiceInfo> xServiceInfo(xParaEnum->nextElement(), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_True, xServiceInfo->supportsService("com.sun.star.text.TextTable"));
}
CPPUNIT_TEST_FIXTURE(LotusWordProTest, paragraphProperties)
{
OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "paragraphProperties.lwp";
getComponent() = loadFromDesktop(aURL);
uno::Reference<text::XTextDocument> textDocument(getComponent(), uno::UNO_QUERY);
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(textDocument->getText(),
uno::UNO_QUERY);
uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
//Ignore the first paragraphs
for (int i = 0; i < 4; ++i)
xParaEnum->nextElement();
// bold
uno::Reference<text::XTextRange> const xParagraph(xParaEnum->nextElement(),
uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> xPropertySet(xParagraph, uno::UNO_QUERY);
float fFontWeight;
xPropertySet->getPropertyValue("CharWeight") >>= fFontWeight;
CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, fFontWeight);
// italic
uno::Reference<text::XTextRange> const xParagraph2(xParaEnum->nextElement(),
uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> xPropertySet2(xParagraph2, uno::UNO_QUERY);
awt::FontSlant fFontSlant;
xPropertySet2->getPropertyValue("CharPosture") >>= fFontSlant;
CPPUNIT_ASSERT_EQUAL(awt::FontSlant_ITALIC, fFontSlant);
// underline
uno::Reference<text::XTextRange> const xParagraph3(xParaEnum->nextElement(),
uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> xPropertySet3(xParagraph3, uno::UNO_QUERY);
sal_Int16 nCharUnderline;
xPropertySet3->getPropertyValue("CharUnderline") >>= nCharUnderline;
CPPUNIT_ASSERT_EQUAL(awt::FontUnderline::SINGLE, nCharUnderline);
// striked through
uno::Reference<text::XTextRange> const xParagraph4(xParaEnum->nextElement(),
uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> xPropertySet4(xParagraph4, uno::UNO_QUERY);
sal_Int16 nFontStrikeout;
xPropertySet4->getPropertyValue("CharStrikeout") >>= nFontStrikeout;
CPPUNIT_ASSERT_EQUAL(awt::FontStrikeout::SINGLE, nFontStrikeout);
//superscript
uno::Reference<text::XTextRange> const xParagraph5(xParaEnum->nextElement(),
uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> xPropertySet5(xParagraph5, uno::UNO_QUERY);
sal_Int32 nCharEscapement;
xPropertySet5->getPropertyValue("CharEscapement") >>= nCharEscapement;
CPPUNIT_ASSERT_EQUAL(sal_Int32(33), nCharEscapement);
sal_Int32 nCharEscapementHeight;
xPropertySet5->getPropertyValue("CharEscapementHeight") >>= nCharEscapementHeight;
CPPUNIT_ASSERT_EQUAL(sal_Int32(58), nCharEscapementHeight);
//subscript
uno::Reference<text::XTextRange> const xParagraph6(xParaEnum->nextElement(),
uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> xPropertySet6(xParagraph6, uno::UNO_QUERY);
sal_Int32 nCharEscapement2;
xPropertySet6->getPropertyValue("CharEscapement") >>= nCharEscapement2;
CPPUNIT_ASSERT_EQUAL(sal_Int32(-33), nCharEscapement2);
sal_Int32 nCharEscapementHeight2;
xPropertySet6->getPropertyValue("CharEscapementHeight") >>= nCharEscapementHeight2;
CPPUNIT_ASSERT_EQUAL(sal_Int32(58), nCharEscapementHeight2);
// red background and borders
uno::Reference<text::XTextRange> const xParagraph7(xParaEnum->nextElement(),
uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> xPropertySet7(xParagraph7, uno::UNO_QUERY);
Color nParaBackColor;
xPropertySet7->getPropertyValue("ParaBackColor") >>= nParaBackColor;
CPPUNIT_ASSERT_EQUAL(Color(0xff0000), nParaBackColor);
table::BorderLine2 aTopBorder;
xPropertySet7->getPropertyValue("TopBorder") >>= aTopBorder;
CPPUNIT_ASSERT_EQUAL(sal_Int16(35), aTopBorder.OuterLineWidth);
table::BorderLine2 aBottomBorder;
xPropertySet7->getPropertyValue("BottomBorder") >>= aBottomBorder;
CPPUNIT_ASSERT_EQUAL(sal_Int16(35), aBottomBorder.OuterLineWidth);
table::BorderLine2 aLeftBorder;
xPropertySet7->getPropertyValue("LeftBorder") >>= aLeftBorder;
CPPUNIT_ASSERT_EQUAL(sal_Int16(35), aLeftBorder.OuterLineWidth);
table::BorderLine2 aRightBorder;
xPropertySet7->getPropertyValue("RightBorder") >>= aRightBorder;
CPPUNIT_ASSERT_EQUAL(sal_Int16(35), aRightBorder.OuterLineWidth);
// centered
uno::Reference<text::XTextRange> const xParagraph8(xParaEnum->nextElement(),
uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> xPropertySet8(xParagraph8, uno::UNO_QUERY);
sal_Int16 nParaAdjust = {}; // spurious -Werror=maybe-uninitialized
xPropertySet8->getPropertyValue("ParaAdjust") >>= nParaAdjust;
CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_CENTER,
static_cast<style::ParagraphAdjust>(nParaAdjust));
// left margin
uno::Reference<text::XTextRange> const xParagraph9(xParaEnum->nextElement(),
uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> xPropertySet9(xParagraph9, uno::UNO_QUERY);
sal_Int32 nParaLeftMargin;
xPropertySet9->getPropertyValue("ParaLeftMargin") >>= nParaLeftMargin;
CPPUNIT_ASSERT_EQUAL(sal_Int32(2000), nParaLeftMargin);
// double line spacing
uno::Reference<text::XTextRange> const xParagraph10(xParaEnum->nextElement(),
uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> xPropertySet10(xParagraph10, uno::UNO_QUERY);
style::LineSpacing nParaLineSpacing;
xPropertySet10->getPropertyValue("ParaLineSpacing") >>= nParaLineSpacing;
CPPUNIT_ASSERT_EQUAL(sal_Int16(200), nParaLineSpacing.Height);
// time new roman 12
uno::Reference<text::XTextRange> const xParagraph11(xParaEnum->nextElement(),
uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> xPropertySet11(xParagraph11, uno::UNO_QUERY);
OUString sCharFontName;
xPropertySet11->getPropertyValue("CharFontName") >>= sCharFontName;
CPPUNIT_ASSERT_EQUAL(OUString("Times New Roman"), sCharFontName);
float fCharFontHeight;
xPropertySet11->getPropertyValue("CharHeight") >>= fCharFontHeight;
CPPUNIT_ASSERT_EQUAL(float(12.), fCharFontHeight);
// time new roman 16
uno::Reference<text::XTextRange> const xParagraph12(xParaEnum->nextElement(),
uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> xPropertySet12(xParagraph12, uno::UNO_QUERY);
OUString sCharFontName2;
xPropertySet12->getPropertyValue("CharFontName") >>= sCharFontName2;
CPPUNIT_ASSERT_EQUAL(OUString("Times New Roman"), sCharFontName2);
float fCharFontHeight2;
xPropertySet12->getPropertyValue("CharHeight") >>= fCharFontHeight2;
CPPUNIT_ASSERT_EQUAL(float(16.), fCharFontHeight2);
//ignore this paragraph
xParaEnum->nextElement();
//text color
uno::Reference<text::XTextRange> const xParagraph13(xParaEnum->nextElement(),
uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> xPropertySet13(xParagraph13, uno::UNO_QUERY);
Color nCharColor;
xPropertySet13->getPropertyValue("CharColor") >>= nCharColor;
CPPUNIT_ASSERT_EQUAL(Color(0x00ff00), nCharColor);
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|