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/unoapi_test.hxx>
11 #include <test/container/xnamed.hxx>
12 #include <test/sheet/sheetlink.hxx>
13 #include <test/util/xrefreshable.hxx>
15 #include <com/sun/star/beans/XPropertySet.hpp>
16 #include <com/sun/star/container/XIndexAccess.hpp>
17 #include <com/sun/star/container/XNameAccess.hpp>
18 #include <com/sun/star/sheet/SheetLinkMode.hpp>
19 #include <com/sun/star/sheet/XSheetLinkable.hpp>
20 #include <com/sun/star/sheet/XSpreadsheet.hpp>
21 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
22 #include <com/sun/star/sheet/XSpreadsheets.hpp>
23 #include <com/sun/star/uno/XInterface.hpp>
25 #include <com/sun/star/uno/Reference.hxx>
31 class ScSheetLinkObj
: public UnoApiTest
,
32 public apitest::SheetLink
,
33 public apitest::XNamed
,
34 public apitest::XRefreshable
39 virtual uno::Reference
<uno::XInterface
> init() override
;
41 virtual void setUp() override
;
43 CPPUNIT_TEST_SUITE(ScSheetLinkObj
);
46 CPPUNIT_TEST(testSheetLinkProperties
);
49 CPPUNIT_TEST(testGetName
);
50 CPPUNIT_TEST(testSetNameByScSheetLinkObj
);
53 CPPUNIT_TEST(testRefreshListener
);
55 CPPUNIT_TEST_SUITE_END();
58 ScSheetLinkObj::ScSheetLinkObj()
59 : UnoApiTest(u
"/sc/qa/extras/testdocuments"_ustr
)
60 , XNamed(m_directories
.getURLFromSrc(u
"/sc/qa/extras/testdocuments/ScSheetLinkObj.ods"))
64 uno::Reference
<uno::XInterface
> ScSheetLinkObj::init()
66 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, uno::UNO_QUERY_THROW
);
68 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), uno::UNO_SET_THROW
);
69 uno::Reference
<container::XIndexAccess
> xIA(xSheets
, uno::UNO_QUERY_THROW
);
70 uno::Reference
<sheet::XSpreadsheet
> xSheet(xIA
->getByIndex(0), uno::UNO_QUERY_THROW
);
72 uno::Reference
<sheet::XSheetLinkable
> xSL(xSheet
, uno::UNO_QUERY_THROW
);
73 xSL
->link(m_directories
.getURLFromSrc(u
"/sc/qa/extras/testdocuments/ScSheetLinkObj.ods"),
74 u
"Sheet1"_ustr
, u
""_ustr
, u
""_ustr
, sheet::SheetLinkMode_VALUE
);
76 uno::Reference
<beans::XPropertySet
> xPropSet(xDoc
, uno::UNO_QUERY_THROW
);
77 uno::Reference
<container::XNameAccess
> sheetLinks
;
78 CPPUNIT_ASSERT(xPropSet
->getPropertyValue(u
"SheetLinks"_ustr
) >>= sheetLinks
);
79 CPPUNIT_ASSERT(sheetLinks
.is());
81 uno::Any aAny
= sheetLinks
->getByName(sheetLinks
->getElementNames()[0]);
82 uno::Reference
<beans::XPropertySet
> sheetLink
;
87 void ScSheetLinkObj::setUp()
90 // create a calc document
91 loadFromURL(u
"private:factory/scalc"_ustr
);
94 CPPUNIT_TEST_SUITE_REGISTRATION(ScSheetLinkObj
);
96 } // namespace sc_apitest
98 CPPUNIT_PLUGIN_IMPLEMENT();
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */