bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextGraphicObjects.java
blobb4897fa824697cd127402d51c364ceb447453513
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.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.text.XText;
32 import com.sun.star.text.XTextContent;
33 import com.sun.star.text.XTextCursor;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.text.XTextGraphicObjectsSupplier;
36 import com.sun.star.uno.UnoRuntime;
37 import com.sun.star.uno.XInterface;
39 public class SwXTextGraphicObjects extends TestCase {
41 XTextDocument xTextDoc;
43 /**
44 * in general this method creates a testdocument
46 * @param tParam class which contains additional test parameters
47 * @param log class to log the test state and result
50 * @see TestParameters
51 * @see PrintWriter
54 protected void initialize( TestParameters tParam, PrintWriter log ) {
55 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
56 try {
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 );
66 /**
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
73 * @see TestParameters
74 * @see PrintWriter
77 protected void cleanup( TestParameters tParam, PrintWriter log ) {
78 log.println( " disposing xTextDoc " );
79 util.DesktopTools.closeDoc(xTextDoc);
83 /**
84 * creating a Testenvironment for the interfaces to be tested
86 * @param tParam class which contains additional test parameters
87 * @param log class to log the test state and result
89 * @return Status class
91 * @see TestParameters
92 * @see PrintWriter
94 public TestEnvironment createTestEnvironment( TestParameters tParam,
95 PrintWriter log )
96 throws StatusException {
98 XInterface oObj = null;
99 Object oGObject = null;
100 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
102 try {
103 oGObject = SOF.createInstance
104 (xTextDoc,"com.sun.star.text.GraphicObject");
106 catch (Exception ex) {
107 log.println("Couldn't create instance");
108 ex.printStackTrace(log);
109 throw new StatusException("Couldn't create instance", ex );
112 oObj = (XInterface) oGObject;
114 XText the_text = xTextDoc.getText();
115 XTextCursor the_cursor = the_text.createTextCursor();
116 XTextContent the_content = UnoRuntime.queryInterface(XTextContent.class,oObj);
118 log.println( "inserting graphic" );
119 try {
120 the_text.insertTextContent(the_cursor,the_content,true);
121 } catch (Exception e) {
122 System.out.println("Couldn't insert Content");
123 e.printStackTrace();
124 throw new StatusException("Couldn't insert Content", e );
127 log.println( "adding graphic" );
128 XPropertySet oProps = UnoRuntime.queryInterface(XPropertySet.class,oObj);
129 try {
130 String wat = util.utils.getFullTestURL("space-metal.jpg");
131 oProps.setPropertyValue("GraphicURL",wat);
132 oProps.setPropertyValue("HoriOrientPosition",new Integer(5500));
133 oProps.setPropertyValue("VertOrientPosition",new Integer(4200));
134 oProps.setPropertyValue("Width",new Integer(4400));
135 oProps.setPropertyValue("Height",new Integer(4000));
136 } catch (Exception e) {
137 System.out.println("Couldn't set property 'GraphicURL'");
138 e.printStackTrace();
139 throw new StatusException("Couldn't set property 'GraphicURL'", e );
142 XTextGraphicObjectsSupplier xTGS = UnoRuntime.queryInterface(XTextGraphicObjectsSupplier.class,
143 xTextDoc);
144 oObj = xTGS.getGraphicObjects();
146 TestEnvironment tEnv = new TestEnvironment( oObj );
148 return tEnv;
150 } // finish method getTestEnvironment
152 } // finish class SwXTextGraphicObjects