1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScDrawPageObj.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.DrawTools
;
40 import util
.InstCreator
;
41 import util
.SOfficeFactory
;
44 import com
.sun
.star
.drawing
.XDrawPage
;
45 import com
.sun
.star
.drawing
.XDrawPages
;
46 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
47 import com
.sun
.star
.drawing
.XShape
;
48 import com
.sun
.star
.lang
.XComponent
;
49 import com
.sun
.star
.lang
.XMultiServiceFactory
;
50 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
51 import com
.sun
.star
.uno
.AnyConverter
;
52 import com
.sun
.star
.uno
.Type
;
53 import com
.sun
.star
.uno
.UnoRuntime
;
54 import com
.sun
.star
.uno
.XInterface
;
56 public class ScDrawPageObj
extends TestCase
{
58 static XSpreadsheetDocument xDoc
= null;
61 * Creates a new Draw document.
63 protected void initialize( TestParameters tParam
, PrintWriter log
) {
64 // get a soffice factory object
65 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
68 log
.println( "creating a sheetdocument" );
69 xDoc
= SOF
.createCalcDoc(null);
70 } catch (com
.sun
.star
.uno
.Exception e
) {
71 // Some exception occures.FAILED
72 e
.printStackTrace( log
);
73 throw new StatusException( "Couldn't create document", e
);
78 * Disposes the Draw document created before
80 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
81 log
.println( " disposing xSheetDoc " );
82 XComponent xComp
= (XComponent
)
83 UnoRuntime
.queryInterface(XComponent
.class, xDoc
);
84 util
.DesktopTools
.closeDoc(xComp
);
89 * Creating a Testenvironment for the interfaces to be tested.
90 * From the Calc document created a collection of its draw
91 * pages is obtained. Two new pages are inserted. And one
92 * page is obtained as a testing component. A shape is added
95 * Object relations created :
97 * <li> <code>'DrawPage'</code> for
98 * {@link ifc.drawing._XShapeGrouper} :
99 * the draw page tested. </li>
100 * <li> <code>'Shape'</code> for
101 * {@link ifc.drawing._XShapes} :
102 * the creator which can create instances of
103 * <code>com.sun.star.drawing.Line</code> service </li>
106 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
108 XInterface oObj
= null;
109 XShape oShape
= null ;
110 XDrawPages oDP
= null;
112 XComponent xComp
= (XComponent
)
113 UnoRuntime
.queryInterface(XComponent
.class, xDoc
);
115 // creation of testobject here
116 // first we write what we are intend to do to log file
117 log
.println( "creating a test environment" );
119 log
.println( "getting Drawpages" );
120 XDrawPagesSupplier oDPS
= (XDrawPagesSupplier
)
121 UnoRuntime
.queryInterface(XDrawPagesSupplier
.class,xDoc
);
122 oDP
= (XDrawPages
) oDPS
.getDrawPages();
123 oDP
.insertNewByIndex(1);
124 oDP
.insertNewByIndex(2);
125 oObj
= (XDrawPage
) AnyConverter
.toObject(
126 new Type(XDrawPage
.class),oDP
.getByIndex(0));
128 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
130 oShape
= SOF
.createShape(xComp
,5000,3500,7500,5000,"Rectangle");
131 DrawTools
.getShapes((XDrawPage
) oObj
).add(oShape
);
132 XShape oShape1
= SOF
.createShape(xComp
,
133 5000,5500,5000,5000,"Rectangle");
134 DrawTools
.getShapes((XDrawPage
) oObj
).add(oShape1
);
135 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
136 log
.println("Couldn't create insance");
137 e
.printStackTrace(log
);
138 throw new StatusException("Can't create enviroment", e
) ;
139 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
140 log
.println("Couldn't create insance");
141 e
.printStackTrace(log
);
142 throw new StatusException("Can't create enviroment", e
) ;
143 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
144 log
.println("Couldn't create insance");
145 e
.printStackTrace(log
);
146 throw new StatusException("Can't create enviroment", e
) ;
149 // create test environment here
150 TestEnvironment tEnv
= new TestEnvironment( oObj
);
152 // relation for XShapes interface
153 ShapeDsc sDsc
= new ShapeDsc(5000,3500,7500,10000,"Line");
154 tEnv
.addObjRelation("Shape", new InstCreator(xDoc
, sDsc
)) ;
156 log
.println("ImplementationName: "+util
.utils
.getImplName(oObj
));
158 // adding relation for XShapeGrouper
159 tEnv
.addObjRelation("DrawPage", oObj
);
162 } // finish method getTestEnvironment