1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: LayoutManager.java,v $
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 ************************************************************************/
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
;
45 import lib
.TestEnvironment
;
46 import lib
.TestParameters
;
47 import util
.WriterTools
;
51 public class LayoutManager
extends TestCase
{
52 XInterface xManager
= null;
53 XTextDocument xTextDoc
;
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 ");
65 XCloseable closer
= (XCloseable
) UnoRuntime
.queryInterface(
66 XCloseable
.class, xTextDoc
);
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");
76 * Create test environment:
78 * <li>Create test doc</li>
79 * <li>Get the frame</li>
80 * <li>Get the LayoutManager from the frame</li>
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
);
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
);