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
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.beans
.XPropertySet
;
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
.uno
.UnoRuntime
;
37 import com
.sun
.star
.uno
.XInterface
;
39 public class SwXTextGraphicObject
extends TestCase
{
41 XTextDocument xTextDoc
;
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() );
57 log
.println( "creating a textdoc" );
58 xTextDoc
= SOF
.createTextDoc( null );
59 } catch ( 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 xDrawDoc " );
79 util
.DesktopTools
.closeDoc(xTextDoc
);
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 protected TestEnvironment createTestEnvironment
95 (TestParameters tParam
, PrintWriter log
) {
97 XInterface oObj
= null;
98 Object oGObject
= null;
99 Object xTextFrame
= null;
100 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
102 Object instance
= null;
105 oGObject
= SOF
.createInstance
106 (xTextDoc
,"com.sun.star.text.GraphicObject");
107 instance
= SOF
.createInstance
108 (xTextDoc
,"com.sun.star.text.GraphicObject");
109 xTextFrame
= SOfficeFactory
.createTextFrame(xTextDoc
, 500, 500);
111 catch (Exception ex
) {
112 log
.println("Couldn't create instance");
113 ex
.printStackTrace(log
);
114 throw new StatusException("Couldn't create instance", ex
);
117 oObj
= (XInterface
) oGObject
;
119 XText the_text
= xTextDoc
.getText();
120 XTextCursor the_cursor
= the_text
.createTextCursor();
121 XTextContent the_content
= UnoRuntime
.queryInterface(XTextContent
.class,oObj
);
123 log
.println("inserting Frame");
125 XTextContent Framecontent
= UnoRuntime
.queryInterface(
126 XTextContent
.class, xTextFrame
);
127 the_text
.insertTextContent(the_cursor
, Framecontent
, true);
128 } catch (Exception e
) {
129 System
.out
.println("Couldn't insert text frame");
131 throw new StatusException("Couldn't insert text frame", e
);
135 log
.println( "inserting graphic" );
137 the_text
.insertTextContent(the_cursor
,the_content
,true);
138 } catch (Exception e
) {
139 System
.out
.println("Couldn't insert Content");
141 throw new StatusException("Couldn't insert Content", e
);
144 log
.println( "adding graphic" );
145 XPropertySet oProps
= UnoRuntime
.queryInterface(XPropertySet
.class,oObj
);
147 String wat
= util
.utils
.getFullTestURL("space-metal.jpg");
148 oProps
.setPropertyValue("AnchorType",
149 TextContentAnchorType
.AT_PARAGRAPH
);
150 oProps
.setPropertyValue("GraphicURL",wat
);
151 oProps
.setPropertyValue("HoriOrientPosition",new Integer(5500));
152 oProps
.setPropertyValue("VertOrientPosition",new Integer(4200));
153 oProps
.setPropertyValue("Width",new Integer(4400));
154 oProps
.setPropertyValue("Height",new Integer(4000));
155 } catch (Exception e
) {
156 System
.out
.println("Couldn't set property 'GraphicURL'");
158 throw new StatusException
159 ("Couldn't set property 'GraphicURL'", e
);
162 TestEnvironment tEnv
= new TestEnvironment( oObj
);
164 log
.println( "adding ObjRelation for XShape "
165 +"(get/setPosition won't work there)" );
166 tEnv
.addObjRelation("NoPos", "SwXTextGraphicObject");
167 tEnv
.addObjRelation("NoSetSize","SwXTextGraphicObject");
168 Object ImgMap
= null;
169 //creating ObjectRelation for the property
170 // 'ImageMap' of 'TextGraphicObject'
172 XMultiServiceFactory xDocMSF
= UnoRuntime
.queryInterface
173 (XMultiServiceFactory
.class,xTextDoc
);
174 ImgMap
= xDocMSF
.createInstance
175 ("com.sun.star.image.ImageMapRectangleObject");
177 catch (Exception ex
) {
178 ex
.printStackTrace();
181 tEnv
.addObjRelation("IMGMAP",ImgMap
);
183 tEnv
.addObjRelation("CONTENT", UnoRuntime
.queryInterface(XTextContent
.class,instance
));
184 tEnv
.addObjRelation("RANGE", xTextDoc
.getText().createTextCursor());
186 //object relation for text.BaseFrameProperties
187 tEnv
.addObjRelation("TextFrame", xTextFrame
);
191 } // finish method getTestEnvironment
193 } // finish class SwXTextGraphicObject