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
55 protected void initialize( TestParameters tParam
, PrintWriter log
) {
56 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
59 oDoc
= SOF
.createTextDoc(null);
60 } catch ( com
.sun
.star
.uno
.Exception e
) {
61 // Some exception occurs.FAILED
62 e
.printStackTrace( log
);
63 throw new StatusException( "Couldn?t create document", e
);
68 * in general this method disposes the testenvironment and document
70 * @param tParam class which contains additional test parameters
71 * @param log class to log the test state and result
79 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
80 log
.println( " disposing xTextDoc " );
81 util
.DesktopTools
.closeDoc(oDoc
);
86 * creating a Testenvironment for the interfaces to be tested
88 * @param tParam class which contains additional test parameters
89 * @param log class to log the test state and result
91 * @return Status class
97 public TestEnvironment
createTestEnvironment( TestParameters tParam
,
98 PrintWriter log
) throws StatusException
{
100 XInterface oObj
= null;
102 // create testobject here
103 XTextCursor xCursor
= oDoc
.getText().createTextCursor();
105 XMultiServiceFactory xMultiServiceFactory
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, oDoc
);
106 Object o
= xMultiServiceFactory
.createInstance("com.sun.star.text.TextEmbeddedObject" );
107 XTextContent xTextContent
= UnoRuntime
.queryInterface(XTextContent
.class, o
);
108 String sChartClassID
= "12dcae26-281f-416f-a234-c3086127382e";
109 XPropertySet xPropertySet
= UnoRuntime
.queryInterface(XPropertySet
.class, xTextContent
);
110 xPropertySet
.setPropertyValue( "CLSID", sChartClassID
);
112 oDoc
.getText().insertTextContent( xCursor
, xTextContent
, false );
114 catch(com
.sun
.star
.uno
.Exception e
) {
115 e
.printStackTrace(log
);
118 XTextEmbeddedObjectsSupplier oTEOS
= UnoRuntime
.queryInterface(XTextEmbeddedObjectsSupplier
.class, oDoc
);
120 oObj
= oTEOS
.getEmbeddedObjects();
122 TestEnvironment tEnv
= new TestEnvironment( oObj
);
125 } // finish method getTestEnvironment
127 } // finish class SwXTextEmbeddedObjects