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
.text
.XText
;
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
.XTextGraphicObjectsSupplier
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import com
.sun
.star
.uno
.XInterface
;
38 public class SwXTextGraphicObjects
extends TestCase
{
40 XTextDocument xTextDoc
;
43 * in general this method creates a testdocument
45 * @param tParam class which contains additional test parameters
46 * @param log class to log the test state and result
54 protected void initialize( TestParameters tParam
, PrintWriter log
) {
55 SOfficeFactory SOF
= SOfficeFactory
.getFactory( 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
78 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
79 log
.println( " disposing xTextDoc " );
80 util
.DesktopTools
.closeDoc(xTextDoc
);
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 public TestEnvironment
createTestEnvironment( TestParameters tParam
,
98 throws StatusException
{
100 XInterface oObj
= null;
101 Object oGObject
= null;
102 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
105 oGObject
= SOF
.createInstance
106 (xTextDoc
,"com.sun.star.text.GraphicObject");
108 catch (Exception ex
) {
109 log
.println("Couldn't create instance");
110 ex
.printStackTrace(log
);
111 throw new StatusException("Couldn't create instance", ex
);
114 oObj
= (XInterface
) oGObject
;
116 XText the_text
= xTextDoc
.getText();
117 XTextCursor the_cursor
= the_text
.createTextCursor();
118 XTextContent the_content
= UnoRuntime
.queryInterface(XTextContent
.class,oObj
);
120 log
.println( "inserting graphic" );
122 the_text
.insertTextContent(the_cursor
,the_content
,true);
123 } catch (Exception e
) {
124 System
.out
.println("Couldn't insert Content");
126 throw new StatusException("Couldn't insert Content", e
);
129 log
.println( "adding graphic" );
130 XPropertySet oProps
= UnoRuntime
.queryInterface(XPropertySet
.class,oObj
);
132 String wat
= util
.utils
.getFullTestURL("space-metal.jpg");
133 oProps
.setPropertyValue("GraphicURL",wat
);
134 oProps
.setPropertyValue("HoriOrientPosition",Integer
.valueOf(5500));
135 oProps
.setPropertyValue("VertOrientPosition",Integer
.valueOf(4200));
136 oProps
.setPropertyValue("Width",Integer
.valueOf(4400));
137 oProps
.setPropertyValue("Height",Integer
.valueOf(4000));
138 } catch (Exception e
) {
139 System
.out
.println("Couldn't set property 'GraphicURL'");
141 throw new StatusException("Couldn't set property 'GraphicURL'", e
);
144 XTextGraphicObjectsSupplier xTGS
= UnoRuntime
.queryInterface(XTextGraphicObjectsSupplier
.class,
146 oObj
= xTGS
.getGraphicObjects();
148 TestEnvironment tEnv
= new TestEnvironment( oObj
);
152 } // finish method getTestEnvironment
154 } // finish class SwXTextGraphicObjects