1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.sheet;
25 
26 import com.sun.star.sheet.DataPilotFieldAutoShowInfo;
27 import com.sun.star.sheet.DataPilotFieldLayoutInfo;
28 import com.sun.star.sheet.DataPilotFieldReference;
29 import com.sun.star.sheet.DataPilotFieldSortInfo;
30 import lib.MultiPropertyTest;
31 
32 /**
33 * Testing <code>com.sun.star.sheet.DataPilotField</code>
34 * service properties :
35 * <ul>
36 *  <li><code> Orientation</code></li>
37 *  <li><code> Function</code></li>
38 * </ul> <p>
39 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
40 * @see com.sun.star.sheet.DataPilotField
41 */
42 public class _DataPilotField extends MultiPropertyTest {
43 
44     /**
45      *This class is destined to custom test of property <code>SortInfo</code>.
46      */
47     protected PropertyTester SortInfoTester = new PropertyTester() {
48         protected Object getNewValue(String propName, Object oldValue) {
49             DataPilotFieldSortInfo sortInfo = new DataPilotFieldSortInfo();
50 	    sortInfo.Mode = com.sun.star.sheet.DataPilotFieldSortMode.MANUAL;
51             sortInfo.IsAscending = false;
52             sortInfo.Field = "COL1";
53             log.println("Having Value and returning a new one");
54             return sortInfo.equals(oldValue) ? null : sortInfo;
55         }
56     };
57 
58     /**
59      * Test property <code>SortInfo</code> using custom <code>PropertyTest</code>.
60      */
_SortInfo()61     public void _SortInfo() {
62         testProperty("SortInfo", SortInfoTester);
63     }
64 
_HasSortInfo()65     public void _HasSortInfo() {
66         requiredMethod("SortInfo");
67         testProperty("HasSortInfo");
68     }
69 
70     /**
71      *This class is destined to custom test of property <code>LayoutInfo</code>.
72      */
73     protected PropertyTester LayoutInfoTester = new PropertyTester() {
74         protected Object getNewValue(String propName, Object oldValue) {
75             DataPilotFieldLayoutInfo layoutInfo = new DataPilotFieldLayoutInfo();
76             layoutInfo.LayoutMode = com.sun.star.sheet.DataPilotFieldLayoutMode.OUTLINE_SUBTOTALS_BOTTOM;
77             layoutInfo.AddEmptyLines = true;
78             log.println("Having Value and returning a new one");
79             return layoutInfo.equals(oldValue) ? null : layoutInfo;
80         }
81     };
82 
83     /**
84      * Test property <code>LayoutInfo</code> using custom <code>PropertyTest</code>.
85      */
_LayoutInfo()86     public void _LayoutInfo() {
87         testProperty("LayoutInfo", LayoutInfoTester);
88     }
89 
_HasLayoutInfo()90     public void _HasLayoutInfo() {
91         requiredMethod("LayoutInfo");
92         testProperty("HasLayoutInfo");
93     }
94 
95     /**
96      *This class is destined to custom test of property <code>AutoShowInfo</code>.
97      */
98     protected PropertyTester AutoShowInfoTester = new PropertyTester() {
99         protected Object getNewValue(String propName, Object oldValue) {
100             DataPilotFieldAutoShowInfo AutoShowInfo = new DataPilotFieldAutoShowInfo();
101             AutoShowInfo.DataField = "Col1";
102             AutoShowInfo.IsEnabled = true;
103             log.println("Having Value and returning a new one");
104             return AutoShowInfo.equals(oldValue) ? null : AutoShowInfo;
105         }
106     };
107 
108     /**
109      * Test property <code>AutoShowInfo</code> using custom <code>PropertyTest</code>.
110      */
_AutoShowInfo()111     public void _AutoShowInfo() {
112         testProperty("AutoShowInfo", AutoShowInfoTester);
113     }
114 
_HasAutoShowInfo()115     public void _HasAutoShowInfo() {
116         requiredMethod("AutoShowInfo");
117         testProperty("HasAutoShowInfo");
118     }
119 
120     /**
121      *This class is destined to custom test of property <code>Reference</code>.
122      */
123     protected PropertyTester ReferenceTester = new PropertyTester() {
124         protected Object getNewValue(String propName, Object oldValue) {
125             DataPilotFieldReference Reference = new DataPilotFieldReference();
126             Reference.ReferenceField="Col1";
127             Reference.ReferenceItemType = com.sun.star.sheet.DataPilotFieldReferenceItemType.NAMED;
128             log.println("Having Value and returning a new one");
129             return Reference.equals(oldValue) ? null : Reference;
130         }
131     };
132 
133     /**
134      * Test property <code>Reference</code> using custom <code>PropertyTest</code>.
135      */
_Reference()136     public void _Reference() {
137         testProperty("Reference", ReferenceTester);
138     }
139 
_HasReference()140     public void _HasReference() {
141         requiredMethod("Reference");
142         testProperty("HasReference");
143     }
144 
145     /*
146      * this property can only set a true value to false, fo ungrouping purposes
147      */
_IsGroupField()148     public void _IsGroupField() {
149         boolean result = true;
150         try {
151             Boolean propValue = (Boolean) oObj.getPropertyValue ("IsGroupField");
152             if (propValue.booleanValue ()) {
153                 oObj.setPropertyValue ("IsGroupField", Boolean.FALSE);
154                 Boolean propV = (Boolean) oObj.getPropertyValue ("IsGroupField");
155                 result = !propV.booleanValue ();
156             }
157         } catch (Exception e) {
158             log.println ("Exception while getting Property 'IsGroupField'"+e);
159             result = false;
160         }
161         tRes.tested ("IsGroupField",result);
162     }
163 }
164 
165 
166