merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / SwXTextEmbeddedObjects.java
blob3ecb0edf3e9b8e094005538f9c65fd8b4946bebf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXTextEmbeddedObjects.java,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
31 package mod._sw;
33 import com.sun.star.beans.XPropertySet;
34 import java.io.PrintWriter;
36 import lib.StatusException;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
40 import util.SOfficeFactory;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.text.XTextContent;
44 import com.sun.star.text.XTextCursor;
45 import com.sun.star.text.XTextDocument;
46 import com.sun.star.text.XTextEmbeddedObjectsSupplier;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
51 public class SwXTextEmbeddedObjects extends TestCase {
53 XTextDocument oDoc;
55 /**
56 * in general this method creates a testdocument
58 * @param tParam class which contains additional test parameters
59 * @param log class to log the test state and result
62 * @see TestParameters
63 * @see PrintWriter
66 protected void initialize( TestParameters tParam, PrintWriter log ) {
67 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
69 try {
70 oDoc = SOF.createTextDoc(null);
71 } catch ( com.sun.star.uno.Exception e ) {
72 // Some exception occures.FAILED
73 e.printStackTrace( log );
74 throw new StatusException( "Couldn?t create document", e );
78 /**
79 * in general this method disposes the testenvironment and document
81 * @param tParam class which contains additional test parameters
82 * @param log class to log the test state and result
85 * @see TestParameters
86 * @see PrintWriter
89 protected void cleanup( TestParameters tParam, PrintWriter log ) {
90 log.println( " disposing xTextDoc " );
91 util.DesktopTools.closeDoc(oDoc);
95 /**
96 * creating a Testenvironment for the interfaces to be tested
98 * @param tParam class which contains additional test parameters
99 * @param log class to log the test state and result
101 * @return Status class
103 * @see TestParameters
104 * @see PrintWriter
106 public TestEnvironment createTestEnvironment( TestParameters tParam,
107 PrintWriter log ) throws StatusException {
109 XInterface oObj = null;
111 // create testobject here
112 XTextCursor xCursor = oDoc.getText().createTextCursor();
113 try {
114 XMultiServiceFactory xMultiServiceFactory = (XMultiServiceFactory)
115 UnoRuntime.queryInterface(XMultiServiceFactory.class, oDoc);
116 Object o = xMultiServiceFactory.createInstance("com.sun.star.text.TextEmbeddedObject" );
117 XTextContent xTextContent = (XTextContent)UnoRuntime.queryInterface(XTextContent.class, o);
118 String sChartClassID = "12dcae26-281f-416f-a234-c3086127382e";
119 XPropertySet xPropertySet = (XPropertySet)
120 UnoRuntime.queryInterface(XPropertySet.class, xTextContent);
121 xPropertySet.setPropertyValue( "CLSID", sChartClassID );
123 oDoc.getText().insertTextContent( xCursor, xTextContent, false );
125 catch(com.sun.star.uno.Exception e) {
126 e.printStackTrace((java.io.PrintWriter)log);
129 XTextEmbeddedObjectsSupplier oTEOS = (XTextEmbeddedObjectsSupplier)
130 UnoRuntime.queryInterface(XTextEmbeddedObjectsSupplier.class, oDoc);
132 oObj = oTEOS.getEmbeddedObjects();
134 TestEnvironment tEnv = new TestEnvironment( oObj );
135 return tEnv;
137 } // finish method getTestEnvironment
139 } // finish class SwXTextEmbeddedObjects