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
.lang
.XMultiServiceFactory
;
38 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
39 import com
.sun
.star
.uno
.AnyConverter
;
40 import com
.sun
.star
.uno
.Type
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
44 public class ScDrawPageObj
extends TestCase
{
46 private XSpreadsheetDocument xDoc
= null;
49 * Creates a new Draw document.
51 protected void initialize( TestParameters tParam
, PrintWriter log
) {
52 // get a soffice factory object
53 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)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
68 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
69 log
.println( " disposing xSheetDoc " );
70 XComponent xComp
= UnoRuntime
.queryInterface(XComponent
.class, xDoc
);
71 util
.DesktopTools
.closeDoc(xComp
);
76 * Creating a Testenvironment for the interfaces to be tested.
77 * From the Calc document created a collection of its draw
78 * pages is obtained. Two new pages are inserted. And one
79 * page is obtained as a testing component. A shape is added
82 * Object relations created :
84 * <li> <code>'DrawPage'</code> for
85 * {@link ifc.drawing._XShapeGrouper} :
86 * the draw page tested. </li>
87 * <li> <code>'Shape'</code> for
88 * {@link ifc.drawing._XShapes} :
89 * the creator which can create instances of
90 * <code>com.sun.star.drawing.Line</code> service </li>
93 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
95 XInterface oObj
= null;
96 XShape oShape
= null ;
97 XDrawPages oDP
= null;
99 XComponent xComp
= UnoRuntime
.queryInterface(XComponent
.class, xDoc
);
101 // creation of testobject here
102 // first we write what we are intend to do to log file
103 log
.println( "creating a test environment" );
105 log
.println( "getting Drawpages" );
106 XDrawPagesSupplier oDPS
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class,xDoc
);
107 oDP
= oDPS
.getDrawPages();
108 oDP
.insertNewByIndex(1);
109 oDP
.insertNewByIndex(2);
110 oObj
= (XDrawPage
) AnyConverter
.toObject(
111 new Type(XDrawPage
.class),oDP
.getByIndex(0));
113 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
115 oShape
= SOF
.createShape(xComp
,5000,3500,7500,5000,"Rectangle");
116 DrawTools
.getShapes((XDrawPage
) oObj
).add(oShape
);
117 XShape oShape1
= SOF
.createShape(xComp
,
118 5000,5500,5000,5000,"Rectangle");
119 DrawTools
.getShapes((XDrawPage
) oObj
).add(oShape1
);
120 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
121 log
.println("Couldn't create insance");
122 e
.printStackTrace(log
);
123 throw new StatusException("Can't create enviroment", e
) ;
124 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
125 log
.println("Couldn't create insance");
126 e
.printStackTrace(log
);
127 throw new StatusException("Can't create enviroment", e
) ;
128 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
129 log
.println("Couldn't create insance");
130 e
.printStackTrace(log
);
131 throw new StatusException("Can't create enviroment", e
) ;
134 // create test environment here
135 TestEnvironment tEnv
= new TestEnvironment( oObj
);
137 // relation for XShapes interface
138 ShapeDsc sDsc
= new ShapeDsc(5000,3500,7500,10000,"Line");
139 tEnv
.addObjRelation("Shape", new InstCreator(xDoc
, sDsc
)) ;
141 log
.println("ImplementationName: "+util
.utils
.getImplName(oObj
));
143 // adding relation for XShapeGrouper
144 tEnv
.addObjRelation("DrawPage", oObj
);
147 } // finish method getTestEnvironment