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
.graphic
.GraphicProvider
;
38 import com
.sun
.star
.uno
.UnoRuntime
;
39 import com
.sun
.star
.uno
.XInterface
;
40 import com
.sun
.star
.uno
.XComponentContext
;
42 public class SwXTextGraphicObjects
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 xTextDoc ");
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 public TestEnvironment
createTestEnvironment(TestParameters tParam
,
100 PrintWriter log
) throws Exception
{
102 XInterface oObj
= null;
103 Object oGObject
= null;
104 SOfficeFactory SOF
= SOfficeFactory
.getFactory(tParam
.getMSF());
106 oGObject
= SOF
.createInstance(xTextDoc
,
107 "com.sun.star.text.GraphicObject");
109 oObj
= (XInterface
) oGObject
;
111 XText the_text
= xTextDoc
.getText();
112 XTextCursor the_cursor
= the_text
.createTextCursor();
113 XTextContent the_content
= UnoRuntime
.queryInterface(
114 XTextContent
.class, oObj
);
116 log
.println("inserting graphic");
117 the_text
.insertTextContent(the_cursor
, the_content
, true);
119 log
.println("adding graphic");
121 XComponentContext xContext
= tParam
.getComponentContext();
123 XGraphicProvider xGraphicProvider
= UnoRuntime
.queryInterface(XGraphicProvider
.class,
124 xContext
.getServiceManager().createInstanceWithContext("com.sun.star.graphic.GraphicProvider", xContext
));
126 String fullURL
= util
.utils
.getFullTestURL("space-metal.jpg");
128 PropertyValue
[] aMediaProps
= new PropertyValue
[] { new PropertyValue() };
129 aMediaProps
[0].Name
= "URL";
130 aMediaProps
[0].Value
= fullURL
;
132 XGraphic xGraphic
= UnoRuntime
.queryInterface(XGraphic
.class,
133 xGraphicProvider
.queryGraphic(aMediaProps
));
135 XPropertySet oProps
= UnoRuntime
.queryInterface(XPropertySet
.class,
137 oProps
.setPropertyValue("Graphic", xGraphic
);
138 oProps
.setPropertyValue("HoriOrientPosition", Integer
.valueOf(5500));
139 oProps
.setPropertyValue("VertOrientPosition", Integer
.valueOf(4200));
140 oProps
.setPropertyValue("Width", Integer
.valueOf(4400));
141 oProps
.setPropertyValue("Height", Integer
.valueOf(4000));
143 XTextGraphicObjectsSupplier xTGS
= UnoRuntime
.queryInterface(
144 XTextGraphicObjectsSupplier
.class, xTextDoc
);
145 oObj
= xTGS
.getGraphicObjects();
147 TestEnvironment tEnv
= new TestEnvironment(oObj
);
151 } // finish method getTestEnvironment
153 } // finish class SwXTextGraphicObjects