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 package mod._sch; 24 25 import com.sun.star.chart.XChartData; 26 import com.sun.star.chart.XChartDocument; 27 import com.sun.star.frame.XController; 28 import com.sun.star.lang.XMultiServiceFactory; 29 import com.sun.star.uno.UnoRuntime; 30 import com.sun.star.uno.XInterface; 31 import com.sun.star.view.XSelectionSupplier; 32 33 import java.io.PrintWriter; 34 35 import lib.StatusException; 36 import lib.TestCase; 37 import lib.TestEnvironment; 38 import lib.TestParameters; 39 40 import util.SOfficeFactory; 41 42 43 /** 44 * Test for object which is represented by service 45 * <code>com.sun.star.chart.ChartDocument</code>. <p> 46 * Object implements the following interfaces : 47 * <ul> 48 * <li> <code>com::sun::star::lang::XComponent</code></li> 49 * <li> <code>com::sun::star::frame::XModel</code></li> 50 * <li> <code>com::sun::star::chart::XChartDocument</code></li> 51 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 52 * <li> <code>com::sun::star::chart::ChartTableAddressSupplier</code></li> 53 * <li> <code>com::sun::star::chart::ChartDocument</code></li> 54 * </ul> 55 * @see com.sun.star.lang.XComponent 56 * @see com.sun.star.frame.XModel 57 * @see com.sun.star.chart.XChartDocument 58 * @see com.sun.star.beans.XPropertySet 59 * @see com.sun.star.chart.ChartTableAddressSupplier 60 * @see com.sun.star.chart.ChartDocument 61 * @see ifc.lang._XComponent 62 * @see ifc.frame._XModel 63 * @see ifc.chart._XChartDocument 64 * @see ifc.beans._XPropertySet 65 * @see ifc.chart._ChartTableAddressSupplier 66 * @see ifc.chart._ChartDocument 67 */ 68 public class ChXChartDocument extends TestCase { 69 XChartDocument xChartDoc = null; 70 XChartDocument doc2 = null; 71 72 /** 73 * Disposes Chart documents. 74 */ cleanup(TestParameters Param, PrintWriter log)75 protected void cleanup(TestParameters Param, PrintWriter log) { 76 if( xChartDoc!=null ) { 77 log.println( " closing xChartDoc" ); 78 util.DesktopTools.closeDoc(xChartDoc); 79 xChartDoc = null; 80 } 81 if( doc2!=null ) { 82 log.println( " closing xChartDoc2" ); 83 util.DesktopTools.closeDoc(doc2); 84 doc2 = null; 85 } 86 } 87 88 /** 89 * Creating a Testenvironment for the interfaces to be tested. 90 * Creates two chart documents and retrieves current controllers from them 91 * using the interface <code>XChartDocument</code>. The created documents 92 * is the instances of the service <code>com.sun.star.chart.ChartDocument</code>. 93 * Obtains the data source of the second created chart and creates 94 * a pie diagram. 95 * Object relations created : 96 * <ul> 97 * <li> <code>'SELSUPP'</code> for 98 * {@link ifc.frame._XModel}(the controller of the first created chart 99 * document)</li> 100 * <li> <code>'TOSELECT'</code> for 101 * {@link ifc.frame._XModel}(the shape of the main title of 102 * the first created chart document)</li> 103 * <li> <code>'CONT2'</code> for 104 * {@link ifc.frame._XModel}(the second created chart document)</li> 105 * <li> <code>'DIAGRAM'</code> for 106 * {@link ifc.chart._XChartDocument}(the created pie diagram)</li> 107 * <li> <code>'CHARTDATA'</code> for 108 * {@link ifc.chart._XChartDocument}(the data source of the second 109 * created chart)</li> 110 * </ul> 111 * @see com.sun.star.chart.XChartData 112 * @see com.sun.star.chart.ChartDocument 113 */ createTestEnvironment(TestParameters tParam, PrintWriter log)114 protected synchronized TestEnvironment createTestEnvironment(TestParameters tParam, 115 PrintWriter log) { 116 // get a soffice factory object 117 SOfficeFactory SOF = SOfficeFactory.getFactory( 118 (XMultiServiceFactory) tParam.getMSF()); 119 120 try { 121 log.println("creating a chartdocument"); 122 xChartDoc = SOF.createChartDoc(null); 123 log.println("Waiting before opening second document"); 124 doc2 = SOF.createChartDoc(null); 125 } catch (com.sun.star.uno.Exception e) { 126 // Some exception occures.FAILED 127 e.printStackTrace(log); 128 throw new StatusException("Couldn't create document", e); 129 } 130 131 132 // get the chartdocument 133 log.println("getting ChartDocument"); 134 135 XInterface oObj = (XChartDocument) xChartDoc; 136 137 XController cont1 = xChartDoc.getCurrentController(); 138 XController cont2 = doc2.getCurrentController(); 139 140 cont1.getFrame().setName("cont1"); 141 cont2.getFrame().setName("cont2"); 142 143 XSelectionSupplier sel = (XSelectionSupplier) UnoRuntime.queryInterface( 144 XSelectionSupplier.class, cont1); 145 146 log.println("creating a new environment for chartdocument object"); 147 148 TestEnvironment tEnv = new TestEnvironment(oObj); 149 150 log.println("Adding SelectionSupplier and Shape to select for XModel"); 151 tEnv.addObjRelation("SELSUPP", sel); 152 tEnv.addObjRelation("TOSELECT", xChartDoc.getTitle()); 153 154 log.println("adding Controller as ObjRelation for XModel"); 155 tEnv.addObjRelation("CONT2", cont2); 156 157 log.println("adding another Diagram as mod relation to environment"); 158 tEnv.addObjRelation("DIAGRAM", 159 SOF.createDiagram(xChartDoc, "PieDiagram")); 160 161 log.println("adding another ChartData as mod relation to environment"); 162 163 XChartData ChartData = doc2.getData(); 164 tEnv.addObjRelation("CHARTDATA", ChartData); 165 166 return tEnv; 167 } // finish method getTestEnvironment 168 } // finish class ChXChartDocument 169