bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _fwk / LayoutManager.java
blob6628add8332e02c0ada67f3dca193d9afaec97f5
1 /*
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 .
19 package mod._fwk;
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;
32 import lib.TestCase;
33 import lib.TestEnvironment;
34 import lib.TestParameters;
35 import util.WriterTools;
37 /**
39 public class LayoutManager extends TestCase {
40 XInterface xManager = null;
41 XTextDocument xTextDoc;
43 /**
44 * Cleanup: close the created document
45 * @param tParam The test parameters.
46 * @param log The log writer.
48 @Override
49 protected void cleanup(TestParameters tParam, PrintWriter log) {
50 log.println(" disposing xTextDoc ");
52 try {
53 XCloseable closer = UnoRuntime.queryInterface(
54 XCloseable.class, xTextDoc);
55 closer.close(true);
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");
63 /**
64 * Create test environment:
65 * <ul>
66 * <li>Create test doc</li>
67 * <li>Get the frame</li>
68 * <li>Get the LayoutManager from the frame</li>
69 * </ul>
70 * @param tParam The test parameters.
71 * @param log The log writer.
72 * @return The test environment.
74 @Override
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);
92 try {
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);
112 return tEnv;