tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextGraphicObjects.java
blob4a0de3b0b8700ff032a6cae05f944bf8eae6a3f2
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.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;
45 /**
46 * in general this method creates a testdocument
48 * @param tParam
49 * class which contains additional test parameters
50 * @param log
51 * class to log the test state and result
54 * @see TestParameters
55 * @see PrintWriter
58 @Override
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);
65 /**
66 * in general this method disposes the testenvironment and document
68 * @param tParam
69 * class which contains additional test parameters
70 * @param log
71 * class to log the test state and result
74 * @see TestParameters
75 * @see PrintWriter
78 @Override
79 protected void cleanup(TestParameters tParam, PrintWriter log) {
80 log.println(" disposing xTextDoc ");
81 util.DesktopTools.closeDoc(xTextDoc);
84 /**
85 * creating a TestEnvironment for the interfaces to be tested
87 * @param tParam
88 * class which contains additional test parameters
89 * @param log
90 * class to log the test state and result
92 * @return Status class
94 * @see TestParameters
95 * @see PrintWriter
97 @Override
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,
135 oObj);
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);
148 return tEnv;
150 } // finish method getTestEnvironment
152 } // finish class SwXTextGraphicObjects