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/beans/XPropertySet.hpp>
12 #include <com/sun/star/sheet/DataPilotFieldSortInfo.hpp>
13 #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
14 #include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
15 #include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp>
16 #include <com/sun/star/sheet/DataPilotFieldLayoutInfo.hpp>
17 #include <com/sun/star/sheet/DataPilotFieldReference.hpp>
18 #include <com/sun/star/sheet/DataPilotFieldAutoShowInfo.hpp>
20 #include <rtl/ustring.hxx>
21 #include <cppunit/TestAssert.h>
25 using namespace css::uno
;
29 void DataPilotField::testSortInfo()
31 uno::Reference
< beans::XPropertySet
> xPropSet(init(),UNO_QUERY_THROW
);
32 sheet::DataPilotFieldSortInfo aSortInfoValue
;
33 OUString
aSortInfo("SortInfo");
34 aSortInfoValue
.Field
= "Col1";
35 aSortInfoValue
.IsAscending
= false;
36 aSortInfoValue
.Mode
= sheet::DataPilotFieldSortMode::MANUAL
;
38 aValue
<<= aSortInfoValue
;
39 xPropSet
->setPropertyValue(aSortInfo
, aValue
);
41 sheet::DataPilotFieldSortInfo aNewSortInfoValue
;
42 aValue
= xPropSet
->getPropertyValue(aSortInfo
);
43 CPPUNIT_ASSERT( aValue
>>= aNewSortInfoValue
);
44 CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as got value", aSortInfoValue
.Field
, aNewSortInfoValue
.Field
);
45 CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as got value", aSortInfoValue
.Mode
, aNewSortInfoValue
.Mode
);
46 CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as got value", aSortInfoValue
.IsAscending
, aNewSortInfoValue
.IsAscending
);
48 //setting HasSortInfo only makes sense for false, for true the uno implementation does nothing
49 bool bHasSortInfo(false);
50 OUString
aHasSortInfo("HasSortInfo");
51 aValue
= xPropSet
->getPropertyValue(aHasSortInfo
);
52 CPPUNIT_ASSERT( aValue
>>= bHasSortInfo
);
53 CPPUNIT_ASSERT_MESSAGE("should have sort info", bHasSortInfo
);
56 aValue
<<= bHasSortInfo
;
57 xPropSet
->setPropertyValue(aHasSortInfo
, aValue
);
59 aValue
= xPropSet
->getPropertyValue(aHasSortInfo
);
60 CPPUNIT_ASSERT( aValue
>>= bHasSortInfo
);
61 CPPUNIT_ASSERT_MESSAGE("should have no sort info", !bHasSortInfo
);
64 void DataPilotField::testLayoutInfo()
66 uno::Reference
< beans::XPropertySet
> xPropSet(init(),UNO_QUERY_THROW
);
67 sheet::DataPilotFieldLayoutInfo aLayoutInfoValue
;
68 OUString
aLayoutInfo("LayoutInfo");
69 aLayoutInfoValue
.AddEmptyLines
= false;
70 aLayoutInfoValue
.LayoutMode
= sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM
;
72 aValue
<<= aLayoutInfoValue
;
73 xPropSet
->setPropertyValue(aLayoutInfo
, aValue
);
75 sheet::DataPilotFieldLayoutInfo aNewLayoutInfoValue
;
76 aValue
= xPropSet
->getPropertyValue(aLayoutInfo
);
77 CPPUNIT_ASSERT( aValue
>>= aNewLayoutInfoValue
);
78 CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as the got value", aLayoutInfoValue
.LayoutMode
, aNewLayoutInfoValue
.LayoutMode
);
79 CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as the got value", aLayoutInfoValue
.AddEmptyLines
, aNewLayoutInfoValue
.AddEmptyLines
);
81 //setting HasLayoutInfo only makes sense for false, tor true the uno implementation does nothing
82 bool bHasLayoutInfo(false);
83 OUString
aHasLayoutInfo("HasLayoutInfo");
84 aValue
= xPropSet
->getPropertyValue(aHasLayoutInfo
);
85 CPPUNIT_ASSERT( aValue
>>= bHasLayoutInfo
);
86 CPPUNIT_ASSERT_MESSAGE("should have layout information", bHasLayoutInfo
);
88 bHasLayoutInfo
= false;
89 aValue
<<= bHasLayoutInfo
;
90 xPropSet
->setPropertyValue(aHasLayoutInfo
, aValue
);
92 aValue
= xPropSet
->getPropertyValue(aHasLayoutInfo
);
93 CPPUNIT_ASSERT( aValue
>>= bHasLayoutInfo
);
94 CPPUNIT_ASSERT_MESSAGE("should have no longer sort information", !bHasLayoutInfo
);
97 void DataPilotField::testAutoShowInfo()
99 uno::Reference
< beans::XPropertySet
> xPropSet(init(),UNO_QUERY_THROW
);
100 sheet::DataPilotFieldAutoShowInfo aAutoShowInfoValue
;
101 aAutoShowInfoValue
.DataField
= "Col1";
102 aAutoShowInfoValue
.IsEnabled
= true;
103 OUString
aAutoShowInfo("AutoShowInfo");
105 aValue
<<= aAutoShowInfoValue
;
106 xPropSet
->setPropertyValue(aAutoShowInfo
, aValue
);
108 sheet::DataPilotFieldAutoShowInfo aNewAutoShowInfoValue
;
109 aValue
= xPropSet
->getPropertyValue(aAutoShowInfo
);
110 CPPUNIT_ASSERT( aValue
>>= aNewAutoShowInfoValue
);
111 CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as the got value", aAutoShowInfoValue
.DataField
, aNewAutoShowInfoValue
.DataField
);
112 CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as the got value", aAutoShowInfoValue
.IsEnabled
, aNewAutoShowInfoValue
.IsEnabled
);
114 //setting HasLayoutInfo only makes sense for false, tor true the uno implementation does nothing
115 bool bHasAutoShowInfo(false);
116 OUString
aHasAutoShowInfo("HasAutoShowInfo");
117 aValue
= xPropSet
->getPropertyValue(aHasAutoShowInfo
);
118 CPPUNIT_ASSERT( aValue
>>= bHasAutoShowInfo
);
119 CPPUNIT_ASSERT_MESSAGE("should have AutoShow information", bHasAutoShowInfo
);
121 bHasAutoShowInfo
= false;
122 aValue
<<= bHasAutoShowInfo
;
123 xPropSet
->setPropertyValue(aHasAutoShowInfo
, aValue
);
125 aValue
= xPropSet
->getPropertyValue(aHasAutoShowInfo
);
126 CPPUNIT_ASSERT( aValue
>>= bHasAutoShowInfo
);
127 CPPUNIT_ASSERT_MESSAGE("should have no longer AutoShow information", !bHasAutoShowInfo
);
130 void DataPilotField::testReference()
132 uno::Reference
< beans::XPropertySet
> xPropSet(init(),UNO_QUERY_THROW
);
133 sheet::DataPilotFieldReference aReferenceValue
;
134 aReferenceValue
.ReferenceField
= "Col1";
135 aReferenceValue
.ReferenceItemType
= sheet::DataPilotFieldReferenceItemType::NAMED
;
136 OUString
aReference("Reference");
138 aValue
<<= aReferenceValue
;
139 xPropSet
->setPropertyValue(aReference
, aValue
);
141 sheet::DataPilotFieldReference aNewReferenceValue
;
142 aValue
= xPropSet
->getPropertyValue(aReference
);
143 CPPUNIT_ASSERT( aValue
>>= aNewReferenceValue
);
144 CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as the got value", aReferenceValue
.ReferenceField
, aNewReferenceValue
.ReferenceField
);
145 CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as the got value", aReferenceValue
.ReferenceItemType
, aNewReferenceValue
.ReferenceItemType
);
147 //setting HasReference only makes sense for false, tor true the uno implementation does nothing
148 bool bHasReference(false);
149 OUString
aHasReference("HasReference");
150 aValue
= xPropSet
->getPropertyValue(aHasReference
);
151 CPPUNIT_ASSERT( aValue
>>= bHasReference
);
152 CPPUNIT_ASSERT_MESSAGE("should have Reference information", bHasReference
);
154 bHasReference
= false;
155 aValue
<<= bHasReference
;
156 xPropSet
->setPropertyValue(aHasReference
, aValue
);
158 aValue
= xPropSet
->getPropertyValue(aHasReference
);
159 CPPUNIT_ASSERT( aValue
>>= bHasReference
);
160 CPPUNIT_ASSERT_MESSAGE("should have no longer reference information", !bHasReference
);
163 void DataPilotField::testIsGroupField()
165 uno::Reference
< beans::XPropertySet
> xPropSet(init(),UNO_QUERY_THROW
);
167 OUString
aIsGroupField("IsGroupField");
168 bool bIsGroupField(false);
170 aValue
= xPropSet
->getPropertyValue(aIsGroupField
);
171 CPPUNIT_ASSERT( aValue
>>= bIsGroupField
);
172 //only setting to false is supported
175 bIsGroupField
= false;
176 aValue
<<= bIsGroupField
;
178 xPropSet
->setPropertyValue(aIsGroupField
, aValue
);
179 aValue
= xPropSet
->getPropertyValue(aIsGroupField
);
180 CPPUNIT_ASSERT(aValue
>>= bIsGroupField
);
181 CPPUNIT_ASSERT_MESSAGE("setting IsGroupField is supported and should have happened", !bIsGroupField
);
184 std::cout
<< "Could not test IsGroupField" << std::endl
;
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */