LibreOffice Module test (master) 1
datapilotfield.cxx
Go to the documentation of this file.
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
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>
19
20#include <rtl/ustring.hxx>
21#include <cppunit/TestAssert.h>
22#include <iostream>
23
24using namespace css;
25using namespace css::uno;
26
27namespace apitest {
28
30{
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;
37 uno::Any aValue;
38 aValue <<= aSortInfoValue;
39 xPropSet->setPropertyValue(aSortInfo, aValue);
40
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);
47
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);
54
55 bHasSortInfo = false;
56 aValue <<= bHasSortInfo;
57 xPropSet->setPropertyValue(aHasSortInfo, aValue);
58
59 aValue = xPropSet->getPropertyValue(aHasSortInfo);
60 CPPUNIT_ASSERT( aValue >>= bHasSortInfo );
61 CPPUNIT_ASSERT_MESSAGE("should have no sort info", !bHasSortInfo);
62}
63
65{
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;
71 uno::Any aValue;
72 aValue <<= aLayoutInfoValue;
73 xPropSet->setPropertyValue(aLayoutInfo, aValue);
74
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);
80
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);
87
88 bHasLayoutInfo = false;
89 aValue <<= bHasLayoutInfo;
90 xPropSet->setPropertyValue(aHasLayoutInfo, aValue);
91
92 aValue = xPropSet->getPropertyValue(aHasLayoutInfo);
93 CPPUNIT_ASSERT( aValue >>= bHasLayoutInfo );
94 CPPUNIT_ASSERT_MESSAGE("should have no longer sort information", !bHasLayoutInfo);
95}
96
98{
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");
104 uno::Any aValue;
105 aValue <<= aAutoShowInfoValue;
106 xPropSet->setPropertyValue(aAutoShowInfo, aValue);
107
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);
113
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);
120
121 bHasAutoShowInfo = false;
122 aValue <<= bHasAutoShowInfo;
123 xPropSet->setPropertyValue(aHasAutoShowInfo, aValue);
124
125 aValue = xPropSet->getPropertyValue(aHasAutoShowInfo);
126 CPPUNIT_ASSERT( aValue >>= bHasAutoShowInfo );
127 CPPUNIT_ASSERT_MESSAGE("should have no longer AutoShow information", !bHasAutoShowInfo);
128}
129
131{
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");
137 uno::Any aValue;
138 aValue <<= aReferenceValue;
139 xPropSet->setPropertyValue(aReference, aValue);
140
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);
146
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);
153
154 bHasReference = false;
155 aValue <<= bHasReference;
156 xPropSet->setPropertyValue(aHasReference, aValue);
157
158 aValue = xPropSet->getPropertyValue(aHasReference);
159 CPPUNIT_ASSERT( aValue >>= bHasReference );
160 CPPUNIT_ASSERT_MESSAGE("should have no longer reference information", !bHasReference);
161}
162
164{
165 uno::Reference< beans::XPropertySet > xPropSet(init(),UNO_QUERY_THROW);
166 uno::Any aValue;
167 OUString aIsGroupField("IsGroupField");
168 bool bIsGroupField(false);
169
170 aValue = xPropSet->getPropertyValue(aIsGroupField);
171 CPPUNIT_ASSERT( aValue >>= bIsGroupField);
172 //only setting to false is supported
173 if (bIsGroupField)
174 {
175 bIsGroupField = false;
176 aValue <<= bIsGroupField;
177
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);
182 }
183 else
184 std::cout << "Could not test IsGroupField" << std::endl;
185}
186
187}
188
189/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::uno::XInterface > init()=0
const PPTXLayoutInfo aLayoutInfo[LAYOUT_SIZE]