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
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.InstCreator
;
27 import util
.ParagraphDsc
;
28 import util
.SOfficeFactory
;
31 import com
.sun
.star
.beans
.XPropertySet
;
32 import com
.sun
.star
.container
.XNameAccess
;
33 import com
.sun
.star
.style
.XStyle
;
34 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
35 import com
.sun
.star
.text
.XText
;
36 import com
.sun
.star
.text
.XTextDocument
;
37 import com
.sun
.star
.uno
.AnyConverter
;
38 import com
.sun
.star
.uno
.Type
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
40 import com
.sun
.star
.uno
.XInterface
;
44 * Object implements the following interfaces :
46 * <li> <code>com::sun::star::text::XTextRangeMover</code></li>
47 * <li> <code>com::sun::star::text::XSimpleText</code></li>
48 * <li> <code>com::sun::star::text::XTextRange</code></li>
49 * <li> <code>com::sun::star::text::XRelativeTextContentInsert</code></li>
50 * <li> <code>com::sun::star::text::XTextRangeCompare</code></li>
51 * <li> <code>com::sun::star::container::XElementAccess</code></li>
52 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
53 * <li> <code>com::sun::star::text::XText</code></li>
55 * This object test <b> is NOT </b> designed to be run in several
56 * threads concurrently.
57 * @see com.sun.star.text.XTextRangeMover
58 * @see com.sun.star.text.XSimpleText
59 * @see com.sun.star.text.XTextRange
60 * @see com.sun.star.text.XRelativeTextContentInsert
61 * @see com.sun.star.text.XTextRangeCompare
62 * @see com.sun.star.container.XElementAccess
63 * @see com.sun.star.container.XEnumerationAccess
64 * @see com.sun.star.text.XText
65 * @see ifc.text._XTextRangeMover
66 * @see ifc.text._XSimpleText
67 * @see ifc.text._XTextRange
68 * @see ifc.text._XRelativeTextContentInsert
69 * @see ifc.text._XTextRangeCompare
70 * @see ifc.container._XElementAccess
71 * @see ifc.container._XEnumerationAccess
72 * @see ifc.text._XText
74 public class SwXHeadFootText
extends TestCase
{
75 XTextDocument xTextDoc
;
78 * Creates text document.
81 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
82 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
83 log
.println( "creating a textdocument" );
84 xTextDoc
= SOF
.createTextDoc( null );
88 * Disposes text document.
91 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
92 log
.println( " disposing xTextDoc " );
93 util
.DesktopTools
.closeDoc(xTextDoc
);
97 * Creating a TestEnvironment for the interfaces to be tested. At first
98 * style families are obtained from text document, then style 'Standard' has
99 * gotten from style family 'PageStyles'. At the end, document header and
100 * footer are switched on and document text is obtained.
101 * Object relations created :
103 * <li> <code>'XTEXTINFO'</code> for
104 * {@link ifc.text._XRelativeTextContentInsert},
105 * {@link ifc.text._XText} : creates tables 6x4</li>
106 * <li> <code>'TEXTDOC'</code> for
107 * {@link ifc.text._XTextRangeCompare} : text document</li>
108 * <li> <code>'PARA'</code> for
109 * {@link ifc.text._XRelativeTextContentInsert} : paragraph creator</li>
113 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) throws Exception
{
114 XInterface oObj
= null;
115 XPropertySet PropSet
;
116 XNameAccess PageStyles
= null;
117 XStyle StdStyle
= null;
119 log
.println( "creating a test environment" );
120 XStyleFamiliesSupplier StyleFam
= UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class, xTextDoc
);
121 XNameAccess StyleFamNames
= StyleFam
.getStyleFamilies();
123 // obtains style 'Standard' from style family 'PageStyles'
124 PageStyles
= (XNameAccess
) AnyConverter
.toObject(
125 new Type(XNameAccess
.class),StyleFamNames
.getByName("PageStyles"));
126 StdStyle
= (XStyle
) AnyConverter
.toObject(
127 new Type(XStyle
.class),PageStyles
.getByName("Standard"));
129 PropSet
= UnoRuntime
.queryInterface( XPropertySet
.class, StdStyle
);
131 // changing/getting some properties
132 log
.println( "Switching on header" );
133 PropSet
.setPropertyValue("HeaderIsOn", Boolean
.TRUE
);
134 log
.println( "Switching on footer" );
135 PropSet
.setPropertyValue("FooterIsOn", Boolean
.TRUE
);
136 log
.println( "Get header text" );
137 oObj
= UnoRuntime
.queryInterface(
138 XText
.class, PropSet
.getPropertyValue("HeaderText"));
140 log
.println( "creating a new environment for bodytext object" );
141 TestEnvironment tEnv
= new TestEnvironment( oObj
);
143 log
.println( " adding Paragraph" );
144 ParagraphDsc pDsc
= new ParagraphDsc();
145 tEnv
.addObjRelation( "PARA", new InstCreator( xTextDoc
, pDsc
) );
147 log
.println( "adding InstDescriptor object" );
148 TableDsc tDsc
= new TableDsc( 6, 4 );
150 log
.println( "adding InstCreator object" );
151 tEnv
.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc
, tDsc
) );
153 tEnv
.addObjRelation( "TEXT", oObj
);
156 } // finish method getTestEnvironment
158 } // finish class SwXHeadFootText