bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXBookmark.java
blob13543e806a0b239ec4667e153765ad4eb01a8752
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.XTextContent;
31 import com.sun.star.text.XTextDocument;
32 import com.sun.star.uno.UnoRuntime;
33 import com.sun.star.uno.XInterface;
35 /**
36 * Test for object which is represented by service
37 * <code>com.sun.star.text.Bookmark</code>. <p>
38 * Object implements the following interfaces :
39 * <ul>
40 * <li> <code>com::sun::star::container::XNamed</code></li>
41 * <li> <code>com::sun::star::lang::XComponent</code></li>
42 * <li> <code>com::sun::star::text::XTextContent</code></li>
43 * <li> <code>com::sun::star::text::TextContent</code></li>
44 * </ul> <p>
45 * This object test <b> is NOT </b> designed to be run in several
46 * threads concurently.
47 * @see com.sun.star.container.XNamed
48 * @see com.sun.star.lang.XComponent
49 * @see com.sun.star.text.XTextContent
50 * @see com.sun.star.text.TextContent
51 * @see ifc.container._XNamed
52 * @see ifc.lang._XComponent
53 * @see ifc.text._XTextContent
54 * @see ifc.text._TextContent
56 public class SwXBookmark extends TestCase {
57 XTextDocument xTextDoc;
58 SOfficeFactory SOF;
60 /**
61 * Creates text document.
63 protected void initialize( TestParameters tParam, PrintWriter log ) {
64 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
65 try {
66 log.println( "creating a textdocument" );
67 xTextDoc = SOF.createTextDoc( null );
68 } catch ( com.sun.star.uno.Exception e ) {
69 e.printStackTrace( log );
70 throw new StatusException( "Couldn't create document", e );
74 /**
75 * Disposes text document.
77 protected void cleanup( TestParameters tParam, PrintWriter log ) {
78 log.println( " disposing xTextDoc " );
79 util.DesktopTools.closeDoc(xTextDoc);
82 /**
83 * Creating a Testenvironment for the interfaces to be tested. After creating
84 * a bookmark, it is inserted to the text document.
86 protected synchronized TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
87 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
88 XInterface oObj = null;
89 Object instance = null;
90 log.println( "creating a test environment" );
91 try {
92 oObj = SOfficeFactory.createBookmark( xTextDoc );
93 SOfficeFactory.insertTextContent( xTextDoc, (XTextContent) oObj );
94 instance = SOF.createInstance(xTextDoc,"com.sun.star.text.Bookmark");
95 } catch ( com.sun.star.uno.Exception e ) {
96 e.printStackTrace( log );
97 throw new StatusException( "Couldn't create Bookmark", e );
99 log.println( "creating a new environment for bodytext object" );
100 TestEnvironment tEnv = new TestEnvironment( oObj );
102 util.dbg.printInterfaces((XInterface) instance);
104 tEnv.addObjRelation("CONTENT", UnoRuntime.queryInterface(XTextContent.class,instance));
105 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
106 return tEnv;
107 } // finish method getTestEnvironment
110 } // finish class SwXBookmark