set Referer on loading IFrames
[LibreOffice.git] / sw / qa / api / SwXTextFrame.cxx
blob81b6e1c847a44f5c9ea83265ffd9d3970c331dc5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <test/bootstrapfixture.hxx>
11 #include <test/lang/xserviceinfo.hxx>
12 #include <test/lang/xcomponent.hxx>
13 #include <unotest/macros_test.hxx>
15 #include <com/sun/star/frame/Desktop.hpp>
17 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
19 #include <com/sun/star/text/XTextDocument.hpp>
20 #include <com/sun/star/text/XTextContent.hpp>
21 #include <com/sun/star/text/XText.hpp>
22 #include <com/sun/star/text/XTextCursor.hpp>
23 #include <com/sun/star/text/XTextRange.hpp>
24 #include <com/sun/star/text/XTextFrame.hpp>
26 using namespace css;
28 namespace
30 /**
31 * Test for Java API test of file com.sun.star.comp.office.SwXTextFrame.csv
33 class SwXTextFrame final : public test::BootstrapFixture,
34 public unotest::MacrosTest,
35 public apitest::XServiceInfo,
36 public apitest::XComponent
38 uno::Reference<text::XTextDocument> mxTextDocument;
40 public:
41 virtual void setUp() override;
42 virtual void tearDown() override;
44 SwXTextFrame()
45 : apitest::XServiceInfo("SwXTextFrame", "com.sun.star.text.TextFrame"){};
46 uno::Reference<uno::XInterface> init() override;
47 const uno::Reference<text::XTextDocument>& getTextDocument() const { return mxTextDocument; }
48 void triggerDesktopTerminate() override { mxDesktop->terminate(); }
50 CPPUNIT_TEST_SUITE(SwXTextFrame);
51 CPPUNIT_TEST(testGetImplementationName);
52 CPPUNIT_TEST(testGetSupportedServiceNames);
53 CPPUNIT_TEST(testSupportsService);
54 CPPUNIT_TEST(testAddEventListener);
55 CPPUNIT_TEST(testRemoveEventListener);
56 CPPUNIT_TEST_SUITE_END();
59 void SwXTextFrame::setUp()
61 test::BootstrapFixture::setUp();
63 mxDesktop.set(frame::Desktop::create(mxComponentContext));
64 mxTextDocument = uno::Reference<text::XTextDocument>(
65 loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"),
66 uno::UNO_QUERY_THROW);
67 CPPUNIT_ASSERT(mxTextDocument.is());
70 void SwXTextFrame::tearDown()
72 if (mxTextDocument.is())
73 mxTextDocument->dispose();
75 test::BootstrapFixture::tearDown();
78 uno::Reference<uno::XInterface> SwXTextFrame::init()
80 uno::Reference<lang::XMultiServiceFactory> xMSF(mxTextDocument, uno::UNO_QUERY_THROW);
81 uno::Reference<text::XTextFrame> xTextFrame(xMSF->createInstance("com.sun.star.text.TextFrame"),
82 uno::UNO_QUERY_THROW);
83 auto xText = getTextDocument()->getText();
84 auto xTextCursor = xText->createTextCursor();
85 CPPUNIT_ASSERT(xTextCursor.is());
86 xText->insertTextContent(xTextCursor, xTextFrame, false);
87 xTextCursor->gotoEnd(false);
88 return xTextFrame;
91 CPPUNIT_TEST_SUITE_REGISTRATION(SwXTextFrame);
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */