Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxShapeControl.java
blob9c778479f48da0fa13ba55b360dd11d86386daec
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod._svx;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.DrawTools;
28 import util.FormTools;
29 import util.SOfficeFactory;
31 import com.sun.star.beans.XPropertySet;
32 import com.sun.star.drawing.XShape;
33 import com.sun.star.lang.XComponent;
34 import com.sun.star.style.XStyle;
35 import com.sun.star.uno.AnyConverter;
36 import com.sun.star.uno.Type;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
40 public class SvxShapeControl extends TestCase {
42 static XComponent xDrawDoc;
44 /**
45 * in general this method creates a testdocument
47 * @param tParam class which contains additional test parameters
48 * @param log class to log the test state and result
51 * @see TestParameters
52 * @see PrintWriter
55 @Override
56 protected void initialize( TestParameters tParam, PrintWriter log ) {
58 try {
59 log.println( "creating a drawdoc" );
60 xDrawDoc = DrawTools.createDrawDoc(tParam.getMSF());
61 } catch ( Exception e ) {
62 // Some exception occurs.FAILED
63 e.printStackTrace( log );
64 throw new StatusException( "Couldn't create document", e );
68 /**
69 * in general this method disposes the testenvironment and document
71 * @param tParam class which contains additional test parameters
72 * @param log class to log the test state and result
75 * @see TestParameters
76 * @see PrintWriter
79 @Override
80 protected void cleanup( TestParameters tParam, PrintWriter log ) {
81 log.println( " disposing xDrawDoc " );
82 util.DesktopTools.closeDoc(xDrawDoc);
86 /**
87 * creating a Testenvironment for the interfaces to be tested
89 * @param tParam class which contains additional test parameters
90 * @param log class to log the test state and result
92 * @return Status class
94 * @see TestParameters
95 * @see PrintWriter
97 @Override
98 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
100 XInterface oObj = null;
101 XShape oShape = null;
103 // creation of testobject here
104 // first we write what we are intend to do to log file
105 log.println( "creating a test environment" );
107 try {
109 oShape = FormTools.insertControlShape(
110 xDrawDoc,3000,4500,15000,1000,"CommandButton");
112 oObj = oShape ;
114 SOfficeFactory SOF = SOfficeFactory.getFactory(tParam.getMSF()) ;
115 oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Line");
116 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
118 catch (Exception e) {
119 log.println("Couldn't create insance");
120 e.printStackTrace(log);
123 // test environment creation
125 TestEnvironment tEnv = new TestEnvironment(oObj);
127 log.println( "adding two styles as ObjRelation for ShapeDescriptor" );
128 XPropertySet oShapeProps = UnoRuntime.queryInterface(XPropertySet.class,oObj);
129 XStyle aStyle = null;
130 try {
131 aStyle = (XStyle) AnyConverter.toObject(
132 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
133 } catch (Exception e) {}
134 tEnv.addObjRelation("Style1",aStyle);
135 oShapeProps = UnoRuntime.queryInterface(XPropertySet.class,oShape);
136 try {
137 aStyle = (XStyle) AnyConverter.toObject(
138 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
139 } catch (Exception e) {}
140 tEnv.addObjRelation("Style2",aStyle);
142 log.println( "adding document relation for XControlShape" );
143 tEnv.addObjRelation("xDoc", xDrawDoc) ;
145 return tEnv;
146 } // finish method getTestEnvironment
148 } // finish class SvxShapeControl