2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiPropertyTest
;
23 import lib
.StatusException
;
25 import com
.sun
.star
.beans
.XPropertySet
;
26 import com
.sun
.star
.chart
.XChartDocument
;
27 import com
.sun
.star
.chart
.XDiagram
;
28 import com
.sun
.star
.uno
.UnoRuntime
;
31 * Testing <code>com.sun.star.chart.BarDiagram</code>
34 * <li><code>'Vertical'</code></li>
35 * <li><code>'Deep'</code></li>
36 * <li><code>'StackedBarsConnected'</code></li>
37 * <li><code>'NumberOfLines'</code></li>
39 * Properties testing is automated
40 * by <code>lib.MultiPropertyTest</code> except property
41 * <code>'NumberOfLines'</code>. <p>
42 * This test needs the following object relations :
44 * <li> <code>'CHARTDOC'</code> (of type <code>XChartDocument</code>):
45 * to have reference to chart document </li>
46 * <li> <code>'BAR'</code> (of type <code>XDiagram</code>):
47 * relation that use as parameter for method setDiagram of chart document </li>
49 * @see com.sun.star.chart.BarDiagram
50 * @see com.sun.star.chart.XChartDocument
51 * @see com.sun.star.chart.XDiagram
52 * @see lib.MultiPropertyTest
54 public class _BarDiagram
extends MultiPropertyTest
{
56 XChartDocument doc
= null;
57 XDiagram oldDiagram
= null;
60 * Retrieves object relations and prepares a chart document.
61 * @throws StatusException if one of relations not found.
64 protected void before() {
65 log
.println("Setting Diagram type to BarDiagram");
66 doc
= (XChartDocument
) tEnv
.getObjRelation("CHARTDOC");
67 if (doc
== null) throw new StatusException(Status
.failed
68 ("Relation 'CHARTDOC' not found"));
70 XDiagram bar
= (XDiagram
) tEnv
.getObjRelation("BAR");
71 if (bar
== null) throw new StatusException(Status
.failed
72 ("Relation 'BAR' not found"));
74 oldDiagram
= doc
.getDiagram();
76 oObj
= UnoRuntime
.queryInterface( XPropertySet
.class, doc
.getDiagram() );
77 log
.println("Set it to 3D");
79 oObj
.setPropertyValue("Dim3D", Boolean
.TRUE
);
80 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
81 log
.println("Exception while set property value");
82 e
.printStackTrace(log
);
83 throw new StatusException("Exception while set property value", e
);
84 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
85 log
.println("Exception while set property value");
86 e
.printStackTrace(log
);
87 throw new StatusException("Exception while set property value", e
);
88 } catch(com
.sun
.star
.beans
.PropertyVetoException e
) {
89 log
.println("Exception while set property value");
90 e
.printStackTrace(log
);
91 throw new StatusException("Exception while set property value", e
);
92 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
93 log
.println("Exception while set property value");
94 e
.printStackTrace(log
);
95 throw new StatusException("Exception while set property value", e
);
100 * Sets the old diagram for a chart document.
103 protected void after() {
104 doc
.setDiagram(oldDiagram
);
107 protected PropertyTester LineTester
= new PropertyTester() {
109 protected Object
getNewValue(String propName
, Object oldValue
)
110 throws java
.lang
.IllegalArgumentException
{
113 if ( ((Integer
) oldValue
).intValue() == a
)
114 return Integer
.valueOf(b
); else
115 return Integer
.valueOf(a
);
120 * Tests property 'NumberOfLines'.
121 * This property tests when diagram in 2D-mode only
122 * except all other properties. This property is currently supported by
123 * two dimensional vertical bar charts only.
125 public void _NumberOfLines() {
126 log
.println("Set it to 2D");
128 oObj
.setPropertyValue("Dim3D", Boolean
.FALSE
);
129 oObj
.setPropertyValue("Vertical", Boolean
.FALSE
);
130 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
131 log
.println("Exception while set property value");
132 e
.printStackTrace(log
);
133 throw new StatusException("Exception while set property value", e
);
134 } catch(com
.sun
.star
.lang
.IllegalArgumentException 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
.beans
.PropertyVetoException 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
.UnknownPropertyException e
) {
143 log
.println("Exception while set property value");
144 e
.printStackTrace(log
);
145 throw new StatusException("Exception while set property value", e
);
148 log
.println("Testing with custom Property tester") ;
149 testProperty("NumberOfLines", LineTester
) ;