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) 2011 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/sheet/datapilotfield.hxx>
30 : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
31 : #include <com/sun/star/sheet/XSpreadsheet.hpp>
32 : #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
33 : #include <com/sun/star/sheet/XDataPilotTables.hpp>
34 : #include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
35 : #include <com/sun/star/beans/XPropertySet.hpp>
36 : #include <com/sun/star/sheet/DataPilotFieldSortInfo.hpp>
37 : #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
38 : #include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
39 : #include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp>
40 : #include <com/sun/star/sheet/DataPilotFieldLayoutInfo.hpp>
41 : #include <com/sun/star/sheet/DataPilotFieldReference.hpp>
42 : #include <com/sun/star/sheet/DataPilotFieldAutoShowInfo.hpp>
43 :
44 : #include <rtl/ustring.hxx>
45 : #include "cppunit/extensions/HelperMacros.h"
46 : #include <iostream>
47 :
48 : using namespace com::sun::star::uno;
49 :
50 : namespace apitest {
51 :
52 0 : void DataPilotField::testSortInfo()
53 : {
54 0 : uno::Reference< beans::XPropertySet> xPropSet(init(),UNO_QUERY_THROW);
55 0 : sheet::DataPilotFieldSortInfo aSortInfoValue;
56 0 : rtl::OUString aSortInfo(RTL_CONSTASCII_USTRINGPARAM("SortInfo"));
57 0 : aSortInfoValue.Field = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Col1"));
58 0 : aSortInfoValue.IsAscending = false;
59 0 : aSortInfoValue.Mode = sheet::DataPilotFieldSortMode::MANUAL;
60 0 : uno::Any xValue;
61 0 : xValue <<= aSortInfoValue;
62 0 : xPropSet->setPropertyValue(aSortInfo, xValue);
63 :
64 0 : sheet::DataPilotFieldSortInfo aNewSortInfoValue;
65 0 : xValue = xPropSet->getPropertyValue(aSortInfo);
66 0 : CPPUNIT_ASSERT( xValue >>= aNewSortInfoValue );
67 0 : CPPUNIT_ASSERT_MESSAGE("set value should be the same as got value", aNewSortInfoValue.Field == aSortInfoValue.Field
68 0 : && aNewSortInfoValue.Mode == aSortInfoValue.Mode && aNewSortInfoValue.IsAscending == aSortInfoValue.IsAscending);
69 :
70 : //setting HasSortInfo only makes sense for false, for true the uno implementation does nothing
71 : sal_Bool bHasSortInfo;
72 0 : rtl::OUString aHasSortInfo(RTL_CONSTASCII_USTRINGPARAM("HasSortInfo"));
73 0 : xValue = xPropSet->getPropertyValue(aHasSortInfo);
74 0 : CPPUNIT_ASSERT( xValue >>= bHasSortInfo );
75 0 : CPPUNIT_ASSERT_MESSAGE("should have sort info", bHasSortInfo);
76 :
77 0 : bHasSortInfo = false;
78 0 : xValue <<= bHasSortInfo;
79 0 : xPropSet->setPropertyValue(aHasSortInfo, xValue);
80 :
81 0 : xValue = xPropSet->getPropertyValue(aHasSortInfo);
82 0 : CPPUNIT_ASSERT( xValue >>= bHasSortInfo );
83 0 : CPPUNIT_ASSERT_MESSAGE("should have no sort info", !bHasSortInfo);
84 0 : }
85 :
86 0 : void DataPilotField::testLayoutInfo()
87 : {
88 0 : uno::Reference< beans::XPropertySet > xPropSet(init(),UNO_QUERY_THROW);
89 0 : sheet::DataPilotFieldLayoutInfo aLayoutInfoValue;
90 0 : rtl::OUString aLayoutInfo(RTL_CONSTASCII_USTRINGPARAM("LayoutInfo"));
91 0 : aLayoutInfoValue.AddEmptyLines = false;
92 0 : aLayoutInfoValue.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM;
93 0 : uno::Any xValue;
94 0 : xValue <<= aLayoutInfoValue;
95 0 : xPropSet->setPropertyValue(aLayoutInfo, xValue);
96 :
97 0 : sheet::DataPilotFieldLayoutInfo aNewLayoutInfoValue;
98 0 : xValue = xPropSet->getPropertyValue(aLayoutInfo);
99 0 : CPPUNIT_ASSERT( xValue >>= aNewLayoutInfoValue );
100 0 : CPPUNIT_ASSERT_MESSAGE("set value should be the same as the got value", aNewLayoutInfoValue.LayoutMode == aLayoutInfoValue.LayoutMode &&
101 0 : aNewLayoutInfoValue.AddEmptyLines == aLayoutInfoValue.AddEmptyLines);
102 :
103 : //setting HasLayoutInfo only makes sense for false, tor true the uno implementation does nothing
104 : sal_Bool bHasLayoutInfo;
105 0 : rtl::OUString aHasLayoutInfo(RTL_CONSTASCII_USTRINGPARAM("HasLayoutInfo"));
106 0 : xValue = xPropSet->getPropertyValue(aHasLayoutInfo);
107 0 : CPPUNIT_ASSERT( xValue >>= bHasLayoutInfo );
108 0 : CPPUNIT_ASSERT_MESSAGE("should have layout information", bHasLayoutInfo);
109 :
110 0 : bHasLayoutInfo = false;
111 0 : xValue <<= bHasLayoutInfo;
112 0 : xPropSet->setPropertyValue(aHasLayoutInfo, xValue);
113 :
114 0 : xValue = xPropSet->getPropertyValue(aHasLayoutInfo);
115 0 : CPPUNIT_ASSERT( xValue >>= bHasLayoutInfo );
116 0 : CPPUNIT_ASSERT_MESSAGE("should have no longer sort information", !bHasLayoutInfo);
117 0 : }
118 :
119 0 : void DataPilotField::testAutoShowInfo()
120 : {
121 0 : uno::Reference< beans::XPropertySet > xPropSet(init(),UNO_QUERY_THROW);
122 0 : sheet::DataPilotFieldAutoShowInfo aAutoShowInfoValue;
123 0 : aAutoShowInfoValue.DataField = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Col1"));
124 0 : aAutoShowInfoValue.IsEnabled = true;
125 0 : rtl::OUString aAutoShowInfo(RTL_CONSTASCII_USTRINGPARAM("AutoShowInfo"));
126 0 : uno::Any xValue;
127 0 : xValue <<= aAutoShowInfoValue;
128 0 : xPropSet->setPropertyValue(aAutoShowInfo, xValue);
129 :
130 0 : sheet::DataPilotFieldAutoShowInfo aNewAutoShowInfoValue;
131 0 : xValue = xPropSet->getPropertyValue(aAutoShowInfo);
132 0 : CPPUNIT_ASSERT( xValue >>= aNewAutoShowInfoValue );
133 0 : CPPUNIT_ASSERT_MESSAGE("set value should be the same as the got value", aNewAutoShowInfoValue.DataField == aAutoShowInfoValue.DataField &&
134 0 : aNewAutoShowInfoValue.IsEnabled == aAutoShowInfoValue.IsEnabled);
135 :
136 : //setting HasLayoutInfo only makes sense for false, tor true the uno implementation does nothing
137 : sal_Bool bHasAutoShowInfo;
138 0 : rtl::OUString aHasAutoShowInfo(RTL_CONSTASCII_USTRINGPARAM("HasAutoShowInfo"));
139 0 : xValue = xPropSet->getPropertyValue(aHasAutoShowInfo);
140 0 : CPPUNIT_ASSERT( xValue >>= bHasAutoShowInfo );
141 0 : CPPUNIT_ASSERT_MESSAGE("should have AutoShow information", bHasAutoShowInfo);
142 :
143 0 : bHasAutoShowInfo = false;
144 0 : xValue <<= bHasAutoShowInfo;
145 0 : xPropSet->setPropertyValue(aHasAutoShowInfo, xValue);
146 :
147 0 : xValue = xPropSet->getPropertyValue(aHasAutoShowInfo);
148 0 : CPPUNIT_ASSERT( xValue >>= bHasAutoShowInfo );
149 0 : CPPUNIT_ASSERT_MESSAGE("should have no longer AutoShow information", !bHasAutoShowInfo);
150 0 : }
151 :
152 0 : void DataPilotField::testReference()
153 : {
154 0 : uno::Reference< beans::XPropertySet > xPropSet(init(),UNO_QUERY_THROW);
155 0 : sheet::DataPilotFieldReference aReferenceValue;
156 0 : aReferenceValue.ReferenceField = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Col1"));
157 0 : aReferenceValue.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::NAMED;
158 0 : rtl::OUString aReference(RTL_CONSTASCII_USTRINGPARAM("Reference"));
159 0 : uno::Any xValue;
160 0 : xValue <<= aReferenceValue;
161 0 : xPropSet->setPropertyValue(aReference, xValue);
162 :
163 0 : sheet::DataPilotFieldReference aNewReferenceValue;
164 0 : xValue = xPropSet->getPropertyValue(aReference);
165 0 : CPPUNIT_ASSERT( xValue >>= aNewReferenceValue );
166 0 : CPPUNIT_ASSERT_MESSAGE("set value should be the same as the got value", aReferenceValue.ReferenceField == aNewReferenceValue.ReferenceField
167 0 : && aReferenceValue.ReferenceItemType == aNewReferenceValue.ReferenceItemType);
168 :
169 : //setting HasReference only makes sense for false, tor true the uno implementation does nothing
170 : sal_Bool bHasReference;
171 0 : rtl::OUString aHasReference(RTL_CONSTASCII_USTRINGPARAM("HasReference"));
172 0 : xValue = xPropSet->getPropertyValue(aHasReference);
173 0 : CPPUNIT_ASSERT( xValue >>= bHasReference );
174 0 : CPPUNIT_ASSERT_MESSAGE("should have Reference information", bHasReference);
175 :
176 0 : bHasReference = false;
177 0 : xValue <<= bHasReference;
178 0 : xPropSet->setPropertyValue(aHasReference, xValue);
179 :
180 0 : xValue = xPropSet->getPropertyValue(aHasReference);
181 0 : CPPUNIT_ASSERT( xValue >>= bHasReference );
182 0 : CPPUNIT_ASSERT_MESSAGE("should have no longer reference information", !bHasReference);
183 0 : }
184 :
185 0 : void DataPilotField::testIsGroupField()
186 : {
187 0 : uno::Reference< beans::XPropertySet > xPropSet(init(),UNO_QUERY_THROW);
188 0 : uno::Any xValue;
189 0 : rtl::OUString aIsGroupField(RTL_CONSTASCII_USTRINGPARAM("IsGroupField"));
190 : sal_Bool bIsGroupField;
191 :
192 0 : xValue = xPropSet->getPropertyValue(aIsGroupField);
193 0 : CPPUNIT_ASSERT( xValue >>= bIsGroupField);
194 : //only setting to false is supported
195 0 : if (bIsGroupField)
196 : {
197 0 : bIsGroupField = false;
198 0 : xValue <<= bIsGroupField;
199 :
200 0 : xPropSet->setPropertyValue(aIsGroupField, xValue);
201 0 : xValue = xPropSet->getPropertyValue(aIsGroupField);
202 0 : CPPUNIT_ASSERT(xValue >>= bIsGroupField);
203 0 : CPPUNIT_ASSERT_MESSAGE("setting IsGroupField is supported and should have happened", !bIsGroupField);
204 : }
205 : else
206 0 : std::cout << "Could not test IsGroupField" << std::endl;
207 0 : }
208 :
209 0 : }
210 :
211 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|