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/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 static utl::TempFile
createTempCopy(OUString
const& url
)
39 tmp
.EnableKillingFile();
40 auto const e
= osl::File::copy(url
, tmp
.GetURL());
41 CPPUNIT_ASSERT_EQUAL_MESSAGE(
42 (OUStringToOString("<" + url
+ "> -> <" + tmp
.GetURL() + ">", RTL_TEXTENCODING_UTF8
)
44 osl::FileBase::E_None
, e
);
52 utl::TempFile m_TempFile
;
53 explicit TempFileBase(OUString
const& url
)
54 : m_TempFile(createTempCopy(url
))
60 class ScDDELinkObj
: public CalcUnoApiTest
,
62 public apitest::XDDELink
,
63 public apitest::XNamed
,
64 public apitest::XRefreshable
69 virtual uno::Reference
<uno::XInterface
> init() override
;
70 virtual void setUp() override
;
71 virtual void tearDown() override
;
73 CPPUNIT_TEST_SUITE(ScDDELinkObj
);
76 CPPUNIT_TEST(testGetApplication
);
77 CPPUNIT_TEST(testGetItem
);
78 CPPUNIT_TEST(testGetTopic
);
81 CPPUNIT_TEST(testGetName
);
82 CPPUNIT_TEST(testSetNameThrowsException
);
85 CPPUNIT_TEST(testRefreshListener
);
87 CPPUNIT_TEST_SUITE_END();
90 uno::Reference
<lang::XComponent
> mxComponent
;
93 ScDDELinkObj::ScDDELinkObj()
94 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
95 , TempFileBase(m_directories
.getURLFromSrc("/sc/qa/unoapi/testdocuments/ScDDELinksObj.ods"))
96 , XDDELink(m_TempFile
.GetURL())
97 , XNamed("soffice|" + m_TempFile
.GetURL() + "!Sheet1.A1")
101 uno::Reference
<uno::XInterface
> ScDDELinkObj::init()
103 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, UNO_QUERY_THROW
);
105 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), UNO_SET_THROW
);
106 uno::Reference
<container::XIndexAccess
> xIA(xSheets
, UNO_QUERY_THROW
);
107 uno::Reference
<sheet::XSpreadsheet
> xSheet(xIA
->getByIndex(0), UNO_QUERY_THROW
);
109 const OUString testdoc
= m_TempFile
.GetURL();
111 xSheet
->getCellByPosition(5, 5)->setFormula("=DDE(\"soffice\";\"" + testdoc
112 + "\";\"Sheet1.A1\")");
113 xSheet
->getCellByPosition(1, 4)->setFormula("=DDE(\"soffice\";\"" + testdoc
114 + "\";\"Sheet1.A1\")");
116 uno::Reference
<beans::XPropertySet
> xPropSet(xDoc
, UNO_QUERY_THROW
);
117 uno::Any aDDELinks
= xPropSet
->getPropertyValue("DDELinks");
118 uno::Reference
<container::XNameAccess
> xNA(aDDELinks
, UNO_QUERY_THROW
);
119 uno::Sequence
<OUString
> sLinkNames
= xNA
->getElementNames();
120 uno::Reference
<sheet::XDDELink
> xDDELink(xNA
->getByName(sLinkNames
[0]), UNO_QUERY_THROW
);
124 void ScDDELinkObj::setUp()
126 Application::SetAppName("soffice"); // Enable DDE
127 CalcUnoApiTest::setUp();
128 // create a calc document
129 mxComponent
= loadFromDesktop("private:factory/scalc");
132 void ScDDELinkObj::tearDown()
134 closeDocument(mxComponent
);
135 CalcUnoApiTest::tearDown();
138 CPPUNIT_TEST_SUITE_REGISTRATION(ScDDELinkObj
);
140 } // namespace sc_apitest
142 CPPUNIT_PLUGIN_IMPLEMENT();
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */