1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package mod._sw;
24 
25 import java.io.PrintWriter;
26 
27 import lib.StatusException;
28 import lib.TestCase;
29 import lib.TestEnvironment;
30 import lib.TestParameters;
31 import util.SOfficeFactory;
32 
33 import com.sun.star.beans.XPropertySet;
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.text.TextContentAnchorType;
36 import com.sun.star.text.XText;
37 import com.sun.star.text.XTextContent;
38 import com.sun.star.text.XTextCursor;
39 import com.sun.star.text.XTextDocument;
40 import com.sun.star.text.XTextFrame;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
43 
44 
45 /**
46  *
47  * initial description
48  * @see com.sun.star.text.XText
49  *
50  */
51 public class SwXTextFrame extends TestCase {
52     XTextDocument xTextDoc;
53 
initialize(TestParameters tParam, PrintWriter log)54     protected void initialize(TestParameters tParam, PrintWriter log) {
55         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF());
56 
57         try {
58             log.println("creating a textdocument");
59             xTextDoc = SOF.createTextDoc(null);
60         } catch (com.sun.star.uno.Exception e) {
61             // Some exception occured.FAILED
62             e.printStackTrace(log);
63             throw new StatusException("Couldn't create document", e);
64         }
65     }
66 
cleanup(TestParameters tParam, PrintWriter log)67     protected void cleanup(TestParameters tParam, PrintWriter log) {
68         log.println("    disposing xTextDoc ");
69         util.DesktopTools.closeDoc(xTextDoc);
70     }
71 
72     /**
73      *    creating a Testenvironment for the interfaces to be tested
74      */
createTestEnvironment(TestParameters Param, PrintWriter log)75     public synchronized TestEnvironment createTestEnvironment(TestParameters Param,
76                                                               PrintWriter log) {
77         XInterface oObj = null;
78         XTextFrame oFrame1 = null;
79         XTextFrame oFrame2 = null;
80         XPropertySet oPropSet = null;
81         XText oText = null;
82         XTextCursor oCursor = null;
83 
84 
85         // creation of testobject here
86         // first we write what we are intend to do to log file
87         log.println("creating a test environment");
88 
89         // get a soffice factory object
90         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) Param.getMSF());
91 
92 
93         // creating Frames
94         log.println("creating Frames");
95 
96 
97         Object instance = null;
98 
99         try {
100             oFrame1 = SOF.createTextFrame(xTextDoc, 500, 500);
101             oFrame2 = SOF.createTextFrame(xTextDoc, 1500, 1500);
102             oPropSet = (XPropertySet) UnoRuntime.queryInterface(
103                                XPropertySet.class, oFrame1);
104 
105 
106             // AnchorTypes: 0 = paragraph, 1 = as char, 2 = page,
107             // 3 = frame/paragraph 4= at char
108             oPropSet.setPropertyValue("AnchorType",
109                                       TextContentAnchorType.AS_CHARACTER);
110             oText = xTextDoc.getText();
111             oCursor = oText.createTextCursor();
112 
113             log.println("inserting Frame1");
114 
115             XTextContent the_content = (XTextContent) UnoRuntime.queryInterface(
116                                                XTextContent.class, oFrame1);
117             oText.insertTextContent(oCursor, the_content, true);
118 
119             log.println("inserting Frame2");
120             the_content = (XTextContent) UnoRuntime.queryInterface(
121                                   XTextContent.class, oFrame2);
122             oText.insertTextContent(oCursor, the_content, true);
123 
124             XText oFrameText = oFrame1.getText();
125             oFrameText.insertString(oFrameText.getStart(), "The FrameText",
126                                     true);
127 
128             instance = SOF.createInstance(xTextDoc,
129                                           "com.sun.star.text.TextFrame");
130         } catch (Exception Ex) {
131             Ex.printStackTrace(log);
132             throw new StatusException("Couldn't insert TextFrame ", Ex);
133         }
134 
135         oObj = oFrame1;
136 
137         log.println("creating a new environment for TextFrame object");
138 
139         TestEnvironment tEnv = new TestEnvironment(oObj);
140 
141         tEnv.addObjRelation("CONTENT",
142                             (XTextContent) UnoRuntime.queryInterface(
143                                     XTextContent.class, instance));
144         tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
145 
146         log.println("adding ObjRelation for XShape " +
147                     "(get/setPosition won't work there)");
148         tEnv.addObjRelation("NoPos", "SwXTextFrame");
149         tEnv.addObjRelation("NoSetSize", "SwXTextFrame");
150 
151         tEnv.addObjRelation("TextFrame", oFrame2);
152 
153         return tEnv;
154     } // finish method getTestEnvironment
155 } // finish class SwXTextFrame
156