xref: /AOO41X/main/qadevOOo/tests/java/ifc/chart/_LineDiagram.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.chart;
29 
30 import lib.MultiPropertyTest;
31 import lib.Status;
32 import lib.StatusException;
33 
34 import com.sun.star.beans.XPropertySet;
35 import com.sun.star.chart.XChartDocument;
36 import com.sun.star.chart.XDiagram;
37 import com.sun.star.uno.UnoRuntime;
38 
39 /**
40 * Testing <code>com.sun.star.chart.LineDiagram</code>
41 * service properties :
42 * <ul>
43 *  <li><code> SymbolType</code></li>
44 *  <li><code> SymbolSize</code></li>
45 *  <li><code> SymbolBitmapURL</code></li>
46 *  <li><code> Lines</code></li>
47 *  <li><code> SplineType</code></li>
48 * </ul> <p>
49 * The following predefined files needed to complete the test:
50 * <ul>
51 *  <li> <code>space-metal.jpg</code> :
52 *  for test of property 'SymbolBitmapURL' </li>
53 * <li> <code>crazy-blue.jpg</code> :
54 *  for test of property 'SymbolBitmapURL' </li>
55 * <ul> <p>
56 * This test needs the following object relations :
57 * <ul>
58 *  <li> <code>'CHARTDOC'</code> (of type <code>XChartDocument</code>):
59 *  to have reference to chart document </li>
60 *  <li> <code>'LINE'</code> (of type <code>XDiagram</code>):
61 *  relation that use as parameter for method setDiagram of chart document </li>
62 * </ul> <p>
63 * @see com.sun.star.chart.LineDiagram
64 */
65 public class _LineDiagram extends MultiPropertyTest {
66 
67     XChartDocument doc = null;
68     XDiagram oldDiagram = null;
69 
70     /**
71     * Retrieves object relations.
72     * @throws StatusException If one of relations not found.
73     */
74     protected void before() {
75         log.println("Setting Diagram type to LineDiagram");
76         doc = (XChartDocument) tEnv.getObjRelation("CHARTDOC");
77         if (doc == null) throw new StatusException(Status.failed
78             ("Relation 'CHARTDOC' not found"));
79 
80         XDiagram Line = (XDiagram) tEnv.getObjRelation("LINE");
81         if (Line == null) throw new StatusException(Status.failed
82             ("Relation 'LINE' not found"));
83 
84         oldDiagram = doc.getDiagram();
85         doc.setDiagram(Line);
86         oObj = (XPropertySet)
87             UnoRuntime.queryInterface( XPropertySet.class, doc.getDiagram() );
88     }
89 
90     /**
91     * Sets the old diagram for a chart document.
92     */
93     protected void after() {
94         doc.setDiagram(oldDiagram);
95     }
96 
97     protected PropertyTester URLTester = new PropertyTester() {
98         protected Object getNewValue(String propName, Object oldValue)
99                 throws java.lang.IllegalArgumentException {
100             if (oldValue.equals(util.utils.getFullTestURL("space-metal.jpg")))
101                 return util.utils.getFullTestURL("crazy-blue.jpg"); else
102                 return util.utils.getFullTestURL("space-metal.jpg");
103         }
104     } ;
105 
106     protected PropertyTester SymbolTester = new PropertyTester() {
107         protected Object getNewValue(String propName, Object oldValue)
108                 throws java.lang.IllegalArgumentException {
109 
110             int a = com.sun.star.chart.ChartSymbolType.AUTO;
111             int b = com.sun.star.chart.ChartSymbolType.NONE;
112             if ( ((Integer) oldValue).intValue() == a)
113                 return new Integer(b); else
114                 return new Integer(a);
115         }
116     } ;
117 
118     protected PropertyTester SplineTester = new PropertyTester() {
119         protected Object getNewValue(String propName, Object oldValue)
120                 throws java.lang.IllegalArgumentException {
121 
122             int a = 0;
123             int b = 2;
124             if ( ((Integer) oldValue).intValue() == a)
125                 return new Integer(b); else
126                 return new Integer(a);
127         }
128     } ;
129 
130     /**
131     * Tests property 'SymbolType'.
132     */
133     public void _SymbolType() {
134         log.println("Testing with custom Property tester") ;
135         testProperty("SymbolType", SymbolTester) ;
136         try {
137             oObj.setPropertyValue("SymbolType",new Integer(-2));
138         } catch(com.sun.star.lang.WrappedTargetException 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.lang.IllegalArgumentException 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.PropertyVetoException e) {
147             log.println("Exception while set property value");
148             e.printStackTrace(log);
149             throw new StatusException("Exception while set property value", e);
150         } catch(com.sun.star.beans.UnknownPropertyException e) {
151             log.println("Exception while set property value");
152             e.printStackTrace(log);
153             throw new StatusException("Exception while set property value", e);
154         }
155     }
156 
157     /**
158     * Tests property 'SplineType'.
159     */
160     public void _SplineType() {
161         log.println("Testing with custom Property tester") ;
162         testProperty("SplineType", SplineTester) ;
163     }
164 
165     /**
166     * Tests property 'SymbolBitmapURL'.
167     */
168     public void _SymbolBitmapURL() {
169         log.println("Testing with custom Property tester") ;
170         try {
171             oObj.setPropertyValue("SymbolType",
172                 new Integer(com.sun.star.chart.ChartSymbolType.BITMAPURL));
173         } catch(com.sun.star.lang.WrappedTargetException 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.lang.IllegalArgumentException 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.PropertyVetoException e) {
182             log.println("Exception while set property value");
183             e.printStackTrace(log);
184             throw new StatusException("Exception while set property value", e);
185         } catch(com.sun.star.beans.UnknownPropertyException e) {
186             log.println("Exception while set property value");
187             e.printStackTrace(log);
188             throw new StatusException("Exception while set property value", e);
189         }
190 
191         testProperty("SymbolBitmapURL", URLTester) ;
192     }
193 } // EOF LineDiagram
194 
195