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