1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
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>
25 #include <rtl/ustring.hxx>
26 #include "cppunit/extensions/HelperMacros.h"
30 using namespace css::uno
;
34 void DataPilotField::testSortInfo()
36 uno::Reference
< beans::XPropertySet
> xPropSet(init(),UNO_QUERY_THROW
);
37 sheet::DataPilotFieldSortInfo aSortInfoValue
;
38 OUString
aSortInfo("SortInfo");
39 aSortInfoValue
.Field
= "Col1";
40 aSortInfoValue
.IsAscending
= false;
41 aSortInfoValue
.Mode
= sheet::DataPilotFieldSortMode::MANUAL
;
43 xValue
<<= aSortInfoValue
;
44 xPropSet
->setPropertyValue(aSortInfo
, xValue
);
46 sheet::DataPilotFieldSortInfo aNewSortInfoValue
;
47 xValue
= xPropSet
->getPropertyValue(aSortInfo
);
48 CPPUNIT_ASSERT( xValue
>>= aNewSortInfoValue
);
49 CPPUNIT_ASSERT_MESSAGE("set value should be the same as got value", aNewSortInfoValue
.Field
== aSortInfoValue
.Field
50 && aNewSortInfoValue
.Mode
== aSortInfoValue
.Mode
&& aNewSortInfoValue
.IsAscending
== aSortInfoValue
.IsAscending
);
52 //setting HasSortInfo only makes sense for false, for true the uno implementation does nothing
53 bool bHasSortInfo(false);
54 OUString
aHasSortInfo("HasSortInfo");
55 xValue
= xPropSet
->getPropertyValue(aHasSortInfo
);
56 CPPUNIT_ASSERT( xValue
>>= bHasSortInfo
);
57 CPPUNIT_ASSERT_MESSAGE("should have sort info", bHasSortInfo
);
60 xValue
<<= bHasSortInfo
;
61 xPropSet
->setPropertyValue(aHasSortInfo
, xValue
);
63 xValue
= xPropSet
->getPropertyValue(aHasSortInfo
);
64 CPPUNIT_ASSERT( xValue
>>= bHasSortInfo
);
65 CPPUNIT_ASSERT_MESSAGE("should have no sort info", !bHasSortInfo
);
68 void DataPilotField::testLayoutInfo()
70 uno::Reference
< beans::XPropertySet
> xPropSet(init(),UNO_QUERY_THROW
);
71 sheet::DataPilotFieldLayoutInfo aLayoutInfoValue
;
72 OUString
aLayoutInfo("LayoutInfo");
73 aLayoutInfoValue
.AddEmptyLines
= false;
74 aLayoutInfoValue
.LayoutMode
= sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM
;
76 xValue
<<= aLayoutInfoValue
;
77 xPropSet
->setPropertyValue(aLayoutInfo
, xValue
);
79 sheet::DataPilotFieldLayoutInfo aNewLayoutInfoValue
;
80 xValue
= xPropSet
->getPropertyValue(aLayoutInfo
);
81 CPPUNIT_ASSERT( xValue
>>= aNewLayoutInfoValue
);
82 CPPUNIT_ASSERT_MESSAGE("set value should be the same as the got value", aNewLayoutInfoValue
.LayoutMode
== aLayoutInfoValue
.LayoutMode
&&
83 aNewLayoutInfoValue
.AddEmptyLines
== aLayoutInfoValue
.AddEmptyLines
);
85 //setting HasLayoutInfo only makes sense for false, tor true the uno implementation does nothing
86 bool bHasLayoutInfo(false);
87 OUString
aHasLayoutInfo("HasLayoutInfo");
88 xValue
= xPropSet
->getPropertyValue(aHasLayoutInfo
);
89 CPPUNIT_ASSERT( xValue
>>= bHasLayoutInfo
);
90 CPPUNIT_ASSERT_MESSAGE("should have layout information", bHasLayoutInfo
);
92 bHasLayoutInfo
= false;
93 xValue
<<= bHasLayoutInfo
;
94 xPropSet
->setPropertyValue(aHasLayoutInfo
, xValue
);
96 xValue
= xPropSet
->getPropertyValue(aHasLayoutInfo
);
97 CPPUNIT_ASSERT( xValue
>>= bHasLayoutInfo
);
98 CPPUNIT_ASSERT_MESSAGE("should have no longer sort information", !bHasLayoutInfo
);
101 void DataPilotField::testAutoShowInfo()
103 uno::Reference
< beans::XPropertySet
> xPropSet(init(),UNO_QUERY_THROW
);
104 sheet::DataPilotFieldAutoShowInfo aAutoShowInfoValue
;
105 aAutoShowInfoValue
.DataField
= "Col1";
106 aAutoShowInfoValue
.IsEnabled
= true;
107 OUString
aAutoShowInfo("AutoShowInfo");
109 xValue
<<= aAutoShowInfoValue
;
110 xPropSet
->setPropertyValue(aAutoShowInfo
, xValue
);
112 sheet::DataPilotFieldAutoShowInfo aNewAutoShowInfoValue
;
113 xValue
= xPropSet
->getPropertyValue(aAutoShowInfo
);
114 CPPUNIT_ASSERT( xValue
>>= aNewAutoShowInfoValue
);
115 CPPUNIT_ASSERT_MESSAGE("set value should be the same as the got value", aNewAutoShowInfoValue
.DataField
== aAutoShowInfoValue
.DataField
&&
116 aNewAutoShowInfoValue
.IsEnabled
== aAutoShowInfoValue
.IsEnabled
);
118 //setting HasLayoutInfo only makes sense for false, tor true the uno implementation does nothing
119 bool bHasAutoShowInfo(false);
120 OUString
aHasAutoShowInfo("HasAutoShowInfo");
121 xValue
= xPropSet
->getPropertyValue(aHasAutoShowInfo
);
122 CPPUNIT_ASSERT( xValue
>>= bHasAutoShowInfo
);
123 CPPUNIT_ASSERT_MESSAGE("should have AutoShow information", bHasAutoShowInfo
);
125 bHasAutoShowInfo
= false;
126 xValue
<<= bHasAutoShowInfo
;
127 xPropSet
->setPropertyValue(aHasAutoShowInfo
, xValue
);
129 xValue
= xPropSet
->getPropertyValue(aHasAutoShowInfo
);
130 CPPUNIT_ASSERT( xValue
>>= bHasAutoShowInfo
);
131 CPPUNIT_ASSERT_MESSAGE("should have no longer AutoShow information", !bHasAutoShowInfo
);
134 void DataPilotField::testReference()
136 uno::Reference
< beans::XPropertySet
> xPropSet(init(),UNO_QUERY_THROW
);
137 sheet::DataPilotFieldReference aReferenceValue
;
138 aReferenceValue
.ReferenceField
= "Col1";
139 aReferenceValue
.ReferenceItemType
= sheet::DataPilotFieldReferenceItemType::NAMED
;
140 OUString
aReference("Reference");
142 xValue
<<= aReferenceValue
;
143 xPropSet
->setPropertyValue(aReference
, xValue
);
145 sheet::DataPilotFieldReference aNewReferenceValue
;
146 xValue
= xPropSet
->getPropertyValue(aReference
);
147 CPPUNIT_ASSERT( xValue
>>= aNewReferenceValue
);
148 CPPUNIT_ASSERT_MESSAGE("set value should be the same as the got value", aReferenceValue
.ReferenceField
== aNewReferenceValue
.ReferenceField
149 && aReferenceValue
.ReferenceItemType
== aNewReferenceValue
.ReferenceItemType
);
151 //setting HasReference only makes sense for false, tor true the uno implementation does nothing
152 bool bHasReference(false);
153 OUString
aHasReference("HasReference");
154 xValue
= xPropSet
->getPropertyValue(aHasReference
);
155 CPPUNIT_ASSERT( xValue
>>= bHasReference
);
156 CPPUNIT_ASSERT_MESSAGE("should have Reference information", bHasReference
);
158 bHasReference
= false;
159 xValue
<<= bHasReference
;
160 xPropSet
->setPropertyValue(aHasReference
, xValue
);
162 xValue
= xPropSet
->getPropertyValue(aHasReference
);
163 CPPUNIT_ASSERT( xValue
>>= bHasReference
);
164 CPPUNIT_ASSERT_MESSAGE("should have no longer reference information", !bHasReference
);
167 void DataPilotField::testIsGroupField()
169 uno::Reference
< beans::XPropertySet
> xPropSet(init(),UNO_QUERY_THROW
);
171 OUString
aIsGroupField("IsGroupField");
172 bool bIsGroupField(false);
174 xValue
= xPropSet
->getPropertyValue(aIsGroupField
);
175 CPPUNIT_ASSERT( xValue
>>= bIsGroupField
);
176 //only setting to false is supported
179 bIsGroupField
= false;
180 xValue
<<= bIsGroupField
;
182 xPropSet
->setPropertyValue(aIsGroupField
, xValue
);
183 xValue
= xPropSet
->getPropertyValue(aIsGroupField
);
184 CPPUNIT_ASSERT(xValue
>>= bIsGroupField
);
185 CPPUNIT_ASSERT_MESSAGE("setting IsGroupField is supported and should have happened", !bIsGroupField
);
188 std::cout
<< "Could not test IsGroupField" << std::endl
;
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */