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/bootstrapfixture.hxx>
11 #include <unotest/macros_test.hxx>
12 
13 #include <com/sun/star/frame/Desktop.hpp>
14 #include <com/sun/star/beans/XPropertySet.hpp>
15 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
16 #include <com/sun/star/text/TextContentAnchorType.hpp>
17 
18 using namespace ::com::sun::star;
19 
20 namespace
21 {
22 /// Tests for writerfilter/source/rtftok/rtfsdrimport.cxx.
23 class Test : public test::BootstrapFixture, public unotest::MacrosTest
24 {
25 private:
26     uno::Reference<lang::XComponent> mxComponent;
27 
28 public:
29     void setUp() override;
30     void tearDown() override;
getComponent()31     uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
32 };
33 
setUp()34 void Test::setUp()
35 {
36     test::BootstrapFixture::setUp();
37 
38     mxDesktop.set(frame::Desktop::create(mxComponentContext));
39 }
40 
tearDown()41 void Test::tearDown()
42 {
43     if (mxComponent.is())
44         mxComponent->dispose();
45 
46     test::BootstrapFixture::tearDown();
47 }
48 
49 constexpr OUStringLiteral DATA_DIRECTORY = u"/writerfilter/qa/cppunittests/rtftok/data/";
50 
CPPUNIT_TEST_FIXTURE(Test,testPictureInTextframe)51 CPPUNIT_TEST_FIXTURE(Test, testPictureInTextframe)
52 {
53     OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "picture-in-textframe.rtf";
54     getComponent() = loadFromDesktop(aURL);
55     uno::Reference<drawing::XDrawPageSupplier> xTextDocument(getComponent(), uno::UNO_QUERY);
56     uno::Reference<drawing::XDrawPage> xDrawPage = xTextDocument->getDrawPage();
57     uno::Reference<beans::XPropertySet> xInnerShape(xDrawPage->getByIndex(1), uno::UNO_QUERY);
58     text::TextContentAnchorType eAnchorType = text::TextContentAnchorType_AT_PARAGRAPH;
59     xInnerShape->getPropertyValue("AnchorType") >>= eAnchorType;
60     // Without the accompanying fix in place, this test would have failed with:
61     // - Expected: 1
62     // - Actual  : 4
63     // i.e. the properties of the inner shape (including its anchor type and bitmap fill) were lost
64     // on import.
65     CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AS_CHARACTER, eAnchorType);
66 }
67 }
68 
69 CPPUNIT_PLUGIN_IMPLEMENT();
70 
71 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
72