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 mod._svx; 25 26 import java.io.PrintWriter; 27 28 import lib.StatusException; 29 import lib.TestCase; 30 import lib.TestEnvironment; 31 import lib.TestParameters; 32 import util.DrawTools; 33 import util.InstCreator; 34 import util.SOfficeFactory; 35 import util.ShapeDsc; 36 37 import com.sun.star.drawing.XShape; 38 import com.sun.star.drawing.XShapes; 39 import com.sun.star.lang.XComponent; 40 import com.sun.star.lang.XMultiServiceFactory; 41 import com.sun.star.uno.UnoRuntime; 42 import com.sun.star.uno.XInterface; 43 44 public class SvxShapeCollection extends TestCase { 45 46 static XComponent xDrawDoc; 47 48 /** 49 * in general this method creates a testdocument 50 * 51 * @param tParam class which contains additional test parameters 52 * @param log class to log the test state and result 53 * 54 * 55 * @see TestParameters 56 * @see PrintWriter 57 * 58 */ initialize( TestParameters tParam, PrintWriter log )59 protected void initialize( TestParameters tParam, PrintWriter log ) { 60 61 try { 62 log.println( "creating a drawdoc" ); 63 xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF()); 64 } catch ( Exception e ) { 65 // Some exception occured.FAILED 66 e.printStackTrace( log ); 67 throw new StatusException( "Couldn't create document", e ); 68 } 69 } 70 71 /** 72 * in general this method disposes the testenvironment and document 73 * 74 * @param tParam class which contains additional test parameters 75 * @param log class to log the test state and result 76 * 77 * 78 * @see TestParameters 79 * @see PrintWriter 80 * 81 */ cleanup( TestParameters tParam, PrintWriter log )82 protected void cleanup( TestParameters tParam, PrintWriter log ) { 83 log.println( " disposing xDrawDoc " ); 84 util.DesktopTools.closeDoc(xDrawDoc); 85 } 86 87 88 /** 89 * creating a Testenvironment for the interfaces to be tested 90 * 91 * @param tParam class which contains additional test parameters 92 * @param log class to log the test state and result 93 * 94 * @return Status class 95 * 96 * @see TestParameters 97 * @see PrintWriter 98 */ createTestEnvironment(TestParameters tParam, PrintWriter log)99 protected TestEnvironment createTestEnvironment 100 (TestParameters tParam, PrintWriter log) { 101 102 XInterface oObj = null; 103 XShape oShape = null; 104 105 // creation of testobject here 106 // first we write what we are intend to do to log file 107 log.println( "creating a test environment" ); 108 109 try { 110 // adding some shapes for testing. 111 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 112 Object col = ((XMultiServiceFactory)tParam.getMSF()).createInstance 113 ("com.sun.star.drawing.ShapeCollection"); 114 XShapes shapes = (XShapes) UnoRuntime.queryInterface 115 (XShapes.class,col); 116 117 oShape = SOF.createShape(xDrawDoc,3000,4500,15000,1000,"Ellipse"); 118 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape); 119 shapes.add(oShape); 120 121 oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Rectangle"); 122 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ; 123 shapes.add(oShape); 124 125 oObj = (XInterface) col ; 126 127 } 128 catch (Exception e) { 129 log.println("Couldn't create insance"); 130 e.printStackTrace(log); 131 } 132 133 // test environment creation 134 135 TestEnvironment tEnv = new TestEnvironment(oObj); 136 System.out.println("IName: "+util.utils.getImplName(oObj)); 137 ShapeDsc sDsc = new ShapeDsc(5000,3500,7500,10000,"Line"); 138 tEnv.addObjRelation("Shape", new InstCreator(xDrawDoc, sDsc)) ; 139 140 return tEnv; 141 } // finish method getTestEnvironment 142 143 } // finish class SvxShapeCollection 144 145