bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextEmbeddedObject.java
blobc4808493a4c9715975a54e463d6392e6a39b6150
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 .
18 package mod._sw;
20 import com.sun.star.beans.XPropertySet;
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.container.XIndexAccess;
30 import com.sun.star.container.XNameAccess;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.text.XText;
33 import com.sun.star.text.XTextContent;
34 import com.sun.star.text.XTextCursor;
35 import com.sun.star.text.XTextDocument;
36 import com.sun.star.text.XTextEmbeddedObjectsSupplier;
37 import com.sun.star.text.XTextFrame;
38 import com.sun.star.uno.AnyConverter;
39 import com.sun.star.uno.Type;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
42 import com.sun.star.util.XCloseable;
45 /**
47 * initial description
48 * @see com.sun.star.container.XNamed
49 * @see com.sun.star.document.XEmbeddedObjectSupplier
50 * @see com.sun.star.lang.XComponent
51 * @see com.sun.star.text.TextEmbeddedObject
52 * @see com.sun.star.text.XTextContent
55 public class SwXTextEmbeddedObject extends TestCase {
56 XTextDocument xTextDoc;
58 /**
59 * in general this method disposes the testenvironment and document
61 * @param tParam class which contains additional test parameters
62 * @param log class to log the test state and result
65 * @see TestParameters
66 * @see PrintWriter
69 protected void cleanup(TestParameters tParam, PrintWriter log) {
70 log.println(" disposing xTextDoc ");
72 try {
73 XCloseable closer = UnoRuntime.queryInterface(
74 XCloseable.class, xTextDoc);
75 closer.close(true);
76 } catch (com.sun.star.util.CloseVetoException e) {
77 log.println("couldn't close document");
78 } catch (com.sun.star.lang.DisposedException e) {
79 log.println("couldn't close document");
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 protected TestEnvironment createTestEnvironment(TestParameters tParam,
95 PrintWriter log) {
96 XInterface oObj = null;
98 // create testobject here
99 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF());
100 try {
101 xTextDoc = SOF.createTextDoc(null);
102 } catch (com.sun.star.uno.Exception e) {
103 e.printStackTrace(log);
104 throw new StatusException("Couldn't open document", e);
107 XTextCursor xCursor = xTextDoc.getText().createTextCursor();
108 try {
109 XMultiServiceFactory xMultiServiceFactory = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
110 Object o = xMultiServiceFactory.createInstance("com.sun.star.text.TextEmbeddedObject" );
111 XTextContent xTextContent = UnoRuntime.queryInterface(XTextContent.class, o);
112 String sChartClassID = "12dcae26-281f-416f-a234-c3086127382e";
113 XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xTextContent);
114 xPropertySet.setPropertyValue( "CLSID", sChartClassID );
116 xTextDoc.getText().insertTextContent( xCursor, xTextContent, false );
118 catch(com.sun.star.uno.Exception e) {
119 e.printStackTrace(log);
122 XTextEmbeddedObjectsSupplier oTEOS = UnoRuntime.queryInterface(
123 XTextEmbeddedObjectsSupplier.class,
124 xTextDoc);
126 XNameAccess oEmObj = oTEOS.getEmbeddedObjects();
127 XIndexAccess oEmIn = UnoRuntime.queryInterface(
128 XIndexAccess.class, oEmObj);
130 try {
131 oObj = (XInterface) AnyConverter.toObject(
132 new Type(XInterface.class), oEmIn.getByIndex(0));
133 } catch (com.sun.star.uno.Exception e) {
134 e.printStackTrace(log);
135 throw new StatusException("Couldn't get Object", e);
138 TestEnvironment tEnv = new TestEnvironment(oObj);
140 tEnv.addObjRelation("NoAttach", "SwXTextEmbeddedObject");
142 XTextFrame aFrame = SOfficeFactory.createTextFrame(xTextDoc, 500, 500);
143 XText oText = xTextDoc.getText();
144 XTextCursor oCursor = oText.createTextCursor();
145 XTextContent the_content = UnoRuntime.queryInterface(
146 XTextContent.class, aFrame);
148 try {
149 oText.insertTextContent(oCursor, the_content, true);
150 } catch (com.sun.star.lang.IllegalArgumentException e) {
151 log.println("Couldn't insert frame " + e.getMessage());
154 tEnv.addObjRelation("TextFrame", aFrame);
156 tEnv.addObjRelation("NoSetSize", "SwXTextEmbeddedObject");
157 tEnv.addObjRelation("NoPos", "SwXTextEmbeddedObject");
159 return tEnv;
160 } // finish method getTestEnvironment
161 } // finish class SwXTextEmbeddedObject