Line data Source code
1 : /*
2 : * This file is part of the LibreOffice project.
3 : *
4 : * This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this
6 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 : */
8 :
9 : #include <swmodeltestbase.hxx>
10 :
11 : #include <com/sun/star/awt/FontDescriptor.hpp>
12 : #include <com/sun/star/document/XFilter.hpp>
13 : #include <com/sun/star/document/XImporter.hpp>
14 : #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
15 : #include <com/sun/star/drawing/EnhancedCustomShapeSegment.hpp>
16 : #include <com/sun/star/drawing/FillStyle.hpp>
17 : #include <com/sun/star/drawing/LineStyle.hpp>
18 : #include <com/sun/star/graphic/GraphicType.hpp>
19 : #include <com/sun/star/lang/XServiceInfo.hpp>
20 : #include <com/sun/star/style/BreakType.hpp>
21 : #include <com/sun/star/style/CaseMap.hpp>
22 : #include <com/sun/star/style/LineSpacing.hpp>
23 : #include <com/sun/star/style/LineSpacingMode.hpp>
24 : #include <com/sun/star/style/ParagraphAdjust.hpp>
25 : #include <com/sun/star/table/BorderLine2.hpp>
26 : #include <com/sun/star/table/BorderLineStyle.hpp>
27 : #include <com/sun/star/text/RelOrientation.hpp>
28 : #include <com/sun/star/text/SizeType.hpp>
29 : #include <com/sun/star/text/TableColumnSeparator.hpp>
30 : #include <com/sun/star/text/TextContentAnchorType.hpp>
31 : #include <com/sun/star/text/XFootnotesSupplier.hpp>
32 : #include <com/sun/star/text/XPageCursor.hpp>
33 : #include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp>
34 : #include <com/sun/star/text/XTextFieldsSupplier.hpp>
35 : #include <com/sun/star/text/XTextFramesSupplier.hpp>
36 : #include <com/sun/star/text/XTextRangeCompare.hpp>
37 : #include <com/sun/star/text/XTextTablesSupplier.hpp>
38 : #include <com/sun/star/text/XTextTable.hpp>
39 : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
40 : #include <com/sun/star/text/WrapTextMode.hpp>
41 : #include <com/sun/star/text/HoriOrientation.hpp>
42 : #include <com/sun/star/text/VertOrientation.hpp>
43 : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
44 :
45 : #include <rtl/ustring.hxx>
46 : #include <vcl/outdev.hxx>
47 : #include <vcl/svapp.hxx>
48 : #include <vcl/settings.hxx>
49 : #include <unotools/ucbstreamhelper.hxx>
50 : #include <unotools/streamwrap.hxx>
51 : #include <comphelper/sequenceashashmap.hxx>
52 :
53 : #include <bordertest.hxx>
54 :
55 135 : class Test : public SwModelTestBase
56 : {
57 : public:
58 135 : Test() : SwModelTestBase("/sw/qa/extras/rtfimport/data/", "Rich Text Format")
59 : {
60 135 : }
61 :
62 135 : virtual void preTest(const char* filename) SAL_OVERRIDE
63 : {
64 135 : m_aSavedSettings = Application::GetSettings();
65 135 : if (OString(filename) == "fdo48023.rtf")
66 : {
67 1 : AllSettings aSettings(m_aSavedSettings);
68 1 : aSettings.SetLanguageTag(LanguageTag("ru"));
69 1 : Application::SetSettings(aSettings);
70 : }
71 134 : else if (OString(filename) == "fdo44211.rtf")
72 : {
73 1 : AllSettings aSettings(m_aSavedSettings);
74 1 : aSettings.SetLanguageTag(LanguageTag("lt"));
75 1 : Application::SetSettings(aSettings);
76 : }
77 135 : }
78 :
79 135 : virtual void postTest(const char* filename) SAL_OVERRIDE
80 : {
81 135 : if (OString(filename) == "fdo48023.rtf" || OString(filename) == "fdo44211.rtf")
82 2 : Application::SetSettings(m_aSavedSettings);
83 135 : }
84 :
85 : protected:
86 : /// Copy&paste helper.
87 7 : void paste(const OUString& aFilename, uno::Reference<text::XTextRange> xTextRange = uno::Reference<text::XTextRange>())
88 : {
89 7 : uno::Reference<document::XFilter> xFilter(m_xSFactory->createInstance("com.sun.star.comp.Writer.RtfFilter"), uno::UNO_QUERY_THROW);
90 14 : uno::Reference<document::XImporter> xImporter(xFilter, uno::UNO_QUERY_THROW);
91 7 : xImporter->setTargetDocument(mxComponent);
92 14 : uno::Sequence<beans::PropertyValue> aDescriptor(xTextRange.is() ? 3 : 2);
93 7 : aDescriptor[0].Name = "InputStream";
94 7 : SvStream* pStream = utl::UcbStreamHelper::CreateStream(getURLFromSrc("/sw/qa/extras/rtfimport/data/") + aFilename, STREAM_WRITE);
95 14 : uno::Reference<io::XStream> xStream(new utl::OStreamWrapper(*pStream));
96 7 : aDescriptor[0].Value <<= xStream;
97 7 : aDescriptor[1].Name = "InsertMode";
98 7 : aDescriptor[1].Value <<= sal_True;
99 7 : if (xTextRange.is())
100 : {
101 6 : aDescriptor[2].Name = "TextInsertModeRange";
102 6 : aDescriptor[2].Value <<= xTextRange;
103 : }
104 14 : xFilter->filter(aDescriptor);
105 7 : }
106 :
107 : AllSettings m_aSavedSettings;
108 : };
109 :
110 : #define DECLARE_RTFIMPORT_TEST(TestName, filename) DECLARE_SW_IMPORT_TEST(TestName, filename, Test)
111 :
112 : #if !defined(MACOSX) && !defined(WNT)
113 :
114 9 : DECLARE_RTFIMPORT_TEST(testFdo45553, "fdo45553.rtf")
115 : {
116 1 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
117 2 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
118 2 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
119 4 : while (xParaEnum->hasMoreElements())
120 : {
121 2 : uno::Reference<container::XEnumerationAccess> xRangeEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
122 4 : uno::Reference<container::XEnumeration> xRangeEnum = xRangeEnumAccess->createEnumeration();
123 6 : while (xRangeEnum->hasMoreElements())
124 : {
125 2 : uno::Reference<text::XTextRange> xRange(xRangeEnum->nextElement(), uno::UNO_QUERY);
126 4 : OUString aStr = xRange->getString();
127 2 : if ( aStr == "space-before" )
128 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(TWIP_TO_MM100(120)), getProperty<sal_Int32>(xRange, "ParaTopMargin"));
129 1 : else if ( aStr == "space-after" )
130 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(TWIP_TO_MM100(240)), getProperty<sal_Int32>(xRange, "ParaBottomMargin"));
131 2 : }
132 3 : }
133 1 : }
134 :
135 9 : DECLARE_RTFIMPORT_TEST(testN192129, "n192129.rtf")
136 : {
137 : // We expect that the result will be 16x16px.
138 1 : Size aExpectedSize(16, 16);
139 1 : MapMode aMap(MAP_100TH_MM);
140 1 : aExpectedSize = Application::GetDefaultDevice()->PixelToLogic( aExpectedSize, aMap );
141 :
142 2 : uno::Reference<text::XTextGraphicObjectsSupplier> xTextGraphicObjectsSupplier(mxComponent, uno::UNO_QUERY);
143 2 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextGraphicObjectsSupplier->getGraphicObjects(), uno::UNO_QUERY);
144 2 : uno::Reference<drawing::XShape> xShape(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
145 1 : awt::Size aActualSize(xShape->getSize());
146 :
147 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(aExpectedSize.Width()), aActualSize.Width);
148 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(aExpectedSize.Height()), aActualSize.Height);
149 1 : }
150 :
151 9 : DECLARE_RTFIMPORT_TEST(testFdo45543, "fdo45543.rtf")
152 : {
153 1 : CPPUNIT_ASSERT_EQUAL(5, getLength());
154 1 : }
155 :
156 9 : DECLARE_RTFIMPORT_TEST(testN695479, "n695479.rtf")
157 : {
158 1 : uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
159 2 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
160 2 : uno::Reference<beans::XPropertySet> xPropertySet(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
161 :
162 : // Negative ABSH should mean fixed size.
163 1 : CPPUNIT_ASSERT_EQUAL(text::SizeType::FIX, getProperty<sal_Int16>(xPropertySet, "SizeType"));
164 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(TWIP_TO_MM100(300)), getProperty<sal_Int32>(xPropertySet, "Height"));
165 :
166 2 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
167 2 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
168 1 : bool bFrameFound = false, bDrawFound = false;
169 4 : for (int i = 0; i < xDraws->getCount(); ++i)
170 : {
171 3 : uno::Reference<lang::XServiceInfo> xServiceInfo(xDraws->getByIndex(i), uno::UNO_QUERY);
172 3 : if (xServiceInfo->supportsService("com.sun.star.text.TextFrame"))
173 : {
174 : // Both frames should be anchored to the first paragraph.
175 2 : bFrameFound = true;
176 2 : uno::Reference<text::XTextContent> xTextContent(xServiceInfo, uno::UNO_QUERY);
177 4 : uno::Reference<text::XTextRange> xRange(xTextContent->getAnchor(), uno::UNO_QUERY);
178 4 : uno::Reference<text::XText> xText(xRange->getText(), uno::UNO_QUERY);
179 2 : CPPUNIT_ASSERT_EQUAL(OUString("plain"), xText->getString());
180 :
181 2 : if (i == 0)
182 : // Additionally, the frist frame should have double border at the bottom.
183 2 : CPPUNIT_ASSERT_EQUAL(table::BorderLineStyle::DOUBLE, getProperty<table::BorderLine2>(xPropertySet, "BottomBorder").LineStyle);
184 : }
185 1 : else if (xServiceInfo->supportsService("com.sun.star.drawing.LineShape"))
186 : {
187 : // The older "drawing objects" syntax should be recognized.
188 1 : bDrawFound = true;
189 1 : xPropertySet.set(xServiceInfo, uno::UNO_QUERY);
190 1 : CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_PRINT_AREA, getProperty<sal_Int16>(xPropertySet, "HoriOrientRelation"));
191 1 : CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(xPropertySet, "VertOrientRelation"));
192 : }
193 3 : }
194 1 : CPPUNIT_ASSERT(bFrameFound);
195 2 : CPPUNIT_ASSERT(bDrawFound);
196 1 : }
197 :
198 9 : DECLARE_RTFIMPORT_TEST(testFdo42465, "fdo42465.rtf")
199 : {
200 1 : CPPUNIT_ASSERT_EQUAL(3, getLength());
201 1 : }
202 :
203 9 : DECLARE_RTFIMPORT_TEST(testFdo45187, "fdo45187.rtf")
204 : {
205 1 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
206 2 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
207 : // There should be two shapes.
208 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xDraws->getCount());
209 :
210 : // They should be anchored to different paragraphs.
211 2 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
212 2 : uno::Reference<text::XTextRangeCompare> xTextRangeCompare(xTextDocument->getText(), uno::UNO_QUERY);
213 2 : uno::Reference<text::XTextRange> xAnchor0 = uno::Reference<text::XTextContent>(xDraws->getByIndex(0), uno::UNO_QUERY)->getAnchor();
214 2 : uno::Reference<text::XTextRange> xAnchor1 = uno::Reference<text::XTextContent>(xDraws->getByIndex(1), uno::UNO_QUERY)->getAnchor();
215 : // Was 0 ("starts at the same position"), should be 1 ("starts before")
216 2 : CPPUNIT_ASSERT_EQUAL(sal_Int16(1), xTextRangeCompare->compareRegionStarts(xAnchor0, xAnchor1));
217 1 : }
218 :
219 9 : DECLARE_RTFIMPORT_TEST(testFdo46662, "fdo46662.rtf")
220 : {
221 1 : uno::Reference<beans::XPropertySet> xPropertySet(getStyles("NumberingStyles")->getByName("WWNum3"), uno::UNO_QUERY);
222 2 : uno::Reference<container::XIndexAccess> xLevels(xPropertySet->getPropertyValue("NumberingRules"), uno::UNO_QUERY);
223 2 : uno::Sequence<beans::PropertyValue> aProps;
224 1 : xLevels->getByIndex(1) >>= aProps; // 2nd level
225 :
226 13 : for (int i = 0; i < aProps.getLength(); ++i)
227 : {
228 12 : const beans::PropertyValue& rProp = aProps[i];
229 :
230 12 : if ( rProp.Name == "ParentNumbering" )
231 1 : CPPUNIT_ASSERT_EQUAL(sal_Int16(2), rProp.Value.get<sal_Int16>());
232 11 : else if ( rProp.Name == "Suffix" )
233 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rProp.Value.get<OUString>().getLength());
234 1 : }
235 1 : }
236 :
237 9 : DECLARE_RTFIMPORT_TEST(testN750757, "n750757.rtf")
238 : {
239 1 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
240 2 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
241 2 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
242 :
243 1 : CPPUNIT_ASSERT_EQUAL(sal_Bool(false), getProperty<sal_Bool>(xParaEnum->nextElement(), "ParaContextMargin"));
244 2 : CPPUNIT_ASSERT_EQUAL(sal_Bool(true), getProperty<sal_Bool>(xParaEnum->nextElement(), "ParaContextMargin"));
245 1 : }
246 :
247 9 : DECLARE_RTFIMPORT_TEST(testFdo45563, "fdo45563.rtf")
248 : {
249 1 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
250 2 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
251 2 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
252 1 : int i = 0;
253 6 : while (xParaEnum->hasMoreElements())
254 : {
255 4 : xParaEnum->nextElement();
256 4 : i++;
257 : }
258 2 : CPPUNIT_ASSERT_EQUAL(4, i);
259 1 : }
260 :
261 9 : DECLARE_RTFIMPORT_TEST(testFdo43965, "fdo43965.rtf")
262 : {
263 1 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
264 2 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
265 2 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
266 :
267 : // First paragraph: the parameter of \up was ignored
268 2 : uno::Reference<container::XEnumerationAccess> xRangeEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
269 2 : uno::Reference<container::XEnumeration> xRangeEnum = xRangeEnumAccess->createEnumeration();
270 2 : uno::Reference<beans::XPropertySet> xPropertySet(xRangeEnum->nextElement(), uno::UNO_QUERY);
271 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(36), getProperty<sal_Int32>(xPropertySet, "CharEscapement"));
272 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(100), getProperty<sal_Int32>(xPropertySet, "CharEscapementHeight"));
273 :
274 : // Second paragraph: Word vs Writer border default problem
275 1 : CPPUNIT_ASSERT_EQUAL(sal_uInt32(26), getProperty<table::BorderLine2>(xParaEnum->nextElement(), "TopBorder").LineWidth);
276 :
277 : // Finally, make sure that we have two pages
278 2 : CPPUNIT_ASSERT_EQUAL(2, getPages());
279 1 : }
280 :
281 9 : DECLARE_RTFIMPORT_TEST(testN751020, "n751020.rtf")
282 : {
283 1 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
284 2 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
285 2 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
286 1 : CPPUNIT_ASSERT(xParaEnum->hasMoreElements());
287 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(TWIP_TO_MM100(200)), getProperty<sal_Int32>(xParaEnum->nextElement(), "ParaBottomMargin"));
288 1 : }
289 :
290 9 : DECLARE_RTFIMPORT_TEST(testFdo47326, "fdo47326.rtf")
291 : {
292 : // This was 15 only, as \super buffered text, then the contents of it got lost.
293 1 : CPPUNIT_ASSERT_EQUAL(19, getLength());
294 1 : }
295 :
296 9 : DECLARE_RTFIMPORT_TEST(testFdo47036, "fdo47036.rtf")
297 : {
298 1 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
299 2 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
300 1 : int nAtCharacter = 0;
301 4 : for (int i = 0; i < xDraws->getCount(); ++i)
302 : {
303 3 : if (getProperty<text::TextContentAnchorType>(xDraws->getByIndex(i), "AnchorType") == text::TextContentAnchorType_AT_CHARACTER)
304 1 : nAtCharacter++;
305 : }
306 : // The image at the document start was ignored.
307 1 : CPPUNIT_ASSERT_EQUAL(1, nAtCharacter);
308 :
309 : // There should be 2 textboxes, not 4
310 2 : uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
311 2 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
312 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount());
313 1 : }
314 :
315 9 : DECLARE_RTFIMPORT_TEST(testFdo46955, "fdo46955.rtf")
316 : {
317 1 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
318 2 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
319 2 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
320 3 : while (xParaEnum->hasMoreElements())
321 : {
322 1 : uno::Reference<container::XEnumerationAccess> xRangeEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
323 2 : uno::Reference<container::XEnumeration> xRangeEnum = xRangeEnumAccess->createEnumeration();
324 3 : while (xRangeEnum->hasMoreElements())
325 1 : CPPUNIT_ASSERT_EQUAL(style::CaseMap::UPPERCASE, getProperty<sal_Int16>(xRangeEnum->nextElement(), "CharCaseMap"));
326 2 : }
327 1 : }
328 :
329 9 : DECLARE_RTFIMPORT_TEST(testFdo45394, "fdo45394.rtf")
330 : {
331 1 : uno::Reference<text::XText> xHeaderText = getProperty< uno::Reference<text::XText> >(getStyles("PageStyles")->getByName(DEFAULT_STYLE), "HeaderText");
332 2 : OUString aActual = xHeaderText->getString();
333 : // Encoding in the header was wrong.
334 2 : OUString aExpected("\xd0\x9f\xd0\x9a \xd0\xa0\xd0\x98\xd0\x9a", 11, RTL_TEXTENCODING_UTF8);
335 1 : CPPUNIT_ASSERT_EQUAL(aExpected, aActual);
336 :
337 2 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
338 2 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
339 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
340 1 : }
341 :
342 9 : DECLARE_RTFIMPORT_TEST(testFdo48104, "fdo48104.rtf")
343 : {
344 1 : CPPUNIT_ASSERT_EQUAL(2, getPages());
345 1 : }
346 :
347 9 : DECLARE_RTFIMPORT_TEST(testFdo47107, "fdo47107.rtf")
348 : {
349 1 : uno::Reference<container::XNameAccess> xNumberingStyles(getStyles("NumberingStyles"));
350 : // Make sure numbered and bullet legacy syntax is recognized, this used to throw a NoSuchElementException
351 1 : xNumberingStyles->getByName("WWNum1");
352 1 : xNumberingStyles->getByName("WWNum2");
353 1 : }
354 :
355 9 : DECLARE_RTFIMPORT_TEST(testFdo45182, "fdo45182.rtf")
356 : {
357 1 : uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY);
358 2 : uno::Reference<container::XIndexAccess> xFootnotes(xFootnotesSupplier->getFootnotes(), uno::UNO_QUERY);
359 2 : uno::Reference<text::XTextRange> xTextRange(xFootnotes->getByIndex(0), uno::UNO_QUERY);
360 : // Encoding in the footnote was wrong.
361 2 : OUString aExpected("\xc5\xbeivnost\xc3\xad\n", 11, RTL_TEXTENCODING_UTF8);
362 2 : CPPUNIT_ASSERT_EQUAL(aExpected, xTextRange->getString());
363 1 : }
364 :
365 9 : DECLARE_RTFIMPORT_TEST(testFdo44176, "fdo44176.rtf")
366 : {
367 1 : uno::Reference<container::XNameAccess> xPageStyles(getStyles("PageStyles"));
368 2 : uno::Reference<beans::XPropertySet> xFirstPage(xPageStyles->getByName("First Page"), uno::UNO_QUERY);
369 2 : uno::Reference<beans::XPropertySet> xDefault(xPageStyles->getByName(DEFAULT_STYLE), uno::UNO_QUERY);
370 1 : sal_Int32 nFirstTop = 0, nDefaultTop = 0, nDefaultHeader = 0;
371 1 : xFirstPage->getPropertyValue("TopMargin") >>= nFirstTop;
372 1 : xDefault->getPropertyValue("TopMargin") >>= nDefaultTop;
373 1 : xDefault->getPropertyValue("HeaderHeight") >>= nDefaultHeader;
374 2 : CPPUNIT_ASSERT_EQUAL(nFirstTop, nDefaultTop + nDefaultHeader);
375 1 : }
376 :
377 9 : DECLARE_RTFIMPORT_TEST(testFdo39053, "fdo39053.rtf")
378 : {
379 1 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
380 2 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
381 1 : int nAsCharacter = 0;
382 2 : for (int i = 0; i < xDraws->getCount(); ++i)
383 1 : if (getProperty<text::TextContentAnchorType>(xDraws->getByIndex(i), "AnchorType") == text::TextContentAnchorType_AS_CHARACTER)
384 1 : nAsCharacter++;
385 : // The image in binary format was ignored.
386 2 : CPPUNIT_ASSERT_EQUAL(1, nAsCharacter);
387 1 : }
388 :
389 9 : DECLARE_RTFIMPORT_TEST(testFdo48356, "fdo48356.rtf")
390 : {
391 1 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
392 2 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
393 2 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
394 1 : int i = 0;
395 3 : while (xParaEnum->hasMoreElements())
396 : {
397 1 : xParaEnum->nextElement();
398 1 : i++;
399 : }
400 : // The document used to be imported as two paragraphs.
401 2 : CPPUNIT_ASSERT_EQUAL(1, i);
402 1 : }
403 :
404 9 : DECLARE_RTFIMPORT_TEST(testFdo48023, "fdo48023.rtf")
405 : {
406 1 : uno::Reference<text::XTextRange> xTextRange = getRun(getParagraph(1), 1);
407 :
408 : // Implicit encoding detection based on locale was missing
409 2 : OUString aExpected("\xd0\x9f\xd1\x80\xd0\xbe\xd0\xb3\xd1\x80\xd0\xb0\xd0\xbc\xd0\xbc\xd0\xb8\xd1\x81\xd1\x82", 22, RTL_TEXTENCODING_UTF8);
410 2 : CPPUNIT_ASSERT_EQUAL(aExpected, xTextRange->getString());
411 1 : }
412 :
413 9 : DECLARE_RTFIMPORT_TEST(testFdo48876, "fdo48876.rtf")
414 : {
415 1 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
416 2 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
417 2 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
418 1 : CPPUNIT_ASSERT(xParaEnum->hasMoreElements());
419 2 : CPPUNIT_ASSERT_EQUAL(style::LineSpacingMode::MINIMUM, getProperty<style::LineSpacing>(xParaEnum->nextElement(), "ParaLineSpacing").Mode);
420 1 : }
421 :
422 9 : DECLARE_RTFIMPORT_TEST(testFdo48193, "fdo48193.rtf")
423 : {
424 1 : CPPUNIT_ASSERT_EQUAL(7, getLength());
425 1 : }
426 :
427 9 : DECLARE_RTFIMPORT_TEST(testFdo44211, "fdo44211.rtf")
428 : {
429 1 : uno::Reference<text::XTextRange> xTextRange = getRun(getParagraph(1), 1);
430 :
431 2 : OUString aExpected("\xc4\x85\xc4\x8d\xc4\x99", 6, RTL_TEXTENCODING_UTF8);
432 2 : CPPUNIT_ASSERT_EQUAL(aExpected, xTextRange->getString());
433 1 : }
434 :
435 9 : DECLARE_RTFIMPORT_TEST(testFdo48037, "fdo48037.rtf")
436 : {
437 1 : uno::Reference<util::XNumberFormatsSupplier> xNumberSupplier(mxComponent, uno::UNO_QUERY_THROW);
438 2 : lang::Locale aUSLocale, aFRLocale;
439 1 : aUSLocale.Language = "en";
440 1 : aFRLocale.Language = "fr";
441 1 : sal_Int32 nExpected = xNumberSupplier->getNumberFormats()->addNewConverted("d MMMM yyyy", aUSLocale, aFRLocale);
442 :
443 2 : uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
444 2 : uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
445 2 : uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
446 2 : uno::Reference<beans::XPropertySet> xPropertySet(xFields->nextElement(), uno::UNO_QUERY);
447 1 : sal_Int32 nActual = 0;
448 1 : xPropertySet->getPropertyValue("NumberFormat") >>= nActual;
449 :
450 2 : CPPUNIT_ASSERT_EQUAL(nExpected, nActual);
451 1 : }
452 :
453 9 : DECLARE_RTFIMPORT_TEST(testFdo47764, "fdo47764.rtf")
454 : {
455 : // \cbpat with zero argument should mean the auto (-1) color, not a default color (black)
456 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty<sal_Int32>(getParagraph(1), "ParaBackColor"));
457 1 : }
458 :
459 9 : DECLARE_RTFIMPORT_TEST(testFdo38786, "fdo38786.rtf")
460 : {
461 1 : uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
462 2 : uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
463 2 : uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
464 : // \chpgn was ignored, so exception was thrown
465 2 : xFields->nextElement();
466 1 : }
467 :
468 9 : DECLARE_RTFIMPORT_TEST(testN757651, "n757651.rtf")
469 : {
470 : // The bug was that due to buggy layout the text expanded to two pages.
471 1 : if (Application::GetDefaultDevice()->IsFontAvailable(OUString("Times New Roman")))
472 0 : CPPUNIT_ASSERT_EQUAL(1, getPages());
473 1 : }
474 :
475 9 : DECLARE_RTFIMPORT_TEST(testFdo49501, "fdo49501.rtf")
476 : {
477 1 : uno::Reference<beans::XPropertySet> xStyle(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY);
478 :
479 1 : CPPUNIT_ASSERT_EQUAL(sal_True, getProperty<sal_Bool>(xStyle, "IsLandscape"));
480 1 : sal_Int32 nExpected(TWIP_TO_MM100(567));
481 1 : CPPUNIT_ASSERT_EQUAL(nExpected, getProperty<sal_Int32>(xStyle, "LeftMargin"));
482 1 : CPPUNIT_ASSERT_EQUAL(nExpected, getProperty<sal_Int32>(xStyle, "RightMargin"));
483 1 : CPPUNIT_ASSERT_EQUAL(nExpected, getProperty<sal_Int32>(xStyle, "TopMargin"));
484 1 : CPPUNIT_ASSERT_EQUAL(nExpected, getProperty<sal_Int32>(xStyle, "BottomMargin"));
485 1 : }
486 :
487 9 : DECLARE_RTFIMPORT_TEST(testFdo49271, "fdo49271.rtf")
488 : {
489 1 : CPPUNIT_ASSERT_EQUAL(25.f, getProperty<float>(getParagraph(2), "CharHeight"));
490 1 : }
491 :
492 9 : DECLARE_RTFIMPORT_TEST(testFdo49692, "fdo49692.rtf")
493 : {
494 1 : uno::Reference<beans::XPropertySet> xPropertySet(getStyles("NumberingStyles")->getByName("WWNum1"), uno::UNO_QUERY);
495 2 : uno::Reference<container::XIndexAccess> xLevels(xPropertySet->getPropertyValue("NumberingRules"), uno::UNO_QUERY);
496 2 : uno::Sequence<beans::PropertyValue> aProps;
497 1 : xLevels->getByIndex(0) >>= aProps; // 1st level
498 :
499 13 : for (int i = 0; i < aProps.getLength(); ++i)
500 : {
501 12 : const beans::PropertyValue& rProp = aProps[i];
502 :
503 12 : if (rProp.Name == "Suffix")
504 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rProp.Value.get<OUString>().getLength());
505 1 : }
506 1 : }
507 :
508 9 : DECLARE_RTFIMPORT_TEST(testFdo45190, "fdo45190.rtf")
509 : {
510 : // inherited \fi should be reset
511 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(getParagraph(1), "ParaFirstLineIndent"));
512 :
513 : // but direct one not
514 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(TWIP_TO_MM100(-100)), getProperty<sal_Int32>(getParagraph(2), "ParaFirstLineIndent"));
515 1 : }
516 :
517 9 : DECLARE_RTFIMPORT_TEST(testFdo50539, "fdo50539.rtf")
518 : {
519 : // \chcbpat with zero argument should mean the auto (-1) color, not a default color (black)
520 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty<sal_Int32>(getRun(getParagraph(1), 1), "CharBackColor"));
521 1 : }
522 :
523 9 : DECLARE_RTFIMPORT_TEST(testFdo50665, "fdo50665.rtf")
524 : {
525 : // Access the second run, which is a textfield
526 1 : uno::Reference<beans::XPropertySet> xRun(getRun(getParagraph(1), 2), uno::UNO_QUERY);
527 : // This used to be the default, as character properties were ignored.
528 1 : CPPUNIT_ASSERT_EQUAL(OUString("Book Antiqua"), getProperty<OUString>(xRun, "CharFontName"));
529 1 : }
530 :
531 9 : DECLARE_RTFIMPORT_TEST(testFdo49659, "fdo49659.rtf")
532 : {
533 : // Both tables were ignored: 1) was in the header, 2) was ignored due to missing empty par at the end of the doc
534 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
535 2 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
536 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount());
537 :
538 : // The graphic was also empty
539 2 : uno::Reference<beans::XPropertySet> xGraphic(getProperty< uno::Reference<beans::XPropertySet> >(getShape(1), "Graphic"), uno::UNO_QUERY);
540 2 : CPPUNIT_ASSERT_EQUAL(graphic::GraphicType::PIXEL, getProperty<sal_Int8>(xGraphic, "GraphicType"));
541 1 : }
542 :
543 9 : DECLARE_RTFIMPORT_TEST(testFdo46966, "fdo46966.rtf")
544 : {
545 : /*
546 : * The problem was the top margin was 1440 (1 inch), but it should be 720 (0.5 inch).
547 : *
548 : * xray ThisComponent.StyleFamilies.PageStyles.Default.TopMargin
549 : */
550 1 : uno::Reference<beans::XPropertySet> xPropertySet(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY);
551 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(TWIP_TO_MM100(720)), getProperty<sal_Int32>(xPropertySet, "TopMargin"));
552 1 : }
553 :
554 9 : DECLARE_RTFIMPORT_TEST(testFdo52066, "fdo52066.rtf")
555 : {
556 : /*
557 : * The problem was that the height of the shape was too big.
558 : *
559 : * xray ThisComponent.DrawPage(0).Size.Height
560 : */
561 1 : uno::Reference<drawing::XShape> xShape(getShape(1), uno::UNO_QUERY);
562 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(TWIP_TO_MM100(19)), xShape->getSize().Height);
563 1 : }
564 :
565 9 : DECLARE_RTFIMPORT_TEST(testFdo48033, "fdo48033.rtf")
566 : {
567 : /*
568 : * The problem was that the picture (48033) or OLE object (53594) was in the first cell,
569 : * instead of the second one.
570 : *
571 : * oTable = ThisComponent.TextTables(0)
572 : * oParas = oTable.getCellByName("B1").Text.createEnumeration
573 : * oPara = oParas.nextElement
574 : * oRuns = oPara.createEnumeration
575 : * oRun = oRuns.nextElement
576 : * xray oRun.TextPortionType ' Frame, was Text
577 : */
578 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
579 2 : uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
580 2 : uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
581 2 : uno::Reference<text::XTextRange> xCell(xTable->getCellByName("B1"), uno::UNO_QUERY);
582 2 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xCell->getText(), uno::UNO_QUERY);
583 2 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
584 2 : uno::Reference<text::XTextRange> xPara(xParaEnum->nextElement(), uno::UNO_QUERY);
585 2 : CPPUNIT_ASSERT_EQUAL(OUString("Frame"), getProperty<OUString>(getRun(xPara, 1), "TextPortionType"));
586 1 : }
587 :
588 9 : DECLARE_RTFIMPORT_TEST(testFdo53594, "fdo53594.rtf")
589 : {
590 : /*
591 : * The problem was that the picture (48033) or OLE object (53594) was in the first cell,
592 : * instead of the second one.
593 : *
594 : * oTable = ThisComponent.TextTables(0)
595 : * oParas = oTable.getCellByName("B1").Text.createEnumeration
596 : * oPara = oParas.nextElement
597 : * oRuns = oPara.createEnumeration
598 : * oRun = oRuns.nextElement
599 : * xray oRun.TextPortionType ' Frame, was Text
600 : */
601 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
602 2 : uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
603 2 : uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
604 2 : uno::Reference<text::XTextRange> xCell(xTable->getCellByName("B1"), uno::UNO_QUERY);
605 2 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xCell->getText(), uno::UNO_QUERY);
606 2 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
607 2 : uno::Reference<text::XTextRange> xPara(xParaEnum->nextElement(), uno::UNO_QUERY);
608 2 : CPPUNIT_ASSERT_EQUAL(OUString("Frame"), getProperty<OUString>(getRun(xPara, 1), "TextPortionType"));
609 1 : }
610 :
611 9 : DECLARE_RTFIMPORT_TEST(testFdo36089, "fdo36089.rtf")
612 : {
613 1 : CPPUNIT_ASSERT_EQUAL(sal_Int16(-50), getProperty<sal_Int16>(getRun(getParagraph(1), 2), "CharEscapement"));
614 1 : }
615 :
616 9 : DECLARE_RTFIMPORT_TEST(testFdo49892, "fdo49892.rtf")
617 : {
618 1 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
619 2 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
620 2 : for (int i = 0; i < xDraws->getCount(); ++i)
621 : {
622 1 : OUString aDescription = getProperty<OUString>(xDraws->getByIndex(i), "Description");
623 1 : if (aDescription == "red")
624 0 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xDraws->getByIndex(i), "ZOrder"));
625 1 : else if (aDescription == "green")
626 0 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty<sal_Int32>(xDraws->getByIndex(i), "ZOrder"));
627 1 : else if (aDescription == "blue")
628 0 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getProperty<sal_Int32>(xDraws->getByIndex(i), "ZOrder"));
629 1 : else if (aDescription == "rect")
630 : {
631 0 : CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(xDraws->getByIndex(i), "HoriOrientRelation"));
632 0 : CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(xDraws->getByIndex(i), "VertOrientRelation"));
633 : }
634 2 : }
635 1 : }
636 :
637 9 : DECLARE_RTFIMPORT_TEST(testFdo48446, "fdo48446.rtf")
638 : {
639 1 : OUString aExpected("\xd0\x98\xd0\xbc\xd1\x8f", 6, RTL_TEXTENCODING_UTF8);
640 1 : getParagraph(1, aExpected);
641 1 : }
642 :
643 9 : DECLARE_RTFIMPORT_TEST(testFdo47495, "fdo47495.rtf")
644 : {
645 : // Used to have 4 paragraphs, as a result the original bugdoc had 2 pages instead of 1.
646 1 : CPPUNIT_ASSERT_EQUAL(2, getParagraphs());
647 1 : }
648 :
649 9 : DECLARE_RTFIMPORT_TEST(testAllGapsWord, "all_gaps_word.rtf")
650 : {
651 1 : BorderTest borderTest;
652 1 : borderTest.testTheBorders(mxComponent);
653 1 : }
654 :
655 9 : DECLARE_RTFIMPORT_TEST(testFdo52052, "fdo52052.rtf")
656 : {
657 : // Make sure the textframe containing the text "third" appears on the 3rd page.
658 1 : CPPUNIT_ASSERT_EQUAL(OUString("third"), parseDump("/root/page[3]/body/txt/anchored/fly/txt/text()"));
659 1 : }
660 :
661 9 : DECLARE_RTFIMPORT_TEST(testInk, "ink.rtf")
662 : {
663 : /*
664 : * The problem was that the second segment had wrong command count and wrap type.
665 : *
666 : * oShape = ThisComponent.DrawPage(0)
667 : * oPathPropVec = oShape.CustomShapeGeometry(1).Value
668 : * oSegments = oPathPropVec(1).Value
669 : * msgbox oSegments(1).Count ' was 0x2000 | 10, should be 10
670 : * msgbox oShape.Surround ' was 2, should be 1
671 : */
672 1 : uno::Sequence<beans::PropertyValue> aProps = getProperty< uno::Sequence<beans::PropertyValue> >(getShape(1), "CustomShapeGeometry");
673 2 : uno::Sequence<beans::PropertyValue> aPathProps;
674 4 : for (int i = 0; i < aProps.getLength(); ++i)
675 : {
676 3 : const beans::PropertyValue& rProp = aProps[i];
677 3 : if (rProp.Name == "Path")
678 1 : rProp.Value >>= aPathProps;
679 : }
680 2 : uno::Sequence<drawing::EnhancedCustomShapeSegment> aSegments;
681 3 : for (int i = 0; i < aPathProps.getLength(); ++i)
682 : {
683 2 : const beans::PropertyValue& rProp = aPathProps[i];
684 2 : if (rProp.Name == "Segments")
685 1 : rProp.Value >>= aSegments;
686 : }
687 1 : CPPUNIT_ASSERT_EQUAL(sal_Int16(10), aSegments[1].Count);
688 2 : CPPUNIT_ASSERT_EQUAL(text::WrapTextMode_THROUGHT, getProperty<text::WrapTextMode>(getShape(1), "Surround"));
689 1 : }
690 :
691 9 : DECLARE_RTFIMPORT_TEST(testFdo52389, "fdo52389.rtf")
692 : {
693 : // The last '!' character at the end of the document was lost
694 1 : CPPUNIT_ASSERT_EQUAL(6, getLength());
695 1 : }
696 :
697 9 : DECLARE_RTFIMPORT_TEST(testFdo49655, "fdo49655.rtf")
698 : {
699 : /*
700 : * 49655 :
701 : * The problem was that the table was not imported due to the ' ' string in the middle of the table definition.
702 : *
703 : * xray ThisComponent.TextTables.Count 'was 0
704 : */
705 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
706 2 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
707 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
708 1 : }
709 :
710 9 : DECLARE_RTFIMPORT_TEST(testFdo62805, "fdo62805.rtf")
711 : {
712 : /*
713 : * 62805 :
714 : * The problem was that the table was not imported due to the absence of \pard after \row.
715 : * The table was instead in a group (the '}' replace the \pard).
716 : */
717 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
718 2 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
719 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
720 1 : }
721 :
722 9 : DECLARE_RTFIMPORT_TEST(testFdo52475, "fdo52475.rtf")
723 : {
724 : // The problem was that \chcbpat0 resulted in no color, instead of COL_AUTO.
725 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty<sal_Int32>(getRun(getParagraph(1), 3), "CharBackColor"));
726 1 : }
727 :
728 9 : DECLARE_RTFIMPORT_TEST(testFdo55493, "fdo55493.rtf")
729 : {
730 : // The problem was that the width of the PNG was detected as 15,24cm, instead of 3.97cm
731 1 : uno::Reference<drawing::XShape> xShape(getShape(1), uno::UNO_QUERY);
732 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(3969), xShape->getSize().Width);
733 1 : }
734 :
735 9 : DECLARE_RTFIMPORT_TEST(testCopyPastePageStyle, "copypaste-pagestyle.rtf")
736 : {
737 : // The problem was that RTF import during copy&paste did not ignore page styles.
738 : // Once we have more copy&paste tests, makes sense to refactor this to some helper method.
739 1 : paste("copypaste-pagestyle-paste.rtf");
740 :
741 1 : uno::Reference<beans::XPropertySet> xPropertySet(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY);
742 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(21001), getProperty<sal_Int32>(xPropertySet, "Width")); // Was letter, i.e. 21590
743 1 : }
744 :
745 9 : DECLARE_RTFIMPORT_TEST(testCopyPasteFootnote, "copypaste-footnote.rtf")
746 : {
747 : // The RTF import did not handle the case when the position wasn't the main document XText, but something different, e.g. a footnote.
748 1 : uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY);
749 2 : uno::Reference<container::XIndexAccess> xFootnotes(xFootnotesSupplier->getFootnotes(), uno::UNO_QUERY);
750 2 : uno::Reference<text::XTextRange> xTextRange(xFootnotes->getByIndex(0), uno::UNO_QUERY);
751 1 : paste("copypaste-footnote-paste.rtf", xTextRange);
752 :
753 2 : CPPUNIT_ASSERT_EQUAL(OUString("bbb"), xTextRange->getString());
754 1 : }
755 :
756 9 : DECLARE_RTFIMPORT_TEST(testFdo61193, "hello.rtf")
757 : {
758 : // Pasting content that contained a footnote caused a crash.
759 1 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
760 2 : uno::Reference<text::XTextRange> xText(xTextDocument->getText(), uno::UNO_QUERY);
761 2 : uno::Reference<text::XTextRange> xEnd = xText->getEnd();
762 2 : paste("fdo61193.rtf", xEnd);
763 1 : }
764 :
765 9 : DECLARE_RTFIMPORT_TEST(testShptxtPard, "shptxt-pard.rtf")
766 : {
767 : // The problem was that \pard inside \shptxt caused loss of shape text
768 1 : uno::Reference<text::XText> xText(getShape(1), uno::UNO_QUERY);
769 1 : CPPUNIT_ASSERT_EQUAL(OUString("shape text"), xText->getString());
770 1 : }
771 :
772 9 : DECLARE_RTFIMPORT_TEST(testDoDhgt, "do-dhgt.rtf")
773 : {
774 1 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
775 2 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
776 4 : for (int i = 0; i < xDraws->getCount(); ++i)
777 : {
778 3 : sal_Int32 nFillColor = getProperty<sal_Int32>(xDraws->getByIndex(i), "FillColor");
779 3 : if (nFillColor == 0xc0504d) // red
780 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xDraws->getByIndex(i), "ZOrder"));
781 2 : else if (nFillColor == 0x9bbb59) // green
782 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty<sal_Int32>(xDraws->getByIndex(i), "ZOrder"));
783 1 : else if (nFillColor == 0x4f81bd) // blue
784 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getProperty<sal_Int32>(xDraws->getByIndex(i), "ZOrder"));
785 1 : }
786 1 : }
787 :
788 9 : DECLARE_RTFIMPORT_TEST(testDplinehollow, "dplinehollow.rtf")
789 : {
790 1 : uno::Reference<beans::XPropertySet> xPropertySet(getShape(1), uno::UNO_QUERY);
791 1 : CPPUNIT_ASSERT_EQUAL(drawing::LineStyle_NONE, getProperty<drawing::LineStyle>(xPropertySet, "LineStyle"));
792 1 : }
793 :
794 9 : DECLARE_RTFIMPORT_TEST(testLeftmarginDefault, "leftmargin-default.rtf")
795 : {
796 : // The default left/right margin was incorrect when the top margin was set to zero.
797 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2540), getProperty<sal_Int32>(getStyles("PageStyles")->getByName(DEFAULT_STYLE), "LeftMargin"));
798 1 : }
799 :
800 9 : DECLARE_RTFIMPORT_TEST(testDppolyline, "dppolyline.rtf")
801 : {
802 : // This was completely ignored, for now, just make sure we have all 4 lines.
803 1 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
804 2 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
805 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xDraws->getCount());
806 1 : }
807 :
808 9 : DECLARE_RTFIMPORT_TEST(testFdo56512, "fdo56512.rtf")
809 : {
810 1 : uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
811 2 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
812 2 : uno::Reference<text::XTextRange> xTextRange(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
813 2 : OUString aExpected("\xd7\xa2\xd7\x95\xd7\xa1\xd7\xa7 \xd7\x9e\xd7\x95\xd7\xa8\xd7\xa9\xd7\x94 ", 20, RTL_TEXTENCODING_UTF8);
814 2 : CPPUNIT_ASSERT_EQUAL(aExpected, xTextRange->getString());
815 1 : }
816 :
817 9 : DECLARE_RTFIMPORT_TEST(testFdo52989, "fdo52989.rtf")
818 : {
819 : // Same as n#192129, but for JPEG files.
820 1 : uno::Reference<drawing::XShape> xShape(getShape(1), uno::UNO_QUERY);
821 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(423), xShape->getSize().Width);
822 1 : }
823 :
824 9 : DECLARE_RTFIMPORT_TEST(testFdo48442, "fdo48442.rtf")
825 : {
826 : // The problem was that \pvmrg is the default in RTF, but not in Writer.
827 1 : uno::Reference<drawing::XShape> xShape = getShape(1);
828 1 : CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_PRINT_AREA, getProperty<sal_Int16>(xShape, "VertOrientRelation")); // was FRAME
829 1 : }
830 :
831 9 : DECLARE_RTFIMPORT_TEST(testFdo55525, "fdo55525.rtf")
832 : {
833 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
834 2 : uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
835 2 : uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
836 : // Negative left margin was ~missing, -191
837 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(-1877), getProperty<sal_Int32>(xTable, "LeftMargin"));
838 : // Cell width of A1 was 3332 (e.g. not set, 30% percent of total width)
839 2 : uno::Reference<table::XTableRows> xTableRows(xTable->getRows(), uno::UNO_QUERY);
840 2 : CPPUNIT_ASSERT_EQUAL(sal_Int16(896), getProperty< uno::Sequence<text::TableColumnSeparator> >(xTableRows->getByIndex(0), "TableColumnSeparators")[0].Position);
841 1 : }
842 :
843 9 : DECLARE_RTFIMPORT_TEST(testFdo57708, "fdo57708.rtf")
844 : {
845 : // There were two issues: the doc was of 2 pages and the picture was missing.
846 1 : CPPUNIT_ASSERT_EQUAL(1, getPages());
847 1 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
848 2 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
849 : // Two objects: a picture and a textframe.
850 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xDraws->getCount());
851 1 : }
852 :
853 9 : DECLARE_RTFIMPORT_TEST(testFdo54473, "fdo54473.rtf")
854 : {
855 : // The problem was that character styles were not imported due to a typo.
856 1 : CPPUNIT_ASSERT_EQUAL(OUString("Anot"), getProperty<OUString>(getRun(getParagraph(1), 1, "Text "), "CharStyleName"));
857 1 : CPPUNIT_ASSERT_EQUAL(OUString("ForeignTxt"), getProperty<OUString>(getRun(getParagraph(1), 3, "character "), "CharStyleName"));
858 1 : }
859 :
860 9 : DECLARE_RTFIMPORT_TEST(testFdo49934, "fdo49934.rtf")
861 : {
862 : // Column break without columns defined should be a page break, but it was just ignored.
863 1 : CPPUNIT_ASSERT_EQUAL(2, getPages());
864 1 : }
865 :
866 9 : DECLARE_RTFIMPORT_TEST(testFdo57886, "fdo57886.rtf")
867 : {
868 : // Was 'int from <?> to <?> <?>'.
869 1 : CPPUNIT_ASSERT_EQUAL(OUString("int from {firstlower} to {firstupper} {firstbody}"), getFormula(getRun(getParagraph(1), 1)));
870 1 : }
871 :
872 9 : DECLARE_RTFIMPORT_TEST(testFdo58076, "fdo58076.rtf")
873 : {
874 : // An additional section was created, so the default page style didn't have the custom margins.
875 1 : uno::Reference<beans::XPropertySet> xStyle(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY);
876 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2251), getProperty<sal_Int32>(xStyle, "LeftMargin"));
877 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1752), getProperty<sal_Int32>(xStyle, "RightMargin"));
878 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(635), getProperty<sal_Int32>(xStyle, "TopMargin"));
879 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(635), getProperty<sal_Int32>(xStyle, "BottomMargin"));
880 1 : }
881 :
882 9 : DECLARE_RTFIMPORT_TEST(testFdo57678, "fdo57678.rtf")
883 : {
884 : // Paragraphs of the two tables were not converted to tables.
885 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
886 2 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
887 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount());
888 1 : }
889 :
890 9 : DECLARE_RTFIMPORT_TEST(testFdo45183, "fdo45183.rtf")
891 : {
892 : // Was text::WrapTextMode_PARALLEL, i.e. shpfblwtxt didn't send the shape below text.
893 1 : CPPUNIT_ASSERT_EQUAL(text::WrapTextMode_THROUGHT, getProperty<text::WrapTextMode>(getShape(1), "Surround"));
894 :
895 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
896 2 : uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
897 : // Was 247, resulting in a table having width almost zero and height of 10+ pages.
898 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(16237), getProperty<sal_Int32>(xTables->getByIndex(0), "Width"));
899 1 : }
900 :
901 9 : DECLARE_RTFIMPORT_TEST(testFdo54612, "fdo54612.rtf")
902 : {
903 : // \dpptx without a \dppolycount caused a crash.
904 1 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
905 2 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
906 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(8), xDraws->getCount());
907 1 : }
908 :
909 9 : DECLARE_RTFIMPORT_TEST(testFdo58933, "fdo58933.rtf")
910 : {
911 : // The problem was that the table had an additional cell in its first line.
912 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
913 2 : uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
914 2 : uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
915 : // This was 4.
916 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable->getCellNames().getLength());
917 1 : }
918 :
919 9 : DECLARE_RTFIMPORT_TEST(testFdo44053, "fdo44053.rtf")
920 : {
921 1 : uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
922 2 : uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables( ), uno::UNO_QUERY);
923 2 : uno::Reference<text::XTextTable> xTextTable(xTables->getByIndex(0), uno::UNO_QUERY);
924 2 : uno::Reference<table::XTableRows> xTableRows(xTextTable->getRows(), uno::UNO_QUERY);
925 : // The with of the table's A1 and A2 cell should equal.
926 2 : CPPUNIT_ASSERT_EQUAL(getProperty< uno::Sequence<text::TableColumnSeparator> >(xTableRows->getByIndex(0), "TableColumnSeparators")[0].Position,
927 2 : getProperty< uno::Sequence<text::TableColumnSeparator> >(xTableRows->getByIndex(1), "TableColumnSeparators")[0].Position);
928 1 : }
929 :
930 9 : DECLARE_RTFIMPORT_TEST(testFdo48440, "fdo48440.rtf")
931 : {
932 : // Page break was ignored.
933 1 : CPPUNIT_ASSERT_EQUAL(2, getPages());
934 1 : }
935 :
936 9 : DECLARE_RTFIMPORT_TEST(testFdo58646line, "fdo58646line.rtf")
937 : {
938 : // \line symbol was ignored
939 1 : getParagraph(1, "foo\nbar");
940 1 : }
941 :
942 9 : DECLARE_RTFIMPORT_TEST(testFdo58646, "fdo58646.rtf")
943 : {
944 : // Page break was ignored inside a continuous section, on title page.
945 1 : CPPUNIT_ASSERT_EQUAL(2, getPages());
946 1 : }
947 :
948 9 : DECLARE_RTFIMPORT_TEST(testFdo59419, "fdo59419.rtf")
949 : {
950 : // Junk to be ignored broke import of the table.
951 1 : uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
952 2 : uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY);
953 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount());
954 1 : }
955 :
956 9 : DECLARE_RTFIMPORT_TEST(testFdo58076_2, "fdo58076-2.rtf")
957 : {
958 : // Position of the picture wasn't correct.
959 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(TWIP_TO_MM100(8345)), getProperty<sal_Int32>(getShape(1), "HoriOrientPosition"));
960 1 : }
961 :
962 9 : DECLARE_RTFIMPORT_TEST(testFdo59953, "fdo59953.rtf")
963 : {
964 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
965 2 : uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
966 2 : uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
967 : // Cell width of A1 was 4998 (e.g. not set / not wide enough, ~50% of total width)
968 2 : uno::Reference<table::XTableRows> xTableRows(xTable->getRows(), uno::UNO_QUERY);
969 2 : CPPUNIT_ASSERT_EQUAL(sal_Int16(7649), getProperty< uno::Sequence<text::TableColumnSeparator> >(xTableRows->getByIndex(0), "TableColumnSeparators")[0].Position);
970 1 : }
971 :
972 9 : DECLARE_RTFIMPORT_TEST(testFdo59638, "fdo59638.rtf")
973 : {
974 : // The problem was that w:lvlOverride inside w:num was ignores by dmapper.
975 :
976 1 : uno::Reference<beans::XPropertySet> xPropertySet(getStyles("NumberingStyles")->getByName("WWNum1"), uno::UNO_QUERY);
977 1 : uno::Reference<container::XIndexAccess> xLevels(xPropertySet->getPropertyValue("NumberingRules"), uno::UNO_QUERY);
978 1 : uno::Sequence<beans::PropertyValue> aProps;
979 1 : xLevels->getByIndex(0) >>= aProps; // 1st level
980 :
981 14 : for (int i = 0; i < aProps.getLength(); ++i)
982 : {
983 14 : const beans::PropertyValue& rProp = aProps[i];
984 :
985 14 : if (rProp.Name == "BulletChar")
986 : {
987 : // Was '*', should be 'o'.
988 1 : CPPUNIT_ASSERT_EQUAL(OUString("\xEF\x82\xB7", 3, RTL_TEXTENCODING_UTF8), rProp.Value.get<OUString>());
989 2 : return;
990 : }
991 : }
992 0 : CPPUNIT_FAIL("no BulletChar property");
993 : }
994 :
995 9 : DECLARE_RTFIMPORT_TEST(testFdo60722, "fdo60722.rtf")
996 : {
997 : // The problem was that the larger shape was over the smaller one, and not the other way around.
998 1 : uno::Reference<beans::XPropertySet> xShape(getShape(1), uno::UNO_QUERY);
999 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xShape, "ZOrder"));
1000 1 : CPPUNIT_ASSERT_EQUAL(OUString("larger"), getProperty<OUString>(xShape, "Description"));
1001 :
1002 1 : xShape.set(getShape(2), uno::UNO_QUERY);
1003 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty<sal_Int32>(xShape, "ZOrder"));
1004 1 : CPPUNIT_ASSERT_EQUAL(OUString("smaller"), getProperty<OUString>(xShape, "Description"));
1005 :
1006 : // Color of the line was blue, and it had zero width.
1007 1 : xShape.set(getShape(3), uno::UNO_QUERY);
1008 1 : CPPUNIT_ASSERT_EQUAL(sal_uInt32(26), getProperty<sal_uInt32>(xShape, "LineWidth"));
1009 1 : CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), getProperty<sal_uInt32>(xShape, "LineColor"));
1010 1 : }
1011 :
1012 9 : DECLARE_RTFIMPORT_TEST(testDoDhgtOld, "do-dhgt-old.rtf")
1013 : {
1014 : // The file contains 3 shapes which have the same dhgt (z-order).
1015 : // Test that the order is 1) a 2) black rectangle 3) b, and not something else
1016 1 : uno::Reference<text::XText> xShape(getShape(1), uno::UNO_QUERY);
1017 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xShape, "ZOrder"));
1018 1 : CPPUNIT_ASSERT_EQUAL(OUString("a"), xShape->getString());
1019 :
1020 1 : xShape.set(getShape(2), uno::UNO_QUERY);
1021 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty<sal_Int32>(xShape, "ZOrder"));
1022 1 : CPPUNIT_ASSERT_EQUAL(COL_BLACK, getProperty<sal_uInt32>(xShape, "FillColor"));
1023 :
1024 1 : xShape.set(getShape(3), uno::UNO_QUERY);
1025 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getProperty<sal_Int32>(xShape, "ZOrder"));
1026 1 : CPPUNIT_ASSERT_EQUAL(OUString("b"), xShape->getString());
1027 1 : }
1028 :
1029 9 : DECLARE_RTFIMPORT_TEST(testFdo61909, "fdo61909.rtf")
1030 : {
1031 1 : uno::Reference<text::XTextRange> xTextRange = getRun(getParagraph(1), 1);
1032 : // Was the Writer default font.
1033 1 : CPPUNIT_ASSERT_EQUAL(OUString("Courier New"), getProperty<OUString>(xTextRange, "CharFontName"));
1034 : // Was 0x008000.
1035 1 : CPPUNIT_ASSERT_EQUAL(COL_AUTO, getProperty<sal_uInt32>(xTextRange, "CharBackColor"));
1036 1 : }
1037 :
1038 9 : DECLARE_RTFIMPORT_TEST(testFdo62288, "fdo62288.rtf")
1039 : {
1040 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
1041 2 : uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
1042 2 : uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
1043 2 : uno::Reference<text::XTextRange> xCell(xTable->getCellByName("B1"), uno::UNO_QUERY);
1044 2 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xCell->getText(), uno::UNO_QUERY);
1045 2 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
1046 2 : uno::Reference<text::XTextRange> xPara(xParaEnum->nextElement(), uno::UNO_QUERY);
1047 : // Margins were inherited from the previous cell, even there was a \pard there.
1048 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xPara, "ParaLeftMargin"));
1049 1 : }
1050 :
1051 9 : DECLARE_RTFIMPORT_TEST(testFdo37716, "fdo37716.rtf")
1052 : {
1053 1 : uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
1054 2 : uno::Reference<container::XIndexAccess> xFrames(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
1055 : // \nowrap got ignored, so Surround was text::WrapTextMode_PARALLEL
1056 2 : CPPUNIT_ASSERT_EQUAL(text::WrapTextMode_NONE, getProperty<text::WrapTextMode>(xFrames->getByIndex(0), "Surround"));
1057 1 : }
1058 :
1059 9 : DECLARE_RTFIMPORT_TEST(testFdo51916, "fdo51916.rtf")
1060 : {
1061 : // Complex nested table caused a crash.
1062 1 : }
1063 :
1064 9 : DECLARE_RTFIMPORT_TEST(testFdo63023, "fdo63023.rtf")
1065 : {
1066 1 : uno::Reference<text::XText> xHeaderText = getProperty< uno::Reference<text::XText> >(getStyles("PageStyles")->getByName(DEFAULT_STYLE), "HeaderText");
1067 : // Back color was black (0) in the header, due to missing color table in the substream.
1068 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0xFFFF99), getProperty<sal_Int32>(getRun(getParagraphOfText(1, xHeaderText), 1), "CharBackColor"));
1069 1 : }
1070 :
1071 9 : DECLARE_RTFIMPORT_TEST(testFdo42109, "fdo42109.rtf")
1072 : {
1073 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
1074 2 : uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
1075 2 : uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
1076 2 : uno::Reference<text::XTextRange> xCell(xTable->getCellByName("B1"), uno::UNO_QUERY);
1077 : // Make sure the page number is imported as a field in the B1 cell.
1078 2 : CPPUNIT_ASSERT_EQUAL(OUString("TextField"), getProperty<OUString>(getRun(getParagraphOfText(1, xCell->getText()), 1), "TextPortionType"));
1079 1 : }
1080 :
1081 9 : DECLARE_RTFIMPORT_TEST(testFdo62977, "fdo62977.rtf")
1082 : {
1083 : // The middle character was imported as '?' instead of the proper unicode value.
1084 1 : getRun(getParagraph(1), 1, OUString("\xE5\xB9\xB4\xEF\xBC\x94\xE6\x9C\x88", 9, RTL_TEXTENCODING_UTF8));
1085 1 : }
1086 :
1087 9 : DECLARE_RTFIMPORT_TEST(testN818997, "n818997.rtf")
1088 : {
1089 : // \page was ignored between two \shp tokens.
1090 1 : CPPUNIT_ASSERT_EQUAL(2, getPages());
1091 1 : }
1092 :
1093 9 : DECLARE_RTFIMPORT_TEST(testFdo64671, "fdo64671.rtf")
1094 : {
1095 : // Additional '}' was inserted before the special character.
1096 1 : getRun(getParagraph(1), 1, OUString("\xC5\xBD", 2, RTL_TEXTENCODING_UTF8));
1097 1 : }
1098 :
1099 9 : DECLARE_RTFIMPORT_TEST(testPageBackground, "page-background.rtf")
1100 : {
1101 : // The problem was that \background was ignored.
1102 1 : uno::Reference<beans::XPropertySet> xPageStyle(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY);
1103 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0x92D050), getProperty<sal_Int32>(xPageStyle, "BackColor"));
1104 1 : }
1105 :
1106 9 : DECLARE_RTFIMPORT_TEST(testFdo62044, "fdo62044.rtf")
1107 : {
1108 : // The problem was that RTF import during copy&paste did not ignore existing paragraph styles.
1109 1 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
1110 2 : uno::Reference<text::XTextRange> xText(xTextDocument->getText(), uno::UNO_QUERY);
1111 2 : uno::Reference<text::XTextRange> xEnd = xText->getEnd();
1112 1 : paste("fdo62044-paste.rtf", xEnd);
1113 :
1114 2 : uno::Reference<beans::XPropertySet> xPropertySet(getStyles("ParagraphStyles")->getByName("Heading 1"), uno::UNO_QUERY);
1115 2 : CPPUNIT_ASSERT_EQUAL(10.f, getProperty<float>(xPropertySet, "CharHeight")); // Was 18, i.e. reset back to original value.
1116 1 : }
1117 :
1118 9 : DECLARE_RTFIMPORT_TEST(testPoshPosv, "posh-posv.rtf")
1119 : {
1120 1 : CPPUNIT_ASSERT_EQUAL(text::HoriOrientation::CENTER, getProperty<sal_Int16>(getShape(1), "HoriOrient"));
1121 1 : CPPUNIT_ASSERT_EQUAL(text::VertOrientation::CENTER, getProperty<sal_Int16>(getShape(1), "VertOrient"));
1122 1 : CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(getShape(1), "FrameIsAutomaticHeight"));
1123 1 : }
1124 :
1125 9 : DECLARE_RTFIMPORT_TEST(testN825305, "n825305.rtf")
1126 : {
1127 : // The problem was that the textbox wasn't transparent, due to unimplemented fFilled == 0.
1128 1 : uno::Reference<beans::XPropertyState> xPropertyState(getShape(2), uno::UNO_QUERY);
1129 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(100), getProperty<sal_Int32>(getShape(2), "BackColorTransparency"));
1130 1 : beans::PropertyState ePropertyState = xPropertyState->getPropertyState("BackColorTransparency");
1131 : // Was beans::PropertyState_DEFAULT_VALUE.
1132 1 : CPPUNIT_ASSERT_EQUAL(beans::PropertyState_DIRECT_VALUE, ePropertyState);
1133 1 : }
1134 :
1135 9 : DECLARE_RTFIMPORT_TEST(testParaBottomMargin, "para-bottom-margin.rtf")
1136 : {
1137 : // This was 353, i.e. bottom margin of the paragraph was 0.35cm instead of 0.
1138 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(getParagraph(1), "ParaBottomMargin"));
1139 1 : }
1140 :
1141 9 : DECLARE_RTFIMPORT_TEST(testN823655, "n823655.rtf")
1142 : {
1143 1 : uno::Sequence<beans::PropertyValue> aProps = getProperty< uno::Sequence<beans::PropertyValue> >(getShape(1), "CustomShapeGeometry");
1144 2 : uno::Sequence<beans::PropertyValue> aPathProps;
1145 4 : for (int i = 0; i < aProps.getLength(); ++i)
1146 : {
1147 3 : const beans::PropertyValue& rProp = aProps[i];
1148 3 : if (rProp.Name == "Path")
1149 1 : aPathProps = rProp.Value.get< uno::Sequence<beans::PropertyValue> >();
1150 : }
1151 2 : uno::Sequence<drawing::EnhancedCustomShapeParameterPair> aCoordinates;
1152 3 : for (int i = 0; i < aPathProps.getLength(); ++i)
1153 : {
1154 2 : const beans::PropertyValue& rProp = aPathProps[i];
1155 2 : if (rProp.Name == "Coordinates")
1156 1 : aCoordinates = rProp.Value.get< uno::Sequence<drawing::EnhancedCustomShapeParameterPair> >();
1157 : }
1158 : // The first coordinate pair of this freeform shape was 286,0 instead of 0,286.
1159 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(286), aCoordinates[0].Second.Value.get<sal_Int32>());
1160 1 : }
1161 :
1162 9 : DECLARE_RTFIMPORT_TEST(testFdo66040, "fdo66040.rtf")
1163 : {
1164 1 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
1165 2 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
1166 : // This was 0 (no shapes were imported), we want two textframes.
1167 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xDraws->getCount());
1168 :
1169 : // The second paragraph of the first shape should be actually a table, with "A" in its A1 cell.
1170 2 : uno::Reference<text::XTextRange> xTextRange(xDraws->getByIndex(0), uno::UNO_QUERY);
1171 2 : uno::Reference<text::XText> xText = xTextRange->getText();
1172 2 : uno::Reference<text::XTextTable> xTable(getParagraphOrTable(2, xText), uno::UNO_QUERY);
1173 1 : CPPUNIT_ASSERT_EQUAL(OUString("A"), uno::Reference<text::XTextRange>(xTable->getCellByName("A1"), uno::UNO_QUERY)->getString());
1174 :
1175 : // Make sure the second shape has the correct position and size.
1176 2 : uno::Reference<drawing::XShape> xShape(xDraws->getByIndex(1), uno::UNO_QUERY);
1177 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(14420), getProperty<sal_Int32>(xShape, "HoriOrientPosition"));
1178 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(-1032), getProperty<sal_Int32>(xShape, "VertOrientPosition"));
1179 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(14000), xShape->getSize().Width);
1180 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(21001), xShape->getSize().Height);
1181 1 : }
1182 :
1183 9 : DECLARE_RTFIMPORT_TEST(testN823675, "n823675.rtf")
1184 : {
1185 1 : uno::Reference<beans::XPropertySet> xPropertySet(getStyles("NumberingStyles")->getByName("WWNum1"), uno::UNO_QUERY);
1186 2 : uno::Reference<container::XIndexAccess> xLevels(xPropertySet->getPropertyValue("NumberingRules"), uno::UNO_QUERY);
1187 2 : uno::Sequence<beans::PropertyValue> aProps;
1188 1 : xLevels->getByIndex(0) >>= aProps; // 1st level
1189 2 : awt::FontDescriptor aFont;
1190 :
1191 17 : for (int i = 0; i < aProps.getLength(); ++i)
1192 : {
1193 16 : const beans::PropertyValue& rProp = aProps[i];
1194 :
1195 16 : if (rProp.Name == "BulletFont")
1196 1 : aFont = rProp.Value.get<awt::FontDescriptor>();
1197 : }
1198 : // This was empty, i.e. no font name was set for the bullet numbering.
1199 2 : CPPUNIT_ASSERT_EQUAL(OUString("Symbol"), aFont.Name);
1200 1 : }
1201 :
1202 9 : DECLARE_RTFIMPORT_TEST(testFdo47802, "fdo47802.rtf")
1203 : {
1204 1 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
1205 2 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
1206 : // Shape inside table was ignored.
1207 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDraws->getCount());
1208 1 : }
1209 :
1210 9 : DECLARE_RTFIMPORT_TEST(testFdo39001, "fdo39001.rtf")
1211 : {
1212 : // Document was of 4 pages, \sect at the end of the doc wasn't ignored.
1213 1 : CPPUNIT_ASSERT_EQUAL(3, getPages());
1214 1 : }
1215 :
1216 9 : DECLARE_RTFIMPORT_TEST(testGroupshape, "groupshape.rtf")
1217 : {
1218 1 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
1219 2 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
1220 : // There should be a single groupshape with 2 children.
1221 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDraws->getCount());
1222 2 : uno::Reference<drawing::XShapes> xGroupshape(xDraws->getByIndex(0), uno::UNO_QUERY);
1223 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xGroupshape->getCount());
1224 1 : }
1225 :
1226 9 : DECLARE_RTFIMPORT_TEST(testGroupshape_notext, "groupshape-notext.rtf")
1227 : {
1228 1 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
1229 2 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
1230 : // There should be a single groupshape with 2 children.
1231 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDraws->getCount());
1232 2 : uno::Reference<drawing::XShapes> xGroupshape(xDraws->getByIndex(0), uno::UNO_QUERY);
1233 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xGroupshape->getCount());
1234 1 : }
1235 :
1236 9 : DECLARE_RTFIMPORT_TEST(testFdo66565, "fdo66565.rtf")
1237 : {
1238 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
1239 2 : uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
1240 2 : uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
1241 : // Cell width of A2 was 554, should be 453/14846*10000
1242 2 : uno::Reference<table::XTableRows> xTableRows(xTable->getRows(), uno::UNO_QUERY);
1243 2 : CPPUNIT_ASSERT_EQUAL(sal_Int16(304), getProperty< uno::Sequence<text::TableColumnSeparator> >(xTableRows->getByIndex(1), "TableColumnSeparators")[0].Position);
1244 1 : }
1245 :
1246 9 : DECLARE_RTFIMPORT_TEST(testFdo54900, "fdo54900.rtf")
1247 : {
1248 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
1249 2 : uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
1250 2 : uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
1251 2 : uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
1252 : // Paragraph was aligned to left, should be center.
1253 2 : CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_CENTER, static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(getParagraphOfText(1, xCell->getText()), "ParaAdjust")));
1254 1 : }
1255 :
1256 9 : DECLARE_RTFIMPORT_TEST(testFdo64637, "fdo64637.rtf")
1257 : {
1258 : // The problem was that the custom "Company" property was added twice, the second invocation resulted in an exception.
1259 1 : uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(mxComponent, uno::UNO_QUERY);
1260 2 : uno::Reference<beans::XPropertySet> xPropertySet(xDocumentPropertiesSupplier->getDocumentProperties()->getUserDefinedProperties(), uno::UNO_QUERY);
1261 2 : CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getProperty<OUString>(xPropertySet, "Company"));
1262 1 : }
1263 :
1264 9 : DECLARE_RTFIMPORT_TEST(testN820504, "n820504.rtf")
1265 : {
1266 : // The shape was anchored at-page instead of at-character (that's incorrect as Word only supports at-character and as-character).
1267 1 : CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER, getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType"));
1268 1 : }
1269 :
1270 9 : DECLARE_RTFIMPORT_TEST(testFdo67365, "fdo67365.rtf")
1271 : {
1272 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
1273 2 : uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
1274 2 : uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
1275 2 : uno::Reference<table::XTableRows> xRows = xTable->getRows();
1276 : // The table only had 3 rows.
1277 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xRows->getCount());
1278 : // This was 4999, i.e. the two cells of the row had equal widths instead of a larger and a smaller cell.
1279 1 : CPPUNIT_ASSERT_EQUAL(sal_Int16(5290), getProperty< uno::Sequence<text::TableColumnSeparator> >(xRows->getByIndex(2), "TableColumnSeparators")[0].Position);
1280 2 : uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A2"), uno::UNO_QUERY);
1281 : // Paragraph was aligned to center, should be left.
1282 2 : CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_LEFT, static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(getParagraphOfText(1, xCell->getText()), "ParaAdjust")));
1283 1 : }
1284 :
1285 9 : DECLARE_RTFIMPORT_TEST(testFdo67498, "fdo67498.rtf")
1286 : {
1287 : // Left margin of the default page style wasn't set (was 2000).
1288 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(TWIP_TO_MM100(5954)), getProperty<sal_Int32>(getStyles("PageStyles")->getByName(DEFAULT_STYLE), "LeftMargin"));
1289 1 : }
1290 :
1291 9 : DECLARE_RTFIMPORT_TEST(testFdo47440, "fdo47440.rtf")
1292 : {
1293 : // Vertical and horizontal orientation of the picture wasn't imported (was text::RelOrientation::FRAME).
1294 1 : CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(getShape(1), "HoriOrientRelation"));
1295 1 : CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(getShape(1), "VertOrientRelation"));
1296 1 : }
1297 :
1298 9 : DECLARE_RTFIMPORT_TEST(testFdo53556, "fdo53556.rtf")
1299 : {
1300 : // This was drawing::FillStyle_SOLID, which resulted in being non-transparent, hiding text which would be visible.
1301 1 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_NONE, getProperty<drawing::FillStyle>(getShape(3), "FillStyle"));
1302 :
1303 : // This was a com.sun.star.drawing.CustomShape, which resulted in lack of word wrapping in the bugdoc.
1304 1 : uno::Reference<beans::XPropertySet> xShapeProperties(getShape(1), uno::UNO_QUERY);
1305 2 : uno::Reference<drawing::XShapeDescriptor> xShapeDescriptor(xShapeProperties, uno::UNO_QUERY);
1306 2 : CPPUNIT_ASSERT_EQUAL(OUString("FrameShape"), xShapeDescriptor->getShapeType());
1307 1 : }
1308 :
1309 9 : DECLARE_RTFIMPORT_TEST(testFdo63428, "hello.rtf")
1310 : {
1311 : // Pasting content that contained an annotation caused a crash.
1312 1 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
1313 2 : uno::Reference<text::XTextRange> xText(xTextDocument->getText(), uno::UNO_QUERY);
1314 2 : uno::Reference<text::XTextRange> xEnd = xText->getEnd();
1315 1 : paste("fdo63428.rtf", xEnd);
1316 :
1317 : // Additionally, commented range was imported as a normal comment.
1318 1 : CPPUNIT_ASSERT_EQUAL(OUString("Annotation"), getProperty<OUString>(getRun(getParagraph(1), 2), "TextPortionType"));
1319 2 : CPPUNIT_ASSERT_EQUAL(OUString("AnnotationEnd"), getProperty<OUString>(getRun(getParagraph(1), 4), "TextPortionType"));
1320 1 : }
1321 :
1322 9 : DECLARE_RTFIMPORT_TEST(testGroupshapeRotation, "groupshape-rotation.rtf")
1323 : {
1324 : // Rotation on groupshapes wasn't handled correctly, RotateAngle was 4500.
1325 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(315 * 100), getProperty<sal_Int32>(getShape(1), "RotateAngle"));
1326 1 : }
1327 :
1328 9 : DECLARE_RTFIMPORT_TEST(testFdo44715, "fdo44715.rtf")
1329 : {
1330 1 : uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY);
1331 2 : uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
1332 : // Style information wasn't reset, which caused character height to be 16.
1333 2 : CPPUNIT_ASSERT_EQUAL(12.f, getProperty<float>(getParagraphOfText(2, xCell->getText()), "CharHeight"));
1334 1 : }
1335 :
1336 9 : DECLARE_RTFIMPORT_TEST(testFdo68076, "fdo68076.rtf")
1337 : {
1338 : // Encoding of the last char was wrong (more 'o' than 'y').
1339 1 : OUString aExpected("\xD0\x9E\xD0\xB1\xD1\x8A\xD0\xB5\xD0\xBA\xD1\x82 \xE2\x80\x93 \xD1\x83", 19, RTL_TEXTENCODING_UTF8);
1340 1 : getParagraph(1, aExpected);
1341 1 : }
1342 :
1343 9 : DECLARE_RTFIMPORT_TEST(testFdo68291, "fdo68291.odt")
1344 : {
1345 1 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
1346 2 : uno::Reference<text::XTextRange> xText(xTextDocument->getText(), uno::UNO_QUERY);
1347 2 : uno::Reference<text::XTextRange> xEnd = xText->getEnd();
1348 1 : paste("fdo68291-paste.rtf", xEnd);
1349 :
1350 : // This was "Standard", causing an unwanted page break on next paste.
1351 2 : CPPUNIT_ASSERT_EQUAL(OUString(), getProperty<OUString>(getParagraph(1), "PageDescName"));
1352 1 : }
1353 :
1354 9 : DECLARE_RTFIMPORT_TEST(testFdo69384, "hello.rtf")
1355 : {
1356 1 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
1357 2 : uno::Reference<text::XTextRange> xText(xTextDocument->getText(), uno::UNO_QUERY);
1358 2 : uno::Reference<text::XTextRange> xEnd = xText->getEnd();
1359 1 : paste("fdo69384-paste.rtf", xEnd);
1360 :
1361 : // Import got interrupted in the middle of style sheet table import,
1362 : // resuling in missing styles and text.
1363 2 : getStyles("ParagraphStyles")->getByName("Text body justified");
1364 1 : }
1365 :
1366 9 : DECLARE_RTFIMPORT_TEST(testFdo70221, "fdo70221.rtf")
1367 : {
1368 1 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
1369 2 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
1370 : // The picture was imported twice.
1371 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDraws->getCount());
1372 1 : }
1373 :
1374 9 : DECLARE_RTFIMPORT_TEST(testCp1000018, "cp1000018.rtf")
1375 : {
1376 : // The problem was that the empty paragraph at the end of the footnote got
1377 : // lost during import.
1378 1 : uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY);
1379 2 : uno::Reference<container::XIndexAccess> xFootnotes(xFootnotesSupplier->getFootnotes(), uno::UNO_QUERY);
1380 2 : uno::Reference<text::XTextRange> xTextRange(xFootnotes->getByIndex(0), uno::UNO_QUERY);
1381 2 : OUString aExpected("Footnote first line.\n");
1382 2 : CPPUNIT_ASSERT_EQUAL(aExpected, xTextRange->getString());
1383 1 : }
1384 :
1385 : #endif
1386 :
1387 9 : DECLARE_RTFIMPORT_TEST(testNestedTable, "rhbz1065629.rtf")
1388 : {
1389 : // nested table in second cell was missing
1390 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
1391 2 : uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
1392 2 : uno::Reference<text::XTextTable> xTable(xTables->getByIndex(1), uno::UNO_QUERY);
1393 2 : uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
1394 2 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xCell->getText(), uno::UNO_QUERY);
1395 2 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
1396 2 : uno::Reference<text::XTextRange> xPara(xParaEnum->nextElement(), uno::UNO_QUERY);
1397 1 : CPPUNIT_ASSERT_EQUAL(OUString("Responsable Commercial:"), xPara->getString());
1398 1 : xCell.set(xTable->getCellByName("A2"), uno::UNO_QUERY);
1399 1 : xParaEnumAccess.set(xCell->getText(), uno::UNO_QUERY);
1400 1 : xParaEnum = xParaEnumAccess->createEnumeration();
1401 1 : xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
1402 1 : xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
1403 1 : CPPUNIT_ASSERT_EQUAL(OUString("Nom: John Doe"), xPara->getString());
1404 :
1405 : // outer table: background color, borders for B1/B2 cell
1406 1 : xTable.set(xTables->getByIndex(2), uno::UNO_QUERY);
1407 1 : xCell.set(xTable->getCellByName("A1"), uno::UNO_QUERY);
1408 1 : CPPUNIT_ASSERT(xCell.is());
1409 : table::BorderLine2 fullPtSolid(
1410 1 : 1, 0, 35, 0, table::BorderLineStyle::SOLID, 35);
1411 2 : CPPUNIT_ASSERT_BORDER_EQUAL(fullPtSolid,
1412 1 : getProperty<table::BorderLine2>(xCell, "LeftBorder"));
1413 2 : CPPUNIT_ASSERT_BORDER_EQUAL(fullPtSolid,
1414 1 : getProperty<table::BorderLine2>(xCell, "RightBorder"));
1415 2 : CPPUNIT_ASSERT_BORDER_EQUAL(fullPtSolid,
1416 1 : getProperty<table::BorderLine2>(xCell, "TopBorder"));
1417 2 : CPPUNIT_ASSERT_BORDER_EQUAL(fullPtSolid,
1418 1 : getProperty<table::BorderLine2>(xCell, "BottomBorder"));
1419 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0xCC0000), getProperty<sal_Int32>(xCell, "BackColor"));
1420 1 : xCell.set(xTable->getCellByName("A2"), uno::UNO_QUERY);
1421 1 : CPPUNIT_ASSERT(xCell.is());
1422 : table::BorderLine2 halfPtSolid(
1423 1 : /*0*/1, 0, 18, 0, table::BorderLineStyle::SOLID, 18);
1424 2 : CPPUNIT_ASSERT_BORDER_EQUAL(halfPtSolid,
1425 1 : getProperty<table::BorderLine2>(xCell, "LeftBorder"));
1426 2 : CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0xffffffff),
1427 1 : getProperty<sal_Int32>(xCell, "BackColor"));
1428 1 : xCell.set(xTable->getCellByName("B2"), uno::UNO_QUERY);
1429 1 : CPPUNIT_ASSERT(xCell.is());
1430 2 : CPPUNIT_ASSERT_BORDER_EQUAL(halfPtSolid,
1431 1 : getProperty<table::BorderLine2>(xCell, "LeftBorder"));
1432 2 : CPPUNIT_ASSERT_BORDER_EQUAL(halfPtSolid,
1433 1 : getProperty<table::BorderLine2>(xCell, "RightBorder"));
1434 2 : CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0xffffffff),
1435 1 : getProperty<sal_Int32>(xCell, "BackColor"));
1436 :
1437 : // \sect at the end resulted in spurious page break
1438 2 : CPPUNIT_ASSERT_EQUAL(1, getPages());
1439 1 : }
1440 :
1441 9 : DECLARE_RTFIMPORT_TEST(testContSectionPageBreak, "cont-section-pagebreak.rtf")
1442 : {
1443 1 : uno::Reference<text::XTextRange> xParaSecond = getParagraph(2);
1444 1 : CPPUNIT_ASSERT_EQUAL(OUString("SECOND"), xParaSecond->getString());
1445 2 : CPPUNIT_ASSERT_EQUAL(style::BreakType_NONE,
1446 1 : getProperty<style::BreakType>(xParaSecond, "BreakType"));
1447 2 : CPPUNIT_ASSERT_EQUAL(OUString(""),
1448 1 : getProperty<OUString>(xParaSecond, "PageDescName"));
1449 : // actually not sure how many paragraph there should be between
1450 : // SECOND and THIRD - important is that the page break is on there
1451 2 : uno::Reference<text::XTextRange> xParaNext = getParagraph(3);
1452 1 : CPPUNIT_ASSERT_EQUAL(OUString(""), xParaNext->getString());
1453 2 : CPPUNIT_ASSERT_EQUAL(OUString("Converted1"),
1454 1 : getProperty<OUString>(xParaNext, "PageDescName"));
1455 2 : uno::Reference<text::XTextRange> xParaThird = getParagraph(4);
1456 1 : CPPUNIT_ASSERT_EQUAL(OUString("THIRD"), xParaThird->getString());
1457 2 : CPPUNIT_ASSERT_EQUAL(style::BreakType_NONE,
1458 1 : getProperty<style::BreakType>(xParaThird, "BreakType"));
1459 2 : CPPUNIT_ASSERT_EQUAL(OUString(""),
1460 1 : getProperty<OUString>(xParaThird, "PageDescName"));
1461 :
1462 2 : CPPUNIT_ASSERT_EQUAL(2, getPages());
1463 1 : }
1464 :
1465 9 : DECLARE_RTFIMPORT_TEST(testFooterPara, "footer-para.rtf")
1466 : {
1467 : // check that paragraph properties in footer are imported
1468 : uno::Reference<text::XText> xFooterText =
1469 : getProperty< uno::Reference<text::XText> >(
1470 1 : getStyles("PageStyles")->getByName("First Page"), "FooterText");
1471 : uno::Reference<text::XTextContent> xParagraph =
1472 2 : getParagraphOrTable(1, xFooterText);
1473 2 : CPPUNIT_ASSERT_EQUAL(OUString("All Rights Reserved."),
1474 1 : uno::Reference<text::XTextRange>(xParagraph, uno::UNO_QUERY)->getString());
1475 2 : CPPUNIT_ASSERT_EQUAL((sal_Int16)style::ParagraphAdjust_CENTER,
1476 2 : getProperty</*style::ParagraphAdjust*/sal_Int16>(xParagraph, "ParaAdjust"));
1477 1 : }
1478 :
1479 9 : DECLARE_RTFIMPORT_TEST(testCp1000016, "hello.rtf")
1480 : {
1481 : // The single-line document had a second fake empty para on Windows.
1482 1 : bool bFound = true;
1483 : try
1484 : {
1485 2 : getParagraph(2);
1486 : }
1487 2 : catch (const container::NoSuchElementException&)
1488 : {
1489 1 : bFound = false;
1490 : }
1491 1 : CPPUNIT_ASSERT_EQUAL(false, bFound);
1492 1 : }
1493 :
1494 9 : DECLARE_RTFIMPORT_TEST(testFdo65090, "fdo65090.rtf")
1495 : {
1496 1 : uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
1497 2 : uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables( ), uno::UNO_QUERY);
1498 2 : uno::Reference<text::XTextTable> xTextTable(xTables->getByIndex(0), uno::UNO_QUERY);
1499 2 : uno::Reference<table::XTableRows> xTableRows(xTextTable->getRows(), uno::UNO_QUERY);
1500 : // The first row had 3 cells, instead of a horizontally merged one and a normal one (2 -> 1 separator).
1501 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty< uno::Sequence<text::TableColumnSeparator> >(xTableRows->getByIndex(0), "TableColumnSeparators").getLength());
1502 1 : }
1503 :
1504 9 : DECLARE_RTFIMPORT_TEST(testTableBorderDefaults, "fdo68779.rtf")
1505 : {
1506 : // table borders without \brdrw were not imported
1507 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
1508 2 : uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
1509 2 : uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
1510 2 : uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
1511 1 : CPPUNIT_ASSERT(xCell.is());
1512 : table::BorderLine2 solid(
1513 1 : 1, 0, 26, 0, table::BorderLineStyle::SOLID, 26);
1514 2 : CPPUNIT_ASSERT_BORDER_EQUAL(solid,
1515 1 : getProperty<table::BorderLine2>(xCell, "LeftBorder"));
1516 2 : CPPUNIT_ASSERT_BORDER_EQUAL(solid,
1517 1 : getProperty<table::BorderLine2>(xCell, "RightBorder"));
1518 2 : CPPUNIT_ASSERT_BORDER_EQUAL(solid,
1519 1 : getProperty<table::BorderLine2>(xCell, "TopBorder"));
1520 2 : CPPUNIT_ASSERT_BORDER_EQUAL(solid,
1521 1 : getProperty<table::BorderLine2>(xCell, "BottomBorder"));
1522 :
1523 1 : xTable.set(xTables->getByIndex(1), uno::UNO_QUERY);
1524 1 : xCell.set(xTable->getCellByName("A1"), uno::UNO_QUERY);
1525 1 : CPPUNIT_ASSERT(xCell.is());
1526 : table::BorderLine2 dotted(
1527 1 : 1, 0, 26, 0, table::BorderLineStyle::DOTTED, 26);
1528 2 : CPPUNIT_ASSERT_BORDER_EQUAL(dotted,
1529 1 : getProperty<table::BorderLine2>(xCell, "LeftBorder"));
1530 2 : CPPUNIT_ASSERT_BORDER_EQUAL(dotted,
1531 1 : getProperty<table::BorderLine2>(xCell, "RightBorder"));
1532 2 : CPPUNIT_ASSERT_BORDER_EQUAL(dotted,
1533 1 : getProperty<table::BorderLine2>(xCell, "TopBorder"));
1534 2 : CPPUNIT_ASSERT_BORDER_EQUAL(dotted,
1535 1 : getProperty<table::BorderLine2>(xCell, "BottomBorder"));
1536 :
1537 1 : xTable.set(xTables->getByIndex(2), uno::UNO_QUERY);
1538 1 : xCell.set(xTable->getCellByName("A1"), uno::UNO_QUERY);
1539 1 : CPPUNIT_ASSERT(xCell.is());
1540 : table::BorderLine2 doubled(
1541 1 : 1, 26, 26, 26, table::BorderLineStyle::DOUBLE, 79);
1542 2 : CPPUNIT_ASSERT_BORDER_EQUAL(doubled,
1543 1 : getProperty<table::BorderLine2>(xCell, "LeftBorder"));
1544 2 : CPPUNIT_ASSERT_BORDER_EQUAL(doubled,
1545 1 : getProperty<table::BorderLine2>(xCell, "RightBorder"));
1546 2 : CPPUNIT_ASSERT_BORDER_EQUAL(doubled,
1547 1 : getProperty<table::BorderLine2>(xCell, "TopBorder"));
1548 2 : CPPUNIT_ASSERT_BORDER_EQUAL(doubled,
1549 1 : getProperty<table::BorderLine2>(xCell, "BottomBorder"));
1550 :
1551 1 : xTable.set(xTables->getByIndex(3), uno::UNO_QUERY);
1552 1 : xCell.set(xTable->getCellByName("A1"), uno::UNO_QUERY);
1553 1 : CPPUNIT_ASSERT(xCell.is());
1554 : table::BorderLine2 thinThickMG(
1555 1 : 1, 14, 26, 14, table::BorderLineStyle::THINTHICK_MEDIUMGAP, 53);
1556 2 : CPPUNIT_ASSERT_BORDER_EQUAL(thinThickMG,
1557 1 : getProperty<table::BorderLine2>(xCell, "LeftBorder"));
1558 2 : CPPUNIT_ASSERT_BORDER_EQUAL(thinThickMG,
1559 1 : getProperty<table::BorderLine2>(xCell, "RightBorder"));
1560 2 : CPPUNIT_ASSERT_BORDER_EQUAL(thinThickMG,
1561 1 : getProperty<table::BorderLine2>(xCell, "TopBorder"));
1562 2 : CPPUNIT_ASSERT_BORDER_EQUAL(thinThickMG,
1563 2 : getProperty<table::BorderLine2>(xCell, "BottomBorder"));
1564 1 : }
1565 :
1566 9 : DECLARE_RTFIMPORT_TEST(testShpzDhgt, "shpz-dhgt.rtf")
1567 : {
1568 : // Test that shpz has priority over dhght and not the other way around.
1569 : // Drawpage is sorted by ZOrder, so first should be red (back).
1570 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0xff0000), getProperty<sal_Int32>(getShape(1), "FillColor"));
1571 : // Second (front) should be green.
1572 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0x00ff00), getProperty<sal_Int32>(getShape(2), "FillColor"));
1573 1 : }
1574 :
1575 9 : DECLARE_RTFIMPORT_TEST(testBackground, "background.rtf")
1576 : {
1577 : // The first shape wasn't in the foreground.
1578 1 : CPPUNIT_ASSERT_EQUAL(true, bool(getProperty<sal_Bool>(getShape(1), "Opaque")));
1579 1 : CPPUNIT_ASSERT_EQUAL(false, bool(getProperty<sal_Bool>(getShape(2), "Opaque")));
1580 1 : }
1581 :
1582 9 : DECLARE_RTFIMPORT_TEST(testLevelfollow, "levelfollow.rtf")
1583 : {
1584 1 : uno::Reference<container::XIndexAccess> xNum1Levels = getProperty< uno::Reference<container::XIndexAccess> >(getStyles("NumberingStyles")->getByName("WWNum1"), "NumberingRules");
1585 1 : CPPUNIT_ASSERT_EQUAL(sal_Int16(SvxNumberFormat::LISTTAB), comphelper::SequenceAsHashMap(xNum1Levels->getByIndex(0))["LabelFollowedBy"].get<sal_Int16>()); // first level, tab
1586 :
1587 2 : uno::Reference<container::XIndexAccess> xNum2Levels = getProperty< uno::Reference<container::XIndexAccess> >(getStyles("NumberingStyles")->getByName("WWNum2"), "NumberingRules");
1588 1 : CPPUNIT_ASSERT_EQUAL(sal_Int16(SvxNumberFormat::SPACE), comphelper::SequenceAsHashMap(xNum2Levels->getByIndex(0))["LabelFollowedBy"].get<sal_Int16>()); // first level, space
1589 :
1590 2 : uno::Reference<container::XIndexAccess> xNum3Levels = getProperty< uno::Reference<container::XIndexAccess> >(getStyles("NumberingStyles")->getByName("WWNum3"), "NumberingRules");
1591 2 : CPPUNIT_ASSERT_EQUAL(sal_Int16(SvxNumberFormat::NOTHING), comphelper::SequenceAsHashMap(xNum3Levels->getByIndex(0))["LabelFollowedBy"].get<sal_Int16>()); // first level, nothing
1592 1 : }
1593 :
1594 9 : DECLARE_RTFIMPORT_TEST(testCharColor, "char-color.rtf")
1595 : {
1596 : // This was -1: character color wasn't set.
1597 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0x365F91), getProperty<sal_Int32>(getParagraph(1), "CharColor"));
1598 1 : }
1599 :
1600 9 : DECLARE_RTFIMPORT_TEST(testFdo69289, "fdo69289.rtf")
1601 : {
1602 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
1603 2 : uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
1604 2 : uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
1605 2 : uno::Reference<table::XTableRows> xTableRows(xTable->getRows(), uno::UNO_QUERY);
1606 : // There were only 2 cells (1 separators) in the table, should be 3 (2 separators).
1607 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getProperty< uno::Sequence<text::TableColumnSeparator> >(xTableRows->getByIndex(0), "TableColumnSeparators").getLength());
1608 1 : }
1609 :
1610 9 : DECLARE_RTFIMPORT_TEST(testDptxbxRelation, "dptxbx-relation.rtf")
1611 : {
1612 : // This was FRAME, not PAGE_FRAME, even if dobxpage is in the document.
1613 1 : CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(getShape(1), "HoriOrientRelation"));
1614 1 : }
1615 :
1616 9 : DECLARE_RTFIMPORT_TEST(testDprectAnchor, "dprect-anchor.rtf")
1617 : {
1618 : // This was at-page, which is not something Word supports, so clearly an import error.
1619 1 : CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER, getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType"));
1620 1 : }
1621 :
1622 9 : DECLARE_RTFIMPORT_TEST(testFdo76628, "fdo76628.rtf")
1623 : {
1624 1 : OUString aExpected("\xd0\x9e\xd0\x91\xd0\xa0\xd0\x90\xd0\x97\xd0\x95\xd0\xa6", 14, RTL_TEXTENCODING_UTF8);
1625 : // Should be 'SAMPLE' in Russian, was garbage.
1626 1 : getParagraph(1, aExpected);
1627 :
1628 2 : uno::Reference<text::XText> xHeaderText = getProperty< uno::Reference<text::XText> >(getStyles("PageStyles")->getByName(DEFAULT_STYLE), "HeaderText");
1629 2 : OUString aExpectedHeader("\xd0\x9f\xd0\xbe\xd0\xb4\xd0\xb3\xd0\xbe\xd1\x82\xd0\xbe\xd0\xb2\xd0\xbb\xd0\xb5\xd0\xbd\xd0\xbe", 24, RTL_TEXTENCODING_UTF8);
1630 : // Should be 'prepared' in Russian, was garbage.
1631 2 : getParagraphOfText(1, xHeaderText, aExpectedHeader);
1632 1 : }
1633 :
1634 9 : DECLARE_RTFIMPORT_TEST(testFdo74823, "fdo74823.rtf")
1635 : {
1636 1 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
1637 2 : uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
1638 2 : uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
1639 : // Cell width of C2 was too large / column separator being 3749 too small (e.g. not set, around 3/7 of total width)
1640 2 : uno::Reference<table::XTableRows> xTableRows(xTable->getRows(), uno::UNO_QUERY);
1641 2 : CPPUNIT_ASSERT_EQUAL(sal_Int16(5391), getProperty< uno::Sequence<text::TableColumnSeparator> >(xTableRows->getByIndex(1), "TableColumnSeparators")[2].Position);
1642 1 : }
1643 :
1644 4 : CPPUNIT_PLUGIN_IMPLEMENT();
1645 :
1646 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|