1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package ifc.chart; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import lib.MultiPropertyTest; 27cdf0e10cSrcweir import lib.Status; 28cdf0e10cSrcweir import lib.StatusException; 29cdf0e10cSrcweir 30cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 31cdf0e10cSrcweir import com.sun.star.chart.XChartDocument; 32cdf0e10cSrcweir import com.sun.star.chart.XDiagram; 33cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 34cdf0e10cSrcweir 35cdf0e10cSrcweir /** 36cdf0e10cSrcweir * Testing <code>com.sun.star.chart.LineDiagram</code> 37cdf0e10cSrcweir * service properties : 38cdf0e10cSrcweir * <ul> 39cdf0e10cSrcweir * <li><code> SymbolType</code></li> 40cdf0e10cSrcweir * <li><code> SymbolSize</code></li> 41cdf0e10cSrcweir * <li><code> SymbolBitmapURL</code></li> 42cdf0e10cSrcweir * <li><code> Lines</code></li> 43cdf0e10cSrcweir * <li><code> SplineType</code></li> 44cdf0e10cSrcweir * </ul> <p> 45cdf0e10cSrcweir * The following predefined files needed to complete the test: 46cdf0e10cSrcweir * <ul> 47cdf0e10cSrcweir * <li> <code>space-metal.jpg</code> : 48cdf0e10cSrcweir * for test of property 'SymbolBitmapURL' </li> 49cdf0e10cSrcweir * <li> <code>crazy-blue.jpg</code> : 50cdf0e10cSrcweir * for test of property 'SymbolBitmapURL' </li> 51cdf0e10cSrcweir * <ul> <p> 52cdf0e10cSrcweir * This test needs the following object relations : 53cdf0e10cSrcweir * <ul> 54cdf0e10cSrcweir * <li> <code>'CHARTDOC'</code> (of type <code>XChartDocument</code>): 55cdf0e10cSrcweir * to have reference to chart document </li> 56cdf0e10cSrcweir * <li> <code>'LINE'</code> (of type <code>XDiagram</code>): 57cdf0e10cSrcweir * relation that use as parameter for method setDiagram of chart document </li> 58cdf0e10cSrcweir * </ul> <p> 59cdf0e10cSrcweir * @see com.sun.star.chart.LineDiagram 60cdf0e10cSrcweir */ 61cdf0e10cSrcweir public class _LineDiagram extends MultiPropertyTest { 62cdf0e10cSrcweir 63cdf0e10cSrcweir XChartDocument doc = null; 64cdf0e10cSrcweir XDiagram oldDiagram = null; 65cdf0e10cSrcweir 66cdf0e10cSrcweir /** 67cdf0e10cSrcweir * Retrieves object relations. 68cdf0e10cSrcweir * @throws StatusException If one of relations not found. 69cdf0e10cSrcweir */ before()70cdf0e10cSrcweir protected void before() { 71cdf0e10cSrcweir log.println("Setting Diagram type to LineDiagram"); 72cdf0e10cSrcweir doc = (XChartDocument) tEnv.getObjRelation("CHARTDOC"); 73cdf0e10cSrcweir if (doc == null) throw new StatusException(Status.failed 74cdf0e10cSrcweir ("Relation 'CHARTDOC' not found")); 75cdf0e10cSrcweir 76cdf0e10cSrcweir XDiagram Line = (XDiagram) tEnv.getObjRelation("LINE"); 77cdf0e10cSrcweir if (Line == null) throw new StatusException(Status.failed 78cdf0e10cSrcweir ("Relation 'LINE' not found")); 79cdf0e10cSrcweir 80cdf0e10cSrcweir oldDiagram = doc.getDiagram(); 81cdf0e10cSrcweir doc.setDiagram(Line); 82cdf0e10cSrcweir oObj = (XPropertySet) 83cdf0e10cSrcweir UnoRuntime.queryInterface( XPropertySet.class, doc.getDiagram() ); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir /** 87cdf0e10cSrcweir * Sets the old diagram for a chart document. 88cdf0e10cSrcweir */ after()89cdf0e10cSrcweir protected void after() { 90cdf0e10cSrcweir doc.setDiagram(oldDiagram); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir protected PropertyTester URLTester = new PropertyTester() { 94cdf0e10cSrcweir protected Object getNewValue(String propName, Object oldValue) 95cdf0e10cSrcweir throws java.lang.IllegalArgumentException { 96cdf0e10cSrcweir if (oldValue.equals(util.utils.getFullTestURL("space-metal.jpg"))) 97cdf0e10cSrcweir return util.utils.getFullTestURL("crazy-blue.jpg"); else 98cdf0e10cSrcweir return util.utils.getFullTestURL("space-metal.jpg"); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir } ; 101cdf0e10cSrcweir 102cdf0e10cSrcweir protected PropertyTester SymbolTester = new PropertyTester() { 103cdf0e10cSrcweir protected Object getNewValue(String propName, Object oldValue) 104cdf0e10cSrcweir throws java.lang.IllegalArgumentException { 105cdf0e10cSrcweir 106cdf0e10cSrcweir int a = com.sun.star.chart.ChartSymbolType.AUTO; 107cdf0e10cSrcweir int b = com.sun.star.chart.ChartSymbolType.NONE; 108cdf0e10cSrcweir if ( ((Integer) oldValue).intValue() == a) 109cdf0e10cSrcweir return new Integer(b); else 110cdf0e10cSrcweir return new Integer(a); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir } ; 113cdf0e10cSrcweir 114cdf0e10cSrcweir protected PropertyTester SplineTester = new PropertyTester() { 115cdf0e10cSrcweir protected Object getNewValue(String propName, Object oldValue) 116cdf0e10cSrcweir throws java.lang.IllegalArgumentException { 117cdf0e10cSrcweir 118cdf0e10cSrcweir int a = 0; 119cdf0e10cSrcweir int b = 2; 120cdf0e10cSrcweir if ( ((Integer) oldValue).intValue() == a) 121cdf0e10cSrcweir return new Integer(b); else 122cdf0e10cSrcweir return new Integer(a); 123cdf0e10cSrcweir } 124cdf0e10cSrcweir } ; 125cdf0e10cSrcweir 126cdf0e10cSrcweir /** 127cdf0e10cSrcweir * Tests property 'SymbolType'. 128cdf0e10cSrcweir */ _SymbolType()129cdf0e10cSrcweir public void _SymbolType() { 130cdf0e10cSrcweir log.println("Testing with custom Property tester") ; 131cdf0e10cSrcweir testProperty("SymbolType", SymbolTester) ; 132cdf0e10cSrcweir try { 133cdf0e10cSrcweir oObj.setPropertyValue("SymbolType",new Integer(-2)); 134cdf0e10cSrcweir } catch(com.sun.star.lang.WrappedTargetException e) { 135cdf0e10cSrcweir log.println("Exception while set property value"); 136cdf0e10cSrcweir e.printStackTrace(log); 137cdf0e10cSrcweir throw new StatusException("Exception while set property value", e); 138cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e) { 139cdf0e10cSrcweir log.println("Exception while set property value"); 140cdf0e10cSrcweir e.printStackTrace(log); 141cdf0e10cSrcweir throw new StatusException("Exception while set property value", e); 142cdf0e10cSrcweir } catch(com.sun.star.beans.PropertyVetoException e) { 143cdf0e10cSrcweir log.println("Exception while set property value"); 144cdf0e10cSrcweir e.printStackTrace(log); 145cdf0e10cSrcweir throw new StatusException("Exception while set property value", e); 146cdf0e10cSrcweir } catch(com.sun.star.beans.UnknownPropertyException e) { 147cdf0e10cSrcweir log.println("Exception while set property value"); 148cdf0e10cSrcweir e.printStackTrace(log); 149cdf0e10cSrcweir throw new StatusException("Exception while set property value", e); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir /** 154cdf0e10cSrcweir * Tests property 'SplineType'. 155cdf0e10cSrcweir */ _SplineType()156cdf0e10cSrcweir public void _SplineType() { 157cdf0e10cSrcweir log.println("Testing with custom Property tester") ; 158cdf0e10cSrcweir testProperty("SplineType", SplineTester) ; 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir /** 162cdf0e10cSrcweir * Tests property 'SymbolBitmapURL'. 163cdf0e10cSrcweir */ _SymbolBitmapURL()164cdf0e10cSrcweir public void _SymbolBitmapURL() { 165cdf0e10cSrcweir log.println("Testing with custom Property tester") ; 166cdf0e10cSrcweir try { 167cdf0e10cSrcweir oObj.setPropertyValue("SymbolType", 168cdf0e10cSrcweir new Integer(com.sun.star.chart.ChartSymbolType.BITMAPURL)); 169cdf0e10cSrcweir } catch(com.sun.star.lang.WrappedTargetException e) { 170cdf0e10cSrcweir log.println("Exception while set property value"); 171cdf0e10cSrcweir e.printStackTrace(log); 172cdf0e10cSrcweir throw new StatusException("Exception while set property value", e); 173cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e) { 174cdf0e10cSrcweir log.println("Exception while set property value"); 175cdf0e10cSrcweir e.printStackTrace(log); 176cdf0e10cSrcweir throw new StatusException("Exception while set property value", e); 177cdf0e10cSrcweir } catch(com.sun.star.beans.PropertyVetoException e) { 178cdf0e10cSrcweir log.println("Exception while set property value"); 179cdf0e10cSrcweir e.printStackTrace(log); 180cdf0e10cSrcweir throw new StatusException("Exception while set property value", e); 181cdf0e10cSrcweir } catch(com.sun.star.beans.UnknownPropertyException e) { 182cdf0e10cSrcweir log.println("Exception while set property value"); 183cdf0e10cSrcweir e.printStackTrace(log); 184cdf0e10cSrcweir throw new StatusException("Exception while set property value", e); 185cdf0e10cSrcweir } 186cdf0e10cSrcweir 187cdf0e10cSrcweir testProperty("SymbolBitmapURL", URLTester) ; 188cdf0e10cSrcweir } 189cdf0e10cSrcweir } // EOF LineDiagram 190cdf0e10cSrcweir 191