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 
24 package mod._fwk;
25 
26 import com.sun.star.beans.XPropertySet;
27 import com.sun.star.frame.XFrame;
28 import com.sun.star.lang.XMultiServiceFactory;
29 import com.sun.star.uno.UnoRuntime;
30 import com.sun.star.uno.XInterface;
31 import java.io.PrintWriter;
32 import com.sun.star.text.XText;
33 import com.sun.star.text.XTextCursor;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.util.XCloseable;
36 import lib.StatusException;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
40 import util.WriterTools;
41 
42 /**
43  */
44 public class LayoutManager extends TestCase {
45     XInterface xManager = null;
46     XTextDocument xTextDoc;
47 
48     /**
49      * Cleanup: close the created document
50      * @param tParam The test parameters.
51      * @param log The log writer.
52      */
cleanup(TestParameters tParam, PrintWriter log)53     protected void cleanup(TestParameters tParam, PrintWriter log) {
54         log.println("    disposing xTextDoc ");
55 
56         try {
57             XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
58             XCloseable.class, xTextDoc);
59             closer.close(true);
60         } catch (com.sun.star.util.CloseVetoException e) {
61             log.println("couldn't close document");
62         } catch (com.sun.star.lang.DisposedException e) {
63             log.println("couldn't close document");
64         }
65     }
66 
67     /**
68      * Create test environment:
69      * <ul>
70      * <li>Create test doc</li>
71      * <li>Get the frame</li>
72      * <li>Get the LayoutManager from the frame</li>
73      * </ul>
74      * @param tParam The test parameters.
75      * @param log The log writer.
76      * @return The test environment.
77      */
createTestEnvironment(TestParameters tParam, PrintWriter log)78     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
79         TestEnvironment tEnv = null;
80         XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
81 
82         log.println("Creating instance...");
83 
84         xTextDoc = WriterTools.createTextDoc(xMSF);
85 
86         XText xText = xTextDoc.getText();
87         XTextCursor xTextCursor = xText.createTextCursor();
88 
89         for (int i = 0; i < 11; i++) {
90             xText.insertString(xTextCursor, "A sample text and why not? ", false);
91         }
92 
93         XFrame xFrame = xTextDoc.getCurrentController().getFrame();
94         XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xFrame);
95         try {
96             Object any = xProp.getPropertyValue("LayoutManager");
97             xManager = (XInterface)UnoRuntime.queryInterface(XInterface.class, any);
98         }
99         catch(com.sun.star.beans.UnknownPropertyException e) {
100             e.printStackTrace(log);
101             throw new StatusException("Could not get property 'LayoutManager' from the current frame.", e);
102         }
103         catch(com.sun.star.lang.WrappedTargetException e) {
104             e.printStackTrace(log);
105             throw new StatusException("Could not get property 'LayoutManager' from the current frame.", e);
106         }
107 
108         // just to make sure, it's the right one.
109         log.println("TestObject: " + util.utils.getImplName(xManager));
110         tEnv = new TestEnvironment(xManager);
111 
112         tEnv.addObjRelation("XLayoutManager.TextDoc", xTextDoc);
113         tEnv.addObjRelation("XLayoutManager.Frame",xFrame);
114 
115         return tEnv;
116     }
117 }
118 
119 
120