Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License or as specified alternatively below. You may obtain a copy of
8 : * the License at http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * Major Contributor(s):
16 : * Copyright (C) 2012 Markus Mohrhard <markus.mohrhard@googlemail.com> (initial developer)
17 : *
18 : * All Rights Reserved.
19 : *
20 : * For minor contributions see the git repository.
21 : *
22 : * Alternatively, the contents of this file may be used under the terms of
23 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : * instead of those above.
27 : */
28 :
29 : #include <test/unoapi_test.hxx>
30 : #include <test/sheet/xdatapilottable.hxx>
31 : #include <test/sheet/xdatapilottable2.hxx>
32 : #include <test/sheet/xdatapilotdescriptor.hxx>
33 : #include <test/container/xnamed.hxx>
34 :
35 : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
36 : #include <com/sun/star/sheet/XSpreadsheet.hpp>
37 : #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
38 : #include <com/sun/star/sheet/XDataPilotTables.hpp>
39 : #include <com/sun/star/sheet/XDataPilotTable.hpp>
40 :
41 : namespace sc_apitest {
42 :
43 : #define NUMBER_OF_TESTS 16
44 :
45 64 : class ScDataPilotTableObj : public UnoApiTest, apitest::XDataPilotDescriptor, apitest::XDataPilotTable,
46 : apitest::XNamed, apitest::XDataPilotTable2
47 : {
48 : public:
49 : ScDataPilotTableObj();
50 :
51 : virtual void setUp();
52 : virtual void tearDown();
53 : virtual uno::Reference< uno::XInterface > init();
54 : virtual uno::Reference< uno::XInterface > initDP2();
55 : virtual uno::Reference< uno::XInterface > getSheets();
56 :
57 4 : CPPUNIT_TEST_SUITE(ScDataPilotTableObj);
58 2 : CPPUNIT_TEST(testRefresh);
59 : //CPPUNIT_TEST(testGetHiddenFields);
60 2 : CPPUNIT_TEST(testGetOutputRange);
61 2 : CPPUNIT_TEST(testSourceRange);
62 2 : CPPUNIT_TEST(testTag);
63 2 : CPPUNIT_TEST(testGetFilterDescriptor);
64 2 : CPPUNIT_TEST(testGetDataPilotFields);
65 2 : CPPUNIT_TEST(testGetColumnFields);
66 2 : CPPUNIT_TEST(testGetRowFields);
67 2 : CPPUNIT_TEST(testGetPageFields);
68 2 : CPPUNIT_TEST(testGetDataFields);
69 2 : CPPUNIT_TEST(testGetName);
70 2 : CPPUNIT_TEST(testSetName);
71 2 : CPPUNIT_TEST(testGetDrillDownData);
72 2 : CPPUNIT_TEST(testInsertDrillDownSheet);
73 2 : CPPUNIT_TEST(testGetPositionData);
74 2 : CPPUNIT_TEST(testGetOutputRangeByType);
75 4 : CPPUNIT_TEST_SUITE_END();
76 :
77 : private:
78 : static sal_Int32 nTest;
79 : static uno::Reference< lang::XComponent > mxComponent;
80 : };
81 :
82 : sal_Int32 ScDataPilotTableObj::nTest = 0;
83 2 : uno::Reference< lang::XComponent > ScDataPilotTableObj::mxComponent;
84 :
85 32 : ScDataPilotTableObj::ScDataPilotTableObj()
86 32 : : apitest::XNamed(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataPilotTable")))
87 : {
88 :
89 32 : }
90 :
91 24 : uno::Reference< uno::XInterface > ScDataPilotTableObj::init()
92 : {
93 24 : rtl::OUString aFileURL;
94 24 : createFileURL(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScDataPilotTableObj.ods")), aFileURL);
95 24 : if(!mxComponent.is())
96 2 : mxComponent = loadFromDesktop(aFileURL);
97 24 : CPPUNIT_ASSERT(mxComponent.is());
98 :
99 24 : uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW);
100 24 : uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), UNO_QUERY_THROW);
101 24 : uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(0), UNO_QUERY_THROW);
102 :
103 : // set variables from xdatapilottable.[ch]xx
104 24 : xCellForChange = xSheet->getCellByPosition( 1, 5 );
105 24 : xCellForCheck = xSheet->getCellByPosition( 7, 11 );
106 24 : CPPUNIT_ASSERT(xCellForCheck.is());
107 24 : CPPUNIT_ASSERT(xCellForChange.is());
108 :
109 24 : CPPUNIT_ASSERT_MESSAGE("Could not create interface of type XSpreadsheet", xSheet.is());
110 24 : uno::Reference< sheet::XDataPilotTablesSupplier > xDPTS(xSheet, UNO_QUERY_THROW);
111 24 : CPPUNIT_ASSERT(xDPTS.is());
112 24 : uno::Reference< sheet::XDataPilotTables > xDPT = xDPTS->getDataPilotTables();
113 24 : CPPUNIT_ASSERT(xDPT.is());
114 :
115 24 : uno::Reference< sheet::XDataPilotTable > xDPTable(xDPT->getByName(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataPilotTable"))),UNO_QUERY_THROW);
116 :
117 24 : CPPUNIT_ASSERT(xDPTable.is());
118 24 : return xDPTable;
119 : }
120 :
121 2 : uno::Reference< uno::XInterface > ScDataPilotTableObj::getSheets()
122 : {
123 2 : uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW);
124 2 : uno::Reference< uno::XInterface > xSheets(xDoc->getSheets());
125 2 : return xSheets;
126 : }
127 :
128 8 : uno::Reference< uno::XInterface > ScDataPilotTableObj::initDP2()
129 : {
130 8 : rtl::OUString aFileURL;
131 8 : createFileURL(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScDataPilotTableObj.ods")), aFileURL);
132 8 : if(!mxComponent.is())
133 0 : mxComponent = loadFromDesktop(aFileURL);
134 8 : CPPUNIT_ASSERT(mxComponent.is());
135 :
136 8 : uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW);
137 8 : uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), UNO_QUERY_THROW);
138 8 : uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(0), UNO_QUERY_THROW);
139 :
140 : // set variables from xdatapilottable.[ch]xx
141 8 : xCellForChange = xSheet->getCellByPosition( 1, 5 );
142 8 : xCellForCheck = xSheet->getCellByPosition( 7, 11 );
143 8 : CPPUNIT_ASSERT(xCellForCheck.is());
144 8 : CPPUNIT_ASSERT(xCellForChange.is());
145 :
146 8 : CPPUNIT_ASSERT_MESSAGE("Could not create interface of type XSpreadsheet", xSheet.is());
147 8 : uno::Reference< sheet::XDataPilotTablesSupplier > xDPTS(xSheet, UNO_QUERY_THROW);
148 8 : CPPUNIT_ASSERT(xDPTS.is());
149 8 : uno::Reference< sheet::XDataPilotTables > xDPT = xDPTS->getDataPilotTables();
150 8 : CPPUNIT_ASSERT(xDPT.is());
151 :
152 8 : uno::Reference< sheet::XDataPilotTable > xDPTable(xDPT->getByName(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataPilotTable2"))),UNO_QUERY_THROW);
153 :
154 8 : CPPUNIT_ASSERT(xDPTable.is());
155 8 : return xDPTable;
156 : }
157 :
158 32 : void ScDataPilotTableObj::setUp()
159 : {
160 32 : nTest++;
161 32 : UnoApiTest::setUp();
162 32 : }
163 :
164 32 : void ScDataPilotTableObj::tearDown()
165 : {
166 32 : if (nTest == NUMBER_OF_TESTS)
167 2 : closeDocument(mxComponent);
168 :
169 32 : UnoApiTest::tearDown();
170 32 : }
171 :
172 2 : CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotTableObj);
173 :
174 2 : CPPUNIT_PLUGIN_IMPLEMENT();
175 :
176 6 : }
177 :
178 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|