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
.ElementExistException
;
22 import com
.sun
.star
.container
.XNameAccess
;
23 import java
.io
.PrintWriter
;
25 import lib
.StatusException
;
27 import lib
.TestEnvironment
;
28 import lib
.TestParameters
;
29 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
;
42 * Test for object which is represented by service
43 * <code>com.sun.star.text.AutoTextGroup</code>. <p>
44 * Object implements the following interfaces :
46 * <li> <code>com::sun::star::container::XNamed</code></li>
47 * <li> <code>com::sun::star::container::XNameAccess</code></li>
48 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
49 * <li> <code>com::sun::star::container::XElementAccess</code></li>
50 * <li> <code>com::sun::star::text::XAutoTextGroup</code></li>
52 * This object test <b> is NOT </b> designed to be run in several
53 * threads concurently.
54 * @see com.sun.star.container.XNamed
55 * @see com.sun.star.container.XNameAccess
56 * @see com.sun.star.container.XIndexAccess
57 * @see com.sun.star.container.XElementAccess
58 * @see com.sun.star.text.XAutoTextGroup
59 * @see com.sun.star.text.AutoTextContainer
60 * @see ifc.container._XNamed
61 * @see ifc.container._XNameAccess
62 * @see ifc.container._XIndexAccess
63 * @see ifc.container._XElementAccess
64 * @see ifc.text._XAutoTextGroup
66 public class SwXAutoTextGroup
extends TestCase
{
67 XTextDocument xTextDoc
;
70 * Creates text document.
73 protected void initialize( TestParameters tParam
, PrintWriter log
) {
74 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
76 log
.println( "creating a textdocument" );
77 xTextDoc
= SOF
.createTextDoc( null );
78 } catch ( com
.sun
.star
.uno
.Exception e
) {
79 e
.printStackTrace( log
);
80 throw new StatusException( "Couldn't create document", e
);
85 * Disposes text document.
88 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
89 log
.println( " disposing xTextDoc " );
90 util
.DesktopTools
.closeDoc(xTextDoc
);
94 * Creating a Testenvironment for the interfaces to be tested.
95 * Creates an instance of the service
96 * <code>com.sun.star.text.AutoTextContainer</code>, then creates a new
97 * group into the container.<p>
98 * Object relations created :
100 * <li> <code>'TextRange'</code> for
101 * {@link ifc.text._XAutoTextGroup} range of text</li>
105 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
107 XInterface oObj
= null;
108 XAutoTextContainer oContainer
;
110 log
.println( "creating a test environment" );
112 XMultiServiceFactory myMSF
= Param
.getMSF();
113 Object oInst
= myMSF
.createInstance("com.sun.star.text.AutoTextContainer");
114 oContainer
= UnoRuntime
.queryInterface(XAutoTextContainer
.class,oInst
);
115 } catch (com
.sun
.star
.uno
.Exception e
) {
116 e
.printStackTrace(log
);
117 throw new StatusException("Couldn't create AutoTextContainer", e
);
119 String myGroupName
="myNewGroup2*1";
121 XAutoTextContainer xATC
= UnoRuntime
.queryInterface(XAutoTextContainer
.class, oContainer
);
124 log
.println("removing element with name '" + myGroupName
+ "'");
125 xATC
.removeByName(myGroupName
);
126 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
130 log
.println("adding element with name '" + myGroupName
+ "'");
131 xATC
.insertNewByName(myGroupName
);
132 } catch (ElementExistException ex
) {
133 ex
.printStackTrace(log
);
134 throw new StatusException("could not insert '"+myGroupName
+"' into container",ex
);
135 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
136 ex
.printStackTrace(log
);
137 throw new StatusException("could not insert '"+myGroupName
+"' into container",ex
);
141 XNameAccess oContNames
= UnoRuntime
.queryInterface(XNameAccess
.class, oContainer
);
143 if (Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
)){
144 String contNames
[] = oContNames
.getElementNames();
145 for (int i
=0; i
< contNames
.length
; i
++){
146 log
.println("ContainerNames[ "+ i
+ "]: " + contNames
[i
]);
151 oObj
= (XInterface
) AnyConverter
.toObject(new Type(XInterface
.class),oContNames
.getByName(myGroupName
));
152 } catch (com
.sun
.star
.uno
.Exception e
) {
153 e
.printStackTrace(log
);
154 throw new StatusException("Couldn't get AutoTextGroup '"+myGroupName
+ "'", e
);
157 log
.println("ImplementationName " + utils
.getImplName(oObj
));
159 log
.println( "creating a new environment for AutoTextGroup object" );
160 TestEnvironment tEnv
= new TestEnvironment( oObj
);
162 XText oText
= xTextDoc
.getText();
163 oText
.insertString(oText
.getStart(), "New AutoText", true);
165 log
.println( "adding TextRange as mod relation to environment" );
166 tEnv
.addObjRelation("TextRange", oText
);
169 } // finish method getTestEnvironment
172 } // finish class SwXAutoTextGroup