Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextGraphicObjects.java
blob87982b31a5ab1024b970b88dc6a32eb51e4ac627
1 /*
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 .
19 package mod._sw;
21 import java.io.PrintWriter;
23 import lib.TestCase;
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;
46 /**
47 * in general this method creates a testdocument
49 * @param tParam
50 * class which contains additional test parameters
51 * @param log
52 * class to log the test state and result
55 * @see TestParameters
56 * @see PrintWriter
59 @Override
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);
66 /**
67 * in general this method disposes the testenvironment and document
69 * @param tParam
70 * class which contains additional test parameters
71 * @param log
72 * class to log the test state and result
75 * @see TestParameters
76 * @see PrintWriter
79 @Override
80 protected void cleanup(TestParameters tParam, PrintWriter log) {
81 log.println(" disposing xTextDoc ");
82 util.DesktopTools.closeDoc(xTextDoc);
85 /**
86 * creating a TestEnvironment for the interfaces to be tested
88 * @param tParam
89 * class which contains additional test parameters
90 * @param log
91 * class to log the test state and result
93 * @return Status class
95 * @see TestParameters
96 * @see PrintWriter
98 @Override
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,
136 oObj);
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);
149 return tEnv;
151 } // finish method getTestEnvironment
153 } // finish class SwXTextGraphicObjects