1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXTextSections.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.container
.XNameAccess
;
42 import com
.sun
.star
.lang
.XMultiServiceFactory
;
43 import com
.sun
.star
.text
.XText
;
44 import com
.sun
.star
.text
.XTextContent
;
45 import com
.sun
.star
.text
.XTextCursor
;
46 import com
.sun
.star
.text
.XTextDocument
;
47 import com
.sun
.star
.text
.XTextSectionsSupplier
;
48 import com
.sun
.star
.uno
.UnoRuntime
;
49 import com
.sun
.star
.uno
.XInterface
;
54 * @see com.sun.star.text.XText
57 public class SwXTextSections
extends TestCase
{
58 XTextDocument xTextDoc
;
60 protected void initialize( TestParameters tParam
, PrintWriter log
) {
61 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
64 log
.println( "creating a textdocument" );
65 xTextDoc
= SOF
.createTextDoc( null );
66 } catch ( com
.sun
.star
.uno
.Exception e
) {
67 // Some exception occures.FAILED
68 e
.printStackTrace( log
);
69 throw new StatusException( "Couldn't create document", e
);
73 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
74 log
.println( " disposing xTextDoc " );
75 util
.DesktopTools
.closeDoc(xTextDoc
);
79 * creating a Testenvironment for the interfaces to be tested
81 public synchronized TestEnvironment createTestEnvironment
82 (TestParameters Param
, PrintWriter log
) throws StatusException
{
84 XInterface oObj
= null;
85 XInterface oTS
= null;
86 XNameAccess oTSSuppName
= null;
90 // creation of testobject here
91 // first we write what we are intend to do to log file
92 log
.println( "creating a test environment" );
95 oText
= xTextDoc
.getText();
96 XTextCursor oCursor
= oText
.createTextCursor();
99 log
.println( "inserting TextSections" );
101 XMultiServiceFactory oDocMSF
= (XMultiServiceFactory
)
102 UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
106 oTS
= (XInterface
) oDocMSF
.createInstance
107 ("com.sun.star.text.TextSection");
108 XTextContent oTSC
= (XTextContent
)
109 UnoRuntime
.queryInterface(XTextContent
.class, oTS
);
110 oText
.insertTextContent(oCursor
, oTSC
, false);
113 e
.printStackTrace( log
);
114 throw new StatusException( "Couldn't create document", e
);
117 // Second TextSection
119 oTS
= (XInterface
) oDocMSF
.createInstance
120 ("com.sun.star.text.TextSection");
121 XTextContent oTSC
= (XTextContent
)
122 UnoRuntime
.queryInterface(XTextContent
.class, oTS
);
123 oText
.insertTextContent(oCursor
, oTSC
, false);
126 e
.printStackTrace( log
);
127 throw new StatusException( "Couldn't create document", e
);
131 log
.println( "try to get a TextSection with the XTextSectionSupplier()" );
134 XTextSectionsSupplier oTSSupp
= (XTextSectionsSupplier
)
135 UnoRuntime
.queryInterface( XTextSectionsSupplier
.class,
137 oTSSuppName
= oTSSupp
.getTextSections();
140 System
.out
.println("Couldn't get Textsection " + e
);
146 log
.println( "creating a new environment for TextSections object" );
147 TestEnvironment tEnv
= new TestEnvironment( oObj
);
149 log
.println( "adding TextDocument as mod relation to environment" );
150 tEnv
.addObjRelation("TEXTDOC", xTextDoc
);
153 } // finish method getTestEnvironment
155 } // finish class SwXTextSection