bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextFrame.java
blob8e3e5131f14d37682f4095880351294a59e38a6a
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 .
18 package mod._sw;
20 import java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.SOfficeFactory;
28 import com.sun.star.beans.XPropertySet;
29 import com.sun.star.text.TextContentAnchorType;
30 import com.sun.star.text.XText;
31 import com.sun.star.text.XTextContent;
32 import com.sun.star.text.XTextCursor;
33 import com.sun.star.text.XTextDocument;
34 import com.sun.star.text.XTextFrame;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
39 /**
41 * initial description
42 * @see com.sun.star.text.XText
45 public class SwXTextFrame extends TestCase {
46 XTextDocument xTextDoc;
48 @Override
49 protected void initialize(TestParameters tParam, PrintWriter log) {
50 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
52 try {
53 log.println("creating a textdocument");
54 xTextDoc = SOF.createTextDoc(null);
55 } catch (com.sun.star.uno.Exception e) {
56 // Some exception occurs.FAILED
57 e.printStackTrace(log);
58 throw new StatusException("Couldn't create document", e);
62 @Override
63 protected void cleanup(TestParameters tParam, PrintWriter log) {
64 log.println(" disposing xTextDoc ");
65 util.DesktopTools.closeDoc(xTextDoc);
68 /**
69 * creating a Testenvironment for the interfaces to be tested
71 @Override
72 public synchronized TestEnvironment createTestEnvironment(TestParameters Param,
73 PrintWriter log) {
74 XInterface oObj = null;
75 XTextFrame oFrame1 = null;
76 XTextFrame oFrame2 = null;
77 XPropertySet oPropSet = null;
78 XText oText = null;
79 XTextCursor oCursor = null;
82 // creation of testobject here
83 // first we write what we are intend to do to log file
84 log.println("creating a test environment");
86 // get a soffice factory object
87 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF());
90 // creating Frames
91 log.println("creating Frames");
94 Object instance = null;
96 try {
97 oFrame1 = SOfficeFactory.createTextFrame(xTextDoc, 500, 500);
98 oFrame2 = SOfficeFactory.createTextFrame(xTextDoc, 1500, 1500);
99 oPropSet = UnoRuntime.queryInterface(
100 XPropertySet.class, oFrame1);
103 // AnchorTypes: 0 = paragraph, 1 = as char, 2 = page,
104 // 3 = frame/paragraph 4= at char
105 oPropSet.setPropertyValue("AnchorType",
106 TextContentAnchorType.AS_CHARACTER);
107 oText = xTextDoc.getText();
108 oCursor = oText.createTextCursor();
110 log.println("inserting Frame1");
112 XTextContent the_content = UnoRuntime.queryInterface(
113 XTextContent.class, oFrame1);
114 oText.insertTextContent(oCursor, the_content, true);
116 log.println("inserting Frame2");
117 the_content = UnoRuntime.queryInterface(
118 XTextContent.class, oFrame2);
119 oText.insertTextContent(oCursor, the_content, true);
121 XText oFrameText = oFrame1.getText();
122 oFrameText.insertString(oFrameText.getStart(), "The FrameText",
123 true);
125 instance = SOF.createInstance(xTextDoc,
126 "com.sun.star.text.TextFrame");
127 } catch (Exception Ex) {
128 Ex.printStackTrace(log);
129 throw new StatusException("Couldn't insert TextFrame ", Ex);
132 oObj = oFrame1;
134 log.println("creating a new environment for TextFrame object");
136 TestEnvironment tEnv = new TestEnvironment(oObj);
138 tEnv.addObjRelation("CONTENT",
139 UnoRuntime.queryInterface(
140 XTextContent.class, instance));
141 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
143 log.println("adding ObjRelation for XShape " +
144 "(get/setPosition won't work there)");
145 tEnv.addObjRelation("NoPos", "SwXTextFrame");
146 tEnv.addObjRelation("NoSetSize", "SwXTextFrame");
148 tEnv.addObjRelation("TextFrame", oFrame2);
150 return tEnv;
151 } // finish method getTestEnvironment
152 } // finish class SwXTextFrame