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/lang/XComponent.hpp>
22 #include <com/sun/star/sheet/XDDELink.hpp>
23 #include <com/sun/star/sheet/XSpreadsheet.hpp>
24 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
25 #include <com/sun/star/sheet/XSpreadsheets.hpp>
26 #include <com/sun/star/uno/XInterface.hpp>
28 #include <com/sun/star/uno/Reference.hxx>
31 using namespace css::uno
;
32 using namespace com::sun::star
;
36 class ScDDELinkObj
: public UnoApiTest
,
37 public apitest::XDDELink
,
38 public apitest::XNamed
,
39 public apitest::XRefreshable
44 virtual uno::Reference
<uno::XInterface
> init() override
;
45 virtual void setUp() override
;
47 CPPUNIT_TEST_SUITE(ScDDELinkObj
);
50 CPPUNIT_TEST(testGetApplication
);
51 CPPUNIT_TEST(testGetItem
);
52 CPPUNIT_TEST(testGetTopic
);
55 CPPUNIT_TEST(testGetName
);
56 CPPUNIT_TEST(testSetNameThrowsException
);
59 CPPUNIT_TEST(testRefreshListener
);
61 CPPUNIT_TEST_SUITE_END();
64 ScDDELinkObj::ScDDELinkObj()
65 : UnoApiTest("/sc/qa/extras/testdocuments")
66 , XDDELink(maTempFile
.GetURL())
67 , XNamed("soffice|" + maTempFile
.GetURL() + "!Sheet1.A1")
71 uno::Reference
<uno::XInterface
> ScDDELinkObj::init()
73 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, UNO_QUERY_THROW
);
75 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), UNO_SET_THROW
);
76 uno::Reference
<container::XIndexAccess
> xIA(xSheets
, UNO_QUERY_THROW
);
77 uno::Reference
<sheet::XSpreadsheet
> xSheet(xIA
->getByIndex(0), UNO_QUERY_THROW
);
79 const OUString testdoc
= maTempFile
.GetURL();
81 xSheet
->getCellByPosition(5, 5)->setFormula("=DDE(\"soffice\";\"" + testdoc
82 + "\";\"Sheet1.A1\")");
83 xSheet
->getCellByPosition(1, 4)->setFormula("=DDE(\"soffice\";\"" + testdoc
84 + "\";\"Sheet1.A1\")");
86 uno::Reference
<beans::XPropertySet
> xPropSet(xDoc
, UNO_QUERY_THROW
);
87 uno::Any aDDELinks
= xPropSet
->getPropertyValue("DDELinks");
88 uno::Reference
<container::XNameAccess
> xNA(aDDELinks
, UNO_QUERY_THROW
);
89 uno::Sequence
<OUString
> sLinkNames
= xNA
->getElementNames();
90 uno::Reference
<sheet::XDDELink
> xDDELink(xNA
->getByName(sLinkNames
[0]), UNO_QUERY_THROW
);
94 void ScDDELinkObj::setUp()
96 Application::SetAppName("soffice"); // Enable DDE
98 // create a calc document
99 mxComponent
= loadFromDesktop("private:factory/scalc");
101 createTempCopy(u
"ScDDELinksObj.ods");
104 CPPUNIT_TEST_SUITE_REGISTRATION(ScDDELinkObj
);
106 } // namespace sc_apitest
108 CPPUNIT_PLUGIN_IMPLEMENT();
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */