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.chart;
25 
26 import lib.MultiPropertyTest;
27 import lib.Status;
28 import lib.StatusException;
29 
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.chart.XChartDocument;
32 import com.sun.star.chart.XDiagram;
33 import com.sun.star.uno.UnoRuntime;
34 
35 /**
36 * Testing <code>com.sun.star.chart.LineDiagram</code>
37 * service properties :
38 * <ul>
39 *  <li><code> SymbolType</code></li>
40 *  <li><code> SymbolSize</code></li>
41 *  <li><code> SymbolBitmapURL</code></li>
42 *  <li><code> Lines</code></li>
43 *  <li><code> SplineType</code></li>
44 * </ul> <p>
45 * The following predefined files needed to complete the test:
46 * <ul>
47 *  <li> <code>space-metal.jpg</code> :
48 *  for test of property 'SymbolBitmapURL' </li>
49 * <li> <code>crazy-blue.jpg</code> :
50 *  for test of property 'SymbolBitmapURL' </li>
51 * <ul> <p>
52 * This test needs the following object relations :
53 * <ul>
54 *  <li> <code>'CHARTDOC'</code> (of type <code>XChartDocument</code>):
55 *  to have reference to chart document </li>
56 *  <li> <code>'LINE'</code> (of type <code>XDiagram</code>):
57 *  relation that use as parameter for method setDiagram of chart document </li>
58 * </ul> <p>
59 * @see com.sun.star.chart.LineDiagram
60 */
61 public class _LineDiagram extends MultiPropertyTest {
62 
63     XChartDocument doc = null;
64     XDiagram oldDiagram = null;
65 
66     /**
67     * Retrieves object relations.
68     * @throws StatusException If one of relations not found.
69     */
before()70     protected void before() {
71         log.println("Setting Diagram type to LineDiagram");
72         doc = (XChartDocument) tEnv.getObjRelation("CHARTDOC");
73         if (doc == null) throw new StatusException(Status.failed
74             ("Relation 'CHARTDOC' not found"));
75 
76         XDiagram Line = (XDiagram) tEnv.getObjRelation("LINE");
77         if (Line == null) throw new StatusException(Status.failed
78             ("Relation 'LINE' not found"));
79 
80         oldDiagram = doc.getDiagram();
81         doc.setDiagram(Line);
82         oObj = (XPropertySet)
83             UnoRuntime.queryInterface( XPropertySet.class, doc.getDiagram() );
84     }
85 
86     /**
87     * Sets the old diagram for a chart document.
88     */
after()89     protected void after() {
90         doc.setDiagram(oldDiagram);
91     }
92 
93     protected PropertyTester URLTester = new PropertyTester() {
94         protected Object getNewValue(String propName, Object oldValue)
95                 throws java.lang.IllegalArgumentException {
96             if (oldValue.equals(util.utils.getFullTestURL("space-metal.jpg")))
97                 return util.utils.getFullTestURL("crazy-blue.jpg"); else
98                 return util.utils.getFullTestURL("space-metal.jpg");
99         }
100     } ;
101 
102     protected PropertyTester SymbolTester = new PropertyTester() {
103         protected Object getNewValue(String propName, Object oldValue)
104                 throws java.lang.IllegalArgumentException {
105 
106             int a = com.sun.star.chart.ChartSymbolType.AUTO;
107             int b = com.sun.star.chart.ChartSymbolType.NONE;
108             if ( ((Integer) oldValue).intValue() == a)
109                 return new Integer(b); else
110                 return new Integer(a);
111         }
112     } ;
113 
114     protected PropertyTester SplineTester = new PropertyTester() {
115         protected Object getNewValue(String propName, Object oldValue)
116                 throws java.lang.IllegalArgumentException {
117 
118             int a = 0;
119             int b = 2;
120             if ( ((Integer) oldValue).intValue() == a)
121                 return new Integer(b); else
122                 return new Integer(a);
123         }
124     } ;
125 
126     /**
127     * Tests property 'SymbolType'.
128     */
_SymbolType()129     public void _SymbolType() {
130         log.println("Testing with custom Property tester") ;
131         testProperty("SymbolType", SymbolTester) ;
132         try {
133             oObj.setPropertyValue("SymbolType",new Integer(-2));
134         } catch(com.sun.star.lang.WrappedTargetException e) {
135             log.println("Exception while set property value");
136             e.printStackTrace(log);
137             throw new StatusException("Exception while set property value", e);
138         } catch(com.sun.star.lang.IllegalArgumentException e) {
139             log.println("Exception while set property value");
140             e.printStackTrace(log);
141             throw new StatusException("Exception while set property value", e);
142         } catch(com.sun.star.beans.PropertyVetoException e) {
143             log.println("Exception while set property value");
144             e.printStackTrace(log);
145             throw new StatusException("Exception while set property value", e);
146         } catch(com.sun.star.beans.UnknownPropertyException e) {
147             log.println("Exception while set property value");
148             e.printStackTrace(log);
149             throw new StatusException("Exception while set property value", e);
150         }
151     }
152 
153     /**
154     * Tests property 'SplineType'.
155     */
_SplineType()156     public void _SplineType() {
157         log.println("Testing with custom Property tester") ;
158         testProperty("SplineType", SplineTester) ;
159     }
160 
161     /**
162     * Tests property 'SymbolBitmapURL'.
163     */
_SymbolBitmapURL()164     public void _SymbolBitmapURL() {
165         log.println("Testing with custom Property tester") ;
166         try {
167             oObj.setPropertyValue("SymbolType",
168                 new Integer(com.sun.star.chart.ChartSymbolType.BITMAPURL));
169         } catch(com.sun.star.lang.WrappedTargetException e) {
170             log.println("Exception while set property value");
171             e.printStackTrace(log);
172             throw new StatusException("Exception while set property value", e);
173         } catch(com.sun.star.lang.IllegalArgumentException e) {
174             log.println("Exception while set property value");
175             e.printStackTrace(log);
176             throw new StatusException("Exception while set property value", e);
177         } catch(com.sun.star.beans.PropertyVetoException e) {
178             log.println("Exception while set property value");
179             e.printStackTrace(log);
180             throw new StatusException("Exception while set property value", e);
181         } catch(com.sun.star.beans.UnknownPropertyException e) {
182             log.println("Exception while set property value");
183             e.printStackTrace(log);
184             throw new StatusException("Exception while set property value", e);
185         }
186 
187         testProperty("SymbolBitmapURL", URLTester) ;
188     }
189 } // EOF LineDiagram
190 
191