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/text/RelOrientation.hpp>
15 #include <com/sun/star/text/XTextFramesSupplier.hpp>
17 using namespace ::com::sun::star
;
21 /// Tests for writerfilter/source/rtftok/rtfdispatchflag.cxx.
22 class Test
: public UnoApiTest
26 : UnoApiTest("/writerfilter/qa/cppunittests/rtftok/data/")
31 CPPUNIT_TEST_FIXTURE(Test
, testFloatingTable
)
33 // Given a document with a floating table, when importing that document:
34 loadFromURL(u
"floating-table.rtf");
36 // Then make sure the floating table is there & has the expected properties:
37 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(mxComponent
, uno::UNO_QUERY
);
38 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
39 // Without the accompanying fix in place, this test would have failed with:
40 // An uncaught exception of type com.sun.star.lang.IndexOutOfBoundsException
41 // i.e. the table was not floating / was not in a fly frame.
42 uno::Reference
<beans::XPropertySet
> xFrame(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
43 bool bIsSplitAllowed
{};
44 xFrame
->getPropertyValue("IsSplitAllowed") >>= bIsSplitAllowed
;
45 CPPUNIT_ASSERT(bIsSplitAllowed
);
46 sal_Int16 nVertOrientRelation
{};
47 xFrame
->getPropertyValue("VertOrientRelation") >>= nVertOrientRelation
;
48 CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME
, nVertOrientRelation
);
49 sal_Int16 nHoriOrientRelation
{};
50 xFrame
->getPropertyValue("HoriOrientRelation") >>= nHoriOrientRelation
;
51 CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME
, nHoriOrientRelation
);
52 sal_Int32 nVertOrientPosition
{};
53 xFrame
->getPropertyValue("VertOrientPosition") >>= nVertOrientPosition
;
54 sal_Int32 nExpected
= o3tl::convert(10, o3tl::Length::twip
, o3tl::Length::mm100
);
55 CPPUNIT_ASSERT_EQUAL(nExpected
, nVertOrientPosition
);
56 sal_Int32 nHoriOrientPosition
{};
57 xFrame
->getPropertyValue("HoriOrientPosition") >>= nHoriOrientPosition
;
58 nExpected
= o3tl::convert(20, o3tl::Length::twip
, o3tl::Length::mm100
);
59 CPPUNIT_ASSERT_EQUAL(nExpected
, nHoriOrientPosition
);
60 sal_Int32 nLeftMargin
{};
61 xFrame
->getPropertyValue("LeftMargin") >>= nLeftMargin
;
62 nExpected
= o3tl::convert(30, o3tl::Length::twip
, o3tl::Length::mm100
);
63 CPPUNIT_ASSERT_EQUAL(nExpected
, nLeftMargin
);
64 sal_Int32 nRightMargin
{};
65 xFrame
->getPropertyValue("RightMargin") >>= nRightMargin
;
66 nExpected
= o3tl::convert(40, o3tl::Length::twip
, o3tl::Length::mm100
);
67 CPPUNIT_ASSERT_EQUAL(nExpected
, nRightMargin
);
70 CPPUNIT_TEST_FIXTURE(Test
, testDoNotBreakWrappedTables
)
72 // Given a document without \nobrkwrptbl:
73 // When importing that document:
74 loadFromURL(u
"do-not-break-wrapped-tables.rtf");
76 // Then make sure that the matching compat flag is set:
77 uno::Reference
<lang::XMultiServiceFactory
> xDocument(mxComponent
, uno::UNO_QUERY
);
78 uno::Reference
<beans::XPropertySet
> xSettings(
79 xDocument
->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY
);
80 bool bDoNotBreakWrappedTables
{};
81 xSettings
->getPropertyValue("DoNotBreakWrappedTables") >>= bDoNotBreakWrappedTables
;
82 // Without the accompanying fix in place, this test would have failed, the compat flag was not
84 CPPUNIT_ASSERT(bDoNotBreakWrappedTables
);
87 CPPUNIT_TEST_FIXTURE(Test
, testTblOverlap
)
89 // Given a document with 2 floating tables, the second is not allowed to overlap:
90 // When importing that document:
91 loadFromURL(u
"floattable-tbl-overlap.rtf");
93 // Then make sure the second table is marked as "can't overlap":
94 uno::Reference
<text::XTextFramesSupplier
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
95 uno::Reference
<container::XIndexAccess
> xFrames(xTextDocument
->getTextFrames(), uno::UNO_QUERY
);
96 uno::Reference
<beans::XPropertySet
> xFrame(xFrames
->getByIndex(1), uno::UNO_QUERY
);
98 CPPUNIT_ASSERT(xFrame
->getPropertyValue("AllowOverlap") >>= bAllowOverlap
);
99 // Without the accompanying fix in place, this test would have failed, the tables were marked as
101 CPPUNIT_ASSERT(!bAllowOverlap
);
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */