xref: /AOO41X/main/qadevOOo/tests/java/mod/_svx/SvxShapeCollection.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._svx;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.DrawTools;
37 import util.InstCreator;
38 import util.SOfficeFactory;
39 import util.ShapeDsc;
40 
41 import com.sun.star.drawing.XShape;
42 import com.sun.star.drawing.XShapes;
43 import com.sun.star.lang.XComponent;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
47 
48 public class SvxShapeCollection extends TestCase {
49 
50     static XComponent xDrawDoc;
51 
52     /**
53      * in general this method creates a testdocument
54      *
55      *  @param tParam    class which contains additional test parameters
56      *  @param log        class to log the test state and result
57      *
58      *
59      *  @see TestParameters
60      *    @see PrintWriter
61      *
62      */
63     protected void initialize( TestParameters tParam, PrintWriter log ) {
64 
65         try {
66             log.println( "creating a drawdoc" );
67             xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF());
68         } catch ( Exception e ) {
69             // Some exception occures.FAILED
70             e.printStackTrace( log );
71             throw new StatusException( "Couldn't create document", e );
72         }
73     }
74 
75     /**
76      * in general this method disposes the testenvironment and document
77      *
78      *  @param tParam    class which contains additional test parameters
79      *  @param log        class to log the test state and result
80      *
81      *
82      *  @see TestParameters
83      *    @see PrintWriter
84      *
85      */
86     protected void cleanup( TestParameters tParam, PrintWriter log ) {
87         log.println( "    disposing xDrawDoc " );
88         util.DesktopTools.closeDoc(xDrawDoc);
89     }
90 
91 
92     /**
93      *    creating a Testenvironment for the interfaces to be tested
94      *
95      *  @param tParam    class which contains additional test parameters
96      *  @param log        class to log the test state and result
97      *
98      *  @return    Status class
99      *
100      *  @see TestParameters
101      *    @see PrintWriter
102      */
103     protected TestEnvironment createTestEnvironment
104             (TestParameters tParam, PrintWriter log) {
105 
106         XInterface oObj = null;
107         XShape oShape = null;
108 
109         // creation of testobject here
110         // first we write what we are intend to do to log file
111         log.println( "creating a test environment" );
112 
113         try {
114             // adding some shapes for testing.
115             SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
116             Object col = ((XMultiServiceFactory)tParam.getMSF()).createInstance
117                 ("com.sun.star.drawing.ShapeCollection");
118             XShapes shapes = (XShapes) UnoRuntime.queryInterface
119                 (XShapes.class,col);
120 
121             oShape = SOF.createShape(xDrawDoc,3000,4500,15000,1000,"Ellipse");
122             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
123             shapes.add(oShape);
124 
125             oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Rectangle");
126             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
127             shapes.add(oShape);
128 
129             oObj = (XInterface) col ;
130 
131         }
132         catch (Exception e) {
133             log.println("Couldn't create insance");
134             e.printStackTrace(log);
135         }
136 
137         // test environment creation
138 
139          TestEnvironment tEnv = new TestEnvironment(oObj);
140          System.out.println("IName: "+util.utils.getImplName(oObj));
141         ShapeDsc sDsc = new ShapeDsc(5000,3500,7500,10000,"Line");
142         tEnv.addObjRelation("Shape", new InstCreator(xDrawDoc, sDsc)) ;
143 
144         return tEnv;
145     } // finish method getTestEnvironment
146 
147 }    // finish class SvxShapeCollection
148 
149