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 com.sun.star.beans.XPropertySet;
27 import java.io.PrintWriter;
28 
29 import lib.StatusException;
30 import lib.TestCase;
31 import lib.TestEnvironment;
32 import lib.TestParameters;
33 import util.SOfficeFactory;
34 
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.text.XTextContent;
37 import com.sun.star.text.XTextCursor;
38 import com.sun.star.text.XTextDocument;
39 import com.sun.star.text.XTextEmbeddedObjectsSupplier;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
42 
43 
44 public class SwXTextEmbeddedObjects extends TestCase {
45 
46     XTextDocument oDoc;
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 
62         try {
63             oDoc = SOF.createTextDoc(null);
64         } catch ( com.sun.star.uno.Exception e ) {
65             // Some exception occures.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(oDoc);
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 ) throws StatusException {
101 
102         XInterface oObj = null;
103 
104         // create testobject here
105         XTextCursor xCursor = oDoc.getText().createTextCursor();
106         try {
107             XMultiServiceFactory xMultiServiceFactory = (XMultiServiceFactory)
108                 UnoRuntime.queryInterface(XMultiServiceFactory.class, oDoc);
109             Object o = xMultiServiceFactory.createInstance("com.sun.star.text.TextEmbeddedObject" );
110             XTextContent xTextContent = (XTextContent)UnoRuntime.queryInterface(XTextContent.class, o);
111             String sChartClassID = "12dcae26-281f-416f-a234-c3086127382e";
112             XPropertySet xPropertySet = (XPropertySet)
113                 UnoRuntime.queryInterface(XPropertySet.class, xTextContent);
114             xPropertySet.setPropertyValue( "CLSID", sChartClassID );
115 
116             oDoc.getText().insertTextContent( xCursor, xTextContent, false );
117         }
118         catch(com.sun.star.uno.Exception e) {
119             e.printStackTrace((java.io.PrintWriter)log);
120         }
121 
122         XTextEmbeddedObjectsSupplier oTEOS = (XTextEmbeddedObjectsSupplier)
123             UnoRuntime.queryInterface(XTextEmbeddedObjectsSupplier.class, oDoc);
124 
125         oObj = oTEOS.getEmbeddedObjects();
126 
127           TestEnvironment tEnv = new TestEnvironment( oObj );
128         return tEnv;
129 
130         } // finish method getTestEnvironment
131 
132 }    // finish class SwXTextEmbeddedObjects
133 
134