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.
48 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
49 log
.println(" disposing xTextDoc ");
52 XCloseable closer
= UnoRuntime
.queryInterface(
53 XCloseable
.class, xTextDoc
);
55 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
56 log
.println("couldn't close document");
57 } catch (com
.sun
.star
.lang
.DisposedException e
) {
58 log
.println("couldn't close document");
63 * Create test environment:
65 * <li>Create test doc</li>
66 * <li>Get the frame</li>
67 * <li>Get the LayoutManager from the frame</li>
69 * @param tParam The test parameters.
70 * @param log The log writer.
71 * @return The test environment.
73 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
74 TestEnvironment tEnv
= null;
75 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF();
77 log
.println("Creating instance...");
79 xTextDoc
= WriterTools
.createTextDoc(xMSF
);
81 XText xText
= xTextDoc
.getText();
82 XTextCursor xTextCursor
= xText
.createTextCursor();
84 for (int i
= 0; i
< 11; i
++) {
85 xText
.insertString(xTextCursor
, "A sample text and why not? ", false);
88 XFrame xFrame
= xTextDoc
.getCurrentController().getFrame();
89 XPropertySet xProp
= UnoRuntime
.queryInterface(XPropertySet
.class, xFrame
);
91 Object any
= xProp
.getPropertyValue("LayoutManager");
92 xManager
= UnoRuntime
.queryInterface(XInterface
.class, any
);
94 catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
95 e
.printStackTrace(log
);
96 throw new StatusException("Could not get property 'LayoutManager' from the current frame.", e
);
98 catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
99 e
.printStackTrace(log
);
100 throw new StatusException("Could not get property 'LayoutManager' from the current frame.", e
);
103 // just to make sure, it's the right one.
104 log
.println("TestObject: " + util
.utils
.getImplName(xManager
));
105 tEnv
= new TestEnvironment(xManager
);
107 tEnv
.addObjRelation("XLayoutManager.TextDoc", xTextDoc
);
108 tEnv
.addObjRelation("XLayoutManager.Frame",xFrame
);