Debian Codegraph @

sw/qa/writerfilter/rtftok/rtfdispatchflag.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 <test/unoapi_test.hxx>
11
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>
16 #include <com/sun/star/text/XTextDocument.hpp>
17
18 using namespace ::com::sun::star;
19
20 namespace
21 {
22 /// Tests for sw/source/writerfilter/rtftok/rtfdispatchflag.cxx.
23 class Test : public UnoApiTest
24 {
25 public:
26 Test()
27 : UnoApiTest(u"sw/qa//writerfilter/rtftok/data/"_ustr)
28 {
29 }
30 };
31
32 CPPUNIT_TEST_FIXTURE(Test, testFloatingTable)
33 {
34 // Given a document with a floating table, when importing that document:
35 loadFromFile(u"floating-table.rtf");
36
37 // Then make sure the floating table is there & has the expected properties:
38 uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
39 uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
40 // Without the accompanying fix in place, this test would have failed with:
41 // An uncaught exception of type com.sun.star.lang.IndexOutOfBoundsException
42 // i.e. the table was not floating / was not in a fly frame.
43 uno::Reference<beans::XPropertySet> xFrame(xDrawPage->getByIndex(0), uno::UNO_QUERY);
44 bool bIsSplitAllowed{};
45 xFrame->getPropertyValue(u"IsSplitAllowed"_ustr) >>= bIsSplitAllowed;
46 CPPUNIT_ASSERT(bIsSplitAllowed);
47 sal_Int16 nVertOrientRelation{};
48 xFrame->getPropertyValue(u"VertOrientRelation"_ustr) >>= nVertOrientRelation;
49 CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME, nVertOrientRelation);
50 sal_Int16 nHoriOrientRelation{};
51 xFrame->getPropertyValue(u"HoriOrientRelation"_ustr) >>= nHoriOrientRelation;
52 CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME, nHoriOrientRelation);
53 sal_Int32 nVertOrientPosition{};
54 xFrame->getPropertyValue(u"VertOrientPosition"_ustr) >>= nVertOrientPosition;
55 sal_Int32 nExpected = o3tl::convert(10, o3tl::Length::twip, o3tl::Length::mm100);
56 CPPUNIT_ASSERT_EQUAL(nExpected, nVertOrientPosition);
57 sal_Int32 nHoriOrientPosition{};
58 xFrame->getPropertyValue(u"HoriOrientPosition"_ustr) >>= nHoriOrientPosition;
59 nExpected = o3tl::convert(20, o3tl::Length::twip, o3tl::Length::mm100);
60 CPPUNIT_ASSERT_EQUAL(nExpected, nHoriOrientPosition);
61 sal_Int32 nLeftMargin{};
62 xFrame->getPropertyValue(u"LeftMargin"_ustr) >>= nLeftMargin;
63 nExpected = o3tl::convert(30, o3tl::Length::twip, o3tl::Length::mm100);
64 CPPUNIT_ASSERT_EQUAL(nExpected, nLeftMargin);
65 sal_Int32 nRightMargin{};
66 xFrame->getPropertyValue(u"RightMargin"_ustr) >>= nRightMargin;
67 nExpected = o3tl::convert(40, o3tl::Length::twip, o3tl::Length::mm100);
68 CPPUNIT_ASSERT_EQUAL(nExpected, nRightMargin);
69 }
70
71 CPPUNIT_TEST_FIXTURE(Test, testDoNotBreakWrappedTables)
72 {
73 // Given a document without \nobrkwrptbl:
74 // When importing that document:
75 loadFromFile(u"do-not-break-wrapped-tables.rtf");
76
77 // Then make sure that the matching compat flag is set:
78 uno::Reference<lang::XMultiServiceFactory> xDocument(mxComponent, uno::UNO_QUERY);
79 uno::Reference<beans::XPropertySet> xSettings(
80 xDocument->createInstance(u"com.sun.star.document.Settings"_ustr), uno::UNO_QUERY);
81 bool bDoNotBreakWrappedTables{};
82 xSettings->getPropertyValue(u"DoNotBreakWrappedTables"_ustr) >>= bDoNotBreakWrappedTables;
83 // Without the accompanying fix in place, this test would have failed, the compat flag was not
84 // set.
85 CPPUNIT_ASSERT(bDoNotBreakWrappedTables);
86 }
87
88 CPPUNIT_TEST_FIXTURE(Test, testTblOverlap)
89 {
90 // Given a document with 2 floating tables, the second is not allowed to overlap:
91 // When importing that document:
92 loadFromFile(u"floattable-tbl-overlap.rtf");
93
94 // Then make sure the second table is marked as "can't overlap":
95 uno::Reference<text::XTextFramesSupplier> xTextDocument(mxComponent, uno::UNO_QUERY);
96 uno::Reference<container::XIndexAccess> xFrames(xTextDocument->getTextFrames(), uno::UNO_QUERY);
97 uno::Reference<beans::XPropertySet> xFrame(xFrames->getByIndex(1), uno::UNO_QUERY);
98 bool bAllowOverlap{};
99 CPPUNIT_ASSERT(xFrame->getPropertyValue(u"AllowOverlap"_ustr) >>= bAllowOverlap);
100 // Without the accompanying fix in place, this test would have failed, the tables were marked as
101 // "can overlap".
102 CPPUNIT_ASSERT(!bAllowOverlap);
103 }
104
105 CPPUNIT_TEST_FIXTURE(Test, testEndnoteAtSectionEndRTFImport)
106 {
107 // Given a document with at-section-end endnotes enabled:
108 // When loading that document:
109 loadFromFile(u"endnote-at-section-end.rtf");
110
111 // Go to the second paragraph, which is inside Word's second section:
112 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
113 uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(),
114 uno::UNO_QUERY);
115 uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
116 xParaEnum->nextElement();
117 uno::Reference<beans::XPropertySet> xPara(xParaEnum->nextElement(), uno::UNO_QUERY);
118 uno::Reference<beans::XPropertySet> xSection;
119 xPara->getPropertyValue(u"TextSection"_ustr) >>= xSection;
120 bool bEndnoteIsCollectAtTextEnd = false;
121 xSection->getPropertyValue(u"EndnoteIsCollectAtTextEnd"_ustr) >>= bEndnoteIsCollectAtTextEnd;
122 // Without the accompanying fix in place, this test would have failed, endnotes were always at
123 // document end.
124 CPPUNIT_ASSERT(bEndnoteIsCollectAtTextEnd);
125 }
126 }
127
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */