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
.SOfficeFactory
;
30 import com
.sun
.star
.container
.XIndexAccess
;
31 import com
.sun
.star
.container
.XNameAccess
;
32 import com
.sun
.star
.container
.XNamed
;
33 import com
.sun
.star
.lang
.XComponent
;
34 import com
.sun
.star
.lang
.XMultiServiceFactory
;
35 import com
.sun
.star
.text
.XText
;
36 import com
.sun
.star
.text
.XTextColumns
;
37 import com
.sun
.star
.text
.XTextContent
;
38 import com
.sun
.star
.text
.XTextCursor
;
39 import com
.sun
.star
.text
.XTextDocument
;
40 import com
.sun
.star
.text
.XTextSection
;
41 import com
.sun
.star
.text
.XTextSectionsSupplier
;
42 import com
.sun
.star
.text
.XWordCursor
;
43 import com
.sun
.star
.uno
.AnyConverter
;
44 import com
.sun
.star
.uno
.Type
;
45 import com
.sun
.star
.uno
.UnoRuntime
;
46 import com
.sun
.star
.uno
.XInterface
;
51 * @see com.sun.star.text.XText
55 public class SwXTextSection
extends TestCase
{
56 XTextDocument xTextDoc
;
59 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
60 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
61 log
.println( "creating a textdocument" );
62 xTextDoc
= SOF
.createTextDoc( null );
66 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
67 log
.println( " disposing xTextDoc " );
68 util
.DesktopTools
.closeDoc(xTextDoc
);
72 * creating a TestEnvironment for the interfaces to be tested
75 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) throws Exception
{
77 XInterface oObj
= null;
78 XInterface oTS
= null;
79 XTextSection xTS
= null;
81 XTextColumns TC
= null;
82 Object instance
= null;
84 log
.println( "creating a test environment" );
86 oText
= xTextDoc
.getText();
87 XTextCursor oCursor
= oText
.createTextCursor();
89 XMultiServiceFactory oDocMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
92 XTextSectionsSupplier oTSSupp
= UnoRuntime
.queryInterface
93 ( XTextSectionsSupplier
.class, xTextDoc
);
94 XNameAccess oTSSuppName
= oTSSupp
.getTextSections();
96 //cleanup if necessary
97 if (oTSSuppName
.hasByName("SwXTextSection")) {
98 XTextSection old
= (XTextSection
) AnyConverter
.toObject(
99 new Type(XTextSection
.class),
100 oTSSuppName
.getByName("SwXTextSection"));
101 XComponent oldC
= UnoRuntime
.queryInterface(XComponent
.class,old
);
106 //insert two sections parent and child
107 oTS
= (XInterface
) oDocMSF
.createInstance
108 ("com.sun.star.text.TextSection");
109 instance
= oDocMSF
.createInstance("com.sun.star.text.TextSection");
110 XTextContent oTSC
= UnoRuntime
.queryInterface(XTextContent
.class, oTS
);
111 oText
.insertTextContent(oCursor
, oTSC
, false);
112 XWordCursor oWordC
= UnoRuntime
.queryInterface(XWordCursor
.class, oCursor
);
113 oCursor
.setString("End of TextSection");
114 oCursor
.gotoStart(false);
115 oCursor
.setString("Start of TextSection ");
116 oWordC
.gotoEndOfWord(false);
117 XInterface oTS2
= (XInterface
) oDocMSF
.createInstance
118 ("com.sun.star.text.TextSection");
119 oTSC
= UnoRuntime
.queryInterface(XTextContent
.class, oTS2
);
120 oText
.insertTextContent(oCursor
, oTSC
, false);
122 XIndexAccess oTSSuppIndex
= UnoRuntime
.queryInterface(XIndexAccess
.class, oTSSuppName
);
124 log
.println( "getting a TextSection with the XTextSectionSupplier()" );
125 xTS
= (XTextSection
) AnyConverter
.toObject(
126 new Type(XTextSection
.class),oTSSuppIndex
.getByIndex(0));
127 XNamed xTSName
= UnoRuntime
.queryInterface( XNamed
.class, xTS
);
128 xTSName
.setName("SwXTextSection");
131 System
.out
.println("Couldn't get Textsection " + e
);
136 log
.println( "creating a new environment for TextSection object" );
137 TestEnvironment tEnv
= new TestEnvironment( oObj
);
139 log
.println( "adding InstDescriptor object" );
140 TableDsc tDsc
= new TableDsc( 6, 4 );
142 log
.println( "adding InstCreator object" );
143 tEnv
.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc
, tDsc
) );
145 tEnv
.addObjRelation("TRO",Boolean
.TRUE
);
147 TC
= UnoRuntime
.queryInterface(XTextColumns
.class,
148 oDocMSF
.createInstance("com.sun.star.text.TextColumns"));
149 tEnv
.addObjRelation("TC",TC
);
151 tEnv
.addObjRelation("CONTENT", UnoRuntime
.queryInterface(XTextContent
.class,instance
));
152 tEnv
.addObjRelation("RANGE", xTextDoc
.getText().createTextCursor());
155 } // finish method getTestEnvironment
157 }// finish class SwXTextSection