bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextRanges.java
blob4cc8e8d71bac19f611cbc1f18e517014b55760ab
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.lang.XMultiServiceFactory;
30 import com.sun.star.text.ControlCharacter;
31 import com.sun.star.text.XText;
32 import com.sun.star.text.XTextCursor;
33 import com.sun.star.text.XTextDocument;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
36 import com.sun.star.util.XSearchDescriptor;
37 import com.sun.star.util.XSearchable;
39 /**
41 * initial description
42 * @see com.sun.star.container.XElementAccess
43 * @see com.sun.star.container.XIndexAccess
46 public class SwXTextRanges extends TestCase {
47 XTextDocument xTextDoc;
49 protected void initialize( TestParameters tParam, PrintWriter log ) {
50 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)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 protected void cleanup( TestParameters tParam, PrintWriter log ) {
63 log.println( " disposing xTextDoc " );
64 util.DesktopTools.closeDoc(xTextDoc);
67 /**
68 * creating a Testenvironment for the interfaces to be tested
70 * @param tParam class which contains additional test parameters
71 * @param log class to log the test state and result
73 * @return Status class
75 * @see TestParameters
76 * @see PrintWriter
78 public synchronized TestEnvironment createTestEnvironment
79 (TestParameters tParam, PrintWriter log) {
81 XInterface oObj = null;
83 // creation of testobject here
84 // first we write what we are intend to do to log file
85 log.println( "creating a test environment" );
87 // create testobject here
88 XText oText = xTextDoc.getText();
89 XTextCursor oCursor = oText.createTextCursor();
91 for (int j =0; j < 5; j++){
92 try{
93 oText.insertString( oCursor,
94 "SwXTextRanges...SwXTextRanges...SwXTextRanges", false);
95 oText.insertControlCharacter( oCursor,
96 ControlCharacter.PARAGRAPH_BREAK, false );
98 catch( Exception e ){
99 log.println( "EXCEPTION: " + e);
103 XSearchable oSearch = UnoRuntime.queryInterface
104 (XSearchable.class, xTextDoc);
105 XSearchDescriptor xSDesc = oSearch.createSearchDescriptor();
106 xSDesc.setSearchString("SwXTextRanges");
108 oObj = oSearch.findAll(xSDesc);
110 log.println( "creating a new environment for textrange object" );
111 TestEnvironment tEnv = new TestEnvironment( oObj );
113 log.println( "adding TextDocument as mod relation to environment" );
114 tEnv.addObjRelation("TEXTDOC", xTextDoc);
116 return tEnv;
117 } // finish method getTestEnvironment
119 } // finish class SwXTextRanges