Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextSections.java
blob4a136e168d86295e5da9ac4421e4b0d6b59b086d
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 @Override
49 protected void initialize( TestParameters tParam, PrintWriter log ) {
50 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
52 try {
53 log.println( "creating a textdocument" );
54 xTextDoc = SOF.createTextDoc( null );
55 } catch ( com.sun.star.uno.Exception e ) {
56 // Some exception occurs.FAILED
57 e.printStackTrace( log );
58 throw new StatusException( "Couldn't create document", e );
62 @Override
63 protected void cleanup( TestParameters tParam, PrintWriter log ) {
64 log.println( " disposing xTextDoc " );
65 util.DesktopTools.closeDoc(xTextDoc);
68 /**
69 * creating a Testenvironment for the interfaces to be tested
71 @Override
72 public synchronized TestEnvironment createTestEnvironment
73 (TestParameters Param, PrintWriter log ) throws StatusException {
75 XInterface oObj = null;
76 XInterface oTS = null;
77 XNameAccess oTSSuppName = null;
79 XText oText = null;
81 // creation of testobject here
82 // first we write what we are intend to do to log file
83 log.println( "creating a test environment" );
86 oText = xTextDoc.getText();
87 XTextCursor oCursor = oText.createTextCursor();
90 log.println( "inserting TextSections" );
92 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
94 // First TextSection
95 try {
96 oTS = (XInterface) oDocMSF.createInstance
97 ("com.sun.star.text.TextSection");
98 XTextContent oTSC = UnoRuntime.queryInterface(XTextContent.class, oTS);
99 oText.insertTextContent(oCursor, oTSC, false);
101 catch(Exception e){
102 e.printStackTrace( log );
103 throw new StatusException( "Couldn't create document", e );
106 // Second TextSection
107 try {
108 oTS = (XInterface) oDocMSF.createInstance
109 ("com.sun.star.text.TextSection");
110 XTextContent oTSC = UnoRuntime.queryInterface(XTextContent.class, oTS);
111 oText.insertTextContent(oCursor, oTSC, false);
113 catch(Exception e){
114 e.printStackTrace( log );
115 throw new StatusException( "Couldn't create document", e );
119 log.println( "try to get a TextSection with the XTextSectionSupplier()" );
121 try{
122 XTextSectionsSupplier oTSSupp = UnoRuntime.queryInterface( XTextSectionsSupplier.class,
123 xTextDoc );
124 oTSSuppName = oTSSupp.getTextSections();
126 catch(Exception e){
127 System.out.println("Couldn't get Textsection " + e);
131 oObj = oTSSuppName;
133 log.println( "creating a new environment for TextSections object" );
134 TestEnvironment tEnv = new TestEnvironment( oObj );
136 log.println( "adding TextDocument as mod relation to environment" );
137 tEnv.addObjRelation("TEXTDOC", xTextDoc);
139 return tEnv;
140 } // finish method getTestEnvironment
142 } // finish class SwXTextSection