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