1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXFrames.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.lang
.XMultiServiceFactory
;
42 import com
.sun
.star
.text
.XText
;
43 import com
.sun
.star
.text
.XTextCursor
;
44 import com
.sun
.star
.text
.XTextDocument
;
45 import com
.sun
.star
.text
.XTextFrame
;
46 import com
.sun
.star
.text
.XTextFramesSupplier
;
47 import com
.sun
.star
.uno
.UnoRuntime
;
48 import com
.sun
.star
.uno
.XInterface
;
51 * Object implements the following interfaces :
53 * <li> <code>com::sun::star::container::XContainer</code></li>
54 * <li> <code>com::sun::star::container::XNameAccess</code></li>
55 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
56 * <li> <code>com::sun::star::container::XElementAccess</code></li>
58 * This object test <b> is NOT </b> designed to be run in several
59 * threads concurently.
60 * @see com.sun.star.container.XContainer
61 * @see com.sun.star.container.XNameAccess
62 * @see com.sun.star.container.XIndexAccess
63 * @see com.sun.star.container.XElementAccess
64 * @see ifc.container._XContainer
65 * @see ifc.container._XNameAccess
66 * @see ifc.container._XIndexAccess
67 * @see ifc.container._XElementAccess
69 public class SwXFrames
extends TestCase
{
70 XTextDocument xTextDoc
;
73 * Creates text document.
75 protected void initialize( TestParameters tParam
, PrintWriter log
) {
76 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
78 log
.println( "creating a textdocument" );
79 xTextDoc
= SOF
.createTextDoc( null );
80 } catch ( com
.sun
.star
.uno
.Exception e
) {
81 e
.printStackTrace( log
);
82 throw new StatusException( "Couldn't create document", e
);
87 * Disposes text document.
89 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
90 log
.println( " disposing xTextDoc " );
91 util
.DesktopTools
.closeDoc(xTextDoc
);
95 * Creating a Testenvironment for the interfaces to be tested.
96 * Creates an instance of the service
97 * <code>com.sun.star.text.TextFrame</code>. Then inserts created text frame
98 * to the text, and finally gets all frames of text document using
99 * <code>XTextFramesSupplier</code> interface.<br>
101 public synchronized TestEnvironment
createTestEnvironment(
102 TestParameters Param
, PrintWriter log
) throws StatusException
{
103 XInterface oObj
= null;
104 XTextFrame oFrame1
= null;
106 XTextCursor oCursor
= null;
107 XMultiServiceFactory oDocMSF
= null;
108 XTextFramesSupplier oInterface
= null;
110 log
.println( "creating a test environment" );
112 oDocMSF
= (XMultiServiceFactory
)
113 UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
114 Object oInt
= oDocMSF
.createInstance("com.sun.star.text.TextFrame");
115 oFrame1
= (XTextFrame
)
116 UnoRuntime
.queryInterface( XTextFrame
.class, oInt
);
117 } catch ( com
.sun
.star
.uno
.Exception e
) {
118 e
.printStackTrace(log
);
119 throw new StatusException
120 ("Couldn't create instance of TextFrame", e
);
123 oText
= xTextDoc
.getText();
124 oCursor
= oText
.createTextCursor();
127 oText
.insertTextContent(oCursor
, oFrame1
, false);
128 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
129 e
.printStackTrace(log
);
130 throw new StatusException
131 ("Error: can't insert text content to text document", e
);
134 oInterface
= (XTextFramesSupplier
)
135 UnoRuntime
.queryInterface( XTextFramesSupplier
.class, xTextDoc
);
137 oObj
= oInterface
.getTextFrames();
139 log
.println( "creating a new environment for Frame object" );
140 TestEnvironment tEnv
= new TestEnvironment( oObj
);
143 } // finish method getTestEnvironment
145 } // finish class SwXFrames