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
;
32 import lib
.TestEnvironment
;
33 import lib
.TestParameters
;
34 import util
.WriterTools
;
38 public class LayoutManager
extends TestCase
{
39 XInterface xManager
= null;
40 XTextDocument xTextDoc
;
43 * Cleanup: close the created document
44 * @param tParam The test parameters.
45 * @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.
74 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) throws Exception
{
75 TestEnvironment tEnv
= null;
76 XMultiServiceFactory xMSF
= tParam
.getMSF();
78 log
.println("Creating instance...");
80 xTextDoc
= WriterTools
.createTextDoc(xMSF
);
82 XText xText
= xTextDoc
.getText();
83 XTextCursor xTextCursor
= xText
.createTextCursor();
85 for (int i
= 0; i
< 11; i
++) {
86 xText
.insertString(xTextCursor
, "A sample text and why not? ", false);
89 XFrame xFrame
= xTextDoc
.getCurrentController().getFrame();
90 XPropertySet xProp
= UnoRuntime
.queryInterface(XPropertySet
.class, xFrame
);
91 Object any
= xProp
.getPropertyValue("LayoutManager");
92 xManager
= UnoRuntime
.queryInterface(XInterface
.class, any
);
94 // just to make sure, it's the right one.
95 log
.println("TestObject: " + util
.utils
.getImplName(xManager
));
96 tEnv
= new TestEnvironment(xManager
);
98 tEnv
.addObjRelation("XLayoutManager.TextDoc", xTextDoc
);
99 tEnv
.addObjRelation("XLayoutManager.Frame",xFrame
);