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