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
.InstCreator
;
28 import util
.SOfficeFactory
;
31 import com
.sun
.star
.container
.XIndexAccess
;
32 import com
.sun
.star
.container
.XNameAccess
;
33 import com
.sun
.star
.container
.XNamed
;
34 import com
.sun
.star
.lang
.XComponent
;
35 import com
.sun
.star
.lang
.XMultiServiceFactory
;
36 import com
.sun
.star
.text
.XText
;
37 import com
.sun
.star
.text
.XTextColumns
;
38 import com
.sun
.star
.text
.XTextContent
;
39 import com
.sun
.star
.text
.XTextCursor
;
40 import com
.sun
.star
.text
.XTextDocument
;
41 import com
.sun
.star
.text
.XTextSection
;
42 import com
.sun
.star
.text
.XTextSectionsSupplier
;
43 import com
.sun
.star
.text
.XWordCursor
;
44 import com
.sun
.star
.uno
.AnyConverter
;
45 import com
.sun
.star
.uno
.Type
;
46 import com
.sun
.star
.uno
.UnoRuntime
;
47 import com
.sun
.star
.uno
.XInterface
;
52 * @see com.sun.star.text.XText
56 public class SwXTextSection
extends TestCase
{
57 XTextDocument xTextDoc
;
59 protected void initialize( TestParameters tParam
, PrintWriter log
) {
60 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
63 log
.println( "creating a textdocument" );
64 xTextDoc
= SOF
.createTextDoc( null );
65 } catch ( com
.sun
.star
.uno
.Exception e
) {
66 // Some exception occurs.FAILED
67 e
.printStackTrace( log
);
68 throw new StatusException( "Couldn't create document", e
);
72 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
73 log
.println( " disposing xTextDoc " );
74 util
.DesktopTools
.closeDoc(xTextDoc
);
78 * creating a Testenvironment for the interfaces to be tested
80 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
82 XInterface oObj
= null;
83 XInterface oTS
= null;
84 XTextSection xTS
= null;
86 XTextColumns TC
= null;
87 Object instance
= null;
89 log
.println( "creating a test environment" );
91 oText
= xTextDoc
.getText();
92 XTextCursor oCursor
= oText
.createTextCursor();
94 XMultiServiceFactory oDocMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
97 XTextSectionsSupplier oTSSupp
= UnoRuntime
.queryInterface
98 ( XTextSectionsSupplier
.class, xTextDoc
);
99 XNameAccess oTSSuppName
= oTSSupp
.getTextSections();
101 //cleanup if necessary
102 if (oTSSuppName
.hasByName("SwXTextSection")) {
103 XTextSection old
= (XTextSection
) AnyConverter
.toObject(
104 new Type(XTextSection
.class),
105 oTSSuppName
.getByName("SwXTextSection"));
106 XComponent oldC
= UnoRuntime
.queryInterface(XComponent
.class,old
);
111 //insert two sections parent and child
112 oTS
= (XInterface
) oDocMSF
.createInstance
113 ("com.sun.star.text.TextSection");
114 instance
= oDocMSF
.createInstance("com.sun.star.text.TextSection");
115 XTextContent oTSC
= UnoRuntime
.queryInterface(XTextContent
.class, oTS
);
116 oText
.insertTextContent(oCursor
, oTSC
, false);
117 XWordCursor oWordC
= UnoRuntime
.queryInterface(XWordCursor
.class, oCursor
);
118 oCursor
.setString("End of TextSection");
119 oCursor
.gotoStart(false);
120 oCursor
.setString("Start of TextSection ");
121 oWordC
.gotoEndOfWord(false);
122 XInterface oTS2
= (XInterface
) oDocMSF
.createInstance
123 ("com.sun.star.text.TextSection");
124 oTSC
= UnoRuntime
.queryInterface(XTextContent
.class, oTS2
);
125 oText
.insertTextContent(oCursor
, oTSC
, false);
127 XIndexAccess oTSSuppIndex
= UnoRuntime
.queryInterface(XIndexAccess
.class, oTSSuppName
);
129 log
.println( "getting a TextSection with the XTextSectionSupplier()" );
130 xTS
= (XTextSection
) AnyConverter
.toObject(
131 new Type(XTextSection
.class),oTSSuppIndex
.getByIndex(0));
132 XNamed xTSName
= UnoRuntime
.queryInterface( XNamed
.class, xTS
);
133 xTSName
.setName("SwXTextSection");
136 System
.out
.println("Couldn't get Textsection " + e
);
141 log
.println( "creating a new environment for TextSection object" );
142 TestEnvironment tEnv
= new TestEnvironment( oObj
);
144 log
.println( "adding InstDescriptor object" );
145 TableDsc tDsc
= new TableDsc( 6, 4 );
147 log
.println( "adding InstCreator object" );
148 tEnv
.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc
, tDsc
) );
150 tEnv
.addObjRelation("TRO",new Boolean(true));
153 TC
= UnoRuntime
.queryInterface(XTextColumns
.class,
154 oDocMSF
.createInstance("com.sun.star.text.TextColumns"));
155 } catch ( com
.sun
.star
.uno
.Exception e
) {
156 e
.printStackTrace(log
);
157 throw new StatusException
158 ("Couldn't create instance of service TextColumns", e
);
160 tEnv
.addObjRelation("TC",TC
);
162 tEnv
.addObjRelation("CONTENT", UnoRuntime
.queryInterface(XTextContent
.class,instance
));
163 tEnv
.addObjRelation("RANGE", xTextDoc
.getText().createTextCursor());
166 } // finish method getTestEnvironment
168 }// finish class SwXTextSection