xref: /AOO41X/main/qadevOOo/tests/java/ifc/chart/_BarDiagram.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.BarDiagram</code>
41 * service properties:
42 * <ul>
43 *   <li><code>'Vertical'</code></li>
44 *   <li><code>'Deep'</code></li>
45 *   <li><code>'StackedBarsConnected'</code></li>
46 *   <li><code>'NumberOfLines'</code></li>
47 * </ul>
48 * Properties testing is automated
49 * by <code>lib.MultiPropertyTest</code> except property
50 * <code>'NumberOfLines'</code>. <p>
51 * This test needs the following object relations :
52 * <ul>
53 *  <li> <code>'CHARTDOC'</code> (of type <code>XChartDocument</code>):
54 *  to have reference to chart document </li>
55 *  <li> <code>'BAR'</code> (of type <code>XDiagram</code>):
56 *  relation that use as parameter for method setDiagram of chart document </li>
57 * <ul> <p>
58 * @see com.sun.star.chart.BarDiagram
59 * @see com.sun.star.chart.XChartDocument
60 * @see com.sun.star.chart.XDiagram
61 * @see lib.MultiPropertyTest
62 */
63 public class _BarDiagram extends MultiPropertyTest {
64 
65     XChartDocument doc = null;
66     XDiagram oldDiagram = null;
67 
68     /**
69     * Retrieves object relations and prepares a chart document.
70     * @throws StatusException if one of relations not found.
71     */
72     protected void before() {
73         log.println("Setting Diagram type to BarDiagram");
74         doc = (XChartDocument) tEnv.getObjRelation("CHARTDOC");
75         if (doc == null) throw new StatusException(Status.failed
76             ("Relation 'CHARTDOC' not found"));
77 
78         XDiagram bar = (XDiagram) tEnv.getObjRelation("BAR");
79         if (bar == null) throw new StatusException(Status.failed
80             ("Relation 'BAR' not found"));
81 
82         oldDiagram = doc.getDiagram();
83         doc.setDiagram(bar);
84         oObj = (XPropertySet)
85             UnoRuntime.queryInterface( XPropertySet.class, doc.getDiagram() );
86         log.println("Set it to 3D");
87         try {
88             oObj.setPropertyValue("Dim3D", new Boolean(true));
89         } catch(com.sun.star.lang.WrappedTargetException e) {
90             log.println("Exception while set property value");
91             e.printStackTrace(log);
92             throw new StatusException("Exception while set property value", e);
93         } catch(com.sun.star.lang.IllegalArgumentException e) {
94             log.println("Exception while set property value");
95             e.printStackTrace(log);
96             throw new StatusException("Exception while set property value", e);
97         } catch(com.sun.star.beans.PropertyVetoException e) {
98             log.println("Exception while set property value");
99             e.printStackTrace(log);
100             throw new StatusException("Exception while set property value", e);
101         } catch(com.sun.star.beans.UnknownPropertyException e) {
102             log.println("Exception while set property value");
103             e.printStackTrace(log);
104             throw new StatusException("Exception while set property value", e);
105         }
106     }
107 
108     /**
109     * Sets the old diagram for a chart document.
110     */
111     protected void after() {
112         doc.setDiagram(oldDiagram);
113     }
114 
115     protected PropertyTester LineTester = new PropertyTester() {
116         protected Object getNewValue(String propName, Object oldValue)
117                 throws java.lang.IllegalArgumentException {
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 'NumberOfLines'.
128     * This property tests when diagram in 2D-mode only
129     * except all other properties. This property is currently supported by
130     * two dimensional vertical bar charts only.
131     */
132     public void _NumberOfLines() {
133         log.println("Set it to 2D");
134         try {
135             oObj.setPropertyValue("Dim3D", new Boolean(false));
136             oObj.setPropertyValue("Vertical", new Boolean(false));
137         } catch(com.sun.star.lang.WrappedTargetException e) {
138             log.println("Exception while set property value");
139             e.printStackTrace(log);
140             throw new StatusException("Exception while set property value", e);
141         } catch(com.sun.star.lang.IllegalArgumentException e) {
142             log.println("Exception while set property value");
143             e.printStackTrace(log);
144             throw new StatusException("Exception while set property value", e);
145         } catch(com.sun.star.beans.PropertyVetoException e) {
146             log.println("Exception while set property value");
147             e.printStackTrace(log);
148             throw new StatusException("Exception while set property value", e);
149         } catch(com.sun.star.beans.UnknownPropertyException e) {
150             log.println("Exception while set property value");
151             e.printStackTrace(log);
152             throw new StatusException("Exception while set property value", e);
153         }
154 
155         log.println("Testing with custom Property tester") ;
156         testProperty("NumberOfLines", LineTester) ;
157     }
158 } // EOF BarDiagram
159 
160