split CreateVirtualDevice into two methods
[LibreOffice.git] / sc / qa / extras / scddelinksobj.cxx
blobb57ecc2dacf58099c1a2cde3ba8cad4d271b1e76
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/container/xindexaccess.hxx>
14 #include <test/container/xnameaccess.hxx>
15 #include <test/lang/xserviceinfo.hxx>
16 #include <test/sheet/xddelinks.hxx>
18 #include <cppu/unotype.hxx>
19 #include <rtl/ustring.hxx>
20 #include <vcl/svapp.hxx>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/sheet/XDDELink.hpp>
24 #include <com/sun/star/sheet/XDDELinks.hpp>
25 #include <com/sun/star/sheet/XSpreadsheet.hpp>
26 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
27 #include <com/sun/star/sheet/XSpreadsheets.hpp>
28 #include <com/sun/star/uno/XInterface.hpp>
30 #include <com/sun/star/uno/Reference.hxx>
32 using namespace css;
33 using namespace css::uno;
34 using namespace com::sun::star;
36 namespace sc_apitest
38 class ScDDELinksObj : public UnoApiTest,
39 public apitest::XDDELinks,
40 public apitest::XElementAccess,
41 public apitest::XEnumerationAccess,
42 public apitest::XIndexAccess,
43 public apitest::XNameAccess,
44 public apitest::XServiceInfo
46 public:
47 ScDDELinksObj();
49 virtual uno::Reference<uno::XInterface> init() override;
50 virtual void setUp() override;
52 CPPUNIT_TEST_SUITE(ScDDELinksObj);
54 // XDDELinks
55 CPPUNIT_TEST(testAddDDELink);
57 // XElementAccess
58 CPPUNIT_TEST(testGetElementType);
59 CPPUNIT_TEST(testHasElements);
61 // XEnumerationAccess
62 CPPUNIT_TEST(testCreateEnumeration);
64 // XIndexAccess
65 CPPUNIT_TEST(testGetByIndex);
66 CPPUNIT_TEST(testGetCount);
68 // XNameAccess
69 CPPUNIT_TEST(testGetByName);
70 CPPUNIT_TEST(testGetElementNames);
71 CPPUNIT_TEST(testHasByName);
73 // XServiceInfo
74 CPPUNIT_TEST(testGetImplementationName);
75 CPPUNIT_TEST(testGetSupportedServiceNames);
76 CPPUNIT_TEST(testSupportsService);
78 CPPUNIT_TEST_SUITE_END();
81 ScDDELinksObj::ScDDELinksObj()
82 : UnoApiTest(u"/sc/qa/extras/testdocuments"_ustr)
83 , XDDELinks(createFileURL(u"ScDDELinksObj.ods"))
84 , XElementAccess(cppu::UnoType<sheet::XDDELink>::get())
85 , XIndexAccess(1)
86 , XNameAccess("soffice|" + createFileURL(u"ScDDELinksObj.ods") + "!Sheet1.A1")
87 , XServiceInfo(u"ScDDELinksObj"_ustr, u"com.sun.star.sheet.DDELinks"_ustr)
91 uno::Reference<uno::XInterface> ScDDELinksObj::init()
93 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
95 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW);
96 uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW);
97 uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
99 const OUString testdoc = createFileURL(u"ScDDELinksObj.ods");
101 xSheet->getCellByPosition(5, 5)->setFormula("=DDE(\"soffice\";\"" + testdoc
102 + "\";\"Sheet1.A1\")");
103 xSheet->getCellByPosition(1, 4)->setFormula("=DDE(\"soffice\";\"" + testdoc
104 + "\";\"Sheet1.A1\")");
105 xSheet->getCellByPosition(2, 0)->setFormula("=DDE(\"soffice\";\"" + testdoc
106 + "\";\"Sheet1.A1\")");
108 uno::Reference<beans::XPropertySet> xPropSet(xDoc, uno::UNO_QUERY_THROW);
109 uno::Any aDDELinks = xPropSet->getPropertyValue(u"DDELinks"_ustr);
110 uno::Reference<sheet::XDDELinks> xDDELinks(aDDELinks, uno::UNO_QUERY_THROW);
112 return xDDELinks;
115 void ScDDELinksObj::setUp()
117 Application::SetAppName(u"soffice"_ustr); // Enable DDE
118 UnoApiTest::setUp();
119 // create a calc document
120 loadFromURL(u"private:factory/scalc"_ustr);
123 CPPUNIT_TEST_SUITE_REGISTRATION(ScDDELinksObj);
125 } // namespace sc_apitest
127 CPPUNIT_PLUGIN_IMPLEMENT();
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */