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 java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.lang
.XMultiServiceFactory
;
30 import com
.sun
.star
.text
.XText
;
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
.text
.XTextFramesSupplier
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import com
.sun
.star
.uno
.XInterface
;
39 * Object implements the following interfaces :
41 * <li> <code>com::sun::star::container::XContainer</code></li>
42 * <li> <code>com::sun::star::container::XNameAccess</code></li>
43 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
44 * <li> <code>com::sun::star::container::XElementAccess</code></li>
46 * This object test <b> is NOT </b> designed to be run in several
47 * threads concurently.
48 * @see com.sun.star.container.XContainer
49 * @see com.sun.star.container.XNameAccess
50 * @see com.sun.star.container.XIndexAccess
51 * @see com.sun.star.container.XElementAccess
52 * @see ifc.container._XContainer
53 * @see ifc.container._XNameAccess
54 * @see ifc.container._XIndexAccess
55 * @see ifc.container._XElementAccess
57 public class SwXFrames
extends TestCase
{
58 XTextDocument xTextDoc
;
61 * Creates text document.
64 protected void initialize( TestParameters tParam
, PrintWriter log
) {
65 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
67 log
.println( "creating a textdocument" );
68 xTextDoc
= SOF
.createTextDoc( null );
69 } catch ( com
.sun
.star
.uno
.Exception e
) {
70 e
.printStackTrace( log
);
71 throw new StatusException( "Couldn't create document", e
);
76 * Disposes text document.
79 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
80 log
.println( " disposing xTextDoc " );
81 util
.DesktopTools
.closeDoc(xTextDoc
);
85 * Creating a Testenvironment for the interfaces to be tested.
86 * Creates an instance of the service
87 * <code>com.sun.star.text.TextFrame</code>. Then inserts created text frame
88 * to the text, and finally gets all frames of text document using
89 * <code>XTextFramesSupplier</code> interface.<br>
92 public synchronized TestEnvironment
createTestEnvironment(
93 TestParameters Param
, PrintWriter log
) throws StatusException
{
94 XInterface oObj
= null;
95 XTextFrame oFrame1
= null;
97 XTextCursor oCursor
= null;
98 XMultiServiceFactory oDocMSF
= null;
99 XTextFramesSupplier oInterface
= null;
101 log
.println( "creating a test environment" );
103 oDocMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
104 Object oInt
= oDocMSF
.createInstance("com.sun.star.text.TextFrame");
105 oFrame1
= UnoRuntime
.queryInterface( XTextFrame
.class, oInt
);
106 } catch ( com
.sun
.star
.uno
.Exception e
) {
107 e
.printStackTrace(log
);
108 throw new StatusException
109 ("Couldn't create instance of TextFrame", e
);
112 oText
= xTextDoc
.getText();
113 oCursor
= oText
.createTextCursor();
116 oText
.insertTextContent(oCursor
, oFrame1
, false);
117 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
118 e
.printStackTrace(log
);
119 throw new StatusException
120 ("Error: can't insert text content to text document", e
);
123 oInterface
= UnoRuntime
.queryInterface( XTextFramesSupplier
.class, xTextDoc
);
125 oObj
= oInterface
.getTextFrames();
127 log
.println( "creating a new environment for Frame object" );
128 TestEnvironment tEnv
= new TestEnvironment( oObj
);
131 } // finish method getTestEnvironment
133 } // finish class SwXFrames