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 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.DrawTools
;
28 import util
.InstCreator
;
29 import util
.SOfficeFactory
;
32 import com
.sun
.star
.drawing
.XDrawPage
;
33 import com
.sun
.star
.drawing
.XDrawPages
;
34 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
35 import com
.sun
.star
.drawing
.XShape
;
36 import com
.sun
.star
.lang
.XComponent
;
37 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
38 import com
.sun
.star
.uno
.AnyConverter
;
39 import com
.sun
.star
.uno
.Type
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
43 public class ScDrawPageObj
extends TestCase
{
45 private XSpreadsheetDocument xDoc
= null;
48 * Creates a new Draw document.
51 protected void initialize( TestParameters tParam
, PrintWriter log
) {
52 // get a soffice factory object
53 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
56 log
.println( "creating a sheetdocument" );
57 xDoc
= SOF
.createCalcDoc(null);
58 } catch (com
.sun
.star
.uno
.Exception e
) {
59 // Some exception occurs.FAILED
60 e
.printStackTrace( log
);
61 throw new StatusException( "Couldn't create document", e
);
66 * Disposes the Draw document created before
69 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
70 log
.println( " disposing xSheetDoc " );
71 XComponent xComp
= UnoRuntime
.queryInterface(XComponent
.class, xDoc
);
72 util
.DesktopTools
.closeDoc(xComp
);
77 * Creating a Testenvironment for the interfaces to be tested.
78 * From the Calc document created a collection of its draw
79 * pages is obtained. Two new pages are inserted. And one
80 * page is obtained as a testing component. A shape is added
83 * Object relations created :
85 * <li> <code>'DrawPage'</code> for
86 * {@link ifc.drawing._XShapeGrouper} :
87 * the draw page tested. </li>
88 * <li> <code>'Shape'</code> for
89 * {@link ifc.drawing._XShapes} :
90 * the creator which can create instances of
91 * <code>com.sun.star.drawing.Line</code> service </li>
95 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
97 XInterface oObj
= null;
98 XShape oShape
= null ;
99 XDrawPages oDP
= null;
101 XComponent xComp
= UnoRuntime
.queryInterface(XComponent
.class, xDoc
);
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 log
.println( "getting Drawpages" );
108 XDrawPagesSupplier oDPS
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class,xDoc
);
109 oDP
= oDPS
.getDrawPages();
110 oDP
.insertNewByIndex(1);
111 oDP
.insertNewByIndex(2);
112 oObj
= (XDrawPage
) AnyConverter
.toObject(
113 new Type(XDrawPage
.class),oDP
.getByIndex(0));
115 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
117 oShape
= SOF
.createShape(xComp
,5000,3500,7500,5000,"Rectangle");
118 DrawTools
.getShapes((XDrawPage
) oObj
).add(oShape
);
119 XShape oShape1
= SOF
.createShape(xComp
,
120 5000,5500,5000,5000,"Rectangle");
121 DrawTools
.getShapes((XDrawPage
) oObj
).add(oShape1
);
122 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
123 log
.println("Couldn't create insance");
124 e
.printStackTrace(log
);
125 throw new StatusException("Can't create environment", e
) ;
126 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
127 log
.println("Couldn't create insance");
128 e
.printStackTrace(log
);
129 throw new StatusException("Can't create environment", e
) ;
130 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
131 log
.println("Couldn't create insance");
132 e
.printStackTrace(log
);
133 throw new StatusException("Can't create environment", e
) ;
136 // create test environment here
137 TestEnvironment tEnv
= new TestEnvironment( oObj
);
139 // relation for XShapes interface
140 ShapeDsc sDsc
= new ShapeDsc(5000,3500,7500,10000,"Line");
141 tEnv
.addObjRelation("Shape", new InstCreator(xDoc
, sDsc
)) ;
143 log
.println("ImplementationName: "+util
.utils
.getImplName(oObj
));
145 // adding relation for XShapeGrouper
146 tEnv
.addObjRelation("DrawPage", oObj
);
149 } // finish method getTestEnvironment