1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XTextCursor.java,v $
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 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import com
.sun
.star
.text
.XTextCursor
;
39 * Testing <code>com.sun.star.text.XTextCursor</code>
42 * <li><code> collapseToStart()</code></li>
43 * <li><code> collapseToEnd()</code></li>
44 * <li><code> isCollapsed()</code></li>
45 * <li><code> goLeft()</code></li>
46 * <li><code> goRight()</code></li>
47 * <li><code> gotoStart()</code></li>
48 * <li><code> gotoEnd()</code></li>
49 * <li><code> gotoRange()</code></li>
52 * During this test the component text is changed,
53 * that's why it must be stored before methods' tests,
54 * and restored after. <p>
56 * Test is <b> NOT </b> multithread compilant. <p>
57 * @see com.sun.star.text.XTextCursor
59 public class _XTextCursor
extends MultiMethodTest
{
61 public XTextCursor oObj
= null; // oObj filled by MultiMethodTest
62 String oldText
= null ;
65 * Stores component's text.
67 public void before() {
68 oObj
.gotoStart(false);
70 oldText
= oObj
.getString() ;
74 * First some text is set (for component to has at least some
75 * text), cursor is expanded to the whole text (to be not collapsed),
76 * the <code>collapseToEnd</code> is called. Then current cursor
77 * text is examined. <p>
79 * Has <b>OK</b> status if the current cursor text is an
82 public void _collapseToEnd(){
85 oObj
.setString("XTextCursor");
86 oObj
.gotoStart(false);
89 bCol
= oObj
.getString().equals("");
90 tRes
.tested("collapseToEnd()", bCol
);
94 * First some text is set (for component to has at least some
95 * text), cursor is expanded to the whole text (to be not collapsed),
96 * the <code>collapseToStart</code> is called. Then current cursor
97 * text is examined. <p>
99 * Has <b>OK</b> status if the current cursor text is an
102 public void _collapseToStart(){
103 boolean bCol
= false;
104 oObj
.setString("XTextCursor");
105 oObj
.gotoStart(false);
108 oObj
.collapseToStart();
109 bCol
= oObj
.getString().equals("");
110 tRes
.tested("collapseToStart()", bCol
);
114 * First the cursor is moved to the end of text (to have a space
115 * for left cursor moving, and moves the cursor left by a number
118 * Has <b>OK</b> status if the method returns <code>true</code>,
119 * and the current cursor string has the same length as number
120 * of characters the cursor was moved by.
122 public void _goLeft(){
123 boolean bLeft
= false;
127 bLeft
= oObj
.goLeft(n
, true);
128 String gStr
= oObj
.getString() ;
129 log
.println("'" + gStr
+ "'") ;
130 bLeft
&= gStr
.length() == n
;
132 tRes
.tested("goLeft()", bLeft
);
136 * First the cursor is moved to the start of text (to have a space
137 * for right cursor moving, and moves the cursor right by a number
140 * Has <b>OK</b> status if the method returns <code>true</code>,
141 * and the current cursor string has the same length as number
142 * of characters the cursor was moved by.
144 public void _goRight(){
145 boolean bRight
= false;
148 oObj
.gotoStart(false);
149 bRight
= oObj
.goRight(n
, true);
151 String gStr
= oObj
.getString() ;
152 log
.println("'" + gStr
+ "'") ;
153 bRight
&= gStr
.length() == n
;
155 tRes
.tested("goRight()", bRight
);
159 * Test calls the method. <p>
160 * Has <b> OK </b> status if the method <code>goRight()</code>
161 * returns <code>false</code> (cursor can't move to the right).
163 public void _gotoEnd(){
164 boolean bEnd
= false;
168 bEnd
= !oObj
.goRight(n
, false) ;
170 tRes
.tested("gotoEnd()", bEnd
);
174 * First the whole text is set to a string, and cursor
175 * is moved to the range situated at the start of the
178 * Has <b>OK</b> status if some characters to the right
179 * of the current cursor position are the beginning of
182 public void _gotoRange(){
183 boolean bRange
= false;
185 oObj
.gotoStart(false);
187 oObj
.setString("XTextCursor,XTextCursor");
188 oObj
.gotoRange(oObj
.getStart(),false);
189 oObj
.goRight((short) 5, true);
190 bRange
= oObj
.getString().equals("XText");
192 if (!bRange
) log
.println("getString() returned '" +
193 oObj
.getString() + "'") ;
195 tRes
.tested("gotoRange()", bRange
);
199 * Test calls the method. <p>
200 * Has <b> OK </b> status if the method <code>goLeft()</code>
201 * returns <code>false</code> (cursor can't move to the left).
203 public void _gotoStart(){
204 boolean bStart
= false;
207 oObj
.gotoStart(false);
208 bStart
= !oObj
.goLeft(n
, false) ;
210 tRes
.tested("gotoStart()", bStart
);
214 * First the cusor is moved to start without expanding
215 * (must be collapsed), and then it's expanded to the
216 * whole text (must not be collapsed). <p>
218 * Has <b>OK</b> status if in the first case method
219 * <code>isCollapsed</code> returns <code>true</code>,
220 * and in the second <code>false</code>
222 public void _isCollapsed(){
223 boolean bCol
= false;
225 oObj
.gotoStart(false);
226 bCol
= oObj
.isCollapsed();
229 bCol
&= !oObj
.isCollapsed() ;
231 tRes
.tested("isCollapsed()", bCol
);
235 * Restores the text of the component to the
236 * state it was before this interafce test.
238 public void after() {
239 oObj
.gotoStart(false);
241 oObj
.setString(oldText
) ;
244 } // finish class _XTextCursor