Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / text / _XTextRangeCompare.java
blobda7f7c98c0baab669d8077205770ea1a6ed23add
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;
31 import lib.Status;
32 import lib.StatusException;
34 import com.sun.star.text.XText;
35 import com.sun.star.text.XTextCursor;
36 import com.sun.star.text.XTextDocument;
37 import com.sun.star.text.XTextRange;
38 import com.sun.star.text.XTextRangeCompare;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
42 /**
43 * Testing <code>com.sun.star.text.XTextRangeCompare</code>
44 * interface methods :
45 * <ul>
46 * <li><code> compareRegionStarts()</code></li>
47 * <li><code> compareRegionEnds()</code></li>
48 * </ul> <p>
49 * This test needs the following object relations :
50 * <ul>
51 * <li> <code>'TEXTDOC'</code> <b>optional</b>
52 * (must implement <code>XTextDocument</code>):
53 * can be used to obtain <code>Text</code> of the document from
54 * which cursors can be created.
55 * If the relation does not exist, the relation <code>TEXT</code>
56 * must be specified. </li>
57 * <li> <code>'TEXT'</code> <b>optional</b>
58 * (of type <code>XText</code>):
59 * used to create text cursor.
60 * If the relation does not exist, the relation <code>TEXTDOC</code>
61 * must be specified. </li>
62 * <ul> <p>
63 * Test is <b> NOT </b> multithread compilant. <p>
64 * @see com.sun.star.text.XTextRangeCompare
66 public class _XTextRangeCompare extends MultiMethodTest {
68 /**
69 * the test object
71 public XTextRangeCompare oObj = null;
74 String nameStr = null;
76 XTextRange oRange = null;
77 XTextCursor cursor1 = null;
78 XTextCursor cursor2 = null;
79 String startStr = null;
80 String endStr = null;
81 XText oText = null;
83 /**
84 * Retrieves <code>XText</code> interface from relation 'TEXTDOC'
85 * or from 'TEXT'.
86 * @throws StatusException If neither 'TEXTDOC' nore 'TEXT'
87 * relation exists.
89 public void before() {
90 nameStr = this.getClass().getName();
92 XInterface oIfc = (XInterface)tEnv.getObjRelation("TEXTDOC");
93 if (oIfc!=null) {
94 XTextDocument oTDoc = (XTextDocument)UnoRuntime.queryInterface(
95 XTextDocument.class, oIfc);
96 oText = oTDoc.getText();
98 XText aText = (XText) tEnv.getObjRelation("TEXT");
99 if (aText != null) {
100 oText = aText;
103 if (oText == null) {
104 throw new StatusException(Status.failed
105 ("Neither 'TEXTDOC' nore 'TEXT' relation not found")) ;
110 * One cursor is created and to its position a paragraph
111 * inserted, then the fist five characters was selected.
112 * A second cursor was created and the last 7 characteres
113 * was selected.<p>
115 * Has <b>OK</b> status if the compare returns 1, i.e.
116 * the second cursor end is before the first.
118 public void _compareRegionEnds() {
119 boolean bResult = false;
120 short n = 0;
121 log.println( "testing compareRegionEnds()" );
123 try{
124 cursor1 = oText.createTextCursor();
125 oText.insertString(cursor1, nameStr, false);
127 cursor1.gotoStart(false);
128 cursor1.goRight((short)5, true);
129 cursor2 = oText.createTextCursor();
130 cursor2.gotoEnd(false);
131 cursor2.goLeft((short)7, true);
133 log.println("hole text: '" + oText.getString() + "'");
134 log.println("cursor1: '"+cursor1.getString() + "'");
135 log.println("cursor2: '"+cursor2.getString() + "'");
136 log.println("check: oObj.compareRegionStarts(cursor1, cursor2)");
138 n = oObj.compareRegionEnds(cursor1, cursor2);
140 log.println( "Result (short) : " + n );
141 }catch(com.sun.star.lang.IllegalArgumentException e){
142 log.println( "Exception: " + e);
143 e.printStackTrace(log);
146 if (n == 1){bResult = true;}
147 tRes.tested( "compareRegionEnds()", bResult );
151 * One cursor is created and to its position a paragraph
152 * inserted, then the fist five characters was selected.
153 * A second cursor was created and the last 7 characters
154 * was selected.<p>
156 * Has <b>OK</b> status if the compare returns 1, i.e.
157 * the second cursor start is before the first.
159 public void _compareRegionStarts() {
160 boolean bResult = false;
161 short n = 0;
163 try{
164 cursor1 = oText.createTextCursor();
165 oText.insertString(cursor1, nameStr, false);
167 cursor1.gotoStart(false);
168 cursor1.goRight((short)5, true);
169 cursor2 = oText.createTextCursor();
170 cursor2.gotoEnd(false);
171 cursor2.goLeft((short)7, true);
173 log.println("hole text: '" + oText.getString() + "'");
174 log.println("cursor1: '"+cursor1.getString() + "'");
175 log.println("cursor2: '"+cursor2.getString() + "'");
176 log.println("check: oObj.compareRegionStarts(cursor1, cursor2)");
177 n = oObj.compareRegionStarts(cursor1, cursor2);
179 log.println( "Result (short) : " + n );
180 }catch(com.sun.star.lang.IllegalArgumentException e){
181 log.println( "Exception: " + e);
182 e.printStackTrace(log);
184 if (n == 1){bResult = true;}
185 tRes.tested( "compareRegionStarts()", bResult );