merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / SwXTextFrame.java
blobd0e802eaf5cbb56440277b013d766502fd622ea1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXTextFrame.java,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package mod._sw;
32 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
38 import util.SOfficeFactory;
40 import com.sun.star.beans.XPropertySet;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.text.TextContentAnchorType;
43 import com.sun.star.text.XText;
44 import com.sun.star.text.XTextContent;
45 import com.sun.star.text.XTextCursor;
46 import com.sun.star.text.XTextDocument;
47 import com.sun.star.text.XTextFrame;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
52 /**
54 * initial description
55 * @see com.sun.star.text.XText
58 public class SwXTextFrame extends TestCase {
59 XTextDocument xTextDoc;
61 protected void initialize(TestParameters tParam, PrintWriter log) {
62 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF());
64 try {
65 log.println("creating a textdocument");
66 xTextDoc = SOF.createTextDoc(null);
67 } catch (com.sun.star.uno.Exception e) {
68 // Some exception occures.FAILED
69 e.printStackTrace(log);
70 throw new StatusException("Couldn't create document", e);
74 protected void cleanup(TestParameters tParam, PrintWriter log) {
75 log.println(" disposing xTextDoc ");
76 util.DesktopTools.closeDoc(xTextDoc);
79 /**
80 * creating a Testenvironment for the interfaces to be tested
82 public synchronized TestEnvironment createTestEnvironment(TestParameters Param,
83 PrintWriter log) {
84 XInterface oObj = null;
85 XTextFrame oFrame1 = null;
86 XTextFrame oFrame2 = null;
87 XPropertySet oPropSet = null;
88 XText oText = null;
89 XTextCursor oCursor = null;
92 // creation of testobject here
93 // first we write what we are intend to do to log file
94 log.println("creating a test environment");
96 // get a soffice factory object
97 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) Param.getMSF());
100 // creating Frames
101 log.println("creating Frames");
104 Object instance = null;
106 try {
107 oFrame1 = SOF.createTextFrame(xTextDoc, 500, 500);
108 oFrame2 = SOF.createTextFrame(xTextDoc, 1500, 1500);
109 oPropSet = (XPropertySet) UnoRuntime.queryInterface(
110 XPropertySet.class, oFrame1);
113 // AnchorTypes: 0 = paragraph, 1 = as char, 2 = page,
114 // 3 = frame/paragraph 4= at char
115 oPropSet.setPropertyValue("AnchorType",
116 TextContentAnchorType.AS_CHARACTER);
117 oText = xTextDoc.getText();
118 oCursor = oText.createTextCursor();
120 log.println("inserting Frame1");
122 XTextContent the_content = (XTextContent) UnoRuntime.queryInterface(
123 XTextContent.class, oFrame1);
124 oText.insertTextContent(oCursor, the_content, true);
126 log.println("inserting Frame2");
127 the_content = (XTextContent) UnoRuntime.queryInterface(
128 XTextContent.class, oFrame2);
129 oText.insertTextContent(oCursor, the_content, true);
131 XText oFrameText = oFrame1.getText();
132 oFrameText.insertString(oFrameText.getStart(), "The FrameText",
133 true);
135 instance = SOF.createInstance(xTextDoc,
136 "com.sun.star.text.TextFrame");
137 } catch (Exception Ex) {
138 Ex.printStackTrace(log);
139 throw new StatusException("Couldn't insert TextFrame ", Ex);
142 oObj = oFrame1;
144 log.println("creating a new environment for TextFrame object");
146 TestEnvironment tEnv = new TestEnvironment(oObj);
148 tEnv.addObjRelation("CONTENT",
149 (XTextContent) UnoRuntime.queryInterface(
150 XTextContent.class, instance));
151 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
153 log.println("adding ObjRelation for XShape " +
154 "(get/setPosition won't work there)");
155 tEnv.addObjRelation("NoPos", "SwXTextFrame");
156 tEnv.addObjRelation("NoSetSize", "SwXTextFrame");
158 tEnv.addObjRelation("TextFrame", oFrame2);
160 return tEnv;
161 } // finish method getTestEnvironment
162 } // finish class SwXTextFrame