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
.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
.graphic
.XGraphic
;
36 import com
.sun
.star
.graphic
.XGraphicProvider
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.uno
.XInterface
;
39 import com
.sun
.star
.uno
.XComponentContext
;
41 public class SwXTextGraphicObjects
extends TestCase
{
43 XTextDocument xTextDoc
;
46 * in general this method creates a testdocument
49 * class which contains additional test parameters
51 * class to log the test state and result
59 protected void initialize(TestParameters tParam
, PrintWriter log
) throws Exception
{
60 SOfficeFactory SOF
= SOfficeFactory
.getFactory(tParam
.getMSF());
61 log
.println("creating a textdoc");
62 xTextDoc
= SOF
.createTextDoc(null);
66 * in general this method disposes the testenvironment and document
69 * class which contains additional test parameters
71 * class to log the test state and result
79 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
80 log
.println(" disposing xTextDoc ");
81 util
.DesktopTools
.closeDoc(xTextDoc
);
85 * creating a TestEnvironment for the interfaces to be tested
88 * class which contains additional test parameters
90 * class to log the test state and result
92 * @return Status class
98 public TestEnvironment
createTestEnvironment(TestParameters tParam
,
99 PrintWriter log
) throws Exception
{
101 XInterface oObj
= null;
102 Object oGObject
= null;
103 SOfficeFactory SOF
= SOfficeFactory
.getFactory(tParam
.getMSF());
105 oGObject
= SOF
.createInstance(xTextDoc
,
106 "com.sun.star.text.GraphicObject");
108 oObj
= (XInterface
) oGObject
;
110 XText the_text
= xTextDoc
.getText();
111 XTextCursor the_cursor
= the_text
.createTextCursor();
112 XTextContent the_content
= UnoRuntime
.queryInterface(
113 XTextContent
.class, oObj
);
115 log
.println("inserting graphic");
116 the_text
.insertTextContent(the_cursor
, the_content
, true);
118 log
.println("adding graphic");
120 XComponentContext xContext
= tParam
.getComponentContext();
122 XGraphicProvider xGraphicProvider
= UnoRuntime
.queryInterface(XGraphicProvider
.class,
123 xContext
.getServiceManager().createInstanceWithContext("com.sun.star.graphic.GraphicProvider", xContext
));
125 String fullURL
= util
.utils
.getFullTestURL("space-metal.jpg");
127 PropertyValue
[] aMediaProps
= new PropertyValue
[] { new PropertyValue() };
128 aMediaProps
[0].Name
= "URL";
129 aMediaProps
[0].Value
= fullURL
;
131 XGraphic xGraphic
= UnoRuntime
.queryInterface(XGraphic
.class,
132 xGraphicProvider
.queryGraphic(aMediaProps
));
134 XPropertySet oProps
= UnoRuntime
.queryInterface(XPropertySet
.class,
136 oProps
.setPropertyValue("Graphic", xGraphic
);
137 oProps
.setPropertyValue("HoriOrientPosition", Integer
.valueOf(5500));
138 oProps
.setPropertyValue("VertOrientPosition", Integer
.valueOf(4200));
139 oProps
.setPropertyValue("Width", Integer
.valueOf(4400));
140 oProps
.setPropertyValue("Height", Integer
.valueOf(4000));
142 XTextGraphicObjectsSupplier xTGS
= UnoRuntime
.queryInterface(
143 XTextGraphicObjectsSupplier
.class, xTextDoc
);
144 oObj
= xTGS
.getGraphicObjects();
146 TestEnvironment tEnv
= new TestEnvironment(oObj
);
150 } // finish method getTestEnvironment
152 } // finish class SwXTextGraphicObjects