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 java
.io
.PrintWriter
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
28 import com
.sun
.star
.beans
.XPropertySet
;
29 import com
.sun
.star
.beans
.PropertyValue
;
30 import com
.sun
.star
.lang
.XMultiServiceFactory
;
31 import com
.sun
.star
.text
.TextContentAnchorType
;
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
.graphic
.XGraphic
;
37 import com
.sun
.star
.graphic
.XGraphicProvider
;
38 import com
.sun
.star
.uno
.UnoRuntime
;
39 import com
.sun
.star
.uno
.XInterface
;
40 import com
.sun
.star
.uno
.XComponentContext
;
42 public class SwXTextGraphicObject
extends TestCase
{
44 XTextDocument xTextDoc
;
47 * in general this method creates a testdocument
50 * class which contains additional test parameters
52 * class to log the test state and result
60 protected void initialize(TestParameters tParam
, PrintWriter log
) throws Exception
{
61 SOfficeFactory SOF
= SOfficeFactory
.getFactory(tParam
.getMSF());
62 log
.println("creating a textdoc");
63 xTextDoc
= SOF
.createTextDoc(null);
67 * in general this method disposes the testenvironment and document
70 * class which contains additional test parameters
72 * class to log the test state and result
80 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
81 log
.println(" disposing xDrawDoc ");
82 util
.DesktopTools
.closeDoc(xTextDoc
);
86 * Creating a TestEnvironment for the interfaces to be tested
89 * class which contains additional test parameters
91 * class to log the test state and result
93 * @return Status class
99 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
100 PrintWriter log
) throws Exception
{
102 XInterface oObj
= null;
103 Object oGObject
= null;
104 Object xTextFrame
= null;
105 SOfficeFactory SOF
= SOfficeFactory
.getFactory(tParam
.getMSF());
107 Object instance
= null;
109 oGObject
= SOF
.createInstance(xTextDoc
,
110 "com.sun.star.text.GraphicObject");
111 instance
= SOF
.createInstance(xTextDoc
,
112 "com.sun.star.text.GraphicObject");
113 xTextFrame
= SOfficeFactory
.createTextFrame(xTextDoc
, 500, 500);
115 oObj
= (XInterface
) oGObject
;
117 XText the_text
= xTextDoc
.getText();
118 XTextCursor the_cursor
= the_text
.createTextCursor();
119 XTextContent the_content
= UnoRuntime
.queryInterface(
120 XTextContent
.class, oObj
);
122 log
.println("inserting Frame");
123 XTextContent Framecontent
= UnoRuntime
.queryInterface(
124 XTextContent
.class, xTextFrame
);
125 the_text
.insertTextContent(the_cursor
, Framecontent
, true);
127 log
.println("inserting graphic");
128 the_text
.insertTextContent(the_cursor
, the_content
, true);
130 log
.println("adding graphic");
132 XComponentContext xContext
= tParam
.getComponentContext();
134 XGraphicProvider xGraphicProvider
= UnoRuntime
.queryInterface(XGraphicProvider
.class,
135 xContext
.getServiceManager().createInstanceWithContext("com.sun.star.graphic.GraphicProvider", xContext
));
137 String fullURL
= util
.utils
.getFullTestURL("space-metal.jpg");
139 PropertyValue
[] aMediaProps
= new PropertyValue
[] { new PropertyValue() };
140 aMediaProps
[0].Name
= "URL";
141 aMediaProps
[0].Value
= fullURL
;
143 XGraphic xGraphic
= UnoRuntime
.queryInterface(XGraphic
.class,
144 xGraphicProvider
.queryGraphic(aMediaProps
));
146 XPropertySet oProps
= UnoRuntime
.queryInterface(XPropertySet
.class,
149 oProps
.setPropertyValue("AnchorType", TextContentAnchorType
.AT_PARAGRAPH
);
150 oProps
.setPropertyValue("Graphic", xGraphic
);
151 oProps
.setPropertyValue("HoriOrientPosition", Integer
.valueOf(5500));
152 oProps
.setPropertyValue("VertOrientPosition", Integer
.valueOf(4200));
153 oProps
.setPropertyValue("Width", Integer
.valueOf(4400));
154 oProps
.setPropertyValue("Height", Integer
.valueOf(4000));
156 TestEnvironment tEnv
= new TestEnvironment(oObj
);
158 log
.println("adding ObjRelation for XShape "
159 + "(get/setPosition won't work there)");
160 tEnv
.addObjRelation("NoPos", "SwXTextGraphicObject");
161 tEnv
.addObjRelation("NoSetSize", "SwXTextGraphicObject");
162 Object ImgMap
= null;
163 // creating ObjectRelation for the property
164 // 'ImageMap' of 'TextGraphicObject'
166 XMultiServiceFactory xDocMSF
= UnoRuntime
.queryInterface(
167 XMultiServiceFactory
.class, xTextDoc
);
169 .createInstance("com.sun.star.image.ImageMapRectangleObject");
170 } catch (Exception ex
) {
171 ex
.printStackTrace();
174 tEnv
.addObjRelation("IMGMAP", ImgMap
);
176 tEnv
.addObjRelation("CONTENT",
177 UnoRuntime
.queryInterface(XTextContent
.class, instance
));
178 tEnv
.addObjRelation("RANGE", xTextDoc
.getText().createTextCursor());
180 // object relation for text.BaseFrameProperties
181 tEnv
.addObjRelation("TextFrame", xTextFrame
);
185 } // finish method getTestEnvironment
187 } // finish class SwXTextGraphicObject