2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import com
.sun
.star
.beans
.XPropertySet
;
22 import java
.io
.PrintWriter
;
24 import lib
.StatusException
;
26 import lib
.TestEnvironment
;
27 import lib
.TestParameters
;
28 import util
.SOfficeFactory
;
30 import com
.sun
.star
.lang
.XMultiServiceFactory
;
31 import com
.sun
.star
.text
.XTextContent
;
32 import com
.sun
.star
.text
.XTextCursor
;
33 import com
.sun
.star
.text
.XTextDocument
;
34 import com
.sun
.star
.text
.XTextEmbeddedObjectsSupplier
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import com
.sun
.star
.uno
.XInterface
;
39 public class SwXTextEmbeddedObjects
extends TestCase
{
44 * in general this method creates a testdocument
46 * @param tParam class which contains additional test parameters
47 * @param log class to log the test state and result
54 protected void initialize( TestParameters tParam
, PrintWriter log
) {
55 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
58 oDoc
= SOF
.createTextDoc(null);
59 } catch ( com
.sun
.star
.uno
.Exception e
) {
60 // Some exception occurs.FAILED
61 e
.printStackTrace( log
);
62 throw new StatusException( "Couldn?t create document", e
);
67 * in general this method disposes the testenvironment and document
69 * @param tParam class which contains additional test parameters
70 * @param log class to log the test state and result
77 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
78 log
.println( " disposing xTextDoc " );
79 util
.DesktopTools
.closeDoc(oDoc
);
84 * creating a Testenvironment for the interfaces to be tested
86 * @param tParam class which contains additional test parameters
87 * @param log class to log the test state and result
89 * @return Status class
94 public TestEnvironment
createTestEnvironment( TestParameters tParam
,
95 PrintWriter log
) throws StatusException
{
97 XInterface oObj
= null;
99 // create testobject here
100 XTextCursor xCursor
= oDoc
.getText().createTextCursor();
102 XMultiServiceFactory xMultiServiceFactory
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, oDoc
);
103 Object o
= xMultiServiceFactory
.createInstance("com.sun.star.text.TextEmbeddedObject" );
104 XTextContent xTextContent
= UnoRuntime
.queryInterface(XTextContent
.class, o
);
105 String sChartClassID
= "12dcae26-281f-416f-a234-c3086127382e";
106 XPropertySet xPropertySet
= UnoRuntime
.queryInterface(XPropertySet
.class, xTextContent
);
107 xPropertySet
.setPropertyValue( "CLSID", sChartClassID
);
109 oDoc
.getText().insertTextContent( xCursor
, xTextContent
, false );
111 catch(com
.sun
.star
.uno
.Exception e
) {
112 e
.printStackTrace(log
);
115 XTextEmbeddedObjectsSupplier oTEOS
= UnoRuntime
.queryInterface(XTextEmbeddedObjectsSupplier
.class, oDoc
);
117 oObj
= oTEOS
.getEmbeddedObjects();
119 TestEnvironment tEnv
= new TestEnvironment( oObj
);
122 } // finish method getTestEnvironment
124 } // finish class SwXTextEmbeddedObjects