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/xddelink.hxx>
13 #include <test/util/xrefreshable.hxx>
15 #include <unotools/tempfile.hxx>
16 #include <vcl/svapp.hxx>
18 #include <com/sun/star/beans/XPropertySet.hpp>
19 #include <com/sun/star/container/XIndexAccess.hpp>
20 #include <com/sun/star/container/XNameAccess.hpp>
21 #include <com/sun/star/sheet/XDDELink.hpp>
22 #include <com/sun/star/sheet/XSpreadsheet.hpp>
23 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
24 #include <com/sun/star/sheet/XSpreadsheets.hpp>
25 #include <com/sun/star/uno/XInterface.hpp>
27 #include <com/sun/star/uno/Reference.hxx>
30 using namespace css::uno
;
31 using namespace com::sun::star
;
35 class ScDDELinkObj
: public UnoApiTest
,
36 public apitest::XDDELink
,
37 public apitest::XNamed
,
38 public apitest::XRefreshable
43 virtual uno::Reference
<uno::XInterface
> init() override
;
44 virtual void setUp() override
;
46 CPPUNIT_TEST_SUITE(ScDDELinkObj
);
49 CPPUNIT_TEST(testGetApplication
);
50 CPPUNIT_TEST(testGetItem
);
51 CPPUNIT_TEST(testGetTopic
);
54 CPPUNIT_TEST(testGetName
);
55 CPPUNIT_TEST(testSetNameThrowsException
);
58 CPPUNIT_TEST(testRefreshListener
);
60 CPPUNIT_TEST_SUITE_END();
63 ScDDELinkObj::ScDDELinkObj()
64 : UnoApiTest(u
"/sc/qa/extras/testdocuments"_ustr
)
65 , XDDELink(maTempFile
.GetURL())
66 , XNamed("soffice|" + maTempFile
.GetURL() + "!Sheet1.A1")
70 uno::Reference
<uno::XInterface
> ScDDELinkObj::init()
72 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, UNO_QUERY_THROW
);
74 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), UNO_SET_THROW
);
75 uno::Reference
<container::XIndexAccess
> xIA(xSheets
, UNO_QUERY_THROW
);
76 uno::Reference
<sheet::XSpreadsheet
> xSheet(xIA
->getByIndex(0), UNO_QUERY_THROW
);
78 const OUString testdoc
= maTempFile
.GetURL();
80 xSheet
->getCellByPosition(5, 5)->setFormula("=DDE(\"soffice\";\"" + testdoc
81 + "\";\"Sheet1.A1\")");
82 xSheet
->getCellByPosition(1, 4)->setFormula("=DDE(\"soffice\";\"" + testdoc
83 + "\";\"Sheet1.A1\")");
85 uno::Reference
<beans::XPropertySet
> xPropSet(xDoc
, UNO_QUERY_THROW
);
86 uno::Any aDDELinks
= xPropSet
->getPropertyValue(u
"DDELinks"_ustr
);
87 uno::Reference
<container::XNameAccess
> xNA(aDDELinks
, UNO_QUERY_THROW
);
88 uno::Sequence
<OUString
> sLinkNames
= xNA
->getElementNames();
89 uno::Reference
<sheet::XDDELink
> xDDELink(xNA
->getByName(sLinkNames
[0]), UNO_QUERY_THROW
);
93 void ScDDELinkObj::setUp()
95 Application::SetAppName(u
"soffice"_ustr
); // Enable DDE
97 // create a calc document
98 loadFromURL(u
"private:factory/scalc"_ustr
);
100 createTempCopy(u
"ScDDELinksObj.ods");
103 CPPUNIT_TEST_SUITE_REGISTRATION(ScDDELinkObj
);
105 } // namespace sc_apitest
107 CPPUNIT_PLUGIN_IMPLEMENT();
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */