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 .
20 import com
.sun
.star
.beans
.XPropertySet
;
22 import java
.io
.PrintWriter
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.container
.XIndexAccess
;
30 import com
.sun
.star
.container
.XNameAccess
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.text
.XText
;
33 import com
.sun
.star
.text
.XTextContent
;
34 import com
.sun
.star
.text
.XTextCursor
;
35 import com
.sun
.star
.text
.XTextDocument
;
36 import com
.sun
.star
.text
.XTextEmbeddedObjectsSupplier
;
37 import com
.sun
.star
.text
.XTextFrame
;
38 import com
.sun
.star
.uno
.AnyConverter
;
39 import com
.sun
.star
.uno
.Type
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
42 import com
.sun
.star
.util
.XCloseable
;
48 * @see com.sun.star.container.XNamed
49 * @see com.sun.star.document.XEmbeddedObjectSupplier
50 * @see com.sun.star.lang.XComponent
51 * @see com.sun.star.text.TextEmbeddedObject
52 * @see com.sun.star.text.XTextContent
55 public class SwXTextEmbeddedObject
extends TestCase
{
56 XTextDocument xTextDoc
;
59 * in general this method disposes the testenvironment and document
61 * @param tParam class which contains additional test parameters
62 * @param log class to log the test state and result
70 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
71 log
.println(" disposing xTextDoc ");
74 XCloseable closer
= UnoRuntime
.queryInterface(
75 XCloseable
.class, xTextDoc
);
77 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
78 log
.println("couldn't close document");
79 } catch (com
.sun
.star
.lang
.DisposedException e
) {
80 log
.println("couldn't close document");
85 * creating a TestEnvironment for the interfaces to be tested
87 * @param tParam class which contains additional test parameters
88 * @param log class to log the test state and result
90 * @return Status class
96 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
97 PrintWriter log
) throws Exception
{
98 XInterface oObj
= null;
100 // create testobject here
101 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
102 xTextDoc
= SOF
.createTextDoc(null);
104 XTextCursor xCursor
= xTextDoc
.getText().createTextCursor();
106 XMultiServiceFactory xMultiServiceFactory
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
107 Object o
= xMultiServiceFactory
.createInstance("com.sun.star.text.TextEmbeddedObject" );
108 XTextContent xTextContent
= UnoRuntime
.queryInterface(XTextContent
.class, o
);
109 String sChartClassID
= "12dcae26-281f-416f-a234-c3086127382e";
110 XPropertySet xPropertySet
= UnoRuntime
.queryInterface(XPropertySet
.class, xTextContent
);
111 xPropertySet
.setPropertyValue( "CLSID", sChartClassID
);
113 xTextDoc
.getText().insertTextContent( xCursor
, xTextContent
, false );
115 catch(com
.sun
.star
.uno
.Exception e
) {
116 e
.printStackTrace(log
);
119 XTextEmbeddedObjectsSupplier oTEOS
= UnoRuntime
.queryInterface(
120 XTextEmbeddedObjectsSupplier
.class,
123 XNameAccess oEmObj
= oTEOS
.getEmbeddedObjects();
124 XIndexAccess oEmIn
= UnoRuntime
.queryInterface(
125 XIndexAccess
.class, oEmObj
);
127 oObj
= (XInterface
) AnyConverter
.toObject(
128 new Type(XInterface
.class), oEmIn
.getByIndex(0));
130 TestEnvironment tEnv
= new TestEnvironment(oObj
);
132 tEnv
.addObjRelation("NoAttach", "SwXTextEmbeddedObject");
134 XTextFrame aFrame
= SOfficeFactory
.createTextFrame(xTextDoc
, 500, 500);
135 XText oText
= xTextDoc
.getText();
136 XTextCursor oCursor
= oText
.createTextCursor();
137 XTextContent the_content
= UnoRuntime
.queryInterface(
138 XTextContent
.class, aFrame
);
141 oText
.insertTextContent(oCursor
, the_content
, true);
142 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
143 log
.println("Couldn't insert frame " + e
.getMessage());
146 tEnv
.addObjRelation("TextFrame", aFrame
);
148 tEnv
.addObjRelation("NoSetSize", "SwXTextEmbeddedObject");
149 tEnv
.addObjRelation("NoPos", "SwXTextEmbeddedObject");
152 } // finish method getTestEnvironment
153 } // finish class SwXTextEmbeddedObject