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