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