merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / SwXTextSections.java
blobaeadc1f43db1ce638c97def6fb2c56a681a1b18e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXTextSections.java,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
31 package mod._sw;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
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;
51 /**
53 * initial description
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() );
63 try {
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);
78 /**
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;
88 XText oText = 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);
104 // First TextSection
105 try {
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);
112 catch(Exception e){
113 e.printStackTrace( log );
114 throw new StatusException( "Couldn't create document", e );
117 // Second TextSection
118 try {
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);
125 catch(Exception e){
126 e.printStackTrace( log );
127 throw new StatusException( "Couldn't create document", e );
131 log.println( "try to get a TextSection with the XTextSectionSupplier()" );
133 try{
134 XTextSectionsSupplier oTSSupp = (XTextSectionsSupplier)
135 UnoRuntime.queryInterface( XTextSectionsSupplier.class,
136 xTextDoc );
137 oTSSuppName = oTSSupp.getTextSections();
139 catch(Exception e){
140 System.out.println("Couldn't get Textsection " + e);
144 oObj = oTSSuppName;
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);
152 return tEnv;
153 } // finish method getTestEnvironment
155 } // finish class SwXTextSection