bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextSections.java
blob7786e19243c6184a0ab627f36c69533d48b2c1f3
1 /*
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 .
19 package mod._sw;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.container.XNameAccess;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.text.XText;
32 import com.sun.star.text.XTextContent;
33 import com.sun.star.text.XTextCursor;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.text.XTextSectionsSupplier;
36 import com.sun.star.uno.UnoRuntime;
37 import com.sun.star.uno.XInterface;
39 /**
41 * initial description
42 * @see com.sun.star.text.XText
45 public class SwXTextSections extends TestCase {
46 XTextDocument xTextDoc;
48 protected void initialize( TestParameters tParam, PrintWriter log ) {
49 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
51 try {
52 log.println( "creating a textdocument" );
53 xTextDoc = SOF.createTextDoc( null );
54 } catch ( com.sun.star.uno.Exception e ) {
55 // Some exception occurs.FAILED
56 e.printStackTrace( log );
57 throw new StatusException( "Couldn't create document", e );
61 protected void cleanup( TestParameters tParam, PrintWriter log ) {
62 log.println( " disposing xTextDoc " );
63 util.DesktopTools.closeDoc(xTextDoc);
66 /**
67 * creating a Testenvironment for the interfaces to be tested
69 public synchronized TestEnvironment createTestEnvironment
70 (TestParameters Param, PrintWriter log ) throws StatusException {
72 XInterface oObj = null;
73 XInterface oTS = null;
74 XNameAccess oTSSuppName = null;
76 XText oText = null;
78 // creation of testobject here
79 // first we write what we are intend to do to log file
80 log.println( "creating a test environment" );
83 oText = xTextDoc.getText();
84 XTextCursor oCursor = oText.createTextCursor();
87 log.println( "inserting TextSections" );
89 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
91 // First TextSection
92 try {
93 oTS = (XInterface) oDocMSF.createInstance
94 ("com.sun.star.text.TextSection");
95 XTextContent oTSC = UnoRuntime.queryInterface(XTextContent.class, oTS);
96 oText.insertTextContent(oCursor, oTSC, false);
98 catch(Exception e){
99 e.printStackTrace( log );
100 throw new StatusException( "Couldn't create document", e );
103 // Second TextSection
104 try {
105 oTS = (XInterface) oDocMSF.createInstance
106 ("com.sun.star.text.TextSection");
107 XTextContent oTSC = UnoRuntime.queryInterface(XTextContent.class, oTS);
108 oText.insertTextContent(oCursor, oTSC, false);
110 catch(Exception e){
111 e.printStackTrace( log );
112 throw new StatusException( "Couldn't create document", e );
116 log.println( "try to get a TextSection with the XTextSectionSupplier()" );
118 try{
119 XTextSectionsSupplier oTSSupp = UnoRuntime.queryInterface( XTextSectionsSupplier.class,
120 xTextDoc );
121 oTSSuppName = oTSSupp.getTextSections();
123 catch(Exception e){
124 System.out.println("Couldn't get Textsection " + e);
128 oObj = oTSSuppName;
130 log.println( "creating a new environment for TextSections object" );
131 TestEnvironment tEnv = new TestEnvironment( oObj );
133 log.println( "adding TextDocument as mod relation to environment" );
134 tEnv.addObjRelation("TEXTDOC", xTextDoc);
136 return tEnv;
137 } // finish method getTestEnvironment
139 } // finish class SwXTextSection