xref: /AOO41X/main/qadevOOo/tests/java/ifc/text/_XDocumentIndex.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 package ifc.text;
29 
30 import lib.MultiMethodTest;
31 
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;
39 
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>
47  *
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>
53  *
54  * Test is <b> NOT </b> multithread compilant. <p>
55  * @see com.sun.star.text.XDocumentIndex
56  */
57 public class _XDocumentIndex extends MultiMethodTest {
58 
59     public XDocumentIndex oObj = null;
60 
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'.
65      */
66     public void _getServiceName() {
67         String serv = oObj.getServiceName();
68         tRes.tested("getServiceName()",
69             serv.equals("com.sun.star.text.DocumentIndex"));
70     }
71 
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>
76      *
77      * Has <b> OK </b> status if index content is changed and
78      * new index contains index mark inserted. <p>
79      */
80      public void _update() {
81         boolean bOK = true;
82 
83         try {
84             XTextDocument xTextDoc = (XTextDocument)
85                 tEnv.getObjRelation("TextDoc");
86             XText xText = xTextDoc.getText();
87             XTextRange xTR = xText.getEnd();
88             xTR.setString("IndexMark");
89 
90             XMultiServiceFactory xDocMSF = (XMultiServiceFactory)
91                 UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
92 
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 ;
102         }
103 
104         String contentBefore = oObj.getAnchor().getString();
105         log.println("Content before: '" + contentBefore + "'");
106 
107         oObj.update();
108 
109         try {
110             Thread.sleep(1000);
111         }
112         catch (InterruptedException ex) {
113         }
114 
115 
116         String contentAfter = oObj.getAnchor().getString();
117         log.println("Content after: '" + contentAfter + "'");
118 
119         bOK &= !contentAfter.equals(contentBefore);
120         bOK &= contentAfter.indexOf("IndexMark") > -1;
121 
122         tRes.tested("update()",bOK);
123     }
124 
125 
126 
127 }  // finish class _XDocumentIndex
128 
129 
130