1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package ifc.chart; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import lib.MultiPropertyTest; 31*cdf0e10cSrcweir import lib.Status; 32*cdf0e10cSrcweir import lib.StatusException; 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 35*cdf0e10cSrcweir import com.sun.star.chart.XChartDocument; 36*cdf0e10cSrcweir import com.sun.star.chart.XDiagram; 37*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir /** 40*cdf0e10cSrcweir * Testing <code>com.sun.star.chart.LineDiagram</code> 41*cdf0e10cSrcweir * service properties : 42*cdf0e10cSrcweir * <ul> 43*cdf0e10cSrcweir * <li><code> SymbolType</code></li> 44*cdf0e10cSrcweir * <li><code> SymbolSize</code></li> 45*cdf0e10cSrcweir * <li><code> SymbolBitmapURL</code></li> 46*cdf0e10cSrcweir * <li><code> Lines</code></li> 47*cdf0e10cSrcweir * <li><code> SplineType</code></li> 48*cdf0e10cSrcweir * </ul> <p> 49*cdf0e10cSrcweir * The following predefined files needed to complete the test: 50*cdf0e10cSrcweir * <ul> 51*cdf0e10cSrcweir * <li> <code>space-metal.jpg</code> : 52*cdf0e10cSrcweir * for test of property 'SymbolBitmapURL' </li> 53*cdf0e10cSrcweir * <li> <code>crazy-blue.jpg</code> : 54*cdf0e10cSrcweir * for test of property 'SymbolBitmapURL' </li> 55*cdf0e10cSrcweir * <ul> <p> 56*cdf0e10cSrcweir * This test needs the following object relations : 57*cdf0e10cSrcweir * <ul> 58*cdf0e10cSrcweir * <li> <code>'CHARTDOC'</code> (of type <code>XChartDocument</code>): 59*cdf0e10cSrcweir * to have reference to chart document </li> 60*cdf0e10cSrcweir * <li> <code>'LINE'</code> (of type <code>XDiagram</code>): 61*cdf0e10cSrcweir * relation that use as parameter for method setDiagram of chart document </li> 62*cdf0e10cSrcweir * </ul> <p> 63*cdf0e10cSrcweir * @see com.sun.star.chart.LineDiagram 64*cdf0e10cSrcweir */ 65*cdf0e10cSrcweir public class _LineDiagram extends MultiPropertyTest { 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir XChartDocument doc = null; 68*cdf0e10cSrcweir XDiagram oldDiagram = null; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir /** 71*cdf0e10cSrcweir * Retrieves object relations. 72*cdf0e10cSrcweir * @throws StatusException If one of relations not found. 73*cdf0e10cSrcweir */ 74*cdf0e10cSrcweir protected void before() { 75*cdf0e10cSrcweir log.println("Setting Diagram type to LineDiagram"); 76*cdf0e10cSrcweir doc = (XChartDocument) tEnv.getObjRelation("CHARTDOC"); 77*cdf0e10cSrcweir if (doc == null) throw new StatusException(Status.failed 78*cdf0e10cSrcweir ("Relation 'CHARTDOC' not found")); 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir XDiagram Line = (XDiagram) tEnv.getObjRelation("LINE"); 81*cdf0e10cSrcweir if (Line == null) throw new StatusException(Status.failed 82*cdf0e10cSrcweir ("Relation 'LINE' not found")); 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir oldDiagram = doc.getDiagram(); 85*cdf0e10cSrcweir doc.setDiagram(Line); 86*cdf0e10cSrcweir oObj = (XPropertySet) 87*cdf0e10cSrcweir UnoRuntime.queryInterface( XPropertySet.class, doc.getDiagram() ); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir /** 91*cdf0e10cSrcweir * Sets the old diagram for a chart document. 92*cdf0e10cSrcweir */ 93*cdf0e10cSrcweir protected void after() { 94*cdf0e10cSrcweir doc.setDiagram(oldDiagram); 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir protected PropertyTester URLTester = new PropertyTester() { 98*cdf0e10cSrcweir protected Object getNewValue(String propName, Object oldValue) 99*cdf0e10cSrcweir throws java.lang.IllegalArgumentException { 100*cdf0e10cSrcweir if (oldValue.equals(util.utils.getFullTestURL("space-metal.jpg"))) 101*cdf0e10cSrcweir return util.utils.getFullTestURL("crazy-blue.jpg"); else 102*cdf0e10cSrcweir return util.utils.getFullTestURL("space-metal.jpg"); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir } ; 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir protected PropertyTester SymbolTester = new PropertyTester() { 107*cdf0e10cSrcweir protected Object getNewValue(String propName, Object oldValue) 108*cdf0e10cSrcweir throws java.lang.IllegalArgumentException { 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir int a = com.sun.star.chart.ChartSymbolType.AUTO; 111*cdf0e10cSrcweir int b = com.sun.star.chart.ChartSymbolType.NONE; 112*cdf0e10cSrcweir if ( ((Integer) oldValue).intValue() == a) 113*cdf0e10cSrcweir return new Integer(b); else 114*cdf0e10cSrcweir return new Integer(a); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir } ; 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir protected PropertyTester SplineTester = new PropertyTester() { 119*cdf0e10cSrcweir protected Object getNewValue(String propName, Object oldValue) 120*cdf0e10cSrcweir throws java.lang.IllegalArgumentException { 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir int a = 0; 123*cdf0e10cSrcweir int b = 2; 124*cdf0e10cSrcweir if ( ((Integer) oldValue).intValue() == a) 125*cdf0e10cSrcweir return new Integer(b); else 126*cdf0e10cSrcweir return new Integer(a); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir } ; 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir /** 131*cdf0e10cSrcweir * Tests property 'SymbolType'. 132*cdf0e10cSrcweir */ 133*cdf0e10cSrcweir public void _SymbolType() { 134*cdf0e10cSrcweir log.println("Testing with custom Property tester") ; 135*cdf0e10cSrcweir testProperty("SymbolType", SymbolTester) ; 136*cdf0e10cSrcweir try { 137*cdf0e10cSrcweir oObj.setPropertyValue("SymbolType",new Integer(-2)); 138*cdf0e10cSrcweir } catch(com.sun.star.lang.WrappedTargetException e) { 139*cdf0e10cSrcweir log.println("Exception while set property value"); 140*cdf0e10cSrcweir e.printStackTrace(log); 141*cdf0e10cSrcweir throw new StatusException("Exception while set property value", e); 142*cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e) { 143*cdf0e10cSrcweir log.println("Exception while set property value"); 144*cdf0e10cSrcweir e.printStackTrace(log); 145*cdf0e10cSrcweir throw new StatusException("Exception while set property value", e); 146*cdf0e10cSrcweir } catch(com.sun.star.beans.PropertyVetoException e) { 147*cdf0e10cSrcweir log.println("Exception while set property value"); 148*cdf0e10cSrcweir e.printStackTrace(log); 149*cdf0e10cSrcweir throw new StatusException("Exception while set property value", e); 150*cdf0e10cSrcweir } catch(com.sun.star.beans.UnknownPropertyException e) { 151*cdf0e10cSrcweir log.println("Exception while set property value"); 152*cdf0e10cSrcweir e.printStackTrace(log); 153*cdf0e10cSrcweir throw new StatusException("Exception while set property value", e); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir /** 158*cdf0e10cSrcweir * Tests property 'SplineType'. 159*cdf0e10cSrcweir */ 160*cdf0e10cSrcweir public void _SplineType() { 161*cdf0e10cSrcweir log.println("Testing with custom Property tester") ; 162*cdf0e10cSrcweir testProperty("SplineType", SplineTester) ; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir /** 166*cdf0e10cSrcweir * Tests property 'SymbolBitmapURL'. 167*cdf0e10cSrcweir */ 168*cdf0e10cSrcweir public void _SymbolBitmapURL() { 169*cdf0e10cSrcweir log.println("Testing with custom Property tester") ; 170*cdf0e10cSrcweir try { 171*cdf0e10cSrcweir oObj.setPropertyValue("SymbolType", 172*cdf0e10cSrcweir new Integer(com.sun.star.chart.ChartSymbolType.BITMAPURL)); 173*cdf0e10cSrcweir } catch(com.sun.star.lang.WrappedTargetException e) { 174*cdf0e10cSrcweir log.println("Exception while set property value"); 175*cdf0e10cSrcweir e.printStackTrace(log); 176*cdf0e10cSrcweir throw new StatusException("Exception while set property value", e); 177*cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e) { 178*cdf0e10cSrcweir log.println("Exception while set property value"); 179*cdf0e10cSrcweir e.printStackTrace(log); 180*cdf0e10cSrcweir throw new StatusException("Exception while set property value", e); 181*cdf0e10cSrcweir } catch(com.sun.star.beans.PropertyVetoException e) { 182*cdf0e10cSrcweir log.println("Exception while set property value"); 183*cdf0e10cSrcweir e.printStackTrace(log); 184*cdf0e10cSrcweir throw new StatusException("Exception while set property value", e); 185*cdf0e10cSrcweir } catch(com.sun.star.beans.UnknownPropertyException e) { 186*cdf0e10cSrcweir log.println("Exception while set property value"); 187*cdf0e10cSrcweir e.printStackTrace(log); 188*cdf0e10cSrcweir throw new StatusException("Exception while set property value", e); 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir testProperty("SymbolBitmapURL", URLTester) ; 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir } // EOF LineDiagram 194*cdf0e10cSrcweir 195