bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXBookmarks.java
blob5ea99e60870960209942d46e759ed93cb704c2b0
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.XBookmarksSupplier;
32 import com.sun.star.text.XTextContent;
33 import com.sun.star.text.XTextDocument;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
37 /**
38 * Test for object which is represented by service
39 * <code>com.sun.star.text.Bookmarks</code>. <p>
40 * Object implements the following interfaces :
41 * <ul>
42 * <li> <code>com::sun::star::container::XNameAccess</code></li>
43 * <li> <code>com::sun::star::container::XElementAccess</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.XNameAccess
48 * @see com.sun.star.container.XElementAccess
49 * @see ifc.container._XNameAccess
50 * @see ifc.container._XElementAccess
52 public class SwXBookmarks extends TestCase {
53 XTextDocument xTextDoc;
54 SOfficeFactory SOF;
56 /**
57 * Creates text document.
59 protected void initialize( TestParameters tParam, PrintWriter log ) {
60 SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
61 try {
62 log.println( "creating a textdocument" );
63 xTextDoc = SOF.createTextDoc( null );
64 } catch ( com.sun.star.uno.Exception e ) {
65 e.printStackTrace( log );
66 throw new StatusException( "Couldn't create document", e );
70 /**
71 * Disposes text document.
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. Method
80 * creates two bookmarks and inserts them to the text document. Then bookmarks
81 * are gotten from text document using <code>XBookmarksSupplier</code>
82 * interface.
84 public synchronized TestEnvironment createTestEnvironment(
85 TestParameters Param, PrintWriter log ) throws StatusException {
86 XInterface oObj = null;
88 log.println( "creating a test environment" );
89 try {
90 oObj = SOfficeFactory.createBookmark( xTextDoc );
91 SOfficeFactory.insertTextContent( xTextDoc, (XTextContent) oObj );
92 oObj = SOfficeFactory.createBookmark( xTextDoc );
93 SOfficeFactory.insertTextContent( xTextDoc, (XTextContent) oObj );
94 } catch( com.sun.star.uno.Exception e ) {
95 e.printStackTrace( log );
96 throw new StatusException( "Couldn't create Bookmark", e );
99 XBookmarksSupplier oBSupp = UnoRuntime.queryInterface(XBookmarksSupplier.class, xTextDoc);
100 XNameAccess oBookNA = oBSupp.getBookmarks();
101 oObj = oBookNA;
102 log.println( "creating a new environment for Bookmarks object" );
104 TestEnvironment tEnv = new TestEnvironment( oObj );
105 return tEnv;
106 } // finish method getTestEnvironment
108 } // finish class SwXBookmarks