1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _BarDiagram.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import lib
.MultiPropertyTest
;
35 import lib
.StatusException
;
37 import com
.sun
.star
.beans
.XPropertySet
;
38 import com
.sun
.star
.chart
.XChartDocument
;
39 import com
.sun
.star
.chart
.XDiagram
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
43 * Testing <code>com.sun.star.chart.BarDiagram</code>
46 * <li><code>'Vertical'</code></li>
47 * <li><code>'Deep'</code></li>
48 * <li><code>'StackedBarsConnected'</code></li>
49 * <li><code>'NumberOfLines'</code></li>
51 * Properties testing is automated
52 * by <code>lib.MultiPropertyTest</code> except property
53 * <code>'NumberOfLines'</code>. <p>
54 * This test needs the following object relations :
56 * <li> <code>'CHARTDOC'</code> (of type <code>XChartDocument</code>):
57 * to have reference to chart document </li>
58 * <li> <code>'BAR'</code> (of type <code>XDiagram</code>):
59 * relation that use as parameter for method setDiagram of chart document </li>
61 * @see com.sun.star.chart.BarDiagram
62 * @see com.sun.star.chart.XChartDocument
63 * @see com.sun.star.chart.XDiagram
64 * @see lib.MultiPropertyTest
66 public class _BarDiagram
extends MultiPropertyTest
{
68 XChartDocument doc
= null;
69 XDiagram oldDiagram
= null;
72 * Retrieves object relations and prepares a chart document.
73 * @throws StatusException if one of relations not found.
75 protected void before() {
76 log
.println("Setting Diagram type to BarDiagram");
77 doc
= (XChartDocument
) tEnv
.getObjRelation("CHARTDOC");
78 if (doc
== null) throw new StatusException(Status
.failed
79 ("Relation 'CHARTDOC' not found"));
81 XDiagram bar
= (XDiagram
) tEnv
.getObjRelation("BAR");
82 if (bar
== null) throw new StatusException(Status
.failed
83 ("Relation 'BAR' not found"));
85 oldDiagram
= doc
.getDiagram();
88 UnoRuntime
.queryInterface( XPropertySet
.class, doc
.getDiagram() );
89 log
.println("Set it to 3D");
91 oObj
.setPropertyValue("Dim3D", new Boolean(true));
92 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
93 log
.println("Exception while set property value");
94 e
.printStackTrace(log
);
95 throw new StatusException("Exception while set property value", e
);
96 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
97 log
.println("Exception while set property value");
98 e
.printStackTrace(log
);
99 throw new StatusException("Exception while set property value", e
);
100 } catch(com
.sun
.star
.beans
.PropertyVetoException e
) {
101 log
.println("Exception while set property value");
102 e
.printStackTrace(log
);
103 throw new StatusException("Exception while set property value", e
);
104 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
105 log
.println("Exception while set property value");
106 e
.printStackTrace(log
);
107 throw new StatusException("Exception while set property value", e
);
112 * Sets the old diagram for a chart document.
114 protected void after() {
115 doc
.setDiagram(oldDiagram
);
118 protected PropertyTester LineTester
= new PropertyTester() {
119 protected Object
getNewValue(String propName
, Object oldValue
)
120 throws java
.lang
.IllegalArgumentException
{
123 if ( ((Integer
) oldValue
).intValue() == a
)
124 return new Integer(b
); else
125 return new Integer(a
);
130 * Tests property 'NumberOfLines'.
131 * This property tests when diagram in 2D-mode only
132 * except all other properties. This property is currently supported by
133 * two dimensional vertical bar charts only.
135 public void _NumberOfLines() {
136 log
.println("Set it to 2D");
138 oObj
.setPropertyValue("Dim3D", new Boolean(false));
139 oObj
.setPropertyValue("Vertical", new Boolean(false));
140 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
141 log
.println("Exception while set property value");
142 e
.printStackTrace(log
);
143 throw new StatusException("Exception while set property value", e
);
144 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
145 log
.println("Exception while set property value");
146 e
.printStackTrace(log
);
147 throw new StatusException("Exception while set property value", e
);
148 } catch(com
.sun
.star
.beans
.PropertyVetoException e
) {
149 log
.println("Exception while set property value");
150 e
.printStackTrace(log
);
151 throw new StatusException("Exception while set property value", e
);
152 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
153 log
.println("Exception while set property value");
154 e
.printStackTrace(log
);
155 throw new StatusException("Exception while set property value", e
);
158 log
.println("Testing with custom Property tester") ;
159 testProperty("NumberOfLines", LineTester
) ;