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 <swmodeltestbase.hxx>
11
12 #include <com/sun/star/text/WritingMode2.hpp>
13 #include <com/sun/star/text/XDocumentIndex.hpp>
14 #include <com/sun/star/style/ParagraphAdjust.hpp>
15 #include <o3tl/cppunittraitshelper.hxx>
16 #include <svx/swframetypes.hxx>
17
18 #include <doc.hxx>
19 #include <unotxdoc.hxx>
20 #include <pam.hxx>
21 #include <fmtanchr.hxx>
22
23 /**
24 Split these tests into their own file because they are really really slow
25 */
26
27 class Test : public SwModelTestBase
28 {
29 public:
Test()30 Test()
31 : SwModelTestBase("/sw/qa/extras/rtfexport/data/", "Rich Text Format")
32 {
33 }
34 };
35
36 DECLARE_RTFEXPORT_TEST(testCjklist12, "cjklist12.rtf")
37 {
38 sal_Int16 numFormat = getNumberingTypeOfParagraph(1);
39 CPPUNIT_ASSERT_EQUAL(style::NumberingType::AIU_HALFWIDTH_JA, numFormat);
40 }
41
42 DECLARE_RTFEXPORT_TEST(testCjklist13, "cjklist13.rtf")
43 {
44 sal_Int16 numFormat = getNumberingTypeOfParagraph(1);
45 CPPUNIT_ASSERT_EQUAL(style::NumberingType::IROHA_HALFWIDTH_JA, numFormat);
46 }
47
48 DECLARE_RTFEXPORT_TEST(testCjklist16, "cjklist16.rtf")
49 {
50 sal_Int16 numFormat = getNumberingTypeOfParagraph(1);
51 CPPUNIT_ASSERT_EQUAL(style::NumberingType::NUMBER_TRADITIONAL_JA, numFormat);
52 }
53
54 DECLARE_RTFEXPORT_TEST(testCjklist20, "cjklist20.rtf")
55 {
56 sal_Int16 numFormat = getNumberingTypeOfParagraph(1);
57 CPPUNIT_ASSERT_EQUAL(style::NumberingType::AIU_FULLWIDTH_JA, numFormat);
58 }
59
60 DECLARE_RTFEXPORT_TEST(testCjklist21, "cjklist21.rtf")
61 {
62 sal_Int16 numFormat = getNumberingTypeOfParagraph(1);
63 CPPUNIT_ASSERT_EQUAL(style::NumberingType::IROHA_FULLWIDTH_JA, numFormat);
64 }
65
66 DECLARE_RTFEXPORT_TEST(testCjklist24, "cjklist24.rtf")
67 {
68 sal_Int16 numFormat = getNumberingTypeOfParagraph(1);
69 CPPUNIT_ASSERT_EQUAL(style::NumberingType::HANGUL_SYLLABLE_KO, numFormat);
70 }
71
72 DECLARE_RTFEXPORT_TEST(testCjklist25, "cjklist25.rtf")
73 {
74 sal_Int16 numFormat = getNumberingTypeOfParagraph(1);
75 CPPUNIT_ASSERT_EQUAL(style::NumberingType::HANGUL_JAMO_KO, numFormat);
76 }
77
78 DECLARE_RTFEXPORT_TEST(testCjklist30, "cjklist30.rtf")
79 {
80 sal_Int16 numFormat = getNumberingTypeOfParagraph(1);
81 CPPUNIT_ASSERT_EQUAL(style::NumberingType::TIAN_GAN_ZH, numFormat);
82 }
83
84 DECLARE_RTFEXPORT_TEST(testCjklist31, "cjklist31.rtf")
85 {
86 sal_Int16 numFormat = getNumberingTypeOfParagraph(1);
87 CPPUNIT_ASSERT_EQUAL(style::NumberingType::DI_ZI_ZH, numFormat);
88 }
89
90 DECLARE_RTFEXPORT_TEST(testAnchoredAtSamePosition, "anchor.fodt")
91 {
92 SwXTextDocument* const pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
93 SwDoc* const pDoc = pTextDoc->GetDocShell()->GetDoc();
94
95 CPPUNIT_ASSERT_EQUAL(OUString("foobar"), getParagraph(1)->getString());
96
97 SwFrameFormats& rFlys(*pDoc->GetSpzFrameFormats());
98 if (mbExported)
99 { // 2, not 3: the form control becomes a field on export...
100 CPPUNIT_ASSERT_EQUAL(size_t(2), rFlys.size());
101 }
102 else
103 {
104 CPPUNIT_ASSERT_EQUAL(size_t(3), rFlys.size());
105 }
106
107 sal_Int32 const nIndex(mbExported ? 4 : 3);
108 CPPUNIT_ASSERT_EQUAL(RndStdIds::FLY_AT_CHAR, rFlys[0]->GetAnchor().GetAnchorId());
109 CPPUNIT_ASSERT_EQUAL(sal_uLong(12), rFlys[0]->GetAnchor().GetContentAnchor()->nNode.GetIndex());
110 CPPUNIT_ASSERT_EQUAL(nIndex, rFlys[0]->GetAnchor().GetContentAnchor()->nContent.GetIndex());
111 CPPUNIT_ASSERT_EQUAL(RndStdIds::FLY_AT_CHAR, rFlys[1]->GetAnchor().GetAnchorId());
112 CPPUNIT_ASSERT_EQUAL(sal_uLong(12), rFlys[1]->GetAnchor().GetContentAnchor()->nNode.GetIndex());
113 CPPUNIT_ASSERT_EQUAL(nIndex, rFlys[1]->GetAnchor().GetContentAnchor()->nContent.GetIndex());
114 }
115
116 DECLARE_RTFEXPORT_TEST(testRedlineInsdel, "redline-insdel.rtf")
117 {
118 uno::Reference<text::XTextRange> xParagraph = getParagraph(1);
119
120 uno::Reference<text::XTextRange> xRun = getRun(xParagraph, 1);
121 CPPUNIT_ASSERT_EQUAL(OUString("Text"), getProperty<OUString>(xRun, "TextPortionType"));
122 CPPUNIT_ASSERT_EQUAL(OUString("aaa"), xRun->getString());
123
124 xRun = getRun(xParagraph, 2);
125 CPPUNIT_ASSERT_EQUAL(OUString("Redline"), getProperty<OUString>(xRun, "TextPortionType"));
126 CPPUNIT_ASSERT_EQUAL(OUString("Delete"), getProperty<OUString>(xRun, "RedlineType"));
127 xRun = getRun(xParagraph, 3);
128 CPPUNIT_ASSERT_EQUAL(OUString("Text"), getProperty<OUString>(xRun, "TextPortionType"));
129 CPPUNIT_ASSERT_EQUAL(OUString("bbb"), xRun->getString());
130 xRun = getRun(xParagraph, 4);
131 CPPUNIT_ASSERT_EQUAL(OUString("Redline"), getProperty<OUString>(xRun, "TextPortionType"));
132 CPPUNIT_ASSERT_EQUAL(OUString("Delete"), getProperty<OUString>(xRun, "RedlineType"));
133
134 xRun = getRun(xParagraph, 5);
135 CPPUNIT_ASSERT_EQUAL(OUString("Redline"), getProperty<OUString>(xRun, "TextPortionType"));
136 CPPUNIT_ASSERT_EQUAL(OUString("Insert"), getProperty<OUString>(xRun, "RedlineType"));
137 xRun = getRun(xParagraph, 6);
138 CPPUNIT_ASSERT_EQUAL(OUString("Text"), getProperty<OUString>(xRun, "TextPortionType"));
139 CPPUNIT_ASSERT_EQUAL(OUString("BBB"), xRun->getString());
140 xRun = getRun(xParagraph, 7);
141 CPPUNIT_ASSERT_EQUAL(OUString("Redline"), getProperty<OUString>(xRun, "TextPortionType"));
142 CPPUNIT_ASSERT_EQUAL(OUString("Insert"), getProperty<OUString>(xRun, "RedlineType"));
143
144 xRun = getRun(xParagraph, 8);
145 CPPUNIT_ASSERT_EQUAL(OUString("Text"), getProperty<OUString>(xRun, "TextPortionType"));
146 CPPUNIT_ASSERT_EQUAL(OUString("ccc"), xRun->getString());
147 }
148
149 DECLARE_RTFEXPORT_TEST(testParaAdjustDistribute, "para-adjust-distribute.rtf")
150 {
151 // Without the accompanying fix in place, this test would have failed with
152 // 'Expected: 2; Actual : 0', i.e. the first paragraph's ParaAdjust was
153 // left, not block.
154 CPPUNIT_ASSERT_EQUAL(
155 style::ParagraphAdjust_BLOCK,
156 static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(getParagraph(1), "ParaAdjust")));
157 CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_BLOCK,
158 static_cast<style::ParagraphAdjust>(
159 getProperty<sal_Int16>(getParagraph(1), "ParaLastLineAdjust")));
160
161 CPPUNIT_ASSERT_EQUAL(
162 style::ParagraphAdjust_BLOCK,
163 static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(getParagraph(2), "ParaAdjust")));
164 CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_LEFT,
165 static_cast<style::ParagraphAdjust>(
166 getProperty<sal_Int16>(getParagraph(2), "ParaLastLineAdjust")));
167 }
168
169 DECLARE_RTFEXPORT_TEST(testTdf129574, "mw00_table_of_contents_templates.doc")
170 {
171 uno::Reference<text::XDocumentIndexesSupplier> xIndexSupplier(mxComponent, uno::UNO_QUERY);
172 uno::Reference<container::XIndexAccess> xIndexes(xIndexSupplier->getDocumentIndexes());
173 uno::Reference<text::XDocumentIndex> xTOC(xIndexes->getByIndex(0), uno::UNO_QUERY);
174 CPPUNIT_ASSERT(xTOC.is());
175 uno::Reference<text::XTextRange> xTextRange(xTOC->getAnchor());
176 // table of contents contains 4 paragraphs
177 CPPUNIT_ASSERT_EQUAL(OUString("1.Koffice 1" SAL_NEWLINE_STRING "2.Kword 1" SAL_NEWLINE_STRING
178 "3.Kspread 1" SAL_NEWLINE_STRING "4.Kpresenter 1"),
179 xTextRange->getString());
180 }
181
182 DECLARE_RTFEXPORT_TEST(testCjklist34, "cjklist34.rtf")
183 {
184 sal_Int16 numFormat = getNumberingTypeOfParagraph(1);
185 CPPUNIT_ASSERT_EQUAL(style::NumberingType::NUMBER_UPPER_ZH_TW, numFormat);
186 }
187
CPPUNIT_TEST_FIXTURE(Test,testTabStopFillChars)188 CPPUNIT_TEST_FIXTURE(Test, testTabStopFillChars)
189 {
190 load(mpTestDocumentPath, "tab-stop-fill-chars.rtf");
191 // tlmdot
192 auto aTabstops = getProperty<uno::Sequence<style::TabStop>>(getParagraph(1), "ParaTabStops");
193 CPPUNIT_ASSERT(aTabstops.hasElements());
194 CPPUNIT_ASSERT_EQUAL(u'·', aTabstops[0].FillChar);
195
196 // tlhyph
197 aTabstops = getProperty<uno::Sequence<style::TabStop>>(getParagraph(2), "ParaTabStops");
198 CPPUNIT_ASSERT(aTabstops.hasElements());
199 CPPUNIT_ASSERT_EQUAL(u'-', aTabstops[0].FillChar);
200
201 // tlth
202 aTabstops = getProperty<uno::Sequence<style::TabStop>>(getParagraph(3), "ParaTabStops");
203 CPPUNIT_ASSERT(aTabstops.hasElements());
204 CPPUNIT_ASSERT_EQUAL(u'_', aTabstops[0].FillChar);
205
206 // tleq
207 aTabstops = getProperty<uno::Sequence<style::TabStop>>(getParagraph(4), "ParaTabStops");
208 CPPUNIT_ASSERT(aTabstops.hasElements());
209 CPPUNIT_ASSERT_EQUAL(u' ', aTabstops[0].FillChar);
210 }
211
212 DECLARE_RTFEXPORT_TEST(testCjklist38, "cjklist38.rtf")
213 {
214 sal_Int16 numFormat = getNumberingTypeOfParagraph(1);
215 CPPUNIT_ASSERT_EQUAL(style::NumberingType::NUMBER_UPPER_ZH, numFormat);
216 }
217
218 DECLARE_RTFEXPORT_TEST(testBtlrCell, "btlr-cell.rtf")
219 {
220 // Without the accompanying fix in place, this test would have failed, as
221 // the btlr text direction in the A1 cell was lost.
222 uno::Reference<text::XTextTablesSupplier> xSupplier(mxComponent, uno::UNO_QUERY);
223 uno::Reference<container::XNameAccess> xTables = xSupplier->getTextTables();
224 uno::Reference<text::XTextTable> xTable(xTables->getByName("Table1"), uno::UNO_QUERY);
225 uno::Reference<beans::XPropertySet> xA1(xTable->getCellByName("A1"), uno::UNO_QUERY);
226 CPPUNIT_ASSERT_EQUAL(text::WritingMode2::BT_LR, getProperty<sal_Int16>(xA1, "WritingMode"));
227
228 uno::Reference<beans::XPropertySet> xB1(xTable->getCellByName("B1"), uno::UNO_QUERY);
229 auto nActual = getProperty<sal_Int16>(xB1, "WritingMode");
230 CPPUNIT_ASSERT(nActual == text::WritingMode2::LR_TB || nActual == text::WritingMode2::CONTEXT);
231
232 uno::Reference<beans::XPropertySet> xC1(xTable->getCellByName("C1"), uno::UNO_QUERY);
233 CPPUNIT_ASSERT_EQUAL(text::WritingMode2::TB_RL, getProperty<sal_Int16>(xC1, "WritingMode"));
234 }
235
236 DECLARE_RTFEXPORT_TEST(testTbrlFrame, "tbrl-frame.odt")
237 {
238 uno::Reference<beans::XPropertySet> xShape(getShape(1), uno::UNO_QUERY);
239 auto nActual = getProperty<sal_Int16>(xShape, "WritingMode");
240 // Without the accompanying fix in place, this test would have failed with:
241 // - Expected: 2
242 // - Actual : 0
243 // i.e. custom writing mode was lost.
244 CPPUNIT_ASSERT_EQUAL(text::WritingMode2::TB_RL, nActual);
245 }
246
247 DECLARE_RTFEXPORT_TEST(testBtlrFrame, "btlr-frame.odt")
248 {
249 uno::Reference<beans::XPropertySet> xShape(getShape(1), uno::UNO_QUERY);
250 auto nActual = getProperty<sal_Int16>(xShape, "WritingMode");
251 // Without the accompanying fix in place, this test would have failed with:
252 // - Expected: 5
253 // - Actual : 0
254 // i.e. custom writing mode was lost.
255 CPPUNIT_ASSERT_EQUAL(text::WritingMode2::BT_LR, nActual);
256 }
257
CPPUNIT_TEST_FIXTURE(Test,testPageBorder)258 CPPUNIT_TEST_FIXTURE(Test, testPageBorder)
259 {
260 load(mpTestDocumentPath, "page-border.rtf");
261 uno::Reference<beans::XPropertySet> xPageStyle(getStyles("PageStyles")->getByName("Standard"),
262 uno::UNO_QUERY);
263 auto aTopBorder = getProperty<table::BorderLine2>(xPageStyle, "TopBorder");
264 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(18), aTopBorder.LineWidth);
265
266 auto aLeftBorder = getProperty<table::BorderLine2>(xPageStyle, "LeftBorder");
267 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(35), aLeftBorder.LineWidth);
268
269 auto aBottomBorder = getProperty<table::BorderLine2>(xPageStyle, "BottomBorder");
270 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(53), aBottomBorder.LineWidth);
271
272 auto aRightBorder = getProperty<table::BorderLine2>(xPageStyle, "RightBorder");
273 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(71), aRightBorder.LineWidth);
274 }
275
276 DECLARE_RTFEXPORT_TEST(testTbrlPage, "tbrl-page.rtf")
277 {
278 uno::Reference<beans::XPropertySet> xPageStyle(getStyles("PageStyles")->getByName("Standard"),
279 uno::UNO_QUERY);
280 auto nActual = getProperty<sal_Int16>(xPageStyle, "WritingMode");
281 // Without the accompanying fix in place, this test would have failed with:
282 // - Expected: 2
283 // - Actual : 0
284 // i.e. custom writing mode was lost.
285 CPPUNIT_ASSERT_EQUAL(text::WritingMode2::TB_RL, nActual);
286 }
287
CPPUNIT_TEST_FIXTURE(Test,testTdf126309)288 CPPUNIT_TEST_FIXTURE(Test, testTdf126309)
289 {
290 load(mpTestDocumentPath, "tdf126309.rtf");
291 // Without the accompanying fix in place, this test would have failed, as
292 // the paragraph was aligned to left, not right.
293 CPPUNIT_ASSERT_EQUAL(
294 style::ParagraphAdjust_RIGHT,
295 static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(getParagraph(1), "ParaAdjust")));
296 }
297
298 CPPUNIT_PLUGIN_IMPLEMENT();
299
300 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
301