Debian Codegraph @

sw/qa/writerfilter/rtftok/rtfdocumentimpl.cxx

raw
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/beans/XPropertySet.hpp>
13 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
14 #include <com/sun/star/graphic/XGraphic.hpp>
15 #include <com/sun/star/text/XTextTablesSupplier.hpp>
16 #include <com/sun/star/text/XTextTable.hpp>
17 #include <com/sun/star/text/XTextDocument.hpp>
18
19 #include <vcl/graph.hxx>
20
21 #include <fmtfsize.hxx>
22
23 using namespace ::com::sun::star;
24
25 namespace
26 {
27 /// Tests for sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx.
28 class Test : public SwModelTestBase
29 {
30 public:
31 Test()
32 : SwModelTestBase(u"/sw/qa/writerfilter/rtftok/data/"_ustr)
33 {
34 }
35 };
36
37 CPPUNIT_TEST_FIXTURE(Test, testPicwPich)
38 {
39 // Given a document with a WMF file where picwgoal and picscalex is provided, so picw is not
40 // relevant:
41 loadFromFile(u"picw-pich.rtf");
42
43 // Then make sure the graphic's preferred size is correct:
44 uno::Reference<drawing::XDrawPageSupplier> xTextDocument(mxComponent, uno::UNO_QUERY);
45 uno::Reference<drawing::XDrawPage> xDrawPage = xTextDocument->getDrawPage();
46 uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
47 uno::Reference<graphic::XGraphic> xGraphic;
48 xShape->getPropertyValue(u"Graphic"_ustr) >>= xGraphic;
49 Graphic aGraphic(xGraphic);
50 Size aPrefSize = aGraphic.GetPrefSize();
51 // Without the accompanying fix in place, this test would have failed with:
52 // - Expected: 2619
53 // - Actual : 132
54 // i.e. the graphic width didn't match 2.62 cm from the Word UI.
55 CPPUNIT_ASSERT_EQUAL(static_cast<tools::Long>(2619), aPrefSize.Width());
56 }
57
58 CPPUNIT_TEST_FIXTURE(Test, testCharHiddenInTable)
59 {
60 // Given a document with a table, and a hidden \line in it:
61 loadFromFile(u"char-hidden-intbl.rtf");
62
63 // Then make sure that line is indeed hidden:
64 uno::Reference<text::XTextTablesSupplier> xTextDocument(mxComponent, uno::UNO_QUERY);
65 uno::Reference<container::XIndexAccess> xTables(xTextDocument->getTextTables(), uno::UNO_QUERY);
66 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
67 uno::Reference<container::XEnumerationAccess> xCell(xTable->getCellByName(u"B1"_ustr),
68 uno::UNO_QUERY);
69 uno::Reference<container::XEnumeration> xParagraphs = xCell->createEnumeration();
70 uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(),
71 uno::UNO_QUERY);
72 uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration();
73 uno::Reference<beans::XPropertySet> xPortion(xPortions->nextElement(), uno::UNO_QUERY);
74 bool bCharHidden{};
75 xPortion->getPropertyValue(u"CharHidden"_ustr) >>= bCharHidden;
76 // Without the accompanying fix in place, this test would have failed, the newline was not
77 // hidden.
78 CPPUNIT_ASSERT(bCharHidden);
79 }
80
81 CPPUNIT_TEST_FIXTURE(Test, testDuplicatedImage)
82 {
83 // Given a document with 2 images:
84 loadFromFile(u"duplicated-image.rtf");
85
86 // Then make sure no duplicated images are created:
87 uno::Reference<drawing::XDrawPageSupplier> xTextDocument(mxComponent, uno::UNO_QUERY);
88 uno::Reference<drawing::XDrawPage> xDrawPage = xTextDocument->getDrawPage();
89 // Without the accompanying fix in place, this test would have failed with:
90 // - Expected: 2
91 // - Actual : 3
92 // i.e. there was a 3rd, duplicated image.
93 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xDrawPage->getCount());
94 }
95
96 CPPUNIT_TEST_FIXTURE(Test, testOldParaNumLeftMargin)
97 {
98 // Given a document with 3 paragraphs, the third one with a left indent:
99 loadFromFile(u"old-para-num-left-margin.rtf");
100
101 // Then make sure that the third paragraph has a left indent:
102 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
103 uno::Reference<container::XEnumerationAccess> xText(xTextDocument->getText(), uno::UNO_QUERY);
104 uno::Reference<container::XEnumeration> xParagraphs = xText->createEnumeration();
105 xParagraphs->nextElement();
106 xParagraphs->nextElement();
107 uno::Reference<beans::XPropertySet> xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY);
108 sal_Int32 nParaLeftMargin{};
109 xParagraph->getPropertyValue(u"ParaLeftMargin"_ustr) >>= nParaLeftMargin;
110 // Without the accompanying fix in place, this test would have failed with:
111 // - Expected: 2101
112 // - Actual : 0
113 // i.e. the left indent was 0, not 1191 twips (from the file) in mm100.
114 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2101), nParaLeftMargin);
115 }
116
117 CPPUNIT_TEST_FIXTURE(Test, testImageSizeInShapeText)
118 {
119 // Given an RTF document with a shape and an icon image inside that:
120 // When loading this document:
121 createSwDoc("image-size-in-shape-text.rtf");
122
123 // Then make sure that the icon image has the correct (small) size:
124 SwDoc* pDoc = getSwDoc();
125 const sw::FrameFormats<sw::SpzFrameFormat*>& rFlyFormats = *pDoc->GetSpzFrameFormats();
126 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rFlyFormats.size());
127 const sw::SpzFrameFormat& rImageFlyFormat = *rFlyFormats[1];
128 const SwFormatFrameSize& rImageSize = rImageFlyFormat.GetFrameSize();
129 // 255 * 0.82 in the RTF file.
130 SwTwips nExpected = 209;
131 // Without the accompanying fix in place, this test would have failed with:
132 // - Expected: 209
133 // - Actual : 8808
134 // i.e. the size of the icon was inherited from the containing shape, losing the own size.
135 CPPUNIT_ASSERT_EQUAL(nExpected, rImageSize.GetWidth());
136 }
137 }
138
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */