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