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 <test/lang/xserviceinfo.hxx>
12 #include <test/lang/xcomponent.hxx>
13 #include <unotest/macros_test.hxx>
14
15 #include <com/sun/star/frame/Desktop.hpp>
16
17 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
18
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>
25
26 using namespace css;
27
28 namespace
29 {
30 /**
31 * Test for Java API test of file com.sun.star.comp.office.SwXTextFrame.csv
32 */
33 class SwXTextFrame final : public test::BootstrapFixture,
34 public unotest::MacrosTest,
35 public apitest::XServiceInfo,
36 public apitest::XComponent
37 {
38 uno::Reference<text::XTextDocument> mxTextDocument;
39
40 public:
41 virtual void setUp() override;
42 virtual void tearDown() override;
43
SwXTextFrame()44 SwXTextFrame()
45 : apitest::XServiceInfo("SwXTextFrame", "com.sun.star.text.TextFrame"){};
46 uno::Reference<uno::XInterface> init() override;
getTextDocument() const47 const uno::Reference<text::XTextDocument>& getTextDocument() const { return mxTextDocument; }
triggerDesktopTerminate()48 void triggerDesktopTerminate() override { mxDesktop->terminate(); }
49
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();
57 };
58
setUp()59 void SwXTextFrame::setUp()
60 {
61 test::BootstrapFixture::setUp();
62
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());
68 }
69
tearDown()70 void SwXTextFrame::tearDown()
71 {
72 if (mxTextDocument.is())
73 mxTextDocument->dispose();
74
75 test::BootstrapFixture::tearDown();
76 }
77
init()78 uno::Reference<uno::XInterface> SwXTextFrame::init()
79 {
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;
89 }
90
91 CPPUNIT_TEST_SUITE_REGISTRATION(SwXTextFrame);
92 }
93
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
95