Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / text / _XDocumentIndex.java
blob704750511e567747b815e7bdd317c4240b04b017
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package ifc.text;
30 import lib.MultiMethodTest;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.text.XDocumentIndex;
34 import com.sun.star.text.XText;
35 import com.sun.star.text.XTextContent;
36 import com.sun.star.text.XTextDocument;
37 import com.sun.star.text.XTextRange;
38 import com.sun.star.uno.UnoRuntime;
40 /**
41 * Testing <code>com.sun.star.text.XDocumentIndex</code>
42 * interface methods :
43 * <ul>
44 * <li><code> getServiceName()</code></li>
45 * <li><code> update()</code></li>
46 * </ul> <p>
48 * This test needs the following object relations :
49 * <ul>
50 * <li> <code>'TextDoc'</code> (of type <code>XTextDocument</code>):
51 * the text document for creating and inserting index mark.</li>
52 * <ul> <p>
54 * Test is <b> NOT </b> multithread compilant. <p>
55 * @see com.sun.star.text.XDocumentIndex
57 public class _XDocumentIndex extends MultiMethodTest {
59 public XDocumentIndex oObj = null;
61 /**
62 * Test calls the method. <p>
63 * Has <b> OK </b> status if the retruned service name
64 * is equal to 'com.sun.star.text.DocumentIndex'.
66 public void _getServiceName() {
67 String serv = oObj.getServiceName();
68 tRes.tested("getServiceName()",
69 serv.equals("com.sun.star.text.DocumentIndex"));
72 /**
73 * Gets the document from relation and insert a new index mark.
74 * Then it stores the text content of document index before
75 * update and after.<p>
77 * Has <b> OK </b> status if index content is changed and
78 * new index contains index mark inserted. <p>
80 public void _update() {
81 boolean bOK = true;
83 try {
84 XTextDocument xTextDoc = (XTextDocument)
85 tEnv.getObjRelation("TextDoc");
86 XText xText = xTextDoc.getText();
87 XTextRange xTR = xText.getEnd();
88 xTR.setString("IndexMark");
90 XMultiServiceFactory xDocMSF = (XMultiServiceFactory)
91 UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
93 Object idxMark = xDocMSF.createInstance
94 ("com.sun.star.text.DocumentIndexMark");
95 XTextContent xTC = (XTextContent) UnoRuntime.queryInterface
96 (XTextContent.class, idxMark);
97 xText.insertTextContent(xTR, xTC, true);
98 } catch (com.sun.star.uno.Exception e) {
99 log.println("Couldn't insert index mark.");
100 e.printStackTrace(log);
101 bOK = false ;
104 String contentBefore = oObj.getAnchor().getString();
105 log.println("Content before: '" + contentBefore + "'");
107 oObj.update();
109 try {
110 Thread.sleep(1000);
112 catch (InterruptedException ex) {
116 String contentAfter = oObj.getAnchor().getString();
117 log.println("Content after: '" + contentAfter + "'");
119 bOK &= !contentAfter.equals(contentBefore);
120 bOK &= contentAfter.indexOf("IndexMark") > -1;
122 tRes.tested("update()",bOK);
127 } // finish class _XDocumentIndex