1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._sw;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.SOfficeFactory;
33 
34 import com.sun.star.beans.XPropertySet;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.text.XText;
37 import com.sun.star.text.XTextContent;
38 import com.sun.star.text.XTextCursor;
39 import com.sun.star.text.XTextDocument;
40 import com.sun.star.text.XTextGraphicObjectsSupplier;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
43 
44 public class SwXTextGraphicObjects extends TestCase {
45 
46     XTextDocument xTextDoc;
47 
48     /**
49      * in general this method creates a testdocument
50      *
51      *  @param tParam    class which contains additional test parameters
52      *  @param log        class to log the test state and result
53      *
54      *
55      *  @see TestParameters
56      *    @see PrintWriter
57      *
58      */
initialize( TestParameters tParam, PrintWriter log )59     protected void initialize( TestParameters tParam, PrintWriter log ) {
60         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
61         try {
62             log.println( "creating a textdoc" );
63             xTextDoc = SOF.createTextDoc( null );
64         } catch ( Exception e ) {
65             // Some exception occured.FAILED
66             e.printStackTrace( log );
67             throw new StatusException( "Couldn't create document", e );
68         }
69     }
70 
71     /**
72      * in general this method disposes the testenvironment and document
73      *
74      *  @param tParam    class which contains additional test parameters
75      *  @param log        class to log the test state and result
76      *
77      *
78      *  @see TestParameters
79      *    @see PrintWriter
80      *
81      */
cleanup( TestParameters tParam, PrintWriter log )82     protected void cleanup( TestParameters tParam, PrintWriter log ) {
83         log.println( "    disposing xTextDoc " );
84         util.DesktopTools.closeDoc(xTextDoc);
85     }
86 
87 
88     /**
89      *    creating a Testenvironment for the interfaces to be tested
90      *
91      *  @param tParam    class which contains additional test parameters
92      *  @param log        class to log the test state and result
93      *
94      *  @return    Status class
95      *
96      *  @see TestParameters
97      *    @see PrintWriter
98      */
createTestEnvironment( TestParameters tParam, PrintWriter log )99     public TestEnvironment createTestEnvironment( TestParameters tParam,
100                                                   PrintWriter log )
101                                                     throws StatusException {
102 
103         XInterface oObj = null;
104         Object oGObject = null;
105         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
106 
107         try {
108             oGObject = SOF.createInstance
109                 (xTextDoc,"com.sun.star.text.GraphicObject");
110         }
111         catch (Exception ex) {
112             log.println("Couldn't create instance");
113             ex.printStackTrace(log);
114             throw new StatusException("Couldn't create instance", ex );
115         }
116 
117         oObj = (XInterface) oGObject;
118 
119         XText the_text = xTextDoc.getText();
120         XTextCursor the_cursor = the_text.createTextCursor();
121         XTextContent the_content = (XTextContent)
122                             UnoRuntime.queryInterface(XTextContent.class,oObj);
123 
124        log.println( "inserting graphic" );
125         try {
126             the_text.insertTextContent(the_cursor,the_content,true);
127         } catch (Exception e) {
128             System.out.println("Couldn't insert Content");
129             e.printStackTrace();
130             throw new StatusException("Couldn't insert Content", e );
131         }
132 
133         log.println( "adding graphic" );
134         XPropertySet oProps = (XPropertySet)
135                             UnoRuntime.queryInterface(XPropertySet.class,oObj);
136         try {
137             String wat = util.utils.getFullTestURL("space-metal.jpg");
138             oProps.setPropertyValue("GraphicURL",wat);
139             oProps.setPropertyValue("HoriOrientPosition",new Integer(5500));
140             oProps.setPropertyValue("VertOrientPosition",new Integer(4200));
141             oProps.setPropertyValue("Width",new Integer(4400));
142             oProps.setPropertyValue("Height",new Integer(4000));
143         } catch (Exception e) {
144             System.out.println("Couldn't set property 'GraphicURL'");
145             e.printStackTrace();
146             throw new StatusException("Couldn't set property 'GraphicURL'", e );
147         }
148 
149         XTextGraphicObjectsSupplier xTGS = (XTextGraphicObjectsSupplier)
150             UnoRuntime.queryInterface(XTextGraphicObjectsSupplier.class,
151             xTextDoc);
152         oObj = xTGS.getGraphicObjects();
153 
154         TestEnvironment tEnv = new TestEnvironment( oObj );
155 
156         return tEnv;
157 
158     } // finish method getTestEnvironment
159 
160 }    // finish class SwXTextGraphicObjects
161 
162