tdf#158198 sw: prevent xBookmark.getAnchor().setString("") from deleting
[LibreOffice.git] / sc / qa / extras / sccellfieldsobj.cxx
blob3eafa094ea39306b95226255168e43b30b3c6164
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/unoapi_test.hxx>
11 #include <test/container/xelementaccess.hxx>
12 #include <test/container/xenumerationaccess.hxx>
13 #include <test/util/xrefreshable.hxx>
15 #include <com/sun/star/container/XIndexAccess.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>
29 #include <cppu/unotype.hxx>
31 using namespace css;
32 using namespace css::uno;
34 namespace sc_apitest
36 class ScCellFieldsObj : public UnoApiTest,
37 public apitest::XElementAccess,
38 public apitest::XEnumerationAccess,
39 public apitest::XRefreshable
41 public:
42 ScCellFieldsObj();
44 virtual uno::Reference<uno::XInterface> init() override;
45 virtual void setUp() override;
47 CPPUNIT_TEST_SUITE(ScCellFieldsObj);
49 // XElementAccess
50 CPPUNIT_TEST(testGetElementType);
51 CPPUNIT_TEST(testHasElements);
53 // XEnumerationAccess
54 CPPUNIT_TEST(testCreateEnumeration);
56 // XRefreshable
57 CPPUNIT_TEST(testRefreshListener);
59 CPPUNIT_TEST_SUITE_END();
62 ScCellFieldsObj::ScCellFieldsObj()
63 : UnoApiTest(u"/sc/qa/extras/testdocuments"_ustr)
64 , XElementAccess(cppu::UnoType<text::XTextField>::get())
68 uno::Reference<uno::XInterface> ScCellFieldsObj::init()
70 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
71 CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is());
73 uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW);
74 uno::Reference<text::XTextContent> xTC(
75 xMSF->createInstance(u"com.sun.star.text.TextField.URL"_ustr), uno::UNO_QUERY_THROW);
77 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW);
78 uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW);
79 uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
81 uno::Reference<table::XCell> xCell(xSheet0->getCellByPosition(2, 3), uno::UNO_SET_THROW);
82 uno::Reference<text::XText> xText(xCell, uno::UNO_QUERY_THROW);
83 xText->insertTextContent(xText->createTextCursor(), xTC, true);
85 uno::Reference<text::XTextFieldsSupplier> xTFS(xCell, uno::UNO_QUERY_THROW);
86 return xTFS->getTextFields();
89 void ScCellFieldsObj::setUp()
91 UnoApiTest::setUp();
92 loadFromURL(u"private:factory/scalc"_ustr);
95 CPPUNIT_TEST_SUITE_REGISTRATION(ScCellFieldsObj);
96 } // namespace sc_apitest
98 CPPUNIT_PLUGIN_IMPLEMENT();
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */