2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import com
.sun
.star
.beans
.XPropertySet
;
22 import com
.sun
.star
.frame
.XFrame
;
23 import com
.sun
.star
.lang
.XMultiServiceFactory
;
24 import com
.sun
.star
.uno
.UnoRuntime
;
25 import com
.sun
.star
.uno
.XInterface
;
26 import java
.io
.PrintWriter
;
27 import com
.sun
.star
.text
.XText
;
28 import com
.sun
.star
.text
.XTextCursor
;
29 import com
.sun
.star
.text
.XTextDocument
;
30 import com
.sun
.star
.util
.XCloseable
;
31 import lib
.StatusException
;
33 import lib
.TestEnvironment
;
34 import lib
.TestParameters
;
35 import util
.WriterTools
;
39 public class LayoutManager
extends TestCase
{
40 XInterface xManager
= null;
41 XTextDocument xTextDoc
;
44 * Cleanup: close the created document
45 * @param tParam The test parameters.
46 * @param log The log writer.
49 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
50 log
.println(" disposing xTextDoc ");
53 XCloseable closer
= UnoRuntime
.queryInterface(
54 XCloseable
.class, xTextDoc
);
56 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
57 log
.println("couldn't close document");
58 } catch (com
.sun
.star
.lang
.DisposedException e
) {
59 log
.println("couldn't close document");
64 * Create test environment:
66 * <li>Create test doc</li>
67 * <li>Get the frame</li>
68 * <li>Get the LayoutManager from the frame</li>
70 * @param tParam The test parameters.
71 * @param log The log writer.
72 * @return The test environment.
75 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
76 TestEnvironment tEnv
= null;
77 XMultiServiceFactory xMSF
= tParam
.getMSF();
79 log
.println("Creating instance...");
81 xTextDoc
= WriterTools
.createTextDoc(xMSF
);
83 XText xText
= xTextDoc
.getText();
84 XTextCursor xTextCursor
= xText
.createTextCursor();
86 for (int i
= 0; i
< 11; i
++) {
87 xText
.insertString(xTextCursor
, "A sample text and why not? ", false);
90 XFrame xFrame
= xTextDoc
.getCurrentController().getFrame();
91 XPropertySet xProp
= UnoRuntime
.queryInterface(XPropertySet
.class, xFrame
);
93 Object any
= xProp
.getPropertyValue("LayoutManager");
94 xManager
= UnoRuntime
.queryInterface(XInterface
.class, any
);
96 catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
97 e
.printStackTrace(log
);
98 throw new StatusException("Could not get property 'LayoutManager' from the current frame.", e
);
100 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
101 e
.printStackTrace(log
);
102 throw new StatusException("Could not get property 'LayoutManager' from the current frame.", e
);
105 // just to make sure, it's the right one.
106 log
.println("TestObject: " + util
.utils
.getImplName(xManager
));
107 tEnv
= new TestEnvironment(xManager
);
109 tEnv
.addObjRelation("XLayoutManager.TextDoc", xTextDoc
);
110 tEnv
.addObjRelation("XLayoutManager.Frame",xFrame
);