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.
4  *
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  */
9 
10 #include <test/calc_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>
17 
18 #include <cppu/unotype.hxx>
19 #include <rtl/ustring.hxx>
20 #include <vcl/svapp.hxx>
21 
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/lang/XComponent.hpp>
24 #include <com/sun/star/sheet/XDDELink.hpp>
25 #include <com/sun/star/sheet/XDDELinks.hpp>
26 #include <com/sun/star/sheet/XSpreadsheet.hpp>
27 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
28 #include <com/sun/star/sheet/XSpreadsheets.hpp>
29 #include <com/sun/star/uno/XInterface.hpp>
30 
31 #include <com/sun/star/uno/Reference.hxx>
32 
33 using namespace css;
34 using namespace css::uno;
35 using namespace com::sun::star;
36 
37 namespace sc_apitest
38 {
39 class ScDDELinksObj : public CalcUnoApiTest,
40                       public apitest::XDDELinks,
41                       public apitest::XElementAccess,
42                       public apitest::XEnumerationAccess,
43                       public apitest::XIndexAccess,
44                       public apitest::XNameAccess,
45                       public apitest::XServiceInfo
46 {
47 public:
48     ScDDELinksObj();
49 
50     virtual uno::Reference<uno::XInterface> init() override;
51     virtual void setUp() override;
52     virtual void tearDown() override;
53 
54     CPPUNIT_TEST_SUITE(ScDDELinksObj);
55 
56     // XDDELinks
57     CPPUNIT_TEST(testAddDDELink);
58 
59     // XElementAccess
60     CPPUNIT_TEST(testGetElementType);
61     CPPUNIT_TEST(testHasElements);
62 
63     // XEnumerationAccess
64     CPPUNIT_TEST(testCreateEnumeration);
65 
66     // XIndexAccess
67     CPPUNIT_TEST(testGetByIndex);
68     CPPUNIT_TEST(testGetCount);
69 
70     // XNameAccess
71     CPPUNIT_TEST(testGetByName);
72     CPPUNIT_TEST(testGetElementNames);
73     CPPUNIT_TEST(testHasByName);
74 
75     // XServiceInfo
76     CPPUNIT_TEST(testGetImplementationName);
77     CPPUNIT_TEST(testGetSupportedServiceNames);
78     CPPUNIT_TEST(testSupportsService);
79 
80     CPPUNIT_TEST_SUITE_END();
81 
82 private:
83     uno::Reference<lang::XComponent> m_xComponent;
84 };
85 
ScDDELinksObj()86 ScDDELinksObj::ScDDELinksObj()
87     : CalcUnoApiTest("/sc/qa/extras/testdocuments")
88     , XDDELinks(m_directories.getURLFromSrc(u"/sc/qa/unoapi/testdocuments/ScDDELinksObj.ods"))
89     , XElementAccess(cppu::UnoType<sheet::XDDELink>::get())
90     , XIndexAccess(1)
91     , XNameAccess("soffice|"
92                   + m_directories.getURLFromSrc(u"/sc/qa/unoapi/testdocuments/ScDDELinksObj.ods")
93                   + "!Sheet1.A1")
94     , XServiceInfo("ScDDELinksObj", "com.sun.star.sheet.DDELinks")
95 {
96 }
97 
init()98 uno::Reference<uno::XInterface> ScDDELinksObj::init()
99 {
100     uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW);
101 
102     uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW);
103     uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW);
104     uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
105 
106     const OUString testdoc
107         = m_directories.getURLFromSrc(u"/sc/qa/unoapi/testdocuments/ScDDELinksObj.ods");
108 
109     xSheet->getCellByPosition(5, 5)->setFormula("=DDE(\"soffice\";\"" + testdoc
110                                                 + "\";\"Sheet1.A1\")");
111     xSheet->getCellByPosition(1, 4)->setFormula("=DDE(\"soffice\";\"" + testdoc
112                                                 + "\";\"Sheet1.A1\")");
113     xSheet->getCellByPosition(2, 0)->setFormula("=DDE(\"soffice\";\"" + testdoc
114                                                 + "\";\"Sheet1.A1\")");
115 
116     uno::Reference<beans::XPropertySet> xPropSet(xDoc, uno::UNO_QUERY_THROW);
117     uno::Any aDDELinks = xPropSet->getPropertyValue("DDELinks");
118     uno::Reference<sheet::XDDELinks> xDDELinks(aDDELinks, uno::UNO_QUERY_THROW);
119 
120     return xDDELinks;
121 }
122 
setUp()123 void ScDDELinksObj::setUp()
124 {
125     Application::SetAppName("soffice"); // Enable DDE
126     CalcUnoApiTest::setUp();
127     // create a calc document
128     m_xComponent = loadFromDesktop("private:factory/scalc");
129 }
130 
tearDown()131 void ScDDELinksObj::tearDown()
132 {
133     closeDocument(m_xComponent);
134     CalcUnoApiTest::tearDown();
135 }
136 
137 CPPUNIT_TEST_SUITE_REGISTRATION(ScDDELinksObj);
138 
139 } // namespace sc_apitest
140 
141 CPPUNIT_PLUGIN_IMPLEMENT();
142 
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
144