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 2 : void DataPilotField::testSortInfo()
53 : {
54 2 : uno::Reference< beans::XPropertySet> xPropSet(init(),UNO_QUERY_THROW);
55 2 : sheet::DataPilotFieldSortInfo aSortInfoValue;
56 2 : rtl::OUString aSortInfo(RTL_CONSTASCII_USTRINGPARAM("SortInfo"));
57 2 : aSortInfoValue.Field = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Col1"));
58 2 : aSortInfoValue.IsAscending = false;
59 2 : aSortInfoValue.Mode = sheet::DataPilotFieldSortMode::MANUAL;
60 2 : uno::Any xValue;
61 2 : xValue <<= aSortInfoValue;
62 2 : xPropSet->setPropertyValue(aSortInfo, xValue);
63 :
64 2 : sheet::DataPilotFieldSortInfo aNewSortInfoValue;
65 2 : xValue = xPropSet->getPropertyValue(aSortInfo);
66 2 : CPPUNIT_ASSERT( xValue >>= aNewSortInfoValue );
67 4 : CPPUNIT_ASSERT_MESSAGE("set value should be the same as got value", aNewSortInfoValue.Field == aSortInfoValue.Field
68 2 : && 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 2 : rtl::OUString aHasSortInfo(RTL_CONSTASCII_USTRINGPARAM("HasSortInfo"));
73 2 : xValue = xPropSet->getPropertyValue(aHasSortInfo);
74 2 : CPPUNIT_ASSERT( xValue >>= bHasSortInfo );
75 2 : CPPUNIT_ASSERT_MESSAGE("should have sort info", bHasSortInfo);
76 :
77 2 : bHasSortInfo = false;
78 2 : xValue <<= bHasSortInfo;
79 2 : xPropSet->setPropertyValue(aHasSortInfo, xValue);
80 :
81 2 : xValue = xPropSet->getPropertyValue(aHasSortInfo);
82 2 : CPPUNIT_ASSERT( xValue >>= bHasSortInfo );
83 2 : CPPUNIT_ASSERT_MESSAGE("should have no sort info", !bHasSortInfo);
84 2 : }
85 :
86 2 : void DataPilotField::testLayoutInfo()
87 : {
88 2 : uno::Reference< beans::XPropertySet > xPropSet(init(),UNO_QUERY_THROW);
89 2 : sheet::DataPilotFieldLayoutInfo aLayoutInfoValue;
90 2 : rtl::OUString aLayoutInfo(RTL_CONSTASCII_USTRINGPARAM("LayoutInfo"));
91 2 : aLayoutInfoValue.AddEmptyLines = false;
92 2 : aLayoutInfoValue.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM;
93 2 : uno::Any xValue;
94 2 : xValue <<= aLayoutInfoValue;
95 2 : xPropSet->setPropertyValue(aLayoutInfo, xValue);
96 :
97 2 : sheet::DataPilotFieldLayoutInfo aNewLayoutInfoValue;
98 2 : xValue = xPropSet->getPropertyValue(aLayoutInfo);
99 2 : CPPUNIT_ASSERT( xValue >>= aNewLayoutInfoValue );
100 4 : CPPUNIT_ASSERT_MESSAGE("set value should be the same as the got value", aNewLayoutInfoValue.LayoutMode == aLayoutInfoValue.LayoutMode &&
101 2 : 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 2 : rtl::OUString aHasLayoutInfo(RTL_CONSTASCII_USTRINGPARAM("HasLayoutInfo"));
106 2 : xValue = xPropSet->getPropertyValue(aHasLayoutInfo);
107 2 : CPPUNIT_ASSERT( xValue >>= bHasLayoutInfo );
108 2 : CPPUNIT_ASSERT_MESSAGE("should have layout information", bHasLayoutInfo);
109 :
110 2 : bHasLayoutInfo = false;
111 2 : xValue <<= bHasLayoutInfo;
112 2 : xPropSet->setPropertyValue(aHasLayoutInfo, xValue);
113 :
114 2 : xValue = xPropSet->getPropertyValue(aHasLayoutInfo);
115 2 : CPPUNIT_ASSERT( xValue >>= bHasLayoutInfo );
116 2 : CPPUNIT_ASSERT_MESSAGE("should have no longer sort information", !bHasLayoutInfo);
117 2 : }
118 :
119 2 : void DataPilotField::testAutoShowInfo()
120 : {
121 2 : uno::Reference< beans::XPropertySet > xPropSet(init(),UNO_QUERY_THROW);
122 2 : sheet::DataPilotFieldAutoShowInfo aAutoShowInfoValue;
123 2 : aAutoShowInfoValue.DataField = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Col1"));
124 2 : aAutoShowInfoValue.IsEnabled = true;
125 2 : rtl::OUString aAutoShowInfo(RTL_CONSTASCII_USTRINGPARAM("AutoShowInfo"));
126 2 : uno::Any xValue;
127 2 : xValue <<= aAutoShowInfoValue;
128 2 : xPropSet->setPropertyValue(aAutoShowInfo, xValue);
129 :
130 2 : sheet::DataPilotFieldAutoShowInfo aNewAutoShowInfoValue;
131 2 : xValue = xPropSet->getPropertyValue(aAutoShowInfo);
132 2 : CPPUNIT_ASSERT( xValue >>= aNewAutoShowInfoValue );
133 4 : CPPUNIT_ASSERT_MESSAGE("set value should be the same as the got value", aNewAutoShowInfoValue.DataField == aAutoShowInfoValue.DataField &&
134 2 : 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 2 : rtl::OUString aHasAutoShowInfo(RTL_CONSTASCII_USTRINGPARAM("HasAutoShowInfo"));
139 2 : xValue = xPropSet->getPropertyValue(aHasAutoShowInfo);
140 2 : CPPUNIT_ASSERT( xValue >>= bHasAutoShowInfo );
141 2 : CPPUNIT_ASSERT_MESSAGE("should have AutoShow information", bHasAutoShowInfo);
142 :
143 2 : bHasAutoShowInfo = false;
144 2 : xValue <<= bHasAutoShowInfo;
145 2 : xPropSet->setPropertyValue(aHasAutoShowInfo, xValue);
146 :
147 2 : xValue = xPropSet->getPropertyValue(aHasAutoShowInfo);
148 2 : CPPUNIT_ASSERT( xValue >>= bHasAutoShowInfo );
149 2 : CPPUNIT_ASSERT_MESSAGE("should have no longer AutoShow information", !bHasAutoShowInfo);
150 2 : }
151 :
152 2 : void DataPilotField::testReference()
153 : {
154 2 : uno::Reference< beans::XPropertySet > xPropSet(init(),UNO_QUERY_THROW);
155 2 : sheet::DataPilotFieldReference aReferenceValue;
156 2 : aReferenceValue.ReferenceField = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Col1"));
157 2 : aReferenceValue.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::NAMED;
158 2 : rtl::OUString aReference(RTL_CONSTASCII_USTRINGPARAM("Reference"));
159 2 : uno::Any xValue;
160 2 : xValue <<= aReferenceValue;
161 2 : xPropSet->setPropertyValue(aReference, xValue);
162 :
163 2 : sheet::DataPilotFieldReference aNewReferenceValue;
164 2 : xValue = xPropSet->getPropertyValue(aReference);
165 2 : CPPUNIT_ASSERT( xValue >>= aNewReferenceValue );
166 4 : CPPUNIT_ASSERT_MESSAGE("set value should be the same as the got value", aReferenceValue.ReferenceField == aNewReferenceValue.ReferenceField
167 2 : && 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 2 : rtl::OUString aHasReference(RTL_CONSTASCII_USTRINGPARAM("HasReference"));
172 2 : xValue = xPropSet->getPropertyValue(aHasReference);
173 2 : CPPUNIT_ASSERT( xValue >>= bHasReference );
174 2 : CPPUNIT_ASSERT_MESSAGE("should have Reference information", bHasReference);
175 :
176 2 : bHasReference = false;
177 2 : xValue <<= bHasReference;
178 2 : xPropSet->setPropertyValue(aHasReference, xValue);
179 :
180 2 : xValue = xPropSet->getPropertyValue(aHasReference);
181 2 : CPPUNIT_ASSERT( xValue >>= bHasReference );
182 2 : CPPUNIT_ASSERT_MESSAGE("should have no longer reference information", !bHasReference);
183 2 : }
184 :
185 2 : void DataPilotField::testIsGroupField()
186 : {
187 2 : uno::Reference< beans::XPropertySet > xPropSet(init(),UNO_QUERY_THROW);
188 2 : uno::Any xValue;
189 2 : rtl::OUString aIsGroupField(RTL_CONSTASCII_USTRINGPARAM("IsGroupField"));
190 : sal_Bool bIsGroupField;
191 :
192 2 : xValue = xPropSet->getPropertyValue(aIsGroupField);
193 2 : CPPUNIT_ASSERT( xValue >>= bIsGroupField);
194 : //only setting to false is supported
195 2 : 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 2 : std::cout << "Could not test IsGroupField" << std::endl;
207 2 : }
208 :
209 66 : }
210 :
211 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|