1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include <test/unoapi_test.hxx>
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>
19 #include <vcl/graph.hxx>
21 using namespace ::com::sun::star
;
25 /// Tests for writerfilter/source/rtftok/rtfdocumentimpl.cxx.
26 class Test
: public UnoApiTest
30 : UnoApiTest("/writerfilter/qa/cppunittests/rtftok/data/")
35 CPPUNIT_TEST_FIXTURE(Test
, testPicwPich
)
37 // Given a document with a WMF file where picwgoal and picscalex is provided, so picw is not
39 loadFromFile(u
"picw-pich.rtf");
41 // Then make sure the graphic's preferred size is correct:
42 uno::Reference
<drawing::XDrawPageSupplier
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
43 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xTextDocument
->getDrawPage();
44 uno::Reference
<beans::XPropertySet
> xShape(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
45 uno::Reference
<graphic::XGraphic
> xGraphic
;
46 xShape
->getPropertyValue("Graphic") >>= xGraphic
;
47 Graphic
aGraphic(xGraphic
);
48 Size aPrefSize
= aGraphic
.GetPrefSize();
49 // Without the accompanying fix in place, this test would have failed with:
52 // i.e. the graphic width didn't match 2.62 cm from the Word UI.
53 CPPUNIT_ASSERT_EQUAL(static_cast<tools::Long
>(2619), aPrefSize
.Width());
56 CPPUNIT_TEST_FIXTURE(Test
, testCharHiddenInTable
)
58 // Given a document with a table, and a hidden \line in it:
59 loadFromFile(u
"char-hidden-intbl.rtf");
61 // Then make sure that line is indeed hidden:
62 uno::Reference
<text::XTextTablesSupplier
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
63 uno::Reference
<container::XIndexAccess
> xTables(xTextDocument
->getTextTables(), uno::UNO_QUERY
);
64 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
65 uno::Reference
<container::XEnumerationAccess
> xCell(xTable
->getCellByName("B1"),
67 uno::Reference
<container::XEnumeration
> xParagraphs
= xCell
->createEnumeration();
68 uno::Reference
<container::XEnumerationAccess
> xParagraph(xParagraphs
->nextElement(),
70 uno::Reference
<container::XEnumeration
> xPortions
= xParagraph
->createEnumeration();
71 uno::Reference
<beans::XPropertySet
> xPortion(xPortions
->nextElement(), uno::UNO_QUERY
);
73 xPortion
->getPropertyValue("CharHidden") >>= bCharHidden
;
74 // Without the accompanying fix in place, this test would have failed, the newline was not
76 CPPUNIT_ASSERT(bCharHidden
);
79 CPPUNIT_TEST_FIXTURE(Test
, testDuplicatedImage
)
81 // Given a document with 2 images:
82 loadFromFile(u
"duplicated-image.rtf");
84 // Then make sure no duplicated images are created:
85 uno::Reference
<drawing::XDrawPageSupplier
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
86 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xTextDocument
->getDrawPage();
87 // Without the accompanying fix in place, this test would have failed with:
90 // i.e. there was a 3rd, duplicated image.
91 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(2), xDrawPage
->getCount());
94 CPPUNIT_TEST_FIXTURE(Test
, testOldParaNumLeftMargin
)
96 // Given a document with 3 paragraphs, the third one with a left indent:
97 loadFromFile(u
"old-para-num-left-margin.rtf");
99 // Then make sure that the third paragraph has a left indent:
100 uno::Reference
<text::XTextDocument
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
101 uno::Reference
<container::XEnumerationAccess
> xText(xTextDocument
->getText(), uno::UNO_QUERY
);
102 uno::Reference
<container::XEnumeration
> xParagraphs
= xText
->createEnumeration();
103 xParagraphs
->nextElement();
104 xParagraphs
->nextElement();
105 uno::Reference
<beans::XPropertySet
> xParagraph(xParagraphs
->nextElement(), uno::UNO_QUERY
);
106 sal_Int32 nParaLeftMargin
{};
107 xParagraph
->getPropertyValue("ParaLeftMargin") >>= nParaLeftMargin
;
108 // Without the accompanying fix in place, this test would have failed with:
111 // i.e. the left indent was 0, not 1191 twips (from the file) in mm100.
112 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(2101), nParaLeftMargin
);
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */