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 com
.sun
.star
.container
.XNameAccess
;
23 import java
.io
.PrintWriter
;
26 import lib
.TestEnvironment
;
27 import lib
.TestParameters
;
28 import util
.SOfficeFactory
;
30 import com
.sun
.star
.lang
.XMultiServiceFactory
;
31 import com
.sun
.star
.text
.XAutoTextContainer
;
32 import com
.sun
.star
.text
.XText
;
33 import com
.sun
.star
.text
.XTextDocument
;
34 import com
.sun
.star
.uno
.AnyConverter
;
35 import com
.sun
.star
.uno
.Type
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.uno
.XInterface
;
43 * Test for object which is represented by service
44 * <code>com.sun.star.text.AutoTextGroup</code>. <p>
45 * Object implements the following interfaces :
47 * <li> <code>com::sun::star::container::XNamed</code></li>
48 * <li> <code>com::sun::star::container::XNameAccess</code></li>
49 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
50 * <li> <code>com::sun::star::container::XElementAccess</code></li>
51 * <li> <code>com::sun::star::text::XAutoTextGroup</code></li>
53 * This object test <b> is NOT </b> designed to be run in several
54 * threads concurrently.
55 * @see com.sun.star.container.XNamed
56 * @see com.sun.star.container.XNameAccess
57 * @see com.sun.star.container.XIndexAccess
58 * @see com.sun.star.container.XElementAccess
59 * @see com.sun.star.text.XAutoTextGroup
60 * @see com.sun.star.text.AutoTextContainer
61 * @see ifc.container._XNamed
62 * @see ifc.container._XNameAccess
63 * @see ifc.container._XIndexAccess
64 * @see ifc.container._XElementAccess
65 * @see ifc.text._XAutoTextGroup
67 public class SwXAutoTextGroup
extends TestCase
{
68 XTextDocument xTextDoc
;
71 * Creates text document.
74 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
75 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
76 log
.println( "creating a textdocument" );
77 xTextDoc
= SOF
.createTextDoc( null );
81 * Disposes text document.
84 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
85 log
.println( " disposing xTextDoc " );
86 util
.DesktopTools
.closeDoc(xTextDoc
);
90 * Creating a TestEnvironment for the interfaces to be tested.
91 * Creates an instance of the service
92 * <code>com.sun.star.text.AutoTextContainer</code>, then creates a new
93 * group into the container.<p>
94 * Object relations created :
96 * <li> <code>'TextRange'</code> for
97 * {@link ifc.text._XAutoTextGroup} range of text</li>
101 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) throws Exception
{
103 XInterface oObj
= null;
104 XAutoTextContainer oContainer
;
106 log
.println( "creating a test environment" );
107 XMultiServiceFactory myMSF
= Param
.getMSF();
108 Object oInst
= myMSF
.createInstance("com.sun.star.text.AutoTextContainer");
109 oContainer
= UnoRuntime
.queryInterface(XAutoTextContainer
.class,oInst
);
110 String myGroupName
="myNewGroup2*1";
112 XAutoTextContainer xATC
= UnoRuntime
.queryInterface(XAutoTextContainer
.class, oContainer
);
115 log
.println("removing element with name '" + myGroupName
+ "'");
116 xATC
.removeByName(myGroupName
);
117 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
120 log
.println("adding element with name '" + myGroupName
+ "'");
121 xATC
.insertNewByName(myGroupName
);
123 XNameAccess oContNames
= UnoRuntime
.queryInterface(XNameAccess
.class, oContainer
);
125 if (Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
)){
126 String contNames
[] = oContNames
.getElementNames();
127 for (int i
=0; i
< contNames
.length
; i
++){
128 log
.println("ContainerNames[ "+ i
+ "]: " + contNames
[i
]);
132 oObj
= (XInterface
) AnyConverter
.toObject(new Type(XInterface
.class),oContNames
.getByName(myGroupName
));
134 log
.println("ImplementationName " + utils
.getImplName(oObj
));
136 log
.println( "creating a new environment for AutoTextGroup object" );
137 TestEnvironment tEnv
= new TestEnvironment( oObj
);
139 XText oText
= xTextDoc
.getText();
140 oText
.insertString(oText
.getStart(), "New AutoText", true);
142 log
.println( "adding TextRange as mod relation to environment" );
143 tEnv
.addObjRelation("TextRange", oText
);
146 } // finish method getTestEnvironment
149 } // finish class SwXAutoTextGroup