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 .
20 import java
.io
.PrintWriter
;
23 import lib
.TestEnvironment
;
24 import lib
.TestParameters
;
25 import util
.SOfficeFactory
;
27 import com
.sun
.star
.beans
.XPropertySet
;
28 import com
.sun
.star
.text
.TextContentAnchorType
;
29 import com
.sun
.star
.text
.XText
;
30 import com
.sun
.star
.text
.XTextContent
;
31 import com
.sun
.star
.text
.XTextCursor
;
32 import com
.sun
.star
.text
.XTextDocument
;
33 import com
.sun
.star
.text
.XTextFrame
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.uno
.XInterface
;
41 * @see com.sun.star.text.XText
44 public class SwXTextFrame
extends TestCase
{
45 XTextDocument xTextDoc
;
48 protected void initialize(TestParameters tParam
, PrintWriter log
) throws Exception
{
49 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
50 log
.println("creating a textdocument");
51 xTextDoc
= SOF
.createTextDoc(null);
55 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
56 log
.println(" disposing xTextDoc ");
57 util
.DesktopTools
.closeDoc(xTextDoc
);
61 * creating a TestEnvironment for the interfaces to be tested
64 public TestEnvironment
createTestEnvironment(TestParameters Param
,
65 PrintWriter log
) throws Exception
{
66 XInterface oObj
= null;
67 XTextFrame oFrame1
= null;
68 XTextFrame oFrame2
= null;
69 XPropertySet oPropSet
= null;
71 XTextCursor oCursor
= null;
74 // creation of testobject here
75 // first we write what we are intend to do to log file
76 log
.println("creating a test environment");
78 // get a soffice factory object
79 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
83 log
.println("creating Frames");
86 Object instance
= null;
88 oFrame1
= SOfficeFactory
.createTextFrame(xTextDoc
, 500, 500);
89 oFrame2
= SOfficeFactory
.createTextFrame(xTextDoc
, 1500, 1500);
90 oPropSet
= UnoRuntime
.queryInterface(
91 XPropertySet
.class, oFrame1
);
94 // AnchorTypes: 0 = paragraph, 1 = as char, 2 = page,
95 // 3 = frame/paragraph 4= at char
96 oPropSet
.setPropertyValue("AnchorType",
97 TextContentAnchorType
.AS_CHARACTER
);
98 oText
= xTextDoc
.getText();
99 oCursor
= oText
.createTextCursor();
101 log
.println("inserting Frame1");
103 XTextContent the_content
= UnoRuntime
.queryInterface(
104 XTextContent
.class, oFrame1
);
105 oText
.insertTextContent(oCursor
, the_content
, true);
107 log
.println("inserting Frame2");
108 the_content
= UnoRuntime
.queryInterface(
109 XTextContent
.class, oFrame2
);
110 oText
.insertTextContent(oCursor
, the_content
, true);
112 XText oFrameText
= oFrame1
.getText();
113 oFrameText
.insertString(oFrameText
.getStart(), "The FrameText",
116 instance
= SOF
.createInstance(xTextDoc
,
117 "com.sun.star.text.TextFrame");
120 log
.println("creating a new environment for TextFrame object");
122 TestEnvironment tEnv
= new TestEnvironment(oObj
);
124 tEnv
.addObjRelation("CONTENT",
125 UnoRuntime
.queryInterface(
126 XTextContent
.class, instance
));
127 tEnv
.addObjRelation("RANGE", xTextDoc
.getText().createTextCursor());
129 log
.println("adding ObjRelation for XShape " +
130 "(get/setPosition won't work there)");
131 tEnv
.addObjRelation("NoPos", "SwXTextFrame");
132 tEnv
.addObjRelation("NoSetSize", "SwXTextFrame");
134 tEnv
.addObjRelation("TextFrame", oFrame2
);
137 } // finish method getTestEnvironment
138 } // finish class SwXTextFrame