merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / text / _XTextRangeCompare.java
blob9d025f8888c74f7f80b056ff1bb963a72cd9df35
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XTextRangeCompare.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.text;
33 import lib.MultiMethodTest;
34 import lib.Status;
35 import lib.StatusException;
37 import com.sun.star.text.XText;
38 import com.sun.star.text.XTextCursor;
39 import com.sun.star.text.XTextDocument;
40 import com.sun.star.text.XTextRange;
41 import com.sun.star.text.XTextRangeCompare;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
45 /**
46 * Testing <code>com.sun.star.text.XTextRangeCompare</code>
47 * interface methods :
48 * <ul>
49 * <li><code> compareRegionStarts()</code></li>
50 * <li><code> compareRegionEnds()</code></li>
51 * </ul> <p>
52 * This test needs the following object relations :
53 * <ul>
54 * <li> <code>'TEXTDOC'</code> <b>optional</b>
55 * (must implement <code>XTextDocument</code>):
56 * can be used to obtain <code>Text</code> of the document from
57 * which cursors can be created.
58 * If the relation does not exist, the relation <code>TEXT</code>
59 * must be specified. </li>
60 * <li> <code>'TEXT'</code> <b>optional</b>
61 * (of type <code>XText</code>):
62 * used to create text cursor.
63 * If the relation does not exist, the relation <code>TEXTDOC</code>
64 * must be specified. </li>
65 * <ul> <p>
66 * Test is <b> NOT </b> multithread compilant. <p>
67 * @see com.sun.star.text.XTextRangeCompare
69 public class _XTextRangeCompare extends MultiMethodTest {
71 /**
72 * the test object
74 public XTextRangeCompare oObj = null;
77 String nameStr = null;
79 XTextRange oRange = null;
80 XTextCursor cursor1 = null;
81 XTextCursor cursor2 = null;
82 String startStr = null;
83 String endStr = null;
84 XText oText = null;
86 /**
87 * Retrieves <code>XText</code> interface from relation 'TEXTDOC'
88 * or from 'TEXT'.
89 * @throws StatusException If neither 'TEXTDOC' nore 'TEXT'
90 * relation exists.
92 public void before() {
93 nameStr = this.getClass().getName();
95 XInterface oIfc = (XInterface)tEnv.getObjRelation("TEXTDOC");
96 if (oIfc!=null) {
97 XTextDocument oTDoc = (XTextDocument)UnoRuntime.queryInterface(
98 XTextDocument.class, oIfc);
99 oText = oTDoc.getText();
101 XText aText = (XText) tEnv.getObjRelation("TEXT");
102 if (aText != null) {
103 oText = aText;
106 if (oText == null) {
107 throw new StatusException(Status.failed
108 ("Neither 'TEXTDOC' nore 'TEXT' relation not found")) ;
113 * One cursor is created and to its position a paragraph
114 * inserted, then the fist five characters was selected.
115 * A second cursor was created and the last 7 characteres
116 * was selected.<p>
118 * Has <b>OK</b> status if the compare returns 1, i.e.
119 * the second cursor end is before the first.
121 public void _compareRegionEnds() {
122 boolean bResult = false;
123 short n = 0;
124 log.println( "testing compareRegionEnds()" );
126 try{
127 cursor1 = oText.createTextCursor();
128 oText.insertString(cursor1, nameStr, false);
130 cursor1.gotoStart(false);
131 cursor1.goRight((short)5, true);
132 cursor2 = oText.createTextCursor();
133 cursor2.gotoEnd(false);
134 cursor2.goLeft((short)7, true);
136 log.println("hole text: '" + oText.getString() + "'");
137 log.println("cursor1: '"+cursor1.getString() + "'");
138 log.println("cursor2: '"+cursor2.getString() + "'");
139 log.println("check: oObj.compareRegionStarts(cursor1, cursor2)");
141 n = oObj.compareRegionEnds(cursor1, cursor2);
143 log.println( "Result (short) : " + n );
144 }catch(com.sun.star.lang.IllegalArgumentException e){
145 log.println( "Exception: " + e);
146 e.printStackTrace(log);
149 if (n == 1){bResult = true;}
150 tRes.tested( "compareRegionEnds()", bResult );
154 * One cursor is created and to its position a paragraph
155 * inserted, then the fist five characters was selected.
156 * A second cursor was created and the last 7 characters
157 * was selected.<p>
159 * Has <b>OK</b> status if the compare returns 1, i.e.
160 * the second cursor start is before the first.
162 public void _compareRegionStarts() {
163 boolean bResult = false;
164 short n = 0;
166 try{
167 cursor1 = oText.createTextCursor();
168 oText.insertString(cursor1, nameStr, false);
170 cursor1.gotoStart(false);
171 cursor1.goRight((short)5, true);
172 cursor2 = oText.createTextCursor();
173 cursor2.gotoEnd(false);
174 cursor2.goLeft((short)7, true);
176 log.println("hole text: '" + oText.getString() + "'");
177 log.println("cursor1: '"+cursor1.getString() + "'");
178 log.println("cursor2: '"+cursor2.getString() + "'");
179 log.println("check: oObj.compareRegionStarts(cursor1, cursor2)");
180 n = oObj.compareRegionStarts(cursor1, cursor2);
182 log.println( "Result (short) : " + n );
183 }catch(com.sun.star.lang.IllegalArgumentException e){
184 log.println( "Exception: " + e);
185 e.printStackTrace(log);
187 if (n == 1){bResult = true;}
188 tRes.tested( "compareRegionStarts()", bResult );