1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXTextGraphicObjects.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.beans
.XPropertySet
;
42 import com
.sun
.star
.lang
.XMultiServiceFactory
;
43 import com
.sun
.star
.text
.XText
;
44 import com
.sun
.star
.text
.XTextContent
;
45 import com
.sun
.star
.text
.XTextCursor
;
46 import com
.sun
.star
.text
.XTextDocument
;
47 import com
.sun
.star
.text
.XTextGraphicObjectsSupplier
;
48 import com
.sun
.star
.uno
.UnoRuntime
;
49 import com
.sun
.star
.uno
.XInterface
;
51 public class SwXTextGraphicObjects
extends TestCase
{
53 XTextDocument xTextDoc
;
56 * in general this method creates a testdocument
58 * @param tParam class which contains additional test parameters
59 * @param log class to log the test state and result
66 protected void initialize( TestParameters tParam
, PrintWriter log
) {
67 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
69 log
.println( "creating a textdoc" );
70 xTextDoc
= SOF
.createTextDoc( null );;
71 } catch ( Exception e
) {
72 // Some exception occures.FAILED
73 e
.printStackTrace( log
);
74 throw new StatusException( "Couldn't create document", e
);
79 * in general this method disposes the testenvironment and document
81 * @param tParam class which contains additional test parameters
82 * @param log class to log the test state and result
89 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
90 log
.println( " disposing xTextDoc " );
91 util
.DesktopTools
.closeDoc(xTextDoc
);
96 * creating a Testenvironment for the interfaces to be tested
98 * @param tParam class which contains additional test parameters
99 * @param log class to log the test state and result
101 * @return Status class
103 * @see TestParameters
106 public TestEnvironment
createTestEnvironment( TestParameters tParam
,
108 throws StatusException
{
110 XInterface oObj
= null;
111 Object oGObject
= null;
112 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
115 oGObject
= SOF
.createInstance
116 (xTextDoc
,"com.sun.star.text.GraphicObject");
118 catch (Exception ex
) {
119 log
.println("Couldn't create instance");
120 ex
.printStackTrace(log
);
121 throw new StatusException("Couldn't create instance", ex
);
124 oObj
= (XInterface
) oGObject
;
126 XText the_text
= xTextDoc
.getText();
127 XTextCursor the_cursor
= the_text
.createTextCursor();
128 XTextContent the_content
= (XTextContent
)
129 UnoRuntime
.queryInterface(XTextContent
.class,oObj
);
131 log
.println( "inserting graphic" );
133 the_text
.insertTextContent(the_cursor
,the_content
,true);
134 } catch (Exception e
) {
135 System
.out
.println("Couldn't insert Content");
137 throw new StatusException("Couldn't insert Content", e
);
140 log
.println( "adding graphic" );
141 XPropertySet oProps
= (XPropertySet
)
142 UnoRuntime
.queryInterface(XPropertySet
.class,oObj
);
144 String wat
= util
.utils
.getFullTestURL("space-metal.jpg");
145 oProps
.setPropertyValue("GraphicURL",wat
);
146 oProps
.setPropertyValue("HoriOrientPosition",new Integer(5500));
147 oProps
.setPropertyValue("VertOrientPosition",new Integer(4200));
148 oProps
.setPropertyValue("Width",new Integer(4400));
149 oProps
.setPropertyValue("Height",new Integer(4000));
150 } catch (Exception e
) {
151 System
.out
.println("Couldn't set property 'GraphicURL'");
153 throw new StatusException("Couldn't set property 'GraphicURL'", e
);
156 XTextGraphicObjectsSupplier xTGS
= (XTextGraphicObjectsSupplier
)
157 UnoRuntime
.queryInterface(XTextGraphicObjectsSupplier
.class,
159 oObj
= xTGS
.getGraphicObjects();
161 TestEnvironment tEnv
= new TestEnvironment( oObj
);
165 } // finish method getTestEnvironment
167 } // finish class SwXTextGraphicObjects