1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/calc_unoapi_test.hxx>
11 #include <test/container/xenumeration.hxx>
13 #include <com/sun/star/container/XEnumerationAccess.hpp>
14 #include <com/sun/star/container/XIndexAccess.hpp>
15 #include <com/sun/star/lang/XComponent.hpp>
16 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
17 #include <com/sun/star/sheet/XSpreadsheet.hpp>
18 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
19 #include <com/sun/star/sheet/XSpreadsheets.hpp>
20 #include <com/sun/star/table/XCell.hpp>
21 #include <com/sun/star/text/XText.hpp>
22 #include <com/sun/star/text/XTextContent.hpp>
23 #include <com/sun/star/text/XTextField.hpp>
24 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
25 #include <com/sun/star/uno/XInterface.hpp>
27 #include <com/sun/star/uno/Reference.hxx>
30 using namespace css::uno
;
34 class ScIndexEnumeration_TextFieldEnumeration
: public CalcUnoApiTest
, public apitest::XEnumeration
37 ScIndexEnumeration_TextFieldEnumeration();
39 virtual uno::Reference
<uno::XInterface
> init() override
;
40 virtual void setUp() override
;
41 virtual void tearDown() override
;
43 CPPUNIT_TEST_SUITE(ScIndexEnumeration_TextFieldEnumeration
);
46 CPPUNIT_TEST(testHasMoreElements
);
47 CPPUNIT_TEST(testNextElement
);
49 CPPUNIT_TEST_SUITE_END();
52 uno::Reference
<lang::XComponent
> m_xComponent
;
55 ScIndexEnumeration_TextFieldEnumeration::ScIndexEnumeration_TextFieldEnumeration()
56 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
60 uno::Reference
<uno::XInterface
> ScIndexEnumeration_TextFieldEnumeration::init()
62 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(m_xComponent
, uno::UNO_QUERY_THROW
);
63 CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc
.is());
65 uno::Reference
<lang::XMultiServiceFactory
> xMSF(xDoc
, uno::UNO_QUERY_THROW
);
66 uno::Reference
<text::XTextField
> xTF(xMSF
->createInstance("com.sun.star.text.TextField.URL"),
67 uno::UNO_QUERY_THROW
);
68 uno::Reference
<text::XTextContent
> xTC(xTF
, uno::UNO_QUERY_THROW
);
70 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), uno::UNO_SET_THROW
);
71 uno::Reference
<container::XIndexAccess
> xIA(xSheets
, uno::UNO_QUERY_THROW
);
72 uno::Reference
<sheet::XSpreadsheet
> xSheet0(xIA
->getByIndex(0), uno::UNO_QUERY_THROW
);
74 uno::Reference
<table::XCell
> xCell(xSheet0
->getCellByPosition(2, 3), uno::UNO_SET_THROW
);
75 uno::Reference
<text::XText
> xText(xCell
, uno::UNO_QUERY_THROW
);
76 xText
->insertTextContent(xText
->createTextCursor(), xTC
, true);
77 uno::Reference
<text::XTextFieldsSupplier
> xTFS(xCell
, uno::UNO_QUERY_THROW
);
78 uno::Reference
<container::XEnumerationAccess
> xEA(xTFS
->getTextFields(), uno::UNO_SET_THROW
);
80 return xEA
->createEnumeration();
83 void ScIndexEnumeration_TextFieldEnumeration::setUp()
85 CalcUnoApiTest::setUp();
86 m_xComponent
= loadFromDesktop("private:factory/scalc");
87 CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent
.is());
90 void ScIndexEnumeration_TextFieldEnumeration::tearDown()
92 closeDocument(m_xComponent
);
93 CalcUnoApiTest::tearDown();
96 CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_TextFieldEnumeration
);
98 } // namespace sc_apitest
100 CPPUNIT_PLUGIN_IMPLEMENT();
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */